]> SALOME platform Git repositories - tools/eficas.git/blob - Aster/Cata/cataSTA73/Macro/impr_fonction_ops.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Aster / Cata / cataSTA73 / Macro / impr_fonction_ops.py
1 #@ MODIF impr_fonction_ops Macro  DATE 22/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    ier=0
36    # La macro compte pour 1 dans la numerotation des commandes
37    self.set_icmd(1)
38
39    # On importe les definitions des commandes a utiliser dans la macro
40    # Le nom de la variable doit etre obligatoirement le nom de la commande
41    CALC_FONC_INTERP = self.get_cmd('CALC_FONC_INTERP')
42    DEFI_LIST_REEL   = self.get_cmd('DEFI_LIST_REEL')
43    DEFI_FICHIER     = self.get_cmd('DEFI_FICHIER')
44    DETRUIRE         = self.get_cmd('DETRUIRE')
45
46    #----------------------------------------------
47    # 0. Traitement des arguments, initialisations
48    # unité logique des fichiers réservés
49    ul_reserve=(8,)
50
51    # 0.1. Fichier
52    nomfich=None
53    if args['UNITE'] and args['UNITE']<>6:
54       nomfich='fort.'+str(args['UNITE'])
55       if INFO==2:
56          print ' Nom du fichier :',nomfich
57    if nomfich and os.path.exists(nomfich):
58       if FORMAT=='XMGRACE':
59          niv='A'
60       else:
61          niv='I'
62       from Utilitai.Utmess import UTMESS
63       UTMESS(niv,macro,'Le fichier '+nomfich+' existe déjà, on écrit ' \
64              'à la suite.',self)
65
66    # 0.2. Récupération des valeurs sous COURBE
67    unparmi=('FONCTION','LIST_RESU','FONC_X','ABSCISSE')
68
69    # i0 : indice du mot-clé facteur qui contient LIST_PARA, sinon i0=0
70    i0=0
71    Courbe=[]
72    iocc=-1
73    for Ci in COURBE:
74       iocc+=1
75       dC = Ci.cree_dict_valeurs(Ci.mc_liste)
76       if dC.has_key('LIST_PARA') and i0==0: i0=iocc
77       for mc in dC.keys():
78          if dC[mc]==None: del dC[mc]
79       Courbe.append(dC)
80    if INFO==2:
81       print ' Nombre de fonctions à analyser : ',len(Courbe)
82
83    # 0.3. Devra-t-on interpoler globalement ?
84    #      Dans ce cas, linter__ est le LIST_PARA
85    #      ou, à défaut, les abscisses de la première courbe
86    interp=False
87    if FORMAT=='TABLEAU':
88       interp=True
89       dCi=Courbe[i0]
90       if dCi.has_key('LIST_PARA'):
91          linter__=dCi['LIST_PARA']
92       else:
93          obj=None
94          for typi in unparmi:
95             if dCi.has_key(typi):
96                obj=dCi[typi]
97                typ=obj.__class__.__name__
98                break
99          if obj==None:
100             from Utilitai.Utmess import UTMESS
101             UTMESS('S',macro,'incohérence entre le catalogue et la macro.', self)
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    from Utilitai import Graph
122    graph=Graph.Graph()
123    iocc=-1
124    for dCi in Courbe:
125       iocc+=1
126
127       # 1.1. Type d'objet à traiter
128       obj=None
129       for typi in unparmi:
130          if dCi.has_key(typi):
131             obj=dCi[typi]
132             typ=obj.__class__.__name__
133             break
134       if not dCi.has_key('LEGENDE'):
135          dCi['LEGENDE']=obj.get_name()
136       if obj==None:
137          from Utilitai.Utmess import UTMESS
138          UTMESS('S',macro,'incohérence entre le catalogue et la macro.',self)
139
140       # 1.2. Extraction des valeurs
141
142       # 1.2.1. Mot-clé FONCTION
143       if   typi=='FONCTION':
144          if typ=='nappe_sdaster':
145             lpar,lval=obj.Valeurs()
146             dico,ldicf=obj.Parametres()
147             for i in range(len(lpar)):
148                p=lpar[i]
149                lx=lval[i][0]
150                ly=lval[i][1]
151                # sur quelle liste interpoler chaque fonction
152                if i==0:
153                   if interp:
154                      li__=linter__
155                   elif dCi.has_key('LIST_PARA'):
156                      li__=dCi['LIST_PARA']
157                   else:
158                      li__=DEFI_LIST_REEL(VALE=lx)
159                # compléter les paramètres d'interpolation
160                dic=dico.copy()
161                dic.update(ldicf[i])
162                
163                if (interp or dCi.has_key('LIST_PARA')) and i>0:
164                   ftmp__=CALC_FONC_INTERP(
165                      FONCTION=obj,
166                      VALE_PARA=p,
167                      LIST_PARA_FONC=li__,
168                      **dic
169                   )
170                   pv,lv2=ftmp__.Valeurs()
171                   lx=lv2[0][0]
172                   ly=lv2[0][1]
173                # on stocke les données dans le Graph
174                dicC={
175                   'Val' : [lx,ly],
176                   'Lab' : [dic['NOM_PARA_FONC'],dic['NOM_RESU']]
177                }
178                AjoutParaCourbe(dicC, args=dCi)
179                graph.AjoutCourbe(**dicC)
180          else:
181             ftmp__=obj
182             dpar=ftmp__.Parametres()
183             if interp:
184                ftmp__=CALC_FONC_INTERP(
185                   FONCTION=obj,
186                   LIST_PARA=linter__,
187                   **dpar
188                )
189             elif dCi.has_key('LIST_PARA'):
190                ftmp__=CALC_FONC_INTERP(
191                   FONCTION=obj,
192                   LIST_PARA=dCi['LIST_PARA'],
193                   **dpar
194                )
195             lval=list(ftmp__.Valeurs())
196             lx=lval[0]
197             lr=lval[1]
198             if typ=='fonction_c' and dCi.has_key('PARTIE'):
199                if dCi['PARTIE']=='COMPLEXE' : lr=lval[2]
200             # on stocke les données dans le Graph
201             if typ=='fonction_c' and not dCi.has_key('PARTIE'):
202                dicC={
203                   'Val' : lval,
204                   'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU']+'_R',dpar['NOM_RESU']+'_I']
205                }
206             else:
207                dicC={
208                   'Val' : [lx,lr],
209                   'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU']]
210                }
211             AjoutParaCourbe(dicC, args=dCi)
212             graph.AjoutCourbe(**dicC)
213
214       # 1.2.2. Mot-clé LIST_RESU
215       elif typi=='LIST_RESU':
216          if interp and iocc>0:
217             from Utilitai.Utmess import UTMESS
218             UTMESS('S',macro,"""Il n'y a pas de règles d'interpolation pour LIST_PARA/LIST_RESU,
219      LIST_PARA/LIST_RESU ne peut donc apparaitre qu'une seule fois
220      et à la première occurence de COURBE""",self)
221          lx=dCi['LIST_PARA'].Valeurs()
222          lr=obj.Valeurs()
223          if len(lx)<>len(lr):
224             from Utilitai.Utmess import UTMESS
225             UTMESS('S',macro,"LIST_PARA et LIST_RESU n'ont pas la meme taille",self)
226          # on stocke les données dans le Graph
227          dicC={
228             'Val' : [lx,lr],
229             'Lab' : [dCi['LIST_PARA'].get_name(),obj.get_name()]
230          }
231          AjoutParaCourbe(dicC, args=dCi)
232          graph.AjoutCourbe(**dicC)
233
234       # 1.2.3. Mot-clé FONC_X
235       # exemple : obj(t)=sin(t), on imprime x=sin(t), y=cos(t)
236       #           ob2(t)=cos(t)
237       elif typi=='FONC_X':
238          ob2=dCi['FONC_Y']
239          # peut-on blinder au niveau du catalogue
240          if typ=="nappe_sdaster" or ob2.__class__.__name__=="nappe_sdaster":
241             from Utilitai.Utmess import UTMESS
242             UTMESS('S',macro,"FONC_X/FONC_Y ne peuvent pas etre des nappes !",self)
243          if interp and iocc>0:
244             from Utilitai.Utmess import UTMESS
245             UTMESS('S',macro,"""Au format 'TABLEAU' ,FONC_X/FONC_Y ne peut apparaitre qu'une seule fois
246      et à la première occurence de COURBE""",self)
247          ftmp__=obj
248          dpar=ftmp__.Parametres()
249          ftm2__=ob2
250          dpa2=ftm2__.Parametres()
251          intloc=False
252          if interp and not dCi.has_key('LIST_PARA'):
253             # dans ce cas, linter__ contient les ordonnées de FONC_X
254             intloc=False
255             li__=linter__
256          elif dCi.has_key('LIST_PARA'):
257             intloc=True
258             li__=dCi['LIST_PARA']
259          if intloc:
260             ftmp__=CALC_FONC_INTERP(
261                FONCTION=obj,
262                LIST_PARA=li__,
263                **dpar
264             )
265             lt,lx=ftmp__.Valeurs()
266             ftm2__=CALC_FONC_INTERP(
267                FONCTION=ob2,
268                LIST_PARA=li__,
269                **dpa2
270             )
271          else:
272             lt,lx=ftmp__.Valeurs()
273             li__=DEFI_LIST_REEL(VALE=lt)
274             ftm2__=CALC_FONC_INTERP(
275                FONCTION=ob2,
276                LIST_PARA=li__,
277                **dpa2
278             )
279          
280          lbid,ly=ftm2__.Valeurs()
281          # on stocke les données dans le Graph
282          # on imprime la liste des paramètres seulement si LIST_PARA
283          if intloc:
284             dicC={
285                'Val' : [lt,lx,ly],
286                'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU'],dpa2['NOM_RESU']]
287             }
288          else:
289             dicC={
290                'Val' : [lx,ly],
291                'Lab' : [dpar['NOM_RESU'],dpa2['NOM_RESU']]
292             }
293          AjoutParaCourbe(dicC, args=dCi)
294          graph.AjoutCourbe(**dicC)
295
296       # 1.2.4. Mot-clé ABSCISSE / ORDONNEE
297       elif typi=='ABSCISSE':
298          if interp and iocc>0:
299             from Utilitai.Utmess import UTMESS
300             UTMESS('S',macro,"""Il n'y a pas de règles d'interpolation pour ABSCISSE/ORDONNEE,
301      ABSCISSE/ORDONNEE ne peut donc apparaitre qu'une seule fois
302      et à la première occurence de COURBE""",self)
303          lx=obj
304          lr=dCi['ORDONNEE']
305          if len(lx)<>len(lr):
306             from Utilitai.Utmess import UTMESS
307             UTMESS('S',macro,"ABSCISSE et ORDONNEE n'ont pas la meme taille",self)
308          # on stocke les données dans le Graph
309          dicC={
310             'Val' : [lx,lr],
311             'Lab' : ['Absc','Ordo']
312          }
313          AjoutParaCourbe(dicC, args=dCi)
314          graph.AjoutCourbe(**dicC)
315
316       # 1.2.9. ménage
317       DETRUIRE(CONCEPT=_F(NOM=('li__','ftmp__','ftm2__'),),ALARME='NON',INFO=1)
318
319    # 1.2.99. ménage hors boucle
320    DETRUIRE(CONCEPT=_F(NOM=('linter__'),), ALARME='NON',INFO=1)
321
322    # 1.3. dbg
323    if INFO==2:
324       print '\n'+'-'*70+'\n Contenu du Graph : \n'+'-'*70
325       print graph
326       print '-'*70+'\n'
327
328    #----------------------------------------------
329    # 2. Impression du 'tableau' de valeurs
330    #----------------------------------------------
331
332    # 2.0. Surcharge des propriétés du graphique et des axes
333    if args['TITRE']<>None:          graph.Titre=args['TITRE']
334    if args['SOUS_TITRE']<>None:     graph.SousTitre=args['SOUS_TITRE']
335    if FORMAT in ('XMGRACE','AGRAF'):
336       if args['BORNE_X']<>None:
337                                        graph.Min_X=args['BORNE_X'][0]
338                                        graph.Max_X=args['BORNE_X'][1]
339       if args['BORNE_Y']<>None:
340                                        graph.Min_Y=args['BORNE_Y'][0]
341                                        graph.Max_Y=args['BORNE_Y'][1]
342       if args['LEGENDE_X']<>None:      graph.Legende_X=args['LEGENDE_X']
343       if args['LEGENDE_Y']<>None:      graph.Legende_Y=args['LEGENDE_Y']
344       if args['ECHELLE_X']<>None:      graph.Echelle_X=args['ECHELLE_X']
345       if args['ECHELLE_Y']<>None:      graph.Echelle_Y=args['ECHELLE_Y']
346       if args['GRILLE_X']<>None:       graph.Grille_X=args['GRILLE_X']
347       if args['GRILLE_Y']<>None:       graph.Grille_Y=args['GRILLE_Y']
348
349    kargs={
350       'FORMAT'    : FORMAT,
351       'FICHIER'   : nomfich,
352    }
353    
354    # 2.1. au format TABLEAU
355    if FORMAT=='TABLEAU':
356       # surcharge par les formats de l'utilisateur
357       kargs['dform']={
358          'csep'  : args['SEPARATEUR'],
359          'ccom'  : args['COMMENTAIRE'],
360          'cdeb'  : args['DEBUT_LIGNE'],
361          'cfin'  : args['FIN_LIGNE']
362       }
363
364    # 2.2. au format AGRAF
365    elif FORMAT=='AGRAF':
366       nomdigr=None
367       if args['UNITE_DIGR']<>6:
368          nomdigr='fort.'+str(args['UNITE_DIGR'])
369       kargs['FICHIER']=[nomfich, nomdigr]
370       kargs['dform']={ 'formR' : '%12.5E' }
371
372    # 2.3. au format XMGRACE et dérivés
373    elif FORMAT=='XMGRACE':
374       kargs['dform']={ 'formR' : '%.8g' }
375       kargs['PILOTE']=args['PILOTE']
376
377    # 2.39. Format inconnu
378    else:
379       from Utilitai.Utmess import UTMESS
380       UTMESS('S',macro,'Format inconnu : '+FORMAT,self)
381
382    # Traiter le cas des UL réservées
383    if args['UNITE'] and args['UNITE'] in ul_reserve:
384       DEFI_FICHIER( ACTION='LIBERER', UNITE=args['UNITE'], )
385    if FORMAT=='AGRAF' and args['UNITE_DIGR']<>args['UNITE'] \
386          and args['UNITE_DIGR'] in ul_reserve:
387       DEFI_FICHIER( ACTION='LIBERER', UNITE=args['UNITE_DIGR'], )
388
389    # 2.4. On trace !
390    graph.Trace(**kargs)
391
392    # 99. Traiter le cas des UL réservées
393    if args['UNITE'] and args['UNITE'] in ul_reserve:
394       DEFI_FICHIER( ACTION='ASSOCIER', UNITE=args['UNITE'],
395             TYPE='ASCII', ACCES='APPEND' )
396    if FORMAT=='AGRAF' and args['UNITE_DIGR']<>args['UNITE'] \
397          and args['UNITE_DIGR'] in ul_reserve:
398       DEFI_FICHIER( ACTION='ASSOCIER', UNITE=args['UNITE_DIGR'],
399             TYPE='ASCII', ACCES='APPEND' )
400
401    return ier
402
403 # ------------------------------------------------------------------------------
404 def AjoutParaCourbe(dCourbe, args):
405    """Ajoute les arguments fournis par l'utilisateur (args) dans le dictionnaire
406    décrivant la courbe (dCourbe).
407    """
408    # correspondance : mot-clé Aster / clé du dico de l'objet Graph
409    keys={
410       'LEGENDE'         : 'Leg',
411       'STYLE'           : 'Sty',
412       'COULEUR'         : 'Coul',
413       'MARQUEUR'        : 'Marq',
414       'FREQ_MARQUEUR'   : 'FreqM',
415       'TRI'             : 'Tri',
416    }
417    for mc, key in keys.items():
418       if args.has_key(mc):
419          dCourbe[key]=args[mc]
420