1 # -*- coding: utf-8 -*-
2 #@ MODIF N_utils Noyau DATE 27/03/2002 AUTEUR DURAND C.DURAND
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 # ======================================================================
23 Ce module contient des fonctions utilitaires
31 from N_Exception import AsException
36 # Si la version de Python possède la fonction _getframe
38 cur_frame=sys._getframe
41 def cur_frame(offset=0):
42 """ Retourne la frame d execution effective eventuellement en remontant
43 de offset niveaux dans la pile d execution
44 Si il y a moins de offset niveaux retourne None
48 frame=sys.exc_info()[2].tb_frame.f_back
50 if frame == None:return None
56 def callee_where(niveau=4):
58 recupere la position de l appel
60 frame=cur_frame(niveau)
61 if frame == None: return 0,"inconnu",0,{}
63 return frame.f_lineno,frame.f_code.co_filename,frame.f_code.co_firstlineno,frame.f_locals
65 return 0,"inconnu",0,{}
69 Retourne le type d'un concept (a) à partir
70 des caractéristiques de l'objet Python
72 if type(a) in (types.TupleType,types.ListType):return AsType(a[0])
73 if type(a) == types.InstanceType:return a.__class__
74 if type(a) == types.FloatType:return "R"
75 if type(a) == types.IntType:return "I"
76 if type(a) == types.StringType:return "TXM"
77 if a == None : return None
79 raise AsException("type inconnu")
83 print "*"*5 + s + "*"*5
86 def repr_float(valeur):
88 Cette fonction représente le réel valeur comme une chaine de caractères
89 sous forme mantisse exposant si nécessaire cad si le nombre contient plus de
91 NB : valeur est un réel au format Python ou une chaine de caractères représentant un réel
93 if type(valeur) == types.StringType : valeur = eval(valeur)
94 if valeur == 0. : return '0.0'
96 if abs(valeur) < 10000. : return repr(valeur)
98 if abs(valeur) > 0.01 : return repr(valeur)
100 if string.find(t,'e') != -1 or string.find(t,'E') != -1 :
101 # le réel est déjà sous forme mantisse exposant !
102 # --> on remplace e par E
103 t=string.replace(t,'e','E')
104 # --> on doit encore vérifier que la mantisse contient bien un '.'
105 if string.find(t,'.')!= -1:
108 # -->il faut rajouter le point avant le E
109 t=string.replace(t,'E','.E')
117 if string.atof(t[0]) == 0.:
118 # réel plus petit que 1
122 while string.atof(t[0]) == 0. :
129 # réel plus grand que 1
131 if string.atof(t[1:]) == 0.:
132 l=string.split(t[1:],'.')
140 if pt != 1 : cpt = cpt + 1
144 if r+1 == len(t) or string.atof(t[r+1:]) == 0.:break
145 s=s+'E'+neg*'-'+repr(cpt)