Next: Automatic Arrays
Up: Procedures and Array Arguments
Previous: Procedures and Array Arguments
Declaring dummy arrays as assumed-shape arrays is the recommended
method in Fortran 90. Consider,
PROGRAM TV
INTERFACE
SUBROUTINE gimlet(a,b)
REAL, INTENT(IN) :: a(:), b(:,:)
END SUBROUTINE gimlet
END INTERFACE
...
REAL, DIMENSION(40) :: X
REAL, DIMENSION(40,40) :: Y
...
CALL gimlet(X,Y)
CALL gimlet(X(1:39:2),Y(2:4,4:4))
CALL gimlet(X(1:39:2),Y(2:4,4)) ! invalid
...
END PROGRAM TV
SUBROUTINE gimlet(a,b)
REAL, INTENT(IN) :: a(:), b(:,:)
...
END SUBROUTINE gimlet
An assumed-shape array declaration must have the same
type, rank and kind as the actual argument. An INTERFACE
block is needed to transfer the type, kind and bounds of the actual
argument into the procedure. These can then be checked alongside the
declaration of the dummy at compile time.
Note:
- array sections can be passed so long as they are regular, that is, not
defined by vector subscripts. The reason for this is concerned with
efficiency. A vector
subscripted section will be non-trivial to find in the memory, it is
likely to be widely scattered and would
probably need to be copied on entry to the procedure and then copied back
on exit, this will create all sorts of runtime penalties.
- the actual argument cannot be an assumed-size array. If an actual
argument were an assumed-size array then the
bound / extent information of the last dimension would not be known meaning
that
the relevant information could not be passed on to a further procedure.
The third call is invalid because
the second section reference has one dimensions whereas the
declaration of the dummy has two.
Next: Automatic Arrays
Up: Procedures and Array Arguments
Previous: Procedures and Array Arguments
Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996Not for commercial use.