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

 

Array-valued Functions

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.

Now try this question gif

Now try this question gif

Return to corresponding overview page gif


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

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.