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.

Internal procedures<br />

An internal procedure is similar to an external procedure except that:<br />

Program units and procedures<br />

Internal procedures<br />

It must be defined within a hosting program unit—a main, external, or module program<br />

unit—following the CONTAINS statement.<br />

It can be referenced by the host only.<br />

It can access other entities by host association within the host.<br />

It cannot have an ENTRY statement.<br />

It cannot be passed as an argument.<br />

It cannot contain an internal procedure.<br />

The syntax of an internal procedure definition is the same as for an external procedure (see<br />

“Procedure definition” on page 129), except that it has no internal procedure part. The<br />

reference to an internal procedure is the same as for an external procedure; see “Procedure<br />

reference” on page 130.<br />

The following example, int_func.f90, declares and references an internal function. Note that<br />

both the external procedure and the internal procedure have an assumed-shape array as a<br />

dummy argument, which requires the procedure to have an explicit interface (see “Procedure<br />

interface” on page 149). External procedures must be declared in an interface block to make<br />

their interface explicit; the interface of internal procedures is explicit by default.<br />

Example 7-2 int_func.f90<br />

PROGRAM main<br />

! declare and initialize an array to pass to an external<br />

! procedure<br />

REAL, DIMENSION(3) :: values = (/2.0, 5.0, 7.0/)<br />

! Because the dummy argument to print_avg is an assumed-shape<br />

! array (see the definition of print_avg below), the<br />

! procedure interface of print_avg must<br />

! be made explicit within the calling program unit.<br />

INTERFACE<br />

SUBROUTINE print_avg(x)<br />

REAL :: x(:)<br />

END SUBROUTINE print_avg<br />

END INTERFACE<br />

CALL print_avg(values)<br />

Chapter 7 135

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

Saved successfully!

Ooh no, something went wrong!