The SUBROUTINE statement identifies a named program unit as a subroutine, and specifies arguments for it.
Name of subroutine subprogram
Variable name, array name, record name, or dummy procedure name, an asterisk, or an ampersand
A subroutine subprogram must have a SUBROUTINE statement as the first statement. A subroutine can have any other statements, except a BLOCK DATA, FUNCTION, PROGRAM, or another SUBROUTINE statement.
sub is the name of a subroutine and is a global name, and must not be the same as any other global name such as a common block name or a function name. Nor can it be the same as any local name in the same subroutine.
d is the dummy argument, and multiple dummy arguments are separated by commas. d can be one of the following:
Dummy procedure name
Asterisk (*) or an ampersand (&) @
The dummy arguments are local to the subroutine and must not appear in any of the following statements, except as a common block name:
The actual arguments in the CALL statement that references a subroutine must agree with the corresponding formal arguments in the SUBROUTINE statement, in order, number, and type. An asterisk (or an ampersand) in the formal argument list denotes an alternate return label. A RETURN statement in this procedure can specify the ordinal number of the alternate return to be taken.
SUBROUTINE SHR ( A, B ) CHARACTER A*8 REAL B(10,10) ... RETURN END
PROGRAM TESTALT CALL RANK ( N, *8, *9 ) WRITE (*,*) 'OK - Normal Return [n=0]' STOP 8 WRITE (*,*) 'Minor - 1st alternate return [n=1]' STOP 9 WRITE (*,*) 'Major - 2nd alternate return [n=2]' END SUBROUTINE RANK ( N, *, * ) IF ( N .EQ. 0 ) RETURN IF ( N .EQ. 1 ) RETURN 1 RETURN 2 END
In this example, the RETURN 1 statement refers to the first alternate return label (first *). The RETURN 2 statement refers to the second alternate return label (second *) specified in the SUBROUTINE statement.