1

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?

3
  • 1
    simply try :character(10) tree(2,maxf) or compile with a more modern fortran compiler (>= f90) Commented Dec 19, 2017 at 20:14
  • 1
    It looks like your code is at lesst Fortran 90 and you are using a Fortran 77 compiler. Commented Dec 19, 2017 at 20:25
  • It was a rather old code, so I thought I should compile with that. Didn't think if trying a more modern compiler. I tried with gfortran and it worked with no issues. Could either of you turn your comment into an answer so I can accept it? Thank you both! Commented Dec 19, 2017 at 20:41

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't remember being exposed to variant CHARACTER TREE*10 before, nice to still learn something about f77
@aka.nice, the form character x*10 is still in modern Fortran. Indeed, it's still useful: it's the only way to override a character length declaration such as in character(len=27) x, y*10, z (much as one would see for overriding array size declarations integer, dimension(12) :: a, b(5), c).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.