LF Fortran 95

PURE Procedure

Fortran procedures can be specified as PURE, meaning that there is no chance that the procedure would have any side effect on data outside the procedure. Only pure procedures can be used in specification expressions. The PURE keyword must be used in the procedure declaration.

Syntax

PURE SUBROUTINE sub-name ( arg-list ) or PURE FUNCTION fun-name ( arg-list ) [result(result-var)]
Where:

sub-name is the subroutine name

fun-name is the function name.

arg-list is a list of dummy arguments.

result-var defines the type and kind of the result, and is assigned the result value.

Remarks

If the PURE procedure is a subroutine, then each argument in arg-list must declare the INTENT attribute, unless that argument corresponds to a procedure, is an alternate return, or has the POINTER attribute.

If the PURE procedure is a function, then each argument in arg-list must be declared as INTENT(IN) unless that argument corresponds to a procedure or has the POINTER attribute.

Local variables within the scope of a PURE procedure cannot have the SAVE attribute, which implies that they cannot be initialized when declared, or by a DATA statement.

Any procedures (including dummy procedures) that are invoked from a PURE procedure must be PURE.

Local variables of pure subroutines must not have the SAVE attribute, either by explicit declaration or by initialization in a type declaration or DATA statement.

Any subprogram contained within a PURE procedure is also PURE.

A PURE procedure may not cause the value of a variable which is in COMMON, or is available by use or host association to be altered.

No external I/O operations may occur within a PURE procedure.

A PURE procedure may not contain a STOP statement.

Example

pure subroutine sub1(a) real,intent(in out) :: a ! intent must be declared interface pure function fun1(a) ! any invoked procedure must be pure real,intent(in) :: a end function fun1 end interface a=fun1(a/10.) end subroutine pure function fun1(a) real :: fun1 real,intent(in) :: a ! all arguments must be intent(in) fun1=a end function fun1