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