Search code examples
debuggingfortranfortran77legacy-code

Syntax error compiling old Fortran code


I'm trying to compile legacy Fortran code with fort77. The command:

fort77 -c leg_code.f leg_code.o

fails with:

Error on line XXX: syntax error

Line XXX reads:

CHARACTER(LEN=10) TREE(2,MAXF)

where MAXF is defined some lines above with:

  INTEGER MAXF, MAXC
  PARAMETER (MAXF=400, MAXC=20)

If I remove (LEN=10), the code compiles with no issues.

Anyone know the reason for this error?


Solution

  • As noted in the comments, the declaration statement

    CHARACTER(LEN=10) TREE(2,MAXF)
    

    is not valid in Fortran 77. This form, declaring a rank-2 array of character of length 10, was introduced to standard Fortran in the Fortran 90 revision.

    To declare such a variable in Fortran 77 the alternative form

    CHARACTER*10 TREE(2,MAXF)
    

    or

    CHARACTER TREE(2,MAXF)*10
    

    would be required. Simply removing the (len=10), as in

    CHARACTER TREE(2,MAXF)
    

    declares the variable to be an array of character of length 1, but this is valid in Fortran 77.