[Numpy-discussion] example reading binary Fortran file
Christopher Barker
Chris.Barker@noaa....
Fri Jan 30 11:30:34 CST 2009
> If you want to be completely safe, read the file in Fortran, then send
> it as an array to Python (use f2py). Aside from that, assuming your
> compiler only writes the raw bytes in Fortran order to the file:
Careful -- the last time I read a Fortran-=written binary file, I found
that the various structures (is that what you call them in Fortran?)
were padded with I think 4 bytes.
I did it by reading through the file bit by bit and parsing it out with
the struct module. Not very efficient, but easy to control.
In that case, there were a bunch of tings written, where a few values
described the size of the next array, then the array, etc. If you've got
a single array, it'll be easier.
You might start that way, and then, when you've got it figured out,
translate to fromfile().
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
More information about the Numpy-discussion
mailing list