I have a binary file with data written in real*4
, 6 variables 18 times.
However, due to Fortran end padding, the file size is
18*(4+6*4+4) = 576.
I tried several ways but couldn't solve this
1)
sdfdffrom scipy.io import FortranFile
fname='2006.bin'
f = FortranFile(fname, 'r')
print( f.read_reals( dtype='float32' ))
I got
Error -only length-1 arrays can be converted to Python scalars
2) this is actually not correct I guess
f = open(fname, 'rb')
recl = np.fromfile(f, dtype='int64', count=1)
f.seek(8)
field = np.fromfile(f, dtype='float32')
print('Record length=',recl)
The data file is written using the following Fortran code
INTEGER,PARAMETER :: r_sngl=kind(0.0e0)
REAL(r_sngl) :: wk(6)
OPEN(90,FILE=obsf,FORM='unformatted',ACCESS='sequential')
WRITE(90) wk
sample wk is like
144 42.856 406.811 -0.2191941E-04 0.1000000E-04 0.3363116E-43