Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spurious syntax error in gfortran READ

Status
Not open for further replies.

RichOlson

Technical User
Nov 16, 2011
2
US
I am getting what I believe to be a spurious syntax error in some old Fortran that I am compiling. A small example illustrates the error
Code:
      PROGRAM TEST
      IMPLICIT REAL*8 (A-H, O-Z)
      READ (I1) NFS
      READ (I1) (FUSGAM(J), J=1,NFS)
      END
gives the following message
Code:
test.F:4.15:

      READ (I1) (FUSGAM(J), J=1,NFS)                                    
               1
Error: Expected variable in READ statement at (1)

Thanks for any help that you can give.


 
I see at least two mistakes :

- You are using a file unit I1 which is undefined. Is it a typo ? 11 could be possible instead because a file unit is always an integer value.

- the variable FUSGAM is undefined. The compiler assumes that FUGSAM is and external function but, in that case, the instruction has no meaning.

In addition, you don't open the file (this is sometimes possible if the file has the name fort.11 for instance). I also suggest the use of IMPLICIT NONE to avoid this kind of mistake due to a problem variable declaration.

Example of corrected version

Code:
      PROGRAM TEST
      IMPLICIT NONE      
      REAL*8 FUSGAM(20)
      INTEGER NFS,J
      OPEN(11,FILE="TOTO",FORM='UNFORMATTED')
      READ (11) NFS
      READ (11) (FUSGAM(J),J=1,NFS)
      WRITE(*,*) (FUSGAM(J),J=1,NFS)
      END

François Jacq
 
Thank you Francois. Your response led me back to the declaration of FUSGAM, which is in a COMMON block in an include file. There was a typo in the declaration of FUSGAM which caused the reference to FUSGAM in the READ statement to be interpreted as a function reference.

My apologies for cutting my example so severely that it was almost unusable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top