Syntax error in DATA statement

2.4k Views Asked by At

I have this code in a Fortran project:

ITEGER IV, IY
DIMENSION IV(NTAB,IDEPTH)
DIMENSION IY(IDEPTH)
DATA IV,IY /(IDEPTH*NTAB)*0,IDEPTH*0)/

Attempting to compile the project generates this error:

    DATA IV,IY /(IDEPTH*NTAB)*0,IDEPTH*0)/
                1

Syntax error in DATA statement at (1).

This worked under f77/g77 (gcc 4.1), but a recent upgrade has moved us to gcc 4.4 and gfortran. Now this code is causing errors but I just can't see the problem.

1

There are 1 best solutions below

0
Alexander Vogt On BEST ANSWER

My guess is that this was an extension to the Standard, which is not supported any more. The FORTRAN 77 Standard, ch. 9.1 states that the repeat value shall be a

nonzero, unsigned, integer constant or the symbolic name of such a constant.

As such, the IDEPTH*NTAB is not allowed as repeat value.

You can circumvent this by using another constant that constitutes the product:

      PROGRAM test
        INTEGER IV, IY
        INTEGER,PARAMETER :: NTAB=1,IDEPTH=1
        INTEGER,PARAMETER :: PROD=NTAB*IDEPTH

        DIMENSION IV(NTAB,IDEPTH)
        DIMENSION IY(IDEPTH)

        DATA IV,IY /PROD*0,IDEPTH*0/
      END

Or, to make it strictly FORTRAN 77 compliant:

      PROGRAM test
        INTEGER IV, IY
        INTEGER NTAB,IDEPTH
        INTEGER PROD

        PARAMETER (NTAB=1,IDEPTH=1)
        PARAMETER (PROD=NTAB*IDEPTH)

        DIMENSION IV(NTAB,IDEPTH)
        DIMENSION IY(IDEPTH)

        DATA IV,IY /PROD*0,IDEPTH*0/
      END