SUBROUTINE statement
Standard: (F77) F90 F95 F2003 F2008 F2018 Example program
<Syntax>
[ prefix ] SUBROUTINE name [ ( args ) [ bind-attr ] ]
args ::= [ arg [ , arg ]... ]
arg ::= name | *}
bind-attr ::= BIND ( C [ , NAME=expression ] )
prefix | ::= | ELEMENTAL |
| | IMPURE | |
| | MODULE | |
| | NON_RECURSIVE | |
| | PURE | |
| | RECURSIVE |
No more than one of each kind of prefix is allowed in a single SUBROUTINE statement. If IMPURE appears, PURE must not appear. If MODULE appears, the interface or definition must be for a separate module procedure. If NON_RECURSIVE appears, RECURSIVE must not appear.
The SUBROUTINE statement can only occur as the first statement of a subroutine subprogram or interface body.
The syntax of a subroutine subprogram is as follows.
subroutine-stmt
specification-part
executable-part
[ contains-stmt
[ internal-subprogram ]... ]
end-subroutine-stmt
An internal-subprogram is a function-subprogram or a subroutine-subprogram, and is not allowed to itself have a contains-stmt.
The syntax of a subroutine interface body is simply:
subroutine-stmt
specification-part
end-subroutine-stmt
<Semantics>
The SUBROUTINE statement begins a subroutine subprogram.
Each dummy argument that is * is an alternate return; the corresponding actual argument must be a label (prefixed by ‘*’). It is possible to transfer control to one of these labels on return from a subroutine by including an expression on the RETURN statement; if the expression has the value 1 control is transferred to the first label, etc.. If the expression is less than 1 or more than the number of label arguments, execution continues with the statement following the CALL statement. Alternate returns are error-prone and their use is not recommended.
<Related>
BIND attribute, CALL statement, CONTAINS statement, ELEMENTAL attribute, END SUBROUTINE statement, ENTRY statement, FUNCTION statement, IMPURE attribute, NON_RECURSIVE attribute, PURE attribute, RECURSIVE attribute, RETURN statement, Separate module procedures