[Numpy-discussion] Another question on reading from binary FORTRAN file
Michael S. Gilbert
michael.s.gilbert@gmail....
Mon Mar 9 17:21:45 CDT 2009
On Mon, 9 Mar 2009 21:45:42 +0100, Mark Bakker wrote:
> Hello -
>
> I tried to figure this out from the list, but haven't succeeded yet.
>
> I have a simple FORTRAN binary file.
> It contains:
> 1 integer
> 1 float
> 1 array with 16 numbers (float)
>
> How do I read these into Python?
I figured this out a long time (4 years) ago, but haven't thought about
it for a while, so I don't really have the answer, but I can provide
a little guidance. Fortran pads its output, so you just have to
figure out how the padding works and how to get around it to get the
information that you actually need.
I suggest writing out some examples via fortran and using hexdump to
view the results, then you can determine the pattern. For example,
you would get something like:
$ hexdump -C fort.out
0000008 0000000F 00000008
when you use fortran to write 15 as an integer. Then you can use
python's binary file i/o to read in the file and extract the
information that you are interested in. Hope this helps.
Regards,
Mike
More information about the Numpy-discussion
mailing list