Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does dimension work in Fortran

I don't get why

IMPLICIT REAL*8(A-Z)
DIMENSION A(20)

compiles fine, and

REAL*8, DIMENSION A(20)

results in error

Missing dimension specification at ...

like image 850
Lev K. Avatar asked Oct 27 '25 14:10

Lev K.


2 Answers

Those are two different meanings of dimension. The first is a dimension statement and the second you mean to specify the dimension attribute in a declaration.

In a declaration where attributes are specified it is necessary to have :::

REAL*8, DIMENSION(20) :: A

Note also that the array specification comes attached to the dimension, not to the variable name.

Use of :: is merely optional in a dimension statement (except in Fortran 77 where it wasn't allowed).

However, it is simply allowed to write

real*8 A(20)

as the dimension attribute is also specified by giving the array specification.


It's possibly also worth noting that, as the declaration line in the question is incorrect, that in fixed-form source the mistake is different.

In fixed-form source, spaces are not of note (beyond the column layout), so

      real*8, dimension a(20)

is the statement

      real*8 dimensiona(20)

with an extraneous comma.

like image 131
francescalus Avatar answered Oct 30 '25 06:10

francescalus


IMPLICIT REAL*8(A-Z)
DIMENSION A(20)

is the array statement declaration introduced in earlier versions of fortran (see this link for example), and it works that way.

REAL*8, DIMENSION A(20)

is not f77, nor f90 or other. Fortran 90 and above uses this

REAL*8, DIMENSION(20) :: A
like image 37
innoSPG Avatar answered Oct 30 '25 07:10

innoSPG