trailm
trailm

Reputation: 65

Parameter List: Meaning of Parenthesis after Name

I'm trying to understand some Fortran code that was passed to me. This is the argument list in a subroutine:

INTEGER, INTENT(IN) :: NKT
REAL, INTENT(IN)    :: NW2(NKT), VAR, SUE
REAL, INTENT(INOUT)   :: MYSPC(NKT,NKT)

I understand the declarations of NKT, VAR, and SUE. But what is the meaning of "(NKT)" and "(NKT,NKT)" in NW2(NKT), MYSPC(NKT,NKT)? Does NKT specify the dimensions of the arrays NW2 and MYSPC? Or is it saying the subroutine stores the passed value in the NKTth position of NW2?

I'm really confused by the usage of () after a variable. It's not covered in the "Introduction to FORTRAN 90" book by Nyhoff. Any help would be appreciated.

(Code is a modified segment of Wavewatch, http://polar.ncep.noaa.gov/waves/wavewatch/)

Upvotes: 2

Views: 256

Answers (3)

casey
casey

Reputation: 6915

To possibly help you reconcile this with your book, consider that

REAL, INTENT(IN)    :: NW2(NKT)
REAL, INTENT(INOUT)   :: MYSPC(NKT,NKT)

is equivalent to

REAL, INTENT(IN), DIMENSION(NKT)  :: NW2
REAL, INTENT(INOUT), DIMENSION(NKT,NKT)  :: MYSPC

These are two ways of saying the same thing when declaring arrays.

Upvotes: 1

M. S. B.
M. S. B.

Reputation: 29391

It's the old style of declaring an array. Your book probably emphasizes the new style of dimension () before the ::. Some might consider it an advantage of this style that arrays and scalars can be mixed on the same declaration, as is done in the second line of your example. I prefer the new style.

Upvotes: 3

janneb
janneb

Reputation: 37198

In your example, NW2(NKT), is an array with NKT elements, MYSPC(NKT,NKT) is a NKTxNKT 2D array. If your Fortran book doesn't cover this, really, get a better book. If you have some previous programming experience, I recommend "Modern Fortran Explained" by Metcalf, Reid, and Cohen.

Upvotes: 5

Related Questions