Using Functions

The way of using a user-defined function is exactly identical to that of using Fortran intrinsic functions. One can use a function in an expression and in a WRITE. Suppose we have the following function:

REAL FUNCTION  Average(x, y, z)
   IMPLICIT  NONE

   REAL, INTENT(IN) :: x, y, z

   Average = (x + y + z) / 3.0
END FUNCTION Average
This function takes three REAL formal arguments and returns their average.

To use this function, one needs to supply values to the formal arguments. For example, one could write the following:

..... = ..... +  Average(1.0, 2.0, 3.0)  * .....
The above expression involves the use of function Average. Since this function has three formal arguments, three values must be presented to the function. Here, the values are 1.0, 2.0 and 3.0 and the returned value is the average of these three numbers (i.e., 2.0). The values or expressions used to invoke a function are referred to as actual arguments.

Please keep the following important rules in mind:

Please continue with the next page on argument association