I've inherited both the source code and a compiled executable for a Fortran77 program. I do not know what compiler was used to make the existing executable, however I'm using GCC 4.9.2. Among other things, the program reads and writes records from/to a binary file. The number of records is also stored in the beginning of the file.
My problem is that the executable I compile myself incorrectly reads the number of records from the file, and consequently throws an error when it tries to read past the last record. The binary data file was generated using the existing executable (the one I inherited), and surprisingly, when I use the existing executable to read from the data file, it works as expected.
My question is, could the Fortran READ/WRITE statements have different semantics (such as file layout) depending on the platform, fortran version, or compiler type/version?
For what it's worth, the read and write code is
WRITE(INLIB,REC=1)NPROD,(ELMNTS(K),K=1,ITE),(ATOMWT(KK),KK=1,
+ ITE),IOUT,INFILE,ITERM,IBM,LINEPR
READ(INLIB,REC=1)NPROD,(ELMNTS(K),K=1,ITE),(ATOMWT(KK),KK=1,ITE)
+ ,IOUT,INFILE,ITERM,IBM,LINEPR
NPROD
is the number of records in the file. When I put a break point after the READ
statement, I can see that NPROD
is about 300,000, when I know for a fact that there are only about 2,000 records.
This is the code for opening the file:
OPEN(UNIT=INLIB,FILE='PRODUCT.BIN',ACCESS='DIRECT',RECL=1188,
+ STATUS='OLD')
With regard to endianess, I think my current platform is compatible with the binary data file because if I open it in a hex editor, I can see some legible ASCII text that makes sense in the context of the program.