HP Fortran Programmer's Reference (September 2007)

Arrays
Array-valued functions
Chapter 3 79
Array-valued functions
A function may be array-valued; that is, its return value may evaluate to an array of values
rather than to a scalar. Array-valued functions may appear in any array expression except:
In an input list
On the left side of an assignment statement (unless returning the result from within a
function)
Array-valued functions may also be used in an array expression wherever a scalar function
reference is allowed but must be conformable—that is, the function result must have the same
shape as the expression.
The following sections describe intrinsic functions and user-defined functions that are
array-valued.
Intrinsic functions
Elemental procedures and transformation procedures have particular relevance to array
expressions. Elemental procedures—for example, SQRT and SIN—are specified for scalar
arguments, but with an array argument they return an array-valued result with the same
shape as the argument. Each element of the result is as if the function were applied to each
corresponding element of the argument.
A transformational procedure—for example, RESHAPE, SUM, and MATMUL—generally has one or
more array arguments that the procedure operates on as a whole, and usually returns an
array-valued result whose elements may depend not only on the corresponding elements of
the arguments but also on the values of other elements of the arguments.
User-defined functions
User-defined functions can return either a scalar-valued result or an array-valued result. A
scalar function can appear in an array expression; its effect is to broadcast its value
throughout a conformable array. A reference to a user-defined array-valued function must
obey the rules for functions in general, and must also conform to the shape of the expression
in which it appears.
User-defined functions are described in “External procedures” on page 161.
The following code segment illustrates two array-valued functions, genrand (user-defined)
and RESHAPE (intrinsic):