2

I'm attempting to compile Fortran code that was written and compiled in the late eighties on a DEC operating system. I'm not sure what version of Fortran the code is written in.

I'm on macOS version 10.14.6, and using gfortran version 8.2.0.

When I attempt to compile on the command-line with:

gfortran -v -fdec- o test CODE.FOR

I receive the following error:

CODE.FOR:1618:72: CODE.FOR: 1599:72: CODE.FOR:1618.72: Error: Variable 'j' at (1) cannot be redefined inside loop beginning at (2) 

When I look at the line 1618, I see: J=J-1, which is inside a DO loop.

Is the code so old that this used to compile on an older compiler but now on gfortran it won't allow variable j to be changed in a DO loop?

 DO 10 J=1,NMAX WRITE(6,*)' Give STA NAME, COMP(Z, R, or T), and WAVE TYPE (P, SV, * or SH)' WRITE(6,*)' Enter blanks to quit' WRITE(6,*)' Reenter STA NAME, COMP and WAVE TYPE to replace old or *incorrect data' WRITE(6,*)' Separate each entry by a space (STA NAME is 4 chars)' READ(5,2) SN(J),COMP(J),PS(J) 2 FORMAT(A,1X,A,1X,A) IF (SN(J).EQ.' ') GO TO 900 WRITE(6,*)' Give DIST, AZ, and AMP' READ(5,*) R(J),AZ(J),AMP(J) IF (J.GT.1) THEN DO 11 I=1,J-1 IF (SN(J).EQ.SN(I).AND.COMP(J).EQ.COMP(I).AND.PS(J).EQ.PS(I)) * THEN R(I)=R(J) AZ(I)=AZ(J) AMP(I)=AMP(J) J=J-1 GO TO 10 END IF 11 CONTINUE END IF 10 CONTINUE 
8
  • We really need to see that code. However, you must likely have to correct the code to be standard conforming. Your code is not valid Fortran and it wasn't valid Fortran in the 80s either. Commented Nov 14, 2020 at 19:34
  • 1
    But if it is doing what you are saying the code is broken - this has never been allowed in standard Fortran. You will have to find a compiler than offers it as an extension - I don't know of one. Commented Nov 14, 2020 at 19:35
  • @VladimirF What's the best way for me to share the code? Commented Nov 14, 2020 at 19:44
  • The code on this site should always be copy-pasted in the question itself. Just make a relevant example. The loop is probably enough and the inside can be simplified. Commented Nov 14, 2020 at 19:48
  • 1
    Apparently the DEC compiler around the time of the transition from F66 to F77 allowed this with a warning. From ibiblio.org/pub/languages/fortran/ch2-18.html " There are compilers (e.g. DEC FORTRAN), that some of the time do use the control-variable to test for termination, in this case changing its value may cause wrong results (DEC FORTRAN issues a warning when doing so). Anyway, this is a bad programming practice." Commented Nov 14, 2020 at 23:06

1 Answer 1

6

You are changing the iteration variable J of loop

DO 10 J=1,NMAX 

in

J=J-1 

That is not allowed.

You can easily rewrite any indexed DO loop to a non-indexed do loop.

 DO 10 J=1,NMAX if (..) J = J - 1 10 CONTINUE 

becomes

 J = 1 DO if (..) J = J - 1 J = J + 1 if (J > NMAX) exit END DO 

or

 J = 1 DO WHILE (J<=NMAX) if (..) J = J - 1 J = J + 1 END DO 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.