# 8 Program Units and Procedures

A Fortran 95/90 program consists of one or more program units. There are four types of program units:

- Main program

  The program unit that denotes the beginning of execution. It may or may not have a PROGRAM statement as its first statement.

- External procedures

  Program units that are either user-written functions or subroutines.

- Modules

  Program units that contain declarations, type definitions, procedures, or interfaces that can be shared by other program units.

- Block data program units

  Program units that provide initial values for variables in named common blocks.

A program unit does not have to contain executable statements; for example, it can be a module containing interface blocks for subroutines.

A procedure can be invoked during program execution to perform a specific task. There are several kinds of procedures, as follows:

Kind of Procedure | Description
--- | ---
External Procedure | A procedure that is not part of any other program unit.
Module Procedure | A procedure defined within a module
Internal Procedure1 | A procedure (other than a statement function) contained within a main program, function, or subroutine
Intrinsic Procedure | A procedure defined by the Fortran language
Dummy Procedure | A dummy argument specified as a procedure or appearing in a procedure reference
Statement function | A computing procedure defined by a single statement
1 The program unit that contains an internal procedure is called its host.

A function is invoked in an expression using the name of the function or a defined operator. It returns a single value (function result) that is used to evaluate the expression.

A subroutine is invoked in a CALL statement or by a defined assignment statement. It does not directly return a value, but values can be passed back to the calling program unit through arguments (or variables) known to the calling program.

Recursion (direct or indirect) is permitted for functions and subroutines.

A procedure interface refers to the properties of a procedure that interact with or are of concern to the calling program. A procedure interface can be explicitly defined in interface blocks. All program units, except block data program units, can contain interface blocks.

This chapter contains information on the following topics:

- Main program (Section 8.1)
- HPF prefixes you can use for some program units (Section 8.2)
- Modules and module procedures (Section 8.3)
- Block data program units (Section 8.4)
- Functions, subroutines, and statement functions (Section 8.5)
- External procedures (Section 8.6)
- Internal procedures (Section 8.7)
- Argument association (Section 8.8)
- Procedure interfaces (Section 8.9)
- The CONTAINS statement (Section 8.10)
- The ENTRY statement (Section 8.11)

For More Information:

- On an overview of program structure, see Section 2.1.
- On intrinsic procedures, see Chapter 9.
- On the scope of program entities, see Section 16.1.
- On recursion, see Section 8.5.1.1.

Previous Page Next Page Table of Contents