Fortran Why Am I Getting a Parenthesis Error in FORTRAN Code Compilation?

  • Thread starter Thread starter FatLynn
  • Start date Start date
  • Tags Tags
    Code Fortran
Click For Summary
The discussion centers around a compilation error encountered while trying to run an old FORTRAN code in gfortran, specifically an issue with a Hollerith constant. The error message indicates a problem with the syntax, particularly in the line containing '1H( ,1H1 ,1HX'. Participants explain that this line is likely misformatted due to the removal of leading spaces, which are crucial for maintaining the columnar structure required by older FORTRAN standards. The leading '1' is identified as a continuation character that should have been positioned in column 6, indicating that the line continues from the previous one. This misalignment is attributed to the code's historical context, suggesting it was originally written on punch cards. Recommendations include restoring the proper indentation and explicitly indicating Hollerith characters for compatibility with modern compilers.
FatLynn
Messages
1
Reaction score
0
Hello, I received some very old cold, and I don't even know for which FORTRAN standard it was originally written, only that it has existed since at least 1993. I'm trying to compile it in gfortran, and I get the following error:

'Error: Expected a right parenthesis in expression at (1)'
1 / 1H( ,1H1 ,1HX ,1H, ,1H ,1H ,1HA ,1H ,1H ,1H) /
1

The code is shown below, and the line indicated in the error message is the fourth line of the code shown here. Anyone know why I am getting this issue?

INTEGER F(10),G(14),LUN(5)
DIMENSION MESSG(NMESSG)
DATA F(1),F(2),F(3),F(4),F(5),F(6),F(7),F(8),F(9),F(10)
1 / 1H( ,1H1 ,1HX ,1H, ,1H ,1H ,1HA ,1H ,1H ,1H) /
DATA G(1),G(2),G(3),G(4),G(5),G(6),G(7),G(8),G(9),G(10)
1 / 1H( ,1H1 ,1HX ,1H ,1H ,1H ,1H ,1H ,1H ,1H /
DATA G(11),G(12),G(13),G(14)
1 / 1H ,1H ,1H ,1H) /
DATA LA/1HA/,LCOM/1H,/,LBLANK/1H /
C PREPARE FORMAT FOR WHOLE LINES
C***FIRST EXECUTABLE STATEMENT XERPRT
NCHAR = I1MACH(6)
NFIELD = 72/NCHAR
CALL S88FMT(2,NFIELD,F(5))
CALL S88FMT(2,NCHAR,F(8))
C PREPARE FORMAT FOR LAST, PARTIAL LINE, IF NEEDED
NCHARL = NFIELD*NCHAR
NLINES = NMESSG/NCHARL
NWORD = NLINES*NFIELD
NCHREM = NMESSG - NLINES*NCHARL
IF (NCHREM.LE.0) GO TO 40
DO 10 I=4,13
10 G(I) = LBLANK
NFIELD = NCHREM/NCHAR
IF (NFIELD.LE.0) GO TO 20
C PREPARE WHOLE WORD FIELDS
G(4) = LCOM
CALL S88FMT(2,NFIELD,G(5))
G(7) = LA
CALL S88FMT(2,NCHAR,G(8))
20 CONTINUE
NCHLST = MOD(NCHREM,NCHAR)
IF (NCHLST.LE.0) GO TO 30
C PREPARE PARTIAL WORD FIELD
G(10) = LCOM
G(11) = LA
CALL S88FMT(2,NCHLST,G(12))
30 CONTINUE
40 CONTINUE
C PRINT THE MESSAGE
NWORD1 = NWORD+1
NWORD2 = (NMESSG+NCHAR-1)/NCHAR
CALL XGETUA(LUN,NUNIT)
DO 50 KUNIT = 1,NUNIT
IUNIT = LUN(KUNIT)
IF (IUNIT.EQ.0) IUNIT = I1MACH(4)
IF (NWORD.GT.0) WRITE (IUNIT,F) (MESSG(I),I=1,NWORD)
IF (NCHREM.GT.0) WRITE (IUNIT,G) (MESSG(I),I=NWORD1,NWORD2)
50 CONTINUE
RETURN
END
 
Technology news on Phys.org
I don't know Fortran, but from a general knowledge of programming, this seems to be a syntax error:
FatLynn said:
1H( ,1H1 ,1HX
You must have something after the opening bracket and before the first comma.
 
I believe that for some old FORTRAN compilers that is not a syntax error.

What you are seeing is called a Hollerith Constant, described here
which consist of a positive integer constant followed by H followed by
the integer constant number of characters, so 1H( is a one byte constant
containing the character (
and that would be followed by the character 1 followed by the character X

Documentation describing GNU FORTRAN support for Hollerith Constants
described here
 
Last edited:
  • Like
Likes FactChecker
What happened to the indentation?

Columns 1-5 are for statement number
C in column 1 makes the rest of the line a comment.
Non blank in column 6 means a continuation of the previous line.
Columns 7-71 are for the FORTRAN
Columns 72-80 are for the sequence number.

FatLynn said:
1 / 1H( ,1H1 ,1HX ,1H, ,1H ,1H ,1HA ,1H ,1H ,1H) /

I suspect that leading 1 is not part of the code, it should have been in column 6 to signal that line is a continuation of the previous line.I suspect that leading 1 was meant to be in column 6. It is not part of the code but a signal that the line is a continuation of the previous line.

If someone threw away the leading blanks on all lines they F*ed up the code.
 
  • Like
  • Informative
Likes FactChecker, Klystron and jedishrfu
Yes I think @anorlunda nailed it. The program was probably written on punch cards and later saved as a file. Whoever did it, didnt realize the need to keep the columnar format of fortran.
 
Also, using a modern or semi-modern compiler, best to explicitly indicate Hollerith characters.
 
anorlunda said:
What happened to the indentation?

Bingo. The 1 is almost certainly a continuation character, and used to be in column 6.
 
  • Like
Likes jedishrfu

Similar threads

  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 9 ·
Replies
9
Views
9K
  • · Replies 1 ·
Replies
1
Views
3K