Intel® Fortran Compiler 18.0 Developer Guide and Reference

MINVAL

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

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

array

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

dim

(Input; optional) Must be a scalar integer 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 positive 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 MINVAL ((/2, 3, 4/)) is 2 because that is the minimum value in the rank-one array.

The value of MINVAL (B, MASK=B .GT. 0.0) finds the minimum value of the positive elements of B.

C is the array

  [ 2  3  4 ]
  [ 5  6  7 ].

MINVAL (C, DIM=1) has the value (2, 3, 4). 2 is the minimum value in column 1; 3 is the minimum value in column 2; and so forth.

MINVAL (C, DIM=2) has the value (2, 5). 2 is the minimum value in row 1 and 5 is the minimum value in row 2.

The following shows another example:

 INTEGER array(2, 3), i(2), minv
 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 number of
                     ! elements in dimension 2
                     ! (a column) of array.
 ALLOCATE(AR2(i(1))) ! dimension AR2 to number of
                     ! elements in dimension 1
                     ! (a row) of array
 minv = MINVAL(array, MASK = array .GT. 4) ! returns 5
 AR1 = MINVAL(array, DIM = 1)   ! returns [ 1 2 3 ]
 AR2 = MINVAL(array, DIM = 2)   ! returns [ 1 2 ]
 END

See Also