[SciPy-user] reading binary files written by a gfortran code...
Sun Jun 15 13:31:14 CDT 2008
Fortran ( and this includes gfortran) seems to add stuff at the
beginning and end of a file.
If the unformatted fortran file just holds one array of real*8 data
the following works for me (and I think it works for real*4 as well).
It may need some modernizing...:
from numpy import *
htot =fromfile(file = file_in ,dtype=float)
c = htot.view(single)
hc = c[1:-1].view(double)
htot =fromfile(file = file_in ,dtype=float32)
hc = c[1:-1]
hc = hc.byteswap()
a1 = readbin.readbin('unf.dat')
2008/6/15 fred <email@example.com>:
> Ok, this is a well known issue that binary files written by a fortran
> program have a "special" format.
> So my question is : is it possible to write binary file _using gfortran_
> (no problem with intel fortran compiler) without this formatting ?
> Is there a peculiar syntax to the open() function ?
> I did not find any relevant information on the web.
> The obvious reason is that I have to read these files with
> scipy.io.numpyio fread method.
> SciPy-user mailing list
More information about the SciPy-user