02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

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<br />

External procedures<br />

As a compatibility extension, <strong>HP</strong> <strong>Fortran</strong> allows the ampersand (&) asaprefixcharacter<br />

instead of the asterisk, but only in fixed source form. Alternate returns cannot be optional,<br />

and the associated actual argument cannot have keywords. For detailed information about<br />

the syntax of the alternate return argument, refer to the descriptions of the CALL and RETURN<br />

statements in Chapter 10, “<strong>HP</strong> <strong>Fortran</strong> Statements.”<br />

The following example, alt_return.f90, illustrates the alternate return mechanism. The<br />

referenced subroutine, subr, selects one of two alternate return arguments based on the value<br />

of the first argument, where_to.<br />

Example 7-1 alt_return.f90<br />

PROGRAM main<br />

! illustrates alternate return arguments<br />

INTEGER :: por ! point of return<br />

por = -1 ! interpreted by arithmetic IF<br />

CALL subr(por, *10, *15) ! executes first<br />

PRINT *, 'Default returning point'<br />

por = 0<br />

CALL subr(por, *10, *15) ! executes second<br />

GOTO 20 ! control should never reach here<br />

10 PRINT *, 'Line 10 in main'<br />

por = 1<br />

CALL subr(por, *10, *15) ! executes third<br />

GOTO 20 ! control should never reach here<br />

15 PRINT *, 'Line 15 in main'<br />

20 CONTINUE<br />

END PROGRAM main<br />

SUBROUTINE subr(where_to, *, *)<br />

! Argument list includes placeholders for two alternate returns;<br />

! the third argument, where_to, is used to select a return<br />

! argument<br />

INTEGER :: where_to<br />

! use arithmetic IF to select a return<br />

IF (where_to) 25, 30, 35 ! labels to transfer control<br />

PRINT *, 'Should never print'<br />

25 PRINT *, 'Line 25 in subr'<br />

RETURN ! default returning point<br />

30 PRINT *, 'Line 30 in subr'<br />

RETURN 1 ! select the first return argument<br />

35 PRINT *, 'Line 35 in subr'<br />

RETURN 2 ! select the second return argument<br />

END SUBROUTINE subr<br />

Chapter 7 133

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

Saved successfully!

Ooh no, something went wrong!