this will help I get output files from very old Fortran programs, which look like:
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Reading a direct access fortran unformatted file in Python
Hope that helps I'm completely new to Python and am writing my visualization codes in Python from scratch (to avoid using expensive proprietary programs like IDL). Until now I've used IDL and gnuplot. What I want to be able to do is this: , Here is a python code that will work for you:
f = open(inputfilename,'rb')
field = np.fromfile(f,dtype='float64',count=nx*ny)
field = np.reshape(field,(nx,ny))
Python reading unformatted direct access Fortran 90 gives incorrect output
Any of those help Unformatted Fortran binary files encode record length to delimit the records. In general the record length will be written both before and after each record, though if memory serves the details of that are processor dependent (See the second half of the post if records are not delimited in this way). Looking at the file you posted, if you interpret the first 4 bytes as an integer and the remaining bytes as 32 bit floating point values you get:
may help you . Ifort and gfortran do not use the same block size for record length by default. In ifort, the value of recl in your open statement is in 4-byte blocks, so your record length isn't 985,600 bytes, it is 3,942,400 bytes long. That means the records are written at intervals of 3.9 million bytes. gfortran uses a recl block size of 1 byte and your record length is 985,600 byes. When you read the first record, everything works, but when you read the second record you look at 985,600 bytes into the file but the data is at 3,942,400 bytes into the file. This also means you are wasting a ton of data in the file, as you are using only 1/4 of its size.
it should still fix some issue Very recently I said in an answer that people should not specify recl directly, but still so many do it... https://stackoverflow.com/a/37784431/721644 Use inquire(iolength=myrecl) as in that link and you will be much more portable.
open(unit=36, file='vel.mod', form='unformatted', access='stream')