Program Units - Fortran

Fortran programs consist of one or more program units. A program unit consists of a sequence of statements and optional comment lines. It can be a main program or a subprogram. The program unit defines the scope for symbolic names and statement labels.

The END statement must always be the last statement of a program unit.

Main Program
The main program is the program unit that initially receives control on execution. It can have a PROGRAM statement as its first statement and contain any Fortran statement except a FUNCTION, SUBROUTINE, BLOCK DATA, ENTRY, or RETURN statement. A SAVE statement in a main program does not affect the status of variables or arrays. A STOP or END statement in a main program terminates execution of the program.

The main program does not need to be a Fortran program. Refer to the
Fortran 77 Programmer’s Guide for information on writing Fortran programs
that interact with programs written in other languages.

The main program cannot be referenced from a subprogram or from itself.

Subprograms

A subprogram is an independent section of code designed for a specialized purpose. It receives control when referenced or called by a statement in the main program or another subprogram.

A subprogram can be a

  • function subprogram identified by a FUNCTION statement
  • subroutine subprogram identified by a SUBROUTINE statement
  • block data subprogram identified by a BLOCK DATA statement
  • non-Fortran subprogram

Subroutines, external functions, statement functions, and intrinsic functions are collectively called procedures. A procedure is a program unit that performs an operational function.

An external procedure is a function or subroutine subprogram that is processed independently of the calling or referencing program unit. It can be written as a non-Fortran subprogram as described in the Fortran 77Programmer’s Guide.

Intrinsic functions are supplied by the processor and are generated as in-line functions or library functions.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Fortran Topics