9.3.96 MAXLOC (ARRAY [, DIM] [, MASK] [, KIND])

Description:  Returns the location of 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. 
Class:  Transformational function; Generic 
Arguments:  ARRAY Must be an array of type integer or real. 
  DIM (opt) Must be a scalar integer with a value in the range 1 to n, where n is the rank of ARRAY. This argument is a Fortran 95 feature. 
  MASK (opt) Must be a logical array that is conformable with ARRAY. 
  KIND (opt) Must be a scalar integer initialization expression.  
Results:  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 MAXLOC (ARRAY) is specified, the elements in the array result form the subscript of the location of the element with the maximum value in ARRAY. The ith subscript returned lies in the range 1 to ei, where ei is the extent of the ith dimension of ARRAY.

  • If MAXLOC (ARRAY, MASK=MASK) is specified, the elements in the array result form the subscript of the location of the element with the maximum 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 (d1, d2, ..., dDIM-1, dDIM+1, ..., dn), where (d1, d2, ..., dn) is the shape of ARRAY.

  • If ARRAY has rank one, MAXLOC (ARRAY, DIM [,MASK]) has a value equal to that of MAXLOC (ARRAY [,MASK = MASK]). Otherwise, the value of element (s1, s2, ..., sDIM-1, sDIM+1, ..., sn) of MAXLOC (ARRAY, DIM [,MASK]) is equal to MAXLOC (ARRAY (s1, s2, ..., sDIM-1, :, sDIM+1, ..., sn) [,MASK = MASK (s1, s2, ..., sDIM-1, :, sDIM+1, ..., sn)]).
If more than one element has maximum 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 undefined. 

Examples

The value of MAXLOC ((/3, 7, 4, 7/)) is (2), which is the subscript of the location of the first occurrence of the maximum value in the rank-one array.

A is the array

  [  4    0   -3    2 ]
  [  3    1   -2    6 ]
  [ -1   -4    5   -5 ].

MAXLOC (A, MASK=A .LT. 5) has the value (1, 1) because these are the subscripts of the location of the maximum value (4) that is less than 5.

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

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


Previous Page Next Page Table of Contents