MAXVAL(ARRAY, DIM, MASK) or MAXVAL(ARRAY, MASK)

Purpose

Returns the maximum value of the elements in the array along a dimension corresponding to the true elements of MASK.

Class

Transformational function

Argument type and attributes

ARRAY
An INTEGER, REAL, or CHARACTER array.
DIM (optional)
An INTEGER scalar. Its value must be in the range 1 ≤ DIM ≤ rank(ARRAY).
MASK (optional)
A LOGICAL array that conforms to ARRAY in shape. If it is absent, the entire array is evaluated.

Result value

The result is an array of rank rank(ARRAY)-1, with the same data type as ARRAY. If DIM is missing or if ARRAY is of rank one, the result is a scalar. If ARRAY is of type character, the length of the result is the same as that of ARRAY.

If DIM is specified, each element of the result value contains the maximum value of all the elements that satisfy the condition specified by MASK along each vector of the dimension DIM. The array element subscripts in the result are (s1, s2, …, s(DIM-1), s(DIM+1), …, sn), where n is the rank of ARRAY and DIM is the dimension specified by DIM.

If DIM is not specified, the function returns the maximum value of all applicable elements.

If ARRAY is of type character, all comparisons are done using the ASCII collating sequence.

If ARRAY is zero-sized or the mask array has all .FALSE. values, then:

Because both DIM and MASK are optional, various combinations of arguments are possible. When the -qintlog option is specified with two arguments, the second argument refers to one of the following:
  • MASK if it is an array of type integer, logical, byte or typeless
  • DIM if it is a scalar of type integer, byte or typeless
  • MASK if it is a scalar of type logical

Examples

! A is the array  | -41  33 25 |
!                 |  12 -61 11 |

! What is the largest value in the entire array?
       RES = MAXVAL(A)
! The result is 33

! What is the largest value in each column?
       RES = MAXVAL(A, DIM=1)
! The result is | 12 33 25 |

! What is the largest value in each row?
       RES = MAXVAL(A, DIM=2)
! The result is | 33 12 |

! What is the largest value in each row, considering only
! elements that are less than 30?
       RES = MAXVAL(A, DIM=2, MASK = A .LT. 30)
! The result is | 25 12 |