**Transformational Intrinsic Function (Generic):** Returns the location of 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 = MINLOC (array [, dim] [, mask] [, kind])

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

dim |
(Input; optional) Must be a scalar integer with a value in the range 1 to n, where |

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

kind |
(Input; optional) Must be a scalar integer initialization expression. |

The result is an array of type integer. If `kind` is present, the kind parameter of the result is that specified by `kind`; otherwise, the kind parameter of the result is that of default integer. If the processor cannot represent the result value in the kind of the result, the result is undefined.

The following rules apply if `dim` is omitted:

The array result has rank one and a size equal to the rank of

`array`.If MINLOC(

`array`) is specified, the elements in the array result form the subscript of the location of the element with the minimum value in`array`.The

`i`th subscript returned lies in the range 1 to`e`_{i}, where`e`_{i}is the extent of the`i`th dimension of`array`.If MINLOC(

`array`, MASK=`mask`) is specified, the elements in the array result form the subscript of the location of the element with the minimum value corresponding to the condition specified by`mask`.

The following rules apply if `dim` is specified:

The array result has a rank that is one less than

`array`, and shape (d_{1}, d_{2},...d_{dim-1}, d_{dim+1},...d_{n}), where (d_{1}, d_{2},...d_{n}) is the shape of`array`.If

`array`has rank one, MINLOC(`array`,`dim`[,`mask`]) has a value equal to that of MINLOC(`array`[,MASK =`mask`]). Otherwise, the value of element (s_{1}, s_{2},...s_{dim-1}, s_{dim+1},...s_{n}) of MINLOC(`array`,`dim`[,`mask`]) is equal to MINLOC(`array`(s_{1}, s_{2},...s_{dim-1}, :, s_{dim+1},...s_{n}) [, MASK =`mask`(s_{1}, s_{2},...s_{dim-1}, :, s_{dim+1},...s_{n})]).

If more than one element has minimum value, the element whose subscripts are returned is the first such element, taken in array element order. If `array` has size zero, or every element of `mask` has the value .FALSE., the value of the result is controlled by compiler option assume [no]old_maxminloc, which
can set the result to either 1 or 0.

The setting of compiler options specifying integer size can affect this function.

The value of MINLOC ((/3, 1, 4, 1/)) is (2), which is the subscript of the location of the first occurrence of the minimum value in the rank-one array.

A is the array

[ 4 0 -3 2 ]

[ 3 1 -2 6 ]

[ -1 -4 5 -5 ].

MINLOC (A, MASK=A .GT. -5) has the value (3, 2) because these are the subscripts of the location of the minimum value (-4) that is greater than -5.

MINLOC (A, DIM=1) has the value (3, 3, 1, 3). 3 is the subscript of the location of the minimum value (-1) in column 1; 3 is the subscript of the location of the minimum value (-4) in column 2; and so forth.

MINLOC (A, DIM=2) has the value (3, 3, 4). 3 is the subscript of the location of the minimum value (-3) in row 1; 3 is the subscript of the location of the minimum value (-2) in row 2; and so forth.

The following shows another example:

INTEGER i, minl(1)

INTEGER array(2, 3)

INTEGER, ALLOCATABLE :: AR1(:)

! put values in array

array = RESHAPE((/-7, 1, -2, -9, 5, 0/),(/2, 3/))

! array is -7 -2 5

! 1 -9 0

i = SIZE(SHAPE(array)) ! Get the number of dimensions

! in array

ALLOCATE (AR1 (i) ) ! Allocate AR1 to number

! of dimensions in array

AR1 = MINLOC (array, MASK = array .GT. -5) ! Get the

! location (subscripts) of

! smallest element greater

! than -5 in array

!

! MASK = array .GT. -5 creates a mask array the same

! size and shape as array whose elements are .TRUE. if

! the corresponding element in array is greater than

! -5, and .FALSE. if it is not. This mask causes MINLOC

! to return the index of the element in array with the

! smallest value greater than -5.

!

!array is -7 -2 5 and MASK= array .GT. -5 is F T T

! 1 -9 0 T F T

! and AR1 = MINLOC(array, MASK = array .GT. -5) returns

! (1, 2), the location of the element with value -2

minl = MINLOC((/-7,2,-7,5/)) ! returns 1, first

! occurrence of minimum

END