I've been tasked with maintaing some legacy fortran code, and I'm having trouble getting it to compile with gfortran. I've written a fair amount of Fortran 95, but this is my first experience with Fortran 77. This snippet of code is the problematic one:
CHARACTER*22 IFILE, OFILE
IFILE='TEST.IN'
OFILE='TEST.OUT'
OPEN(5,FILE=IFILE,STATUS='NEW')
OPEN(6,FILE=OFILE,STATUS='NEW')
common/pabcde/nfghi
When I compile with gfortran file.FOR
, all lines starting with the common
statement are errors (e.g. Error: Unexpected COMMON statement at (1)
for each following line until it hits the 25 error limit). I compiled with -Wall -pedantic
, but fixing the warnings did not fix this problem.
The crazy thing is that if I comment out all 4 lines starting with IF='TEST.IN'
, the program compiles and works as expected, but I must comment out all of them. Leaving any of them uncommented gives me the same errors starting with the common
statement. If I comment out the common
statement, I get the same errors, just starting on the following line.
I am on OS X Leopard (not Snow Leopard) using gfortran
. I've used this very system with gfortran
extensively to write Fortran 95 programs, so in theory the compiler itself is sane. What the hell is going on with this code?
Edit: Compiling with g77 gives:
test.FOR: In program `MAIN__':
test.FOR:154:
IFILE='TEST.IN'
1
test.FOR:158: (continued):
common/pabcde/nfghi
2
Statement at (2) invalid in context established by statement at (1)
Er, what context is established at (1)?