Procedures

A procedure is a sub program that is written as a separate, named block of code. Procedures can have arguments that are used to input information into the procedure and to return information to the program or procedure making the call. Within the procedure the arguments are called dummy arguments. The corresponding arguments at the point of call are called actual arguments. Procedures are used to represent identifiable sub tasks within a program.

A procedure is either a FUNCTION or a SUBROUTINE.

Typically, FUNCTIONs have arguments that are used to input information and a single output value that is returned via the function name. A FUNCTION is called from within an expression.

A SUBROUTINE has arguments that can be used for input or output (or both) and is called using a CALL statement.

A procedure is external if it is not presented within a PROGRAM, MODULE or another procedure. It is either presented in a separate file or after the END of a PROGRAM, MODULE or another procedure.

A procedure is internal if it is presented between a CONTAINS statement and the END of a PROGRAM, MODULE or an external procedure.

An internal procedure is a module procedure if it is presented between a CONTAINS statement and the END of a MODULE.

Here is an example of an internal FUNCTION in a main PROGRAM:

PROGRAM Prog3
REAL a
READ *, a
PRINT *, func(a)

CONTAINS

REAL FUNCTION func(x)
REAL x
func=x*x+1.0
END
END Prog3

Internal procedures can also use variables that are declared in the host (i.e. before the CONTAINS statement).

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited