We have been writing large binary files of less than 2GB using C++ and reading them successfully with Fortran programs compiled with pgf95 using UNFORMATTED reads on the same Linux computer.
We have now exceeded the 2GB limit (more correctly, 2 to the power 9 bytes) and find the read fails in the Fortran programs with the message “attempt to read past end of file”.
The C++ program writes the data as described in the following pseudo code:
int nloci = 45000;
int nanis = 3000;
int bytesInArray = nloci * nanis * 8;
double cz (nloci,nanis);
write (bostream, bytesInArray);
write (bostream, cz);
write (bostream, bytesInArray);
The Fortran programs read the file in the following way:
double precision, dimension(:,:), allocatable :: z
integer nloci = 45000
integer nanis = 3000
allocate( z(nloci,nanis))
open(32,file=infile,status=‘old’,form=‘unformatted’)
read(32) z
close(32)
The Fortran code is complied with the -Mlarge_arrays option.
The focus of our search for a solution has been the Type and Value of the first record in the file (ie, bytesInArray).
If bytesInArray is less than 2 to the power 9, then it can be stored in a variable of Type integer and correctly specifies the number of bytes to follow in the binary array.
If bytesInArray is more than 2 to the power 9, then it will overflow an integer and no longer specify the number of bytes in the array.
What does a Fortran UNFORMATTED read expect to find at the beginning of a file if the file is more than 2 GB?
Any suggestions that will help us solve our problem will be greatly appreciated.