[Numpy-discussion] example reading binary Fortran file

Sturla Molden sturla@molden...
Fri Jan 30 14:06:11 CST 2009


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

That is precisely why I suggested using f2py. If you let Fortran read the
file (be careful to the same compiler!), it is easy to pass the data on to
Python.

Otherwise, you will have to figure out how your Fortran program writes the
file. I.e. what padding, metainformation, etc. that are used. If you
switch Fortran compiler, or even compiler version from the same vendor,
you must start over again. On the other hand, an f2py'd solution just
requires a recompile.

For my own work, I just makes sure NEVER to do any I/O in Fortran! It is
asking for trouble. I leave the I/O to Python or C, where it belongs. That
way I know what data are written and what data are read.

S. M.



More information about the Numpy-discussion mailing list