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.

<strong>HP</strong> <strong>Fortran</strong> statements<br />

OPTIONAL (statement and attribute)<br />

The OPTIONAL attribute may be specified only for dummy arguments. It may occur in a<br />

subprogram and in any corresponding interface body.<br />

An optional dummy argument whose actual argument is not present may not be<br />

referenced or defined (or invoked if it is a dummy procedure), except that it may be passed<br />

to another procedure as an optional argument and will be considered not present.<br />

When an argument is omitted in a procedure reference, all arguments that follow it must<br />

use the keyword form.<br />

If a procedure has an optional argument, the procedure interface must be explicit.<br />

Examples<br />

The following are two examples of the OPTIONAL statement. In the first example, the call to<br />

the subroutine trip can legally omit the path argument because it has the OPTIONAL<br />

attribute:<br />

CALL TRIP ( distance = 17.0 ) ! path is omitted<br />

SUBROUTINE trip ( distance, path )<br />

OPTIONAL distance, path<br />

In the next example, the subroutine plot uses the PRESENT function to determine whether or<br />

not to execute code that depends on the presence of arguments that have the OPTIONAL<br />

attribute:<br />

SUBROUTINE plot (pts, o_xaxis, o_yaxis, smooth)<br />

TYPE (point) pts<br />

REAL, OPTIONAL :: o_xaxis, o_yaxis<br />

! Origin - default (0.,0.)<br />

LOGICAL, OPTIONAL :: smooth<br />

REAL ox, oy<br />

IF (PRESENT (o_xaxis)) THEN<br />

ox = o_xaxis<br />

ELSE<br />

ox = 0.<br />

! Note that the o_xaxis dummy argument cannot be referenced if<br />

! the actual argument is not present. The same applies<br />

! to o_yaxis (below).<br />

END IF<br />

IF (PRESENT (o_yaxis)) THEN<br />

oy = o_yaxis<br />

ELSE<br />

oy = 0.<br />

END IF<br />

IF (PRESENT(smooth)) THEN<br />

IF (smooth) THEN<br />

... ! Smooth algorithm<br />

RETURN<br />

END IF<br />

Chapter 10 383

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

Saved successfully!

Ooh no, something went wrong!