02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Program units and procedures<br />

Procedure interface<br />

A generic procedure is defined in an interface block that specifies its name and the interfaces<br />

of the specific procedures; see “Interface blocks” on page 150. The specific procedures within<br />

the interface block must all be subroutines or all functions. The interface for each procedure<br />

must differ from the others in one or more of the following ways:<br />

152<br />

The number of dummy arguments must differ.<br />

Arguments that occupy the same position in the dummy argument lists must differ in<br />

type, kind, or rank.<br />

The name of a dummy argument must differ from the names of the other dummy<br />

arguments in the argument lists of the other procedures, or all dummy arguments with<br />

thesamenamemustdifferintype,kind,orrank.<br />

There may be more than one interface block with the same generic name, but the specific<br />

procedures whose interfaces appear in all such interface blocks must be distinguishable by<br />

the above criteria.<br />

The MODULE PROCEDURE statement can be used to extend the list of specific procedures to<br />

include procedures that are otherwise accessible to the program unit containing the interface<br />

block. The MODULE PROCEDURE statement specifies only the procedure names; the procedure<br />

interfaces are already explicit. The MODULE PROCEDURE statement may appear only in an<br />

interface block that has a generic specification. Furthermore, the interface block must be<br />

contained either in the same module that contains the definitions of the named procedures or<br />

in a program unit in which the procedures are accessible through use association.<br />

The following example assumes that two subroutines have been coded for solving linear<br />

equations: rlineq for when the coefficients are real, and zlineq for when the coefficients are<br />

complex. A generic name, lineq, isdeclaredintheINTERFACE statement, enabling it to be<br />

used for referencing either of the specific procedures, depending on whether the arguments<br />

are real or complex:<br />

INTERFACE lineq<br />

SUBROUTINE rlineq(ra,rb,rx)<br />

REAL,DIMENSION(:,:) :: ra<br />

REAL,DIMENSION(:) :: rb,rx<br />

END SUBROUTINE rlineq<br />

SUBROUTINE zlineq(za,zb,zx)<br />

COMPLEX,DIMENSION(:,:) :: za<br />

COMPLEX,DIMENSION(:) :: zb,zx<br />

END SUBROUTINE zlineq<br />

END INTERFACE lineq<br />

Chapter 7

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

Saved successfully!

Ooh no, something went wrong!