scipy/scipy — pull request #499 by sargas (2013-04-05 19:13:37+00:00)
Title: ENH: Add class for reading unformatted Fortran files

Here's a patch for adding a class for reading unformulated sequential Fortran files. This is a scratch-your-own-itch kind of thing, the defaults are the values I was using.

This is based on the ideas in http://www.scipy.org/Cookbook/FortranIO/FortranFile and http://www-astro.physics.ox.ac.uk/~Zuntz/page4/files/fortranFile.tar.gz , although I have Py3k compatibility and much simpler code due to using numpy dtypes and fromfile.

Some features of this code:
- Python2 and Python3 compatibility.
- Documented
- Tests for reading/writing
- Uses numpy.fromfile for reading
- Lets the user specify endianness and sizes with any dtype numpy accepts
- Some convenience methods for reading real*8 and integer*4, instead of specifying the dtype
- I am this available under the simplified 2-clause BSD license.

Known disadvantages:
- I couldn't find examples of generated Fortran files others have made. I also don't have access to a big-endian computer to generate test files for that. For these reasons I don't think the test coverage is varied enough.
- Some versions of Fortran supposedly don't have the ending size at the end of each record. I don't have an example of this, so I didn't add support for it, although I imagine this could be a simple flag in the __init__ constructor.
- The test files are generated on my machine (GNU Fortran 4.8.0 on Linux 3.8.5-1-ARCH x86_64, if it matters). I'm not sure where to put the Fortran code that I used to generate them; it's literally 484 bytes when compressed.