What is wrong with this Fortran '77 snippet?

Posted by notJim on Stack Overflow See other posts from Stack Overflow or by notJim
Published on 2010-05-16T20:41:54Z Indexed on 2010/05/16 20:50 UTC
Read the original article Hit count: 222

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about fortran77

Related posts about gfortran