HP OpenVMS Systems Documentation

Content starts here

HP Fortran for OpenVMS
Language Reference Manual

Previous Contents Index

  1. The statement function named SIN is defined in terms of the generic function name COS. Because the argument of COS is double precision, the double-precision cosine function is evaluated. The statement function SIN is itself single precision.
  2. The statement function SIN is called.
  3. The name SIN is declared intrinsic so that the single-precision intrinsic sine function can be passed as an actual argument at .
  4. The generic function name SIN is used to refer to the double-precision sine function.
  5. The single-precision intrinsic sine function is used as an actual argument.
  6. The name SIN is declared a user-defined function name.
  7. The type of SIN is declared double precision.
  8. The single-precision sine function passed at is evaluated.
  9. The user-defined SIN function is evaluated.
  10. The user-defined SIN function is defined as a simple Taylor series using a user-defined function FACTOR to compute the factorial function.

For More Information: References to Elemental Intrinsic Procedures

An elemental intrinsic procedure has scalar dummy arguments that can be called with scalar or array actual arguments. If actual arguments are array-valued, they must have the same shape. There are many elemental intrinsic functions, but only one elemental intrinsic subroutine (MVBITS).

If the actual arguments are scalar, the result is scalar. If the actual arguments are array-valued, the scalar-valued procedure is applied element-by-element to the actual argument, resulting in an array that has the same shape as the actual argument.

The values of the elements of the resulting array are the same as if the scalar-valued procedure had been applied separately to the corresponding elements of each argument.

For example, if A and B are arrays of shape (5,6), MAX(A, 0.0, B) is an array expression of shape (5,6) whose elements have the value MAX(A (i, j), 0.0, B (i, j)), where i = 1, 2,..., 5, and j = 1, 2,..., 6.

A reference to an elemental intrinsic procedure is an elemental reference if one or more actual arguments are arrays and all array arguments have the same shape.

For More Information:

8.8.9 References to Non-Fortran Procedures

To facilitate references to non-Fortran procedures, HP Fortran provides built-in functions %DESCR, %REF, and %VAL to pass actual arguments; and %LOC, which computes the internal address of a storage item. %DESCR, %REF, and %VAL Argument List Functions

When a procedure is called, Fortran (by default) passes the address of the actual argument, and its length if it is of type character. To call non-Fortran procedures, you may need to pass the actual arguments in a form different from that used by Fortran.

The built-in functions %DESCR, %REF, and %VAL let you change the form of an actual argument. You must specify these functions in the actual argument list of a CALL statement or function reference. You cannot use them in any other context.

These functions specify how to pass an actual argument (for example, a) to a non-Fortran procedure, as follows:

Function Effect
%VAL ( a) Passes argument a as an n-bit 1 immediate value. If a is integer (or logical) and shorter than n bits, it is sign-extended to an n-bit value. For complex data types, %VAL passes two n-bit arguments.
%REF ( a) Passes argument a by reference.
%DESCR ( a) Passes argument a by descriptor.

1n is 64.

Table 8-1 lists the HP Fortran defaults for argument passing, and the allowed uses of %DESCR, %REF, and %VAL.

Table 8-1 Defaults for Argument List Functions
    Allowed Functions
Actual Argument
Data Type
Default %VAL %REF %DESCR
Logical REF Yes Yes Yes
Integer REF Yes Yes Yes
REAL(4) REF Yes Yes Yes
REAL(8) REF Yes Yes Yes
REAL(16) REF No Yes Yes
COMPLEX(4) REF Yes Yes Yes
COMPLEX(8) REF Yes Yes Yes
COMPLEX(16) REF No Yes Yes
Character DESCR No Yes Yes
Hollerith REF No No No
Aggregate 1 REF No Yes No
Derived REF No Yes No
Array Name:        
Numeric REF No Yes Yes
Character DESCR No Yes Yes
Aggregate 1 REF No Yes No
Derived REF No Yes No
Procedure Name:        
Numeric REF No Yes Yes
Character DESCR No Yes Yes

1In HP Fortran record structures.

The %VAL, %REF, and %DESCR functions override related cDEC$ ATTRIBUTE settings.

For More Information:

On how to use the %VAL, %REF, and %DESCR functions, see the HP Fortran for OpenVMS User Manual. %LOC Function

The built-in function %LOC computes the internal address of a storage item. It takes the following form:

  • %LOC (arg)


Is the name of an actual argument. It must be a variable, an expression, or the name of a procedure. (It must not be the name of an internal procedure or statement function.)

The %LOC function produces an integer value that represents the location of the given argument. The value is INTEGER(8). You can use this integer value as an item in an arithmetic expression.

The LOC intrinsic function serves the same purpose as the %LOC built-in function.

For More Information:

  • On how to use the %LOC function, see the HP Fortran for OpenVMS User Manual.
  • On the LOC intrinsic function, see Section 9.4.88.

8.9 Procedure Interfaces

Every procedure has an interface, which consists of the name and characteristics of a procedure, the name and characteristics of each dummy argument, and the generic identifier (if any) by which the procedure can be referenced. The characteristics of a procedure are fixed, but the remainder of the interface can change in different scoping units.

If these properties are all known within the scope of the calling program, the procedure interface is explicit; otherwise it is implicit (deduced from its reference and declaration). The following table shows which procedures have implicit or explicit interfaces:

Kind of Procedure Interface
External procedure Implicit 1
Module Procedure Explicit
Internal Procedure Explicit
Intrinsic Procedure Explicit
Dummy Procedure Implicit 1
Statement function Implicit

1Unless an interface block is supplied for the procedure.

The interface of a recursive subroutine or function is explicit within the subprogram that defines it.

An explicit interface can appear in a procedure's definition, in an interface block, or both. (Internal procedures must not appear in an interface block.)

The following sections describe when explicit interfaces are required, how to define explicit interfaces, and how to define generic names, operators, and assignment.

8.9.1 Determining When Procedures Require Explicit Interfaces

A procedure must have an explicit interface in the following cases:

  • If the procedure has any of the following:
    • An optional dummy argument
    • A dummy argument that is an assumed-shape array, a pointer, or a target
    • A result that is array-valued or a pointer (functions only)
    • A result whose length is neither assumed nor a constant (character functions only)
  • If a reference to the procedure appears as follows:
    • With an argument keyword
    • As a reference by its generic name
    • As a defined assignment (subroutines only)
    • In an expression as a defined operator (functions only)
    • In a context that requires it to be pure
  • If the procedure is elemental

For More Information:

8.9.2 Defining Explicit Interfaces

Interface blocks define explicit interfaces for external or dummy procedures. They can also be used to define a generic name for procedures, a new operator for functions, and a new form of assignment for subroutines.

An interface block takes the following form:

  • INTERFACE [generic-spec]
  • [interface-body]...
  • [MODULE PROCEDURE name-list]...
  • END INTERFACE [generic-spec]


Is one of the following:
  • A generic name
  • OPERATOR (op)
    Defines a generic operator (op). It can be a defined unary, defined binary, or extended intrinsic operator.
    Defines generic assignment.


Is one or more function or subroutine subprograms. A function must end with END FUNCTION and a subroutine must end with END SUBROUTINE.

The subprogram must not contain a statement function or a DATA, ENTRY, or FORMAT statement; an entry name can be used as a procedure name.

The subprogram can contain a USE statement.


Is the name of one or more module procedures that are accessible in the host. The MODULE PROCEDURE statement is only allowed if the interface block specifies a generic-spec and has a host that is a module (or accesses a module by use association).

The characteristics of module procedures are not given in interface blocks, but are assumed from the module subprogram definitions.

Rules and Behavior

Interface blocks can appear in the specification part of the program unit that invokes the external or dummy procedure.

A generic-spec can only appear in the END INTERFACE statement (a Fortran 95 feature) if one appears in the INTERFACE statement; they must be identical.

The characteristics specified for the external or dummy procedure must be consistent with those specified in the procedure's definition.

An interface block must not appear in a block data program unit.

An interface block comprises its own scoping unit, and does not inherit anything from its host through host association.

A procedure must not have more than one explicit interface in a given scoping unit.

A interface block containing generic-spec specifies a generic interface for the following procedures:

  • The procedures within the interface block
    Any generic name, defined operator, or equals symbol that appears is a generic identifier for all the procedures in the interface block. For the rules on how any two procedures with the same generic identifier must differ, see Section 15.3.
  • The module procedures listed in the MODULE PROCEDURE statement
    The module procedures must be accessible by a USE statement.

To make an interface block available to multiple program units (through a USE statement), place the interface block in a module.

The following rules apply to interface blocks containing pure procedures:

  • The interface specification of a pure procedure must declare the INTENT of all dummy arguments except pointer and procedure arguments.
  • A procedure that is declared pure in its definition can also be declared pure in an interface block. However, if it is not declared pure in its definition, it must not be declared pure in an interface block.


The following example shows a simple procedure interface block with no generic specification:

      REAL FB, GN

For More Information:

8.9.3 Defining Generic Names for Procedures

An interface block can be used to specify a generic name to reference all of the procedures within the interface block.

The initial line for such an interface block takes the following form:

  • INTERFACE generic-name


Is the generic name. It can be the same as any of the procedure names in the interface block, or the same as any accessible generic name (including a generic intrinsic name).

This kind of interface block can be used to extend or redefine a generic intrinsic procedure.

The procedures that are given the generic name must be the same kind of subprogram: all must be functions, or all must be subroutines.

Any procedure reference involving a generic procedure name must be resolvable to one specific procedure; it must be unambiguous. For more information, see Section 15.3.

The following is an example of a procedure interface block defining a generic name:




The three subroutines can be referenced by their individual specific names or by the group name GROUP_SUBS.

The following example shows a reference to INTEGER_SUB:


For More Information:

On interface blocks, see Section 8.9.2.

8.9.4 Defining Generic Operators

An interface block can be used to define a generic operator. The only procedures allowed in the interface block are functions that can be referenced as defined operations.

The initial line for such an interface block takes the following form:



Is one of the following:
  • A defined unary operator (one argument)
  • A defined binary operator (two arguments)
  • An extended intrinsic operator (number of arguments must be consistent with the intrinsic uses of that operator)

The functions within the interface block must have one or two nonoptional arguments with intent IN, and the function result must not be of type character with assumed length. A defined operation is treated as a reference to the function.

The following shows the form (and an example) of a defined unary and defined binary operation:

Operation Form Example
Defined Unary .defined-operator. operand 1 .MINUS. C
Defined Binary operand 2 .defined-operator. operand 3 B .MINUS. C

1The operand corresponds to the function's dummy argument.
2The left operand corresponds to the first dummy argument of the function.
3The right operand corresponds to the second argument.

For intrinsic operator symbols, the generic properties include the intrinsic operations they represent. Both forms of each relational operator have the same interpretation, so extending one form (such as >=) defines both forms (>= and .GE.).

The following is an example of a procedure interface block defining a new operator:


The following example shows a way to reference function BAR by using the new operator:

I = 4 + (.BAR. B)

The following is an example of a procedure interface block with a defined operator extending an existing operator:


The following example shows two equivalent ways to reference function LGFUNC:

N = 10
E = LGFUNC(C(1:N), D(1:N))
E = C(1:N) + D(1:N)

For More Information:

Previous Next Contents Index