next up previous contents index
Next: Adjustable Arrays Up: Procedures Previous: Passed-length Character Arguments

Arrays as Arguments

  If the dummy argument of a procedure is an array then the actual argument can be either:

The first form transfers the entire array; the second form, which just transfers a section starting at the specified element, is described in more detail further on.

The simplest, and most common, requirement is to make the entire contents of an array available in a procedure. If the actual argument arrays are always going to be the same size then the dummy arrays in the procedure can use fixed bounds. For example:

 
       SUBROUTINE DOT(X, Y, Z) 
*Computes the dot product of arrays X and Y of 100 elements 
* producing array Z of the same size. 
       REAL X(100), Y(100), Z(100) 
       DO 15, I = 1,100 
          Z(I) = X(I) * Y(I) 
15     CONTINUE 
       END
This procedure could be used within a program unit like this:
 
       PROGRAM PROD 
       REAL A(100), B(100), C(100) 
       READ(UNIT=*,FMT=*)A,B 
       CALL DOT(A, B, C) 
       WRITE(UNIT=*,FMT=*)C 
       END
This is perfectly legitimate, if inflexible, since it will not work on arrays of any other size.



Mario Storti
Wed Nov 4 19:32:56 ART 1998