| United States-English |
|
|
|
![]() |
HP Fortran 90 Programmer's Reference: HP Series 700/800 Computers > Chapter 4 ArraysArray functions |
|
Functions may be used in array expressions. As well as returning a scalar result, a function may also be defined to return an array result. Array functions may be used in any array expression provided that they do not appear:
Array 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. Functions that return arrays are also known as array-valued functions and may be either:
Intrinsic functions are an integral part of the Fortran 90 Standard and are described in detail in Chapter 11. The group of functions known as elemental procedures and transformation procedures have particular relevance to array expressions. Elemental procedures are specified for scalar arguments, but when used with an array argument will return an array result with the same shape as its argument(s); each element of the result is as if the function were applied to each corresponding element of the argument. Examples of elemental intrinsic procedures are the mathematical functions SQRT and SIN. A transformational procedure on the other hand generally has one or more array arguments which the procedure operates on as a whole, and usually returns an array 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. The RESHAPE intrinsic mentioned earlier in the chapter is an example of a transformational procedure; other examples are the intrinsic functions SUM and MATMUL. User-defined functions are not elemental in that they are defined to return either a scalar result or to return an array result; also they cannot be used interchangeably with scalar or array arguments. A scalar function may of course appear in an array expression but the effect, as with any other scalar, is to first broadcast its value throughout a conformable array. A reference to a user-defined array 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 Chapter 7. The following example shows how an array-valued function may be referenced.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||