next up previous contents
Next: Automatic Arrays Up: Procedures and Array Arguments Previous: Procedures and Array Arguments

 

Assumed-shape Arrays

 

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:

The third call is invalid because the second section reference has one dimensions whereas the declaration of the dummy has two.


next up previous contents
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 1996
Not for commercial use.