subroutine commut(A,B,C) implicit none real, dimension(:,:), intent(in) :: A, B real, dimension(:,:), intent(out) :: C real, dimension(size(A,1),size(B,2)) :: P1 real, dimension(size(B,1),size(A,2)) :: P2 P1 = matmul(A,B) P2 = matmul(B,A) C = P1 - P2 end subroutine commutWhen using automatic arrays we have to include an interface in the calling program.
In F77 we had to explicitly pass the size of A in the argument list, and use this dummy variable to declare P1,P2:
subroutine commut(A,B,C,N) real, dimension(N,N) :: P1,P2}
Note that automatic arrays cannot have the SAVE attribute - the reason being that they can have different shapes and sizes during different procedure calls.