views:

303

answers:

2

I suppose the type of Y below is REAL.

      SUBROUTINE F(X, Y)
C        IMPLICIT NONE
        REAL :: X, Y
C        REAL :: A, B
C        REAL, PARAMETER :: C = 3.14E0
C        X = Y + 2 * SIN(Y)
      END

But what is it's type here?

      SUBROUTINE F(X, Y)
C        IMPLICIT NONE
        REAL X, Y
C        REAL :: A, B
C        REAL, PARAMETER :: C = 3.14E0
C        X = Y + 2 * SIN(Y)
      END

Is it implicitly typed or REAL because of the REAL token at beginning of that line? I mean what's the scope of a type declaration, just up to the , or all the way to the end of line?

And what purpose does :: serve?

(Sorry, working on a parser in a confused state at midnight makes you afraid of making wrong assumptions and wisdom of the moment says go consult others with more experience.)

+1  A: 

scope to the end of the line: Y is REAL

As for "::", it's something new in FORTRAN 90.

duffymo
Is there a way to use ifort of gfortran so that they refuse anything that's not in a specific version of the Fortran standard? When I say gfortran -x f77 -c some.f, it still does its business o__O.
Cetin Sert
+1  A: 

You have declared IMPLICIT NONE, so there is no implicit typing going on. You're correct that Y will be REAL - you're allowed to declare multiple variables on one line.

The :: character is used in Fortran 90 declarations to specify the type and options from the actual variable name. As you found, the compiler is usually happy if you leave it out, but I find that it makes it much more readable to include it.

As a side note, it looks like this code is written using FORTRAN 77 style - if it's new code you may want write the code using Fortran 90-style syntax for everything from comments to indenting (e.g. you don't have to start your commands in certain columns, there are more intrinsic functions available, dynamic memory, etc.)

Tim Whitcomb
Although in both examples he gives, IMPLICIT NONE is commented out.
Scottie T
I missed that - you're right.
Tim Whitcomb