[Numpy-discussion] example reading binary Fortran file

Francesc Alted faltet@pytables....
Tue Feb 3 03:15:16 CST 2009

A Friday 30 January 2009, David Froger escrigué:
> ok for f2py!
> > 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.
> In my experience, I never had this kind of problem. I just have to
> convert files between big/little endian with uswap
> (http://linux.die.net/man/1/uswap), but I never see, in my
> experience, a Fortran program writting data differently given the
> compilator.
> >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.
> Unfortunately., binary files are mandatory in the contex I work. I
> use a scientific code written in Fortran to compute fluid dynamics.
> Typically the simulation is run on supercalculator and generate giga
> and giga of datum, so we must use the binary format, which recquire
> less memory for the stockage. Then, I like to post-trait the datum
> using Python and Gnuplot.py.
> That's why I'm looking for a performantant, easy and 'standard'  way
> to read binary Fortran files. (I think many people have the same
> need).

If you need to compact your datafiles to a maximum, you may want to 
write your data with the HDF5 library [1] that, besides using a binary 
format, it allows on-the-flight compression.  HDF5 is a fairly growing 
standard in scientific computing and it has wrappers for the most 
important languages like C, Fortran, Java and, of course, Python ;-)
In particular, the available HDF5 interfaces to Python allows to 
read/write HDF5 native files very easily.  Also, many computational 
environments, like Matlab, Octave or IDL do support HDF5 files.

[1] http://www.hdfgroup.org/HDF5/


Francesc Alted

More information about the Numpy-discussion mailing list