As well as returning `conventional' scalar results, functions can return pointers, arrays or derived types. For array valued functions the size of the result can be determined in a fashion which is similar to the way that automatic arrays are declared.
Consider the following example of an array valued function:
PROGRAM proggie IMPLICIT NONE INTEGER, PARAMETER :: m = 6 INTEGER, DIMENSION(M,M) :: im1, im2 ... IM2 = funnie(IM1,1) ! invoke ... CONTAINS FUNCTION funnie(ima,scal) INTEGER, INTENT(IN) :: ima(:,:) INTEGER, INTENT(IN) :: scal INTEGER :: funnie(SIZE(ima,1),SIZE(ima,2)) funnie(:,:) = ima(:,:)*scal END FUNCTION funnie END PROGRAM proggie
here the bounds of funnie are inherited from the actual argument and used to determine the size of the result array; a fixed sized result could have been returned by declaring the result to be an explicit-shape array but this approach is less flexible.
Return to corresponding overview page