Minimal sample for reading a fortran unformatted data from Mathematica

Reference : Google search: fortran unformatted file structure

a sample fortran source code


INTEGER,PARAMETER::NDAT=256;
REAL(8),DIMENSION(0:NDAT-1)::dat=1D0
OPEN(1,FILE='dirname/filename',FORM='UNFORMATTED')
WRITE(1)NDAT
WRITE(1)dat
CLOSE(1)
END
an example of corresponding reading Mathematica script

str=OpenRead["dirname/filename",BinaryFormat->True]
len=BinaryRead[str,"Integer32"] <- this line reads record header written by WRITE(1)NDAT.
ndat=BinaryRead[str,"Integer32"] <- this line reads "NDAT" data.
Skip[str,"Integer32"] <- this line skips the 4 byte trailer of the first line.
len=BinaryRead[str,"Integer32"] <- this line reads record header written by WRITE(1)dat and the variable "len" has the BYTE size of "dat" record.
dat=BinaryReadList[str,"Real64",len/8] <- this line reads "dat" data. "len/8" gives the number of "dat" elements.
Skip[str,"Integer32"]
Close[str]