インテル® Fortran コンパイラー 19.0 デベロッパー・ガイドおよびリファレンス

MAXVAL

Transformational Intrinsic Function (Generic): Returns the maximum value of all elements in an array, a set of elements in an array, or elements in a specified dimension of an array.

result = MAXVAL (array[,dim] [,mask])

array

(Input) Must be an array of type integer, real, or character.

dim

(Input; optional) Must be a scalar integer expression with a value in the range 1 to n, where n is the rank of array.

mask

(Input; optional) Must be a logical array that is conformable with array.

Results

The result is an array or a scalar of the same data type as array.

The result is a scalar if dim is omitted or array has rank one.

The following rules apply if dim is omitted:

The following rules apply if dim is specified:

If array has size zero or if there are no true elements in mask, the result (if dim is omitted), or each element in the result array (if dim is specified), has the value of the negative number of the largest magnitude supported by the processor for numbers of the type and kind parameters of array.

If array is of type character, the comparison is done using the ASCII collating sequence.

Example

The value of MAXVAL ((/2, 3, 4/)) is 4 because that is the maximum value in the rank-one array.

MAXVAL (B, MASK=B .LT. 0.0) finds the maximum value of the negative elements of B.

C is the array

  [ 2  3  4 ]
  [ 5  6  7 ].

MAXVAL (C, DIM=1) has the value (5, 6, 7). 5 is the maximum value in column 1; 6 is the maximum value in column 2; and so forth.

MAXVAL (C, DIM=2) has the value (4, 7). 4 is the maximum value in row 1 and 7 is the maximum value in row 2.

The following shows another example:

 INTEGER array(2,3), i(2), max
 INTEGER, ALLOCATABLE :: AR1(:), AR2(:)
 array = RESHAPE((/1, 4, 5, 2, 3, 6/),(/2, 3/))
 ! array is   1 5 3
 !            4 2 6
 i = SHAPE(array)      ! i = [2 3]
 ALLOCATE (AR1(i(2)))  ! dimension AR1 to the number of
                       ! elements in dimension 2
                       ! (a column) of array
 ALLOCATE (AR2(i(1)))  ! dimension AR2 to the number of
                       ! elements in dimension 1
                       ! (a row) of array
 max = MAXVAL(array, MASK = array .LT. 4) ! returns 3
 AR1 = MAXVAL(array, DIM = 1)  ! returns [ 4 5 6 ]
 AR2 = MAXVAL(array, DIM = 2)  ! returns [ 5 6 ]
 END

See Also