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 commutAn 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