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

William Henney w.henney@astrosmo.unam...
Mon Jun 16 08:44:43 CDT 2008


fred <fredmfp <at> gmail.com> writes:

> The trick I don't understand is that if my file is 4 bytes length,
> there is no marker, no, as in the case of a binary file written by
> say a C code ? Or I'm completely stupid ?

I think you had the right answer to start with: you must use
access='stream'

This is a new feature of Fortran 2003, but it is already supported by
most compilers.

> > BTW, which version of gfortran are you using? 
> 4.1.1 on debian etch box.

And here is your trouble - this is a very old version of gfortran. I
have 4.3.0 and the following code works fine:

----------------- streamio.f90 --------------------------
program streamio
  implicit none
  real :: a = 0.0
  open(unit=20, file='foo.dat', form='unformatted', access='stream')
  write(20) a
  close(20)
end program streamio
------------------------------------------------------

$ gfortran -o streamio streamio.f90 && ./streamio && hexdump foo.dat
0000000 00 00 00 00                                    
0000004

You might also want to read this page:

http://www.star.le.ac.uk/~cgp/streamIO.html

Cheers

Will









More information about the SciPy-user mailing list