[Numpy-discussion] Another question on reading from binary FORTRAN file
Christopher Barker
Chris.Barker at noaa.gov
Mon Mar 9 18:43:15 EDT 2009
> On Mon, 9 Mar 2009 21:45:42 +0100, Mark Bakker wrote:
>> 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?
there was a lengthy discussion of reading FORTRAN binary files on this
list within the last few months -- lots of good info there.
However, this is a pretty simple subset of the problem, so you might
start with the struct module:
http://www.python.org/doc/2.5.4/lib/module-struct.html
pad = 1
format = "%ixi5ixf%ix16f"%(pad,pad,pad)
num_bytes = struct.calcsize(format)
data = infile.read(struct.calcsize(format))
you will need to play with the pad value (1 or 2), and you may not need
it between the single values ( I htink this all depends on your FORTRAN
compiler)
-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 at noaa.gov
More information about the NumPy-Discussion
mailing list