J3/05-124r3 Date: 2005 Feb 09 To: J3 From: Dan Nagle Subject: FINDLOC A Public Comment for f03 requested a FIRSTLOC and a LASTLOC pair of intrinsics to return the first or last elements evaluating to true. Paper 04-113 replaced that suggestion with FINDLOC, and included a BACK= argument, similarly to the string search intrinsics. The 167 Hate .. Love vote was 0 - 1 - 9 - 0. This paper is a proposed "doneness" paper for FINDLOC. This paper slightly generalizes the proposal by changing the search for true by a search for a specified value of any intrinsic type. Number: Title: FINDLOC Submitted By: J3 Status: For Consideration References: J3/03-106, Public Comment by Jean Vezina Basic Functionality: Intrinsic returns location of first element containing a specified value (which may be .true. or .false.), searching from the first or last element of an array. Rationale: Considered in response to a public comment, this formulation is modeled on the MINLOC/MAXLOC procedures. Rather than propose two procedures, a BACK= is proposed modeled after similar argument to the character search routines INDEX, SCAN, and VERIFY. The BACK= is used to distinguish forward and backward searches, this may result is coding convenience or in more compact code. Estimated Impact: The impact score was 3 on the John Reid scale at 167. Detailed Specification: FINDLOC( ARRAY= , VALUE= [, DIM= s-i-e, BACK= s-l-e, KIND= i-i-e]) may be of any intrinsic TKR. shall be a scalar and shall be == compatible with , or if both are logical. shall be an array. DIM and KIND are defined as per MAXLOC and MINLOC. DIM selects the dimension(s) to be scanned, KIND sets the kind value of the result. BACK is defined as per INDEX, SCAN, and VERIFY. If present with the value of .TRUE., the array search scans backwards from the last element of the array, and the indices returned are those of the last element whose value equals the . Returns the indices of the first element of where the value of an element is equal to the scalar specified by the VALUE argument. If is type logical, the test is .eqv. value. Otherwise, the test is == value. If BACK= is present and the s-l-e evaluates to true, returns the index of the first element whose value is starting with the last element and searching backwards (so it returns the last element overall). Example: given integer, dimension( 3) :: i = [ 3, 5, 5] integer, dimension( 1) :: idx idx = findloc( i, value= 5) assigns [2] to idx. For symmetry, it may be desirable to add a BACK= to MAXLOC and MINLOC. However, this paper does not propose to do so. History: J3/04-113 at Meeting 167