HP Fortran Programmer's Reference (September 2007)

Program units and procedures
External procedures
Chapter 7 165
As a compatibility extension, HP Fortran allows the ampersand (&) as a prefix character
instead of the asterisk, but only in fixed source form. Alternate returns cannot be optional,
and the associated actual argument cannot have keywords. For detailed information about
the syntax of the alternate return argument, refer to the descriptions of the CALL and RETURN
statements in Chapter 10, “HP Fortran Statements.”
The following example, alt_return.f90, illustrates the alternate return mechanism. The
referenced subroutine, subr, selects one of two alternate return arguments based on the value
of the first argument, where_to.
Example 7-1 alt_return.f90
PROGRAM main
! illustrates alternate return arguments
INTEGER :: por ! point of return
por = -1 ! interpreted by arithmetic IF
CALL subr(por, *10, *15) ! executes first
PRINT *, 'Default returning point'
por = 0
CALL subr(por, *10, *15) ! executes second
GOTO 20 ! control should never reach here
10 PRINT *, 'Line 10 in main'
por = 1
CALL subr(por, *10, *15) ! executes third
GOTO 20 ! control should never reach here
15 PRINT *, 'Line 15 in main'
20 CONTINUE
END PROGRAM main
SUBROUTINE subr(where_to, *, *)
! Argument list includes placeholders for two alternate returns;
! the third argument, where_to, is used to select a return
! argument
INTEGER :: where_to
! use arithmetic IF to select a return
IF (where_to) 25, 30, 35 ! labels to transfer control
PRINT *, 'Should never print'
25 PRINT *, 'Line 25 in subr'
RETURN ! default returning point
30 PRINT *, 'Line 30 in subr'
RETURN 1 ! select the first return argument
35 PRINT *, 'Line 35 in subr'
RETURN 2 ! select the second return argument
END SUBROUTINE subr