Function and subroutine subprograms

A function or subroutine subprogram is a subprogram that has a FUNCTION or SUBROUTINE statement as its first statement. You can also specify a function in a statement function statement. An external function or subroutine subprogram is a program unit.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-subprogram_statement----------------------------------------><

Read syntax diagramSkip visual syntax diagram
>>-+--------------------+--------------------------------------><
   '-specification_part-'   

Read syntax diagramSkip visual syntax diagram
>>-+----------------+------------------------------------------><
   '-execution_part-'   

Read syntax diagramSkip visual syntax diagram
>>-+--------------------------+--------------------------------><
   '-internal_subprogram_part-'   

Read syntax diagramSkip visual syntax diagram
>>-end_subprogram_statement------------------------------------><

subprogram_statement
See FUNCTION or SUBROUTINE for syntax details
specification_part
is a sequence of statements from the statement groups numbered  2 ,  4  and  5  in Order of statements and execution sequence
execution_part
is a sequence of statements from the statement groups numbered  4  and  6  in Order of statements and execution sequence, and which must begin with a statement from statement group  6 
internal_subprogram_part
See Internal procedures for details
end_subprogram_statement
See END for syntax details on the END statement for functions and subroutines

Rules

An internal subprogram is declared after the CONTAINS statement in the main program, a module subprogram, or an external subprogram, but before the END statement of the host program. The name of an internal subprogram must not be defined in the specification section in the host scoping unit.

An external procedure has global scope with respect to the executable program. In the calling program unit, you can specify the interface to an external procedure in an interface block or you can define the external procedure name with the EXTERNAL attribute.

A subprogram can contain any statement except PROGRAM, BLOCK DATA, MODULE, and Fortran 2008 beginsSUBMODULEFortran 2008 ends statements. An internal subprogram cannot contain an ENTRY statement or an internal subprogram.



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us