# Program Units

A Fortran program consists of one or more program units. A program unit is usually a sequence of statements that define the data environment and the steps necessary to perform calculations; it is terminated by an END statement.

A program unit can be either a main program, an external subprogram, a module, a submodule, or a block data program unit. An executable program contains one main program, and, optionally, any number of the other kinds of program units. Program units can be separately compiled.

An external subprogram is a function or subroutine that is not contained within a main program, a module, a submodule, or another subprogram. It defines a procedure to be performed and can be invoked from other program units of the Fortran program. Modules, submodules, and block data program units are not executable, so they are not considered to be procedures. (Modules and submodules can contain module procedures, though, which are executable.)

Modules contain definitions that can be made accessible to other program units: data and type definitions, definitions of procedures (called module subprograms), and procedure interfaces. Module subprograms can be either functions or subroutines. They can be invoked by other module subprograms in the module, or by other program units that access the module.

A submodule extends a module or another submodule. It can contain the definitions of procedures declared in a module or submodule.

A block data program unit specifies initial values for data objects in named common blocks. In Standard Fortran, this type of program unit can be replaced by a module program unit.

Main programs, external subprograms, and module subprograms can contain internal subprograms. The entity that contains the internal subprogram is its host. Internal subprograms can be invoked only by their host or by other internal subprograms in the same host. Internal subprograms must not contain internal subprograms.

The following sections discuss Statements, Names, and Keywords.

## See Also

Program Units and Procedures