The SUBROUTINE statement begins a subroutine subprogram. It specifies the subroutines name and dummy arguments, and any special characteristics such as PURE, ELEMENTAL, or RECURSIVE.
Syntax[PURE] [ELEMENTAL] [RECURSIVE] SUBROUTINE sub-name ([dummy-args])Where:
sub-name is the name of the subroutine.
dummy-args is a comma-separated list of dummy argument names.
The prefixes PURE, ELEMENTAL, and RECURSIVE may appear in any order.
A subroutine with the prefix PURE or ELEMENTAL is subject to the additional constraints of pure procedures, which ensure that no unseen side effects occur on invocation of the subroutine.
An ELEMENTAL subroutine is subject to the constraints of elemental procedures.
The keyword RECURSIVE must be present if the subroutine directly or indirectly calls itself or a subroutine defined by an ENTRY statement in the same subprogram. RECURSIVE must also be present if a subroutine defined by an ENTRY statement directly or indirectly calls itself, another subroutine defined by an ENTRY statement, or the subroutine defined by the SUBROUTINE statement.
Examplesubroutine sub1() ! subroutine statement with no arguments common /c1/ a a=1. end subroutine subroutine sub2(a,b,c) ! subroutine statement with arguments real :: a,b,c a=b+c end subroutine recursive subroutine sub3(i) ! recursive required if the i=i-1 ! subroutine calls itself if(i > 0) call sub3(i) ! directly or indirectly end subroutine