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