fortran - Parameter encoding in gfortran module files -
let's have module:
module testparam real, parameter :: x=1.0, xx=10.0 real, parameter :: pi=3.14 end module testparam
compile with
gfortran -c testparam.f90
and in generated module file
cp testparam.mod testparam.gz gunzip testparam.gz
the trimmed output is:
(2 'pi' 'testparam' '' 1 ((parameter unknown-intent unknown-proc unknown implicit-save 0 0) () (real 4 0 0 0 real ()) 0 0 () (constant (real 4 0 0 0 real ()) 0 '0.323d70c@1') () 0 () () 0 0) 4 'x' 'testparam' '' 1 ((parameter unknown-intent unknown-proc unknown implicit-save 0 0) () (real 4 0 0 0 real ()) 0 0 () (constant (real 4 0 0 0 real ()) 0 '0.1000000@1') () 0 () () 0 0) 5 'xx' 'testparam' '' 1 ((parameter unknown-intent unknown-proc unknown implicit-save 0 0) () (real 4 0 0 0 real ()) 0 0 () (constant (real 4 0 0 0 real ()) 0 '0.a000000@1') () 0 () () 0 0)
then can see value of x has been stored '0.1000000@1' , pi has been stored '0.323d70c@1' , xx '0.a000000@1'. how can convert string encoded parameter number?
given value of x term assumed simply, format a@b, a*10^b value pi hex encoded (and xx variable int(0xa)==10.0 @ least part of hex). maybe sort of hex encoded floating point number?
with of @roygvib comment works python
def hextofloat(s): # given hex parameter '0.12decde@9' returns 5065465344.0 man, exp =s.split('@') exp=int(exp) decimal = man.index('.') man = man[decimal+1:] man = man.ljust(exp,'0') man = man[:exp]+'.'+man[exp:] man = man +'p0' return float.fromhex(man)
split string value mantisa (0.12decde) , exponent (9), hex number right of decimal place (12decde) , pad enough zeros (12decde00) @ least long exponent, put decimal place in (12decde00.0) put 'p0' (12decde00.p0) on end , pass float.fromhex()
Comments
Post a Comment