06.03.2014 Views

Intel Fortran Language Reference - NCI National Facility

Intel Fortran Language Reference - NCI National Facility

Intel Fortran Language Reference - NCI National Facility

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Program Units and Procedures 8<br />

The SUBROUTINE statement is the initial statement of a subroutine subprogram. It takes the<br />

following form:<br />

[prefix] SUBROUTINE name [([d-arg-list])]<br />

prefix<br />

Is one of the following:<br />

Keyword<br />

RECURSIVE<br />

PURE<br />

ELEMENTAL<br />

Meaning<br />

Permits direct recursion to occur. If a function is directly recursive and<br />

array valued, RESULT must also be specified (see “Recursive<br />

Procedures”).<br />

Asserts that the procedure has no side effects (see “Pure Procedures”).<br />

A restricted form of pure procedure that acts on one array element at a<br />

time (see “Elemental Procedures”).<br />

name<br />

Is the name of the subroutine.<br />

d-arg-list<br />

Is a list of one or more dummy arguments or alternate return specifiers (*).<br />

Rules and Behavior<br />

A subroutine is invoked by a CALL statement or defined assignment. When a subroutine is<br />

invoked, dummy arguments (if present) become associated with the corresponding actual<br />

arguments specified in the call.<br />

Execution begins with the first executable construct or statement following the SUBROUTINE<br />

statement. Control returns to the calling program unit once the END statement (or a RETURN<br />

statement) is executed.<br />

A subroutine subprogram cannot contain a FUNCTION statement, a BLOCK DATA statement, a<br />

PROGRAM statement, or another SUBROUTINE statement. ENTRY statements can be included<br />

to provide multiple entry points to the subprogram.<br />

Examples<br />

The following example shows a subroutine:<br />

Main Program<br />

Subroutine<br />

CALL HELLO_WORLD SUBROUTINE HELLO_WORLD<br />

. . . PRINT *, "Hello World"<br />

8-25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!