02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Array-valued functions<br />

Arrays<br />

Array-valued functions<br />

A function may be array-valued; that is, its return value may evaluate to an array of values<br />

rather than to a scalar. Array-valued functions may appear in any array expression except:<br />

Inaninputlist<br />

On the left side of an assignment statement (unless returning the result from within a<br />

function)<br />

Array-valued functions may also be used in an array expression wherever a scalar function<br />

reference is allowed but must be conformable—that is, the function result must have the same<br />

shape as the expression.<br />

The following sections describe intrinsic functions and user-defined functions that are<br />

array-valued.<br />

Intrinsic functions<br />

Elemental procedures and transformation procedures have particular relevance to array<br />

expressions. Elemental procedures—for example, SQRT and SIN—are specified for scalar<br />

arguments, but with an array argument they return an array-valued result with the same<br />

shape as the argument. Each element of the result is as if the function were applied to each<br />

corresponding element of the argument.<br />

A transformational procedure—for example, RESHAPE, SUM, andMATMUL—generally has one or<br />

more array arguments that the procedure operates on as a whole, and usually returns an<br />

array-valued result whose elements may depend not only on the corresponding elements of<br />

the arguments but also on the values of other elements of the arguments.<br />

User-defined functions<br />

User-defined functions can return either a scalar-valued result or an array-valued result. A<br />

scalar function can appear in an array expression; its effect is to broadcast its value<br />

throughout a conformable array. A reference to a user-defined array-valued function must<br />

obey the rules for functions in general, and must also conform to the shape of the expression<br />

in which it appears.<br />

User-defined functions are described in “External procedures” on page 129.<br />

The following code segment illustrates two array-valued functions, genrand (user-defined)<br />

and RESHAPE (intrinsic):<br />

Chapter 4 77

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

Saved successfully!

Ooh no, something went wrong!