[SciPy-user] reading binary files written by a gfortran code...

Benedikt Koenig lists@benair....
Mon Jun 16 03:38:55 CDT 2008


Hi Fred,



> > This was caused by the marker length Fortran uses in binary files. Ifort
> > and g77 used a length of 4 bytes, whereas gfortran uses whatever is
> > stored in "off_t" on the parcticular system. So adding the following
> > compile option to gfortran did the job for me:
> > FFLOAT = -frecord-marker=4
> I guess you mean to put this flag in a Makefile, right?
yeah, the -frecord-marker option is in my case used in the Makefile.
Actually I am using '-fdefault-real-8 -frecord-marker=4' together with
the usual OPT settings and library stuff as compile options to gfortran.

> However, how do you open and write your file in your fortran code?
> I use this:
> 
>    real :: x
> 
>    x = 0
> 
>    open(unit=20, file='a.dat', form='unformatted')
>    write(20) x
>    close(20)
> 
> With FFLOAT set as above, I still have a 20 bytes file size for one float.
> In fact, whatever I set in FFLOT (even negative values), I get the same 
> result.
Unfortunately, I am not really familiar with fortran. The code I am
using was not written by myself, I am just using the source code to
compile on different platforms I am working on. So I am not the right
one to ask about ways of Fortran.

However, IIRC Fortran writes a marker before and after every record. If
you write one real (4 byte) and you end up with 20 byte output this
seems to me like you still have the markers of 8 byte length rather than
the 4 bytes as should be the case using  -frecord-marker=4. Maybe you
want to check the hex code, that is acutally written? The record markers
should be 4 bytes length and contain the length of the record (in your
case 1 real)

BTW, which version of gfortran are you using? 

cheers,
bene


> 
> Cheers,
> 



More information about the SciPy-user mailing list