toliveira
toliveira

Reputation: 1703

Reading large binary files with gfortran / size of RECL= of the OPEN statement

The following portion of code works correctly when RECL < 2,147,483,647:

mult = imax*jmax*kmax*sizeofdouble
PRINT *,mult
OPEN (UNIT=2000, FILE=binaryFile, FORM='unformatted',access='direct',recl=mult)
READ (2000,rec=1) fromBinary
CLOSE (2000)

For larger values, even though mult is printed correctly (it is a 64-bit integer), I get the error Fortran runtime error: RECL parameter is non-positive in OPEN statement. Apparently, this is due to the bug #44292.

Beside using another compiler, do you see a way of rewriting the above piece of code so that I don't need to use large values for RECL?

Upvotes: 1

Views: 713

Answers (1)

It is not guaranteed, but very likely your file will be readable with the stream access too. Especially with gfortran.

OPEN (UNIT=2000, FILE=binaryFile, FORM='unformatted',access='stream')
READ (2000) fromBinary
CLOSE (2000)

It will read as many bytes as necessary depending on the size of the array fromBinary.

The advantage is that there is no processor dependence and the stream files are the same for all compilers. Still one should be cautios about endianness as with all unformatted files.

Upvotes: 2

Related Questions