6.2 User-Written Subprograms

A user-written subprogram is a Fortran statement or group of Fortran statements that perform a computing procedure. The computing procedure can be either a series of arithmetic operations or a series of Fortran statements. A single subprogram can perform a computing procedure in several places in your program, and so avoid duplicating a series of operations or statements in each place.

There are three types of subprograms. Table 6-2 lists each type of subprogram, the statements needed to define the subprogram, and the method of transferring control to it.

Table 6-2 Types of User-Written Subprograms

Subprogram Type  Defining Statements  Control Transfer Method 
Statement function  Statement function definition  Function reference 
Function  FUNCTION
ENTRY 
Function reference 
Subroutine  SUBROUTINE
ENTRY 
CALL statement 

A function reference is used in an expression and consists of the function name and the function arguments. A function reference returns a value that is used in evaluating the expression in which the function appears.

Function and subroutine subprograms can change the values of their arguments, and the calling program can use the changed values.

A subprogram can refer to other subprograms. Recursion is permitted if you specify the compiler option RECURSIVE.

For more information:


Previous Page Next Page Table of Contents