HP Fortran Programmer's Reference (September 2007)

Program units and procedures
Procedure interface
Chapter 7 183
is a comma-separated list of names of module procedures that have
generic-spec
as a generic interface. Each module-procedure name must be
accessible either by use association or—if this interface block is in a module
that defines the module procedure—by host association.
If the MODULE PROCEDURE statement is present, then
generic-spec
must
also be present.
The following example, proc_interface.f90, uses an interface block in the main program unit to
provide an explicit interface for the function avg.
Example 7-8 proc_interface.f90
! Define an external function avg with one assumed-shape dummy
! argument. Note that the definition of the function must
! lexically precede its declaration in the interface block.
REAL FUNCTION avg(a)
REAL a(:)
avg = SUM(a)/SIZE(a)
END FUNCTION avg
PROGRAM main
REAL,DIMENSION(3) :: x
INTERFACE
REAL FUNCTION avg(a)
REAL, INTENT(IN) :: a(:)
END FUNCTION avg
END INTERFACE
x=(/2.0, 4.0, 7.0/)
PRINT *, avg(x)
END PROGRAM main
Here are the command lines to compile and execute the program, along with the output from
a sample run:
$ f90 proc_interface.f90
$ a.out
4.33333
Generic procedures
The Fortran 90 concept of generic procedures extends the FORTRAN 77 concept of generic
intrinsics to allow user-defined generic procedures. A procedure is generic if its name—a
generic name
—is associated with a set of specific procedures. Referencing the generic name
allows actual arguments to differ in type, kind, and rank. The differences in the arguments
determine which specific procedure is invoked.