1 #@ MODIF N_utils Noyau DATE 14/09/2004 AUTEUR MCOURTOI M.COURTOIS
2 # -*- coding: iso-8859-1 -*-
3 # CONFIGURATION MANAGEMENT OF EDF VERSION
4 # ======================================================================
5 # COPYRIGHT (C) 1991 - 2002 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.
21 # ======================================================================
25 Ce module contient des fonctions utilitaires
33 from N_Exception import AsException
38 # Si la version de Python possède la fonction _getframe
40 cur_frame=sys._getframe
43 def cur_frame(offset=0):
44 """ Retourne la frame d execution effective eventuellement en remontant
45 de offset niveaux dans la pile d execution
46 Si il y a moins de offset niveaux retourne None
50 frame=sys.exc_info()[2].tb_frame.f_back
52 if frame == None:return None
58 def callee_where(niveau=4):
60 recupere la position de l appel
62 frame=cur_frame(niveau)
63 if frame == None: return 0,"inconnu",0,{}
65 return frame.f_lineno,frame.f_code.co_filename,frame.f_code.co_firstlineno,frame.f_locals
67 return 0,"inconnu",0,{}
71 Retourne le type d'un concept (a) à partir
72 des caractéristiques de l'objet Python
74 if type(a) in (types.TupleType,types.ListType):return AsType(a[0])
75 if type(a) == types.InstanceType:return a.__class__
76 if type(a) == types.FloatType:return "R"
77 if type(a) == types.IntType:return "I"
78 if type(a) == types.StringType:return "TXM"
79 if a == None : return None
81 raise AsException("type inconnu")
85 print "*"*5 + s + "*"*5
88 def repr_float(valeur):
90 Cette fonction représente le réel valeur comme une chaine de caractères
91 sous forme mantisse exposant si nécessaire cad si le nombre contient plus de
93 NB : valeur est un réel au format Python ou une chaine de caractères représentant un réel
95 if type(valeur) == types.StringType : valeur = eval(valeur)
96 if valeur == 0. : return '0.0'
98 if abs(valeur) < 10000. : return repr(valeur)
100 if abs(valeur) > 0.01 : return repr(valeur)
102 if string.find(t,'e') != -1 or string.find(t,'E') != -1 :
103 # le réel est déjà sous forme mantisse exposant !
104 # --> on remplace e par E
105 t=string.replace(t,'e','E')
106 # --> on doit encore vérifier que la mantisse contient bien un '.'
107 if string.find(t,'.')!= -1:
110 # -->il faut rajouter le point avant le E
111 t=string.replace(t,'E','.E')
119 if string.atof(t[0]) == 0.:
120 # réel plus petit que 1
124 while string.atof(t[0]) == 0. :
131 # réel plus grand que 1
133 if string.atof(t[1:]) == 0.:
134 l=string.split(t[1:],'.')
142 if pt != 1 : cpt = cpt + 1
146 if r+1 == len(t) or string.atof(t[r+1:]) == 0.:break
147 s=s+'E'+neg*'-'+repr(cpt)