next up previous contents
Next: Automatic Arrays Up: Array Arguments Previous: Explicit Shape Arrays   Contents

Assumed Shape Arrays

We want the routine to work for square arrays of any dimension. To allow this, the recommended method in F90 is to declare dummy array arguments as assumed shape arrays:
subroutine commut(A,B,C)
  implicit none
  real, dimension(:,:), intent(in)  :: A, B
  real, dimension(:,:), intent(out) :: C
  C = matmul(A,B)-matmul(B,A)
end subroutine commut
An assumed-shape declaration must have the same type and rank as the actual argument declaration.

When the subroutine is called, the dummy arrays A,B,C assume the shape of the associated actual arguments. The actual argument can be an array, or an array section, but needs to have an explicit shape. An assumed-shape array as actual argument lacks the bound/extent information and cannot be passed on to a further procedure. Note that the program units which call procedures with assumed shape arguments need to have explicit interfaces available at the point of call (we will iscuss later about this).

Note that, whenever an external subroutine uses assumed-shape array arguments, the calling program must contain an interface of the respective procedure. This allows the compiler to prepare the necessary information when passing array arguments. An interface is placed before local declarations; it contains the subroutine headers and argument declarations. The syntax can be viewed in the following example:

interface
 subroutine commut(A,B,C)
  implicit none
  real, dimension(:,:), intent(in)  :: A, B
  real, dimension(:,:), intent(out) :: C
 end subroutine commut
end interface


next up previous contents
Next: Automatic Arrays Up: Array Arguments Previous: Explicit Shape Arrays   Contents
Adrian Sandu 2001-08-26