8.1 Main Program

A Fortran program must include one main program. It takes the following form:

[PROGRAM name]
      [specification-part]
      [execution-part]
[CONTAINS
      internal-subprogram-part]
END [PROGRAM [name]]

name
Is the name of the program.

specification-part
Is one or more specification statements, except for the following:

An automatic object must not appear in a specification statement. If a SAVE statement is specified, it has no effect.

execution-part
Is one or more executable constructs or statements, except for ENTRY or RETURN statements.

internal-subprogram-part
Is one or more internal subprograms (defining internal procedures). The internal-subprogram-part is preceded by a CONTAINS statement.

Rules and Behavior

The PROGRAM statement is optional. Within a program unit, a PROGRAM statement can be preceded only by comment lines or an OPTIONS statement.

The END statement is the only required part of a program. If a name follows the END statement, it must be the same as the name specified in the PROGRAM statement.

The program name is considered global and must be unique. It cannot be the same as any local name in the main program or the name of any other program unit, external procedure, or common block in the executable program.

A main program must not reference itself (either directly or indirectly).

Examples

The following is an example of a main program:

PROGRAM TEST
  INTEGER C, D, E(20,20)     ! Specification part
  CALL SUB_1                 ! Executable part
...
CONTAINS
  SUBROUTINE SUB_1           ! Internal subprogram
  ...
  END SUBROUTINE SUB_1
END PROGRAM TEST

For More Information:

For details on the default name for a main program, see your user manual or programmer's guide.


Previous Page Next Page Table of Contents