HP Fortran Programmer's Reference (September 2007)

Program units and procedures
Procedure interface
Chapter 7184
A generic procedure is defined in an interface block that specifies its name and the interfaces
of the specific procedures; see “Interface blocks” on page 182. The specific procedures within
the interface block must all be subroutines or all functions. The interface for each procedure
must differ from the others in one or more of the following ways:
The number of dummy arguments must differ.
Arguments that occupy the same position in the dummy argument lists must differ in
type, kind, or rank.
The name of a dummy argument must differ from the names of the other dummy
arguments in the argument lists of the other procedures, or all dummy arguments with
the same name must differ in type, kind, or rank.
There may be more than one interface block with the same generic name, but the specific
procedures whose interfaces appear in all such interface blocks must be distinguishable by
the above criteria.
The MODULE PROCEDURE statement can be used to extend the list of specific procedures to
include procedures that are otherwise accessible to the program unit containing the interface
block. The MODULE PROCEDURE statement specifies only the procedure names; the procedure
interfaces are already explicit. The MODULE PROCEDURE statement may appear only in an
interface block that has a generic specification. Furthermore, the interface block must be
contained either in the same module that contains the definitions of the named procedures or
in a program unit in which the procedures are accessible through use association.
The following example assumes that two subroutines have been coded for solving linear
equations: rlineq for when the coefficients are real, and zlineq for when the coefficients are
complex. A generic name, lineq, is declared in the INTERFACE statement, enabling it to be
used for referencing either of the specific procedures, depending on whether the arguments
are real or complex:
INTERFACE lineq
SUBROUTINE rlineq(ra,rb,rx)
REAL,DIMENSION(:,:) :: ra
REAL,DIMENSION(:) :: rb,rx
END SUBROUTINE rlineq
SUBROUTINE zlineq(za,zb,zx)
COMPLEX,DIMENSION(:,:) :: za
COMPLEX,DIMENSION(:) :: zb,zx
END SUBROUTINE zlineq
END INTERFACE lineq