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.
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.
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 # ======================================================================
21 # RESPONSABLE MCOURTOI M.COURTOIS
25 # ------------------------------------------------------------------------------
26 def impr_fonction_ops(self, FORMAT, COURBE, INFO, **args):
28 Macro IMPR_FONCTION permettant d'imprimer dans un fichier des fonctions,
30 Erreurs<S> dans IMPR_FONCTION pour ne pas perdre la base.
36 # La macro compte pour 1 dans la numerotation des commandes
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')
46 #----------------------------------------------
47 # 0. Traitement des arguments, initialisations
48 # unité logique des fichiers réservés
53 if args['UNITE'] and args['UNITE']<>6:
54 nomfich='fort.'+str(args['UNITE'])
56 print ' Nom du fichier :',nomfich
57 if nomfich and os.path.exists(nomfich):
62 from Utilitai.Utmess import UTMESS
63 UTMESS(niv,macro,'Le fichier '+nomfich+' existe déjà, on écrit ' \
66 # 0.2. Récupération des valeurs sous COURBE
67 unparmi=('FONCTION','LIST_RESU','FONC_X','ABSCISSE')
69 # i0 : indice du mot-clé facteur qui contient LIST_PARA, sinon i0=0
75 dC = Ci.cree_dict_valeurs(Ci.mc_liste)
76 if dC.has_key('LIST_PARA') and i0==0: i0=iocc
78 if dC[mc]==None: del dC[mc]
81 print ' Nombre de fonctions à analyser : ',len(Courbe)
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
90 if dCi.has_key('LIST_PARA'):
91 linter__=dCi['LIST_PARA']
97 typ=obj.__class__.__name__
100 from Utilitai.Utmess import UTMESS
101 UTMESS('S',macro,'incohérence entre le catalogue et la macro.', self)
103 if typ=='nappe_sdaster':
104 lpar,lval=obj.Valeurs()
107 linterp=obj.Valeurs()[0]
109 lbid,linterp=obj.Valeurs()
110 elif typi=='ABSCISSE':
112 linter__=DEFI_LIST_REEL(VALE=linterp)
114 print ' Interpolation globale sur la liste :\n',linter__.Valeurs()
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
127 # 1.1. Type d'objet à traiter
130 if dCi.has_key(typi):
132 typ=obj.__class__.__name__
134 if not dCi.has_key('LEGENDE'):
135 dCi['LEGENDE']=obj.get_name()
137 from Utilitai.Utmess import UTMESS
138 UTMESS('S',macro,'incohérence entre le catalogue et la macro.',self)
140 # 1.2. Extraction des valeurs
142 # 1.2.1. Mot-clé FONCTION
144 if typ=='nappe_sdaster':
145 lpar,lval=obj.Valeurs()
146 dico,ldicf=obj.Parametres()
147 for i in range(len(lpar)):
151 # sur quelle liste interpoler chaque fonction
155 elif dCi.has_key('LIST_PARA'):
156 li__=dCi['LIST_PARA']
158 li__=DEFI_LIST_REEL(VALE=lx)
159 # compléter les paramètres d'interpolation
163 if (interp or dCi.has_key('LIST_PARA')) and i>0:
164 ftmp__=CALC_FONC_INTERP(
170 pv,lv2=ftmp__.Valeurs()
173 # on stocke les données dans le Graph
176 'Lab' : [dic['NOM_PARA_FONC'],dic['NOM_RESU']]
178 AjoutParaCourbe(dicC, args=dCi)
179 graph.AjoutCourbe(**dicC)
182 dpar=ftmp__.Parametres()
184 ftmp__=CALC_FONC_INTERP(
189 elif dCi.has_key('LIST_PARA'):
190 ftmp__=CALC_FONC_INTERP(
192 LIST_PARA=dCi['LIST_PARA'],
195 lval=list(ftmp__.Valeurs())
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'):
204 'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU']+'_R',dpar['NOM_RESU']+'_I']
209 'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU']]
211 AjoutParaCourbe(dicC, args=dCi)
212 graph.AjoutCourbe(**dicC)
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()
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
229 'Lab' : [dCi['LIST_PARA'].get_name(),obj.get_name()]
231 AjoutParaCourbe(dicC, args=dCi)
232 graph.AjoutCourbe(**dicC)
234 # 1.2.3. Mot-clé FONC_X
235 # exemple : obj(t)=sin(t), on imprime x=sin(t), y=cos(t)
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)
248 dpar=ftmp__.Parametres()
250 dpa2=ftm2__.Parametres()
252 if interp and not dCi.has_key('LIST_PARA'):
253 # dans ce cas, linter__ contient les ordonnées de FONC_X
256 elif dCi.has_key('LIST_PARA'):
258 li__=dCi['LIST_PARA']
260 ftmp__=CALC_FONC_INTERP(
265 lt,lx=ftmp__.Valeurs()
266 ftm2__=CALC_FONC_INTERP(
272 lt,lx=ftmp__.Valeurs()
273 li__=DEFI_LIST_REEL(VALE=lt)
274 ftm2__=CALC_FONC_INTERP(
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
286 'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU'],dpa2['NOM_RESU']]
291 'Lab' : [dpar['NOM_RESU'],dpa2['NOM_RESU']]
293 AjoutParaCourbe(dicC, args=dCi)
294 graph.AjoutCourbe(**dicC)
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)
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
311 'Lab' : ['Absc','Ordo']
313 AjoutParaCourbe(dicC, args=dCi)
314 graph.AjoutCourbe(**dicC)
317 DETRUIRE(CONCEPT=_F(NOM=('li__','ftmp__','ftm2__'),),ALARME='NON',INFO=1)
319 # 1.2.99. ménage hors boucle
320 DETRUIRE(CONCEPT=_F(NOM=('linter__'),), ALARME='NON',INFO=1)
324 print '\n'+'-'*70+'\n Contenu du Graph : \n'+'-'*70
328 #----------------------------------------------
329 # 2. Impression du 'tableau' de valeurs
330 #----------------------------------------------
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']
354 # 2.1. au format TABLEAU
355 if FORMAT=='TABLEAU':
356 # surcharge par les formats de l'utilisateur
358 'csep' : args['SEPARATEUR'],
359 'ccom' : args['COMMENTAIRE'],
360 'cdeb' : args['DEBUT_LIGNE'],
361 'cfin' : args['FIN_LIGNE']
364 # 2.2. au format AGRAF
365 elif FORMAT=='AGRAF':
367 if args['UNITE_DIGR']<>6:
368 nomdigr='fort.'+str(args['UNITE_DIGR'])
369 kargs['FICHIER']=[nomfich, nomdigr]
370 kargs['dform']={ 'formR' : '%12.5E' }
372 # 2.3. au format XMGRACE et dérivés
373 elif FORMAT=='XMGRACE':
374 kargs['dform']={ 'formR' : '%.8g' }
375 kargs['PILOTE']=args['PILOTE']
377 # 2.39. Format inconnu
379 from Utilitai.Utmess import UTMESS
380 UTMESS('S',macro,'Format inconnu : '+FORMAT,self)
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'], )
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' )
403 # ------------------------------------------------------------------------------
404 def AjoutParaCourbe(dCourbe, args):
405 """Ajoute les arguments fournis par l'utilisateur (args) dans le dictionnaire
406 décrivant la courbe (dCourbe).
408 # correspondance : mot-clé Aster / clé du dico de l'objet Graph
414 'FREQ_MARQUEUR' : 'FreqM',
417 for mc, key in keys.items():
419 dCourbe[key]=args[mc]