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.
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
37 from Utilitai.UniteAster import UniteAster
39 # La macro compte pour 1 dans la numerotation des commandes
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')
48 #----------------------------------------------
49 # 0. Traitement des arguments, initialisations
50 # unité logique des fichiers réservés
56 if args['UNITE'] and args['UNITE']<>6:
57 nomfich=UL.Nom(args['UNITE'])
59 print ' Nom du fichier :',nomfich
60 if nomfich and os.path.exists(nomfich) and os.stat(nomfich).st_size<>0:
65 UTMESS(niv,macro,'Le fichier '+nomfich+' existe déjà, on écrit ' \
68 # 0.2. Récupération des valeurs sous COURBE
69 unparmi=('FONCTION','LIST_RESU','FONC_X','ABSCISSE')
71 # i0 : indice du mot-clé facteur qui contient LIST_PARA, sinon i0=0
77 dC = Ci.cree_dict_valeurs(Ci.mc_liste)
78 if dC.has_key('LIST_PARA') and dC['LIST_PARA']!=None and i0==0:
81 if dC[mc]==None: del dC[mc]
84 print ' Nombre de fonctions à analyser : ',len(Courbe)
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
93 if dCi.has_key('LIST_PARA'):
94 linter__=dCi['LIST_PARA']
100 typ=obj.__class__.__name__
103 UTMESS('S',macro,'incohérence entre le catalogue et la macro.')
105 if typ=='nappe_sdaster':
106 lpar,lval=obj.Valeurs()
109 linterp=obj.Valeurs()[0]
111 lbid,linterp=obj.Valeurs()
112 elif typi=='ABSCISSE':
114 linter__=DEFI_LIST_REEL(VALE=linterp)
116 print ' Interpolation globale sur la liste :\n',linter__.Valeurs()
119 #----------------------------------------------
120 # 1. Récupération des valeurs des N courbes sous forme
121 # d'une liste de N listes
122 #----------------------------------------------
128 # 1.1. Type d'objet à traiter
131 if dCi.has_key(typi):
133 typ=obj.__class__.__name__
135 if not dCi.has_key('LEGENDE') and hasattr(obj,'get_name'):
136 dCi['LEGENDE']=obj.get_name()
138 UTMESS('S',macro,'incohérence entre le catalogue et la macro.')
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()
148 for i in range(len(lpar)):
152 # sur quelle liste interpoler chaque fonction
156 elif dCi.has_key('LIST_PARA'):
157 li__=dCi['LIST_PARA']
159 li__=DEFI_LIST_REEL(VALE=lx)
160 # compléter les paramètres d'interpolation
164 if (interp or dCi.has_key('LIST_PARA')) and i>0:
165 ftmp__=CALC_FONC_INTERP(
171 pv,lv2=ftmp__.Valeurs()
174 # on stocke les données dans le Graph
175 nomresu=dic['NOM_RESU'].strip()+'_'+str(len(graph.Legendes))
178 'Lab' : [dic['NOM_PARA_FONC'],nomresu]
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)
187 dpar=ftmp__.Parametres()
189 ftmp__=CALC_FONC_INTERP(
194 elif dCi.has_key('LIST_PARA'):
195 ftmp__=CALC_FONC_INTERP(
197 LIST_PARA=dCi['LIST_PARA'],
200 lval=list(ftmp__.Valeurs())
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))
210 'Lab' : [dpar['NOM_PARA'],nomresu+'_R',nomresu+'_I']
213 nomresu=dpar['NOM_RESU'].strip()+'_'+str(len(graph.Legendes))
216 'Lab' : [dpar['NOM_PARA'],nomresu]
218 Graph.AjoutParaCourbe(dicC, args=dCi)
219 graph.AjoutCourbe(**dicC)
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()
230 UTMESS('S',macro,"LIST_PARA et LIST_RESU n'ont pas la meme taille")
231 # on stocke les données dans le Graph
234 'Lab' : [dCi['LIST_PARA'].get_name(),obj.get_name()]
236 Graph.AjoutParaCourbe(dicC, args=dCi)
237 graph.AjoutCourbe(**dicC)
239 # 1.2.3. Mot-clé FONC_X
240 # exemple : obj(t)=sin(t), on imprime x=sin(t), y=cos(t)
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""")
251 dpar=ftmp__.Parametres()
253 dpa2=ftm2__.Parametres()
255 if interp and not dCi.has_key('LIST_PARA'):
256 # dans ce cas, linter__ contient les ordonnées de FONC_X
259 elif dCi.has_key('LIST_PARA'):
261 li__=dCi['LIST_PARA']
263 ftmp__=CALC_FONC_INTERP(
268 lt,lx=ftmp__.Valeurs()
269 ftm2__=CALC_FONC_INTERP(
275 lt,lx=ftmp__.Valeurs()
276 li__=DEFI_LIST_REEL(VALE=lt)
277 ftm2__=CALC_FONC_INTERP(
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
287 nomresur=dpar['NOM_RESU'].strip()+'_'+str(len(graph.Legendes))
288 nomresu2=dpa2['NOM_RESU'].strip()+'_'+str(len(graph.Legendes)+1)
291 'Lab' : [dpar['NOM_PARA'],nomresur,nomresu2]
294 nomresur=dpar['NOM_RESU'].strip()+'_'+str(len(graph.Legendes))
295 nomresu2=dpa2['NOM_RESU'].strip()+'_'+str(len(graph.Legendes)+1)
298 'Lab' : [nomresur,nomresu2]
300 Graph.AjoutParaCourbe(dicC, args=dCi)
301 graph.AjoutCourbe(**dicC)
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""")
312 UTMESS('S',macro,"ABSCISSE et ORDONNEE n'ont pas la meme taille")
313 # on stocke les données dans le Graph
316 'Lab' : ['Absc','Ordo']
318 Graph.AjoutParaCourbe(dicC, args=dCi)
319 graph.AjoutCourbe(**dicC)
322 DETRUIRE(CONCEPT=_F(NOM=('li__','ftmp__','ftm2__'),),ALARME='NON',INFO=1)
324 # 1.2.99. ménage hors boucle
325 DETRUIRE(CONCEPT=_F(NOM=('linter__'),), ALARME='NON',INFO=1)
329 print '\n'+'-'*70+'\n Contenu du Graph : \n'+'-'*70
333 #----------------------------------------------
334 # 2. Impression du 'tableau' de valeurs
335 #----------------------------------------------
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']
360 # 2.1. au format TABLEAU
361 if FORMAT=='TABLEAU':
362 # surcharge par les formats de l'utilisateur
364 'csep' : args['SEPARATEUR'],
365 'ccom' : args['COMMENTAIRE'],
366 'cdeb' : args['DEBUT_LIGNE'],
367 'cfin' : args['FIN_LIGNE']
370 # 2.2. au format AGRAF
371 elif FORMAT=='AGRAF':
373 if args['UNITE_DIGR']<>6:
374 nomdigr=UL.Nom(args['UNITE_DIGR'])
375 kargs['FICHIER']=[nomfich, nomdigr]
376 kargs['dform']={ 'formR' : '%12.5E' }
378 # 2.3. au format XMGRACE et dérivés
379 elif FORMAT=='XMGRACE':
380 kargs['dform']={ 'formR' : '%.8g' }
381 kargs['PILOTE']=args['PILOTE']
383 # 2.39. Format inconnu
385 UTMESS('S',macro,'Format inconnu : '+FORMAT)
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')
397 # 99. Traiter le cas des UL réservées