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.
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.
35 from Utilitai import Graph
36 from Utilitai.Utmess import UTMESS
38 # La macro compte pour 1 dans la numerotation des commandes
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')
48 #----------------------------------------------
49 # 0. Traitement des arguments, initialisations
50 # unité logique des fichiers réservés
55 if args['UNITE'] and args['UNITE']<>6:
56 nomfich='fort.'+str(args['UNITE'])
58 print ' Nom du fichier :',nomfich
59 if nomfich and os.path.exists(nomfich):
64 UTMESS(niv,macro,'Le fichier '+nomfich+' existe déjà, on écrit ' \
67 # 0.2. Récupération des valeurs sous COURBE
68 unparmi=('FONCTION','LIST_RESU','FONC_X','ABSCISSE')
70 # i0 : indice du mot-clé facteur qui contient LIST_PARA, sinon i0=0
76 dC = Ci.cree_dict_valeurs(Ci.mc_liste)
77 if dC.has_key('LIST_PARA') and i0==0: i0=iocc
79 if dC[mc]==None: del dC[mc]
82 print ' Nombre de fonctions à analyser : ',len(Courbe)
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
91 if dCi.has_key('LIST_PARA'):
92 linter__=dCi['LIST_PARA']
98 typ=obj.__class__.__name__
101 UTMESS('S',macro,'incohérence entre le catalogue et la macro.')
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 #----------------------------------------------
126 # 1.1. Type d'objet à traiter
129 if dCi.has_key(typi):
131 typ=obj.__class__.__name__
133 if not dCi.has_key('LEGENDE') and hasattr(obj,'get_name'):
134 dCi['LEGENDE']=obj.get_name()
136 UTMESS('S',macro,'incohérence entre le catalogue et la macro.')
138 # 1.2. Extraction des valeurs
140 # 1.2.1. Mot-clé FONCTION
142 if typ=='nappe_sdaster':
143 lpar,lval=obj.Valeurs()
144 dico,ldicf=obj.Parametres()
145 for i in range(len(lpar)):
149 # sur quelle liste interpoler chaque fonction
153 elif dCi.has_key('LIST_PARA'):
154 li__=dCi['LIST_PARA']
156 li__=DEFI_LIST_REEL(VALE=lx)
157 # compléter les paramètres d'interpolation
161 if (interp or dCi.has_key('LIST_PARA')) and i>0:
162 ftmp__=CALC_FONC_INTERP(
168 pv,lv2=ftmp__.Valeurs()
171 # on stocke les données dans le Graph
174 'Lab' : [dic['NOM_PARA_FONC'],dic['NOM_RESU']]
176 Graph.AjoutParaCourbe(dicC, args=dCi)
177 graph.AjoutCourbe(**dicC)
180 dpar=ftmp__.Parametres()
182 ftmp__=CALC_FONC_INTERP(
187 elif dCi.has_key('LIST_PARA'):
188 ftmp__=CALC_FONC_INTERP(
190 LIST_PARA=dCi['LIST_PARA'],
193 lval=list(ftmp__.Valeurs())
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'):
202 'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU']+'_R',dpar['NOM_RESU']+'_I']
207 'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU']]
209 Graph.AjoutParaCourbe(dicC, args=dCi)
210 graph.AjoutCourbe(**dicC)
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()
221 UTMESS('S',macro,"LIST_PARA et LIST_RESU n'ont pas la meme taille")
222 # on stocke les données dans le Graph
225 'Lab' : [dCi['LIST_PARA'].get_name(),obj.get_name()]
227 Graph.AjoutParaCourbe(dicC, args=dCi)
228 graph.AjoutCourbe(**dicC)
230 # 1.2.3. Mot-clé FONC_X
231 # exemple : obj(t)=sin(t), on imprime x=sin(t), y=cos(t)
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""")
242 dpar=ftmp__.Parametres()
244 dpa2=ftm2__.Parametres()
246 if interp and not dCi.has_key('LIST_PARA'):
247 # dans ce cas, linter__ contient les ordonnées de FONC_X
250 elif dCi.has_key('LIST_PARA'):
252 li__=dCi['LIST_PARA']
254 ftmp__=CALC_FONC_INTERP(
259 lt,lx=ftmp__.Valeurs()
260 ftm2__=CALC_FONC_INTERP(
266 lt,lx=ftmp__.Valeurs()
267 li__=DEFI_LIST_REEL(VALE=lt)
268 ftm2__=CALC_FONC_INTERP(
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
280 'Lab' : [dpar['NOM_PARA'],dpar['NOM_RESU'],dpa2['NOM_RESU']]
285 'Lab' : [dpar['NOM_RESU'],dpa2['NOM_RESU']]
287 Graph.AjoutParaCourbe(dicC, args=dCi)
288 graph.AjoutCourbe(**dicC)
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""")
299 UTMESS('S',macro,"ABSCISSE et ORDONNEE n'ont pas la meme taille")
300 # on stocke les données dans le Graph
303 'Lab' : ['Absc','Ordo']
305 Graph.AjoutParaCourbe(dicC, args=dCi)
306 graph.AjoutCourbe(**dicC)
309 DETRUIRE(CONCEPT=_F(NOM=('li__','ftmp__','ftm2__'),),ALARME='NON',INFO=1)
311 # 1.2.99. ménage hors boucle
312 DETRUIRE(CONCEPT=_F(NOM=('linter__'),), ALARME='NON',INFO=1)
316 print '\n'+'-'*70+'\n Contenu du Graph : \n'+'-'*70
320 #----------------------------------------------
321 # 2. Impression du 'tableau' de valeurs
322 #----------------------------------------------
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']
347 # 2.1. au format TABLEAU
348 if FORMAT=='TABLEAU':
349 # surcharge par les formats de l'utilisateur
351 'csep' : args['SEPARATEUR'],
352 'ccom' : args['COMMENTAIRE'],
353 'cdeb' : args['DEBUT_LIGNE'],
354 'cfin' : args['FIN_LIGNE']
357 # 2.2. au format AGRAF
358 elif FORMAT=='AGRAF':
360 if args['UNITE_DIGR']<>6:
361 nomdigr='fort.'+str(args['UNITE_DIGR'])
362 kargs['FICHIER']=[nomfich, nomdigr]
363 kargs['dform']={ 'formR' : '%12.5E' }
365 # 2.3. au format XMGRACE et dérivés
366 elif FORMAT=='XMGRACE':
367 kargs['dform']={ 'formR' : '%.8g' }
368 kargs['PILOTE']=args['PILOTE']
370 # 2.39. Format inconnu
372 UTMESS('S',macro,'Format inconnu : '+FORMAT)
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'], )
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' )