]> SALOME platform Git repositories - tools/eficas.git/blob - Aster/Cata/cataSTA74/Macro/impr_fonction_ops.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Aster / Cata / cataSTA74 / Macro / impr_fonction_ops.py
1 #@ MODIF impr_fonction_ops Macro  DATE 30/11/2004   AUTEUR MCOURTOI M.COURTOIS 
2 # -*- coding: iso-8859-1 -*-
3 #            CONFIGURATION MANAGEMENT OF EDF VERSION
4 # ======================================================================
5 # COPYRIGHT (C) 1991 - 2004  EDF R&D                  WWW.CODE-ASTER.ORG
6 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY  
7 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY  
8 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR     
9 # (AT YOUR OPTION) ANY LATER VERSION.                                                  
10 #                                                                       
11 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT   
12 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF            
13 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU      
14 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.                              
15 #                                                                       
16 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE     
17 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,         
18 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.        
19 # ======================================================================
20
21 # RESPONSABLE MCOURTOI M.COURTOIS
22
23 import os.path
24
25 # ------------------------------------------------------------------------------
26 def impr_fonction_ops(self, FORMAT, COURBE, INFO, **args):
27    """
28    Macro IMPR_FONCTION permettant d'imprimer dans un fichier des fonctions,
29    colonnes de table...
30    Erreurs<S> dans IMPR_FONCTION pour ne pas perdre la base.
31    """
32    macro='IMPR_FONCTION'
33    import aster
34    from Accas import _F
35    from Utilitai import Graph
36    from Utilitai.Utmess import UTMESS
37    ier=0
38    # La macro compte pour 1 dans la numerotation des commandes
39    self.set_icmd(1)
40
41    # On importe les definitions des commandes a utiliser dans la macro
42    # Le nom de la variable doit etre obligatoirement le nom de la commande
43    CALC_FONC_INTERP = self.get_cmd('CALC_FONC_INTERP')
44    DEFI_LIST_REEL   = self.get_cmd('DEFI_LIST_REEL')
45    DEFI_FICHIER     = self.get_cmd('DEFI_FICHIER')
46    DETRUIRE         = self.get_cmd('DETRUIRE')
47
48    #----------------------------------------------
49    # 0. Traitement des arguments, initialisations
50    # unité logique des fichiers réservés
51    ul_reserve=(8,)
52
53    # 0.1. Fichier
54    nomfich=None
55    if args['UNITE'] and args['UNITE']<>6:
56       nomfich='fort.'+str(args['UNITE'])
57       if INFO==2:
58          print ' Nom du fichier :',nomfich
59    if nomfich and os.path.exists(nomfich):
60       if FORMAT=='XMGRACE':
61          niv='A'
62       else:
63          niv='I'
64       UTMESS(niv,macro,'Le fichier '+nomfich+' existe déjà, on écrit ' \
65              'à la suite.')
66
67    # 0.2. Récupération des valeurs sous COURBE
68    unparmi=('FONCTION','LIST_RESU','FONC_X','ABSCISSE')
69
70    # i0 : indice du mot-clé facteur qui contient LIST_PARA, sinon i0=0
71    i0=0
72    Courbe=[]
73    iocc=-1
74    for Ci in COURBE:
75       iocc+=1
76       dC = Ci.cree_dict_valeurs(Ci.mc_liste)
77       if dC.has_key('LIST_PARA') and i0==0: i0=iocc
78       for mc in dC.keys():
79          if dC[mc]==None: del dC[mc]
80       Courbe.append(dC)
81    if INFO==2:
82       print ' Nombre de fonctions à analyser : ',len(Courbe)
83
84    # 0.3. Devra-t-on interpoler globalement ?
85    #      Dans ce cas, linter__ est le LIST_PARA
86    #      ou, à défaut, les abscisses de la première courbe
87    interp=False
88    if FORMAT=='TABLEAU':
89       interp=True
90       dCi=Courbe[i0]
91       if dCi.has_key('LIST_PARA'):
92          linter__=dCi['LIST_PARA']
93       else:
94          obj=None
95          for typi in unparmi:
96             if dCi.has_key(typi):
97                obj=dCi[typi]
98                typ=obj.__class__.__name__
99                break
100          if obj==None:
101             UTMESS('S',macro,'incohérence entre le catalogue et la macro.')
102          if typi=='FONCTION':
103             if typ=='nappe_sdaster':
104                lpar,lval=obj.Valeurs()
105                linterp=lval[0][0]
106             else:
107                linterp=obj.Valeurs()[0]
108          elif typi=='FONC_X':
109             lbid,linterp=obj.Valeurs()
110          elif typi=='ABSCISSE':
111             linterp=obj
112          linter__=DEFI_LIST_REEL(VALE=linterp)
113       if INFO==2:
114          print ' Interpolation globale sur la liste :\n',linter__.Valeurs()
115
116
117    #----------------------------------------------
118    # 1. Récupération des valeurs des N courbes sous forme
119    #    d'une liste de N listes
120    #----------------------------------------------
121    graph=Graph.Graph()
122    iocc=-1
123    for dCi in Courbe:
124       iocc+=1
125
126       # 1.1. Type d'objet à traiter
127       obj=None
128       for typi in unparmi:
129          if dCi.has_key(typi):
130             obj=dCi[typi]
131             typ=obj.__class__.__name__
132             break
133       if not dCi.has_key('LEGENDE') and hasattr(obj,'get_name'):
134             dCi['LEGENDE']=obj.get_name()
135       if obj==None:
136          UTMESS('S',macro,'incohérence entre le catalogue et la macro.')
137
138       # 1.2. Extraction des valeurs
139
140       # 1.2.1. Mot-clé FONCTION
141       if   typi=='FONCTION':
142          if typ=='nappe_sdaster':
143             lpar,lval=obj.Valeurs()
144             dico,ldicf=obj.Parametres()
145             for i in range(len(lpar)):
146                p=lpar[i]
147                lx=lval[i][0]
148                ly=lval[i][1]
149                # sur quelle liste interpoler chaque fonction
150                if i==0:
151                   if interp:
152                      li__=linter__
153                   elif dCi.has_key('LIST_PARA'):
154                      li__=dCi['LIST_PARA']
155                   else:
156                      li__=DEFI_LIST_REEL(VALE=lx)
157                # compléter les paramètres d'interpolation
158                dic=dico.copy()
159                dic.update(ldicf[i])
160                
161                if (interp or dCi.has_key('LIST_PARA')) and i>0:
162                   ftmp__=CALC_FONC_INTERP(
163                      FONCTION=obj,
164                      VALE_PARA=p,
165                      LIST_PARA_FONC=li__,
166                      **dic
167                   )
168                   pv,lv2=ftmp__.Valeurs()
169                   lx=lv2[0][0]
170                   ly=lv2[0][1]
171                # on stocke les données dans le Graph
172                dicC={
173                   'Val' : [lx,ly],
174                   'Lab' : [dic['NOM_PARA_FONC'],dic['NOM_RESU']]
175                }
176                Graph.AjoutParaCourbe(dicC, args=dCi)
177                graph.AjoutCourbe(**dicC)
178          else:
179             ftmp__=obj
180             dpar=ftmp__.Parametres()
181             if interp:
182                ftmp__=CALC_FONC_INTERP(
183                   FONCTION=obj,
184                   LIST_PARA=linter__,
185                   **dpar
186                )
187             elif dCi.has_key('LIST_PARA'):
188                ftmp__=CALC_FONC_INTERP(
189                   FONCTION=obj,
190                   LIST_PARA=dCi['LIST_PARA'],
191                   **dpar
192                )
193             lval=list(ftmp__.Valeurs())
194             lx=lval[0]
195             lr=lval[1]
196             if typ=='fonction_c' and dCi.has_key('PARTIE'):
197                if dCi['PARTIE']=='COMPLEXE' : lr=lval[2]
198             # on stocke les données dans le Graph
199             if typ=='fonction_c' and not dCi.has_key('PARTIE'):
200                dicC={
201                   'Val' : lval,
202                   'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU']+'_R',dpar['NOM_RESU']+'_I']
203                }
204             else:
205                dicC={
206                   'Val' : [lx,lr],
207                   'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU']]
208                }
209             Graph.AjoutParaCourbe(dicC, args=dCi)
210             graph.AjoutCourbe(**dicC)
211
212       # 1.2.2. Mot-clé LIST_RESU
213       elif typi=='LIST_RESU':
214          if interp and iocc>0:
215             UTMESS('S',macro,"""Il n'y a pas de règles d'interpolation pour LIST_PARA/LIST_RESU,
216      LIST_PARA/LIST_RESU ne peut donc apparaitre qu'une seule fois
217      et à la première occurence de COURBE""")
218          lx=dCi['LIST_PARA'].Valeurs()
219          lr=obj.Valeurs()
220          if len(lx)<>len(lr):
221             UTMESS('S',macro,"LIST_PARA et LIST_RESU n'ont pas la meme taille")
222          # on stocke les données dans le Graph
223          dicC={
224             'Val' : [lx,lr],
225             'Lab' : [dCi['LIST_PARA'].get_name(),obj.get_name()]
226          }
227          Graph.AjoutParaCourbe(dicC, args=dCi)
228          graph.AjoutCourbe(**dicC)
229
230       # 1.2.3. Mot-clé FONC_X
231       # exemple : obj(t)=sin(t), on imprime x=sin(t), y=cos(t)
232       #           ob2(t)=cos(t)
233       elif typi=='FONC_X':
234          ob2=dCi['FONC_Y']
235          # peut-on blinder au niveau du catalogue
236          if typ=="nappe_sdaster" or ob2.__class__.__name__=="nappe_sdaster":
237             UTMESS('S',macro,"FONC_X/FONC_Y ne peuvent pas etre des nappes !")
238          if interp and iocc>0:
239             UTMESS('S',macro,"""Au format 'TABLEAU' ,FONC_X/FONC_Y ne peut apparaitre qu'une seule fois
240      et à la première occurence de COURBE""")
241          ftmp__=obj
242          dpar=ftmp__.Parametres()
243          ftm2__=ob2
244          dpa2=ftm2__.Parametres()
245          intloc=False
246          if interp and not dCi.has_key('LIST_PARA'):
247             # dans ce cas, linter__ contient les ordonnées de FONC_X
248             intloc=False
249             li__=linter__
250          elif dCi.has_key('LIST_PARA'):
251             intloc=True
252             li__=dCi['LIST_PARA']
253          if intloc:
254             ftmp__=CALC_FONC_INTERP(
255                FONCTION=obj,
256                LIST_PARA=li__,
257                **dpar
258             )
259             lt,lx=ftmp__.Valeurs()
260             ftm2__=CALC_FONC_INTERP(
261                FONCTION=ob2,
262                LIST_PARA=li__,
263                **dpa2
264             )
265          else:
266             lt,lx=ftmp__.Valeurs()
267             li__=DEFI_LIST_REEL(VALE=lt)
268             ftm2__=CALC_FONC_INTERP(
269                FONCTION=ob2,
270                LIST_PARA=li__,
271                **dpa2
272             )
273          
274          lbid,ly=ftm2__.Valeurs()
275          # on stocke les données dans le Graph
276          # on imprime la liste des paramètres seulement si LIST_PARA
277          if intloc:
278             dicC={
279                'Val' : [lt,lx,ly],
280                'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU'],dpa2['NOM_RESU']]
281             }
282          else:
283             dicC={
284                'Val' : [lx,ly],
285                'Lab' : [dpar['NOM_RESU'],dpa2['NOM_RESU']]
286             }
287          Graph.AjoutParaCourbe(dicC, args=dCi)
288          graph.AjoutCourbe(**dicC)
289
290       # 1.2.4. Mot-clé ABSCISSE / ORDONNEE
291       elif typi=='ABSCISSE':
292          if interp and iocc>0:
293             UTMESS('S',macro,"""Il n'y a pas de règles d'interpolation pour ABSCISSE/ORDONNEE,
294      ABSCISSE/ORDONNEE ne peut donc apparaitre qu'une seule fois
295      et à la première occurence de COURBE""")
296          lx=obj
297          lr=dCi['ORDONNEE']
298          if len(lx)<>len(lr):
299             UTMESS('S',macro,"ABSCISSE et ORDONNEE n'ont pas la meme taille")
300          # on stocke les données dans le Graph
301          dicC={
302             'Val' : [lx,lr],
303             'Lab' : ['Absc','Ordo']
304          }
305          Graph.AjoutParaCourbe(dicC, args=dCi)
306          graph.AjoutCourbe(**dicC)
307
308       # 1.2.9. ménage
309       DETRUIRE(CONCEPT=_F(NOM=('li__','ftmp__','ftm2__'),),ALARME='NON',INFO=1)
310
311    # 1.2.99. ménage hors boucle
312    DETRUIRE(CONCEPT=_F(NOM=('linter__'),), ALARME='NON',INFO=1)
313
314    # 1.3. dbg
315    if INFO==2:
316       print '\n'+'-'*70+'\n Contenu du Graph : \n'+'-'*70
317       print graph
318       print '-'*70+'\n'
319
320    #----------------------------------------------
321    # 2. Impression du 'tableau' de valeurs
322    #----------------------------------------------
323
324    # 2.0. Surcharge des propriétés du graphique et des axes
325    # (bloc quasiment identique dans Table)
326    if args['TITRE']<>None:          graph.Titre=args['TITRE']
327    if args['SOUS_TITRE']<>None:     graph.SousTitre=args['SOUS_TITRE']
328    if FORMAT in ('XMGRACE','AGRAF'):
329       if args['BORNE_X']<>None:
330                                        graph.Min_X=args['BORNE_X'][0]
331                                        graph.Max_X=args['BORNE_X'][1]
332       if args['BORNE_Y']<>None:
333                                        graph.Min_Y=args['BORNE_Y'][0]
334                                        graph.Max_Y=args['BORNE_Y'][1]
335       if args['LEGENDE_X']<>None:      graph.Legende_X=args['LEGENDE_X']
336       if args['LEGENDE_Y']<>None:      graph.Legende_Y=args['LEGENDE_Y']
337       if args['ECHELLE_X']<>None:      graph.Echelle_X=args['ECHELLE_X']
338       if args['ECHELLE_Y']<>None:      graph.Echelle_Y=args['ECHELLE_Y']
339       if args['GRILLE_X']<>None:       graph.Grille_X=args['GRILLE_X']
340       if args['GRILLE_Y']<>None:       graph.Grille_Y=args['GRILLE_Y']
341
342    kargs={
343       'FORMAT'    : FORMAT,
344       'FICHIER'   : nomfich,
345    }
346    
347    # 2.1. au format TABLEAU
348    if FORMAT=='TABLEAU':
349       # surcharge par les formats de l'utilisateur
350       kargs['dform']={
351          'csep'  : args['SEPARATEUR'],
352          'ccom'  : args['COMMENTAIRE'],
353          'cdeb'  : args['DEBUT_LIGNE'],
354          'cfin'  : args['FIN_LIGNE']
355       }
356
357    # 2.2. au format AGRAF
358    elif FORMAT=='AGRAF':
359       nomdigr=None
360       if args['UNITE_DIGR']<>6:
361          nomdigr='fort.'+str(args['UNITE_DIGR'])
362       kargs['FICHIER']=[nomfich, nomdigr]
363       kargs['dform']={ 'formR' : '%12.5E' }
364
365    # 2.3. au format XMGRACE et dérivés
366    elif FORMAT=='XMGRACE':
367       kargs['dform']={ 'formR' : '%.8g' }
368       kargs['PILOTE']=args['PILOTE']
369
370    # 2.39. Format inconnu
371    else:
372       UTMESS('S',macro,'Format inconnu : '+FORMAT)
373
374    # Traiter le cas des UL réservées
375    if args['UNITE'] and args['UNITE'] in ul_reserve:
376       DEFI_FICHIER( ACTION='LIBERER', UNITE=args['UNITE'], )
377    if FORMAT=='AGRAF' and args['UNITE_DIGR']<>args['UNITE'] \
378          and args['UNITE_DIGR'] in ul_reserve:
379       DEFI_FICHIER( ACTION='LIBERER', UNITE=args['UNITE_DIGR'], )
380
381    # 2.4. On trace !
382    graph.Trace(**kargs)
383
384    # 99. Traiter le cas des UL réservées
385    if args['UNITE'] and args['UNITE'] in ul_reserve:
386       DEFI_FICHIER( ACTION='ASSOCIER', UNITE=args['UNITE'],
387             TYPE='ASCII', ACCES='APPEND' )
388    if FORMAT=='AGRAF' and args['UNITE_DIGR']<>args['UNITE'] \
389          and args['UNITE_DIGR'] in ul_reserve:
390       DEFI_FICHIER( ACTION='ASSOCIER', UNITE=args['UNITE_DIGR'],
391             TYPE='ASCII', ACCES='APPEND' )
392
393    return ier