## MAXLOC intrinsic function

### Standard: F77 F90 F95 F2003 F2008 F2018 Example program

### ＜Syntax＞

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

MAXLOC ( ARRAY [ , MASK , KIND , BACK ] )

ARRAY : rank *N* array of type Integer, Real or Character;

DIM : scalar Integer in the range 1 to *N*;

MASK : array of type Logical and the same shape as ARRAY;

KIND : scalar Integer constant expression;

BACK : scalar Logical;

Result: Integer or Integer(Kind=KIND).
In the form without DIM, the result is a vector of length *N*.
In the form with DIM, the result has rank *N*−1 (thus scalar if ARRAY is a vector), and the shape is that of ARRAY with dimension DIM removed.

### ＜Semantics＞

Reduces an array (either completely, or by collapsing one dimension) by the “location of maximum value” pseudo-operation.

In the form without DIM, the result is the location of the maximum value of the masked elements of ARRAY. In the form with DIM, each element of the result is the location of the maximum element in the dimension DIM vector.

Note that the first element is location number one, regardless of the actual array bounds. If all elements are masked out, or the array has size zero, the result is zero.

If more than one element has the maximum value, the location returned is the first such element (in array element order), unless the BACK argument is present with value .TRUE., in which case it is the last such element (the BACK argument was added by Fortran 2008).

In Fortran 2003, the KIND argument should be used if the array dimensions might be too large for default integer. Fortran 2003 also allows MAXLOC to be applied to type Character.

### ＜Related＞

FINDLOC intrinsic function, MAXVAL intrinsic function, MINLOC intrinsic function, MINVAL intrinsic function, Reduction intrinsic functions