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

fred fredmfp at gmail.com
Mon Jun 16 04:11:54 EDT 2008


Benedikt Koenig a écrit :
> Hi Fred,
Hi Benedikt,

> I am not sure whether I get you question right, but I once had the
> problem, that a program complied with gfortran could not read binaries
> written by the same version but compiled with ifort or g77.
One can say it like this, yes ;-)
I want my program compiled with gfortran to write binary files with the 
_right_ size, say, 1 float -> 4 bytes.
No more, no less ;-)

> 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?
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.

Cheers,

-- 
Fred



More information about the SciPy-User mailing list