1 #@ MODIF N_utils Noyau DATE 27/03/2002 AUTEUR DURAND C.DURAND
2 # CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
20 # ======================================================================
22 Ce module contient des fonctions utilitaires
30 from N_Exception import AsException
35 # Si la version de Python possède la fonction _getframe
37 cur_frame=sys._getframe
40 def cur_frame(offset=0):
41 """ Retourne la frame d execution effective eventuellement en remontant
42 de offset niveaux dans la pile d execution
43 Si il y a moins de offset niveaux retourne None
47 frame=sys.exc_info()[2].tb_frame.f_back
49 if frame == None:return None
55 def callee_where(niveau=4):
57 recupere la position de l appel
59 frame=cur_frame(niveau)
60 if frame == None: return 0,"inconnu",0,{}
62 return frame.f_lineno,frame.f_code.co_filename,frame.f_code.co_firstlineno,frame.f_locals
64 return 0,"inconnu",0,{}
68 Retourne le type d'un concept (a) à partir
69 des caractéristiques de l'objet Python
71 if type(a) in (types.TupleType,types.ListType):return AsType(a[0])
72 if type(a) == types.InstanceType:return a.__class__
73 if type(a) == types.FloatType:return "R"
74 if type(a) == types.IntType:return "I"
75 if type(a) == types.StringType:return "TXM"
76 if a == None : return None
78 raise AsException("type inconnu")
82 print "*"*5 + s + "*"*5
85 def repr_float(valeur):
87 Cette fonction représente le réel valeur comme une chaine de caractères
88 sous forme mantisse exposant si nécessaire cad si le nombre contient plus de
90 NB : valeur est un réel au format Python ou une chaine de caractères représentant un réel
92 if type(valeur) == types.StringType : valeur = eval(valeur)
93 if valeur == 0. : return '0.0'
95 if abs(valeur) < 10000. : return repr(valeur)
97 if abs(valeur) > 0.01 : return repr(valeur)
99 if string.find(t,'e') != -1 or string.find(t,'E') != -1 :
100 # le réel est déjà sous forme mantisse exposant !
101 # --> on remplace e par E
102 t=string.replace(t,'e','E')
103 # --> on doit encore vérifier que la mantisse contient bien un '.'
104 if string.find(t,'.')!= -1:
107 # -->il faut rajouter le point avant le E
108 t=string.replace(t,'E','.E')
116 if string.atof(t[0]) == 0.:
117 # réel plus petit que 1
121 while string.atof(t[0]) == 0. :
128 # réel plus grand que 1
130 if string.atof(t[1:]) == 0.:
131 l=string.split(t[1:],'.')
139 if pt != 1 : cpt = cpt + 1
143 if r+1 == len(t) or string.atof(t[r+1:]) == 0.:break
144 s=s+'E'+neg*'-'+repr(cpt)