FINDLOC intrinsic function

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


<Syntax>

FINDLOC ( ARRAY, VALUE, DIM [ , MASK , KIND , BACK ] )
FINDLOC ( ARRAY VALUE, [ , MASK , KIND , BACK ] )

ARRAY : rank N array of intrinsic type;
VALUE : scalar value that is comparable (with == or .EQV. to ARRAY);
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 the specified value” pseudo-operation.

In the form without DIM, the result is the location of the specified value among the masked elements of ARRAY. In the form with DIM, each element of the result is the location of the specified value 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 specified 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 KIND argument should be used if the array dimensions might be too large for default integer.

<Related>

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