NCL Home > Documentation > Functions > Array query

get1Dindex

Finds the indices of a one-dimensional array which exactly match a user specified list of values.

Prototype

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

	function get1Dindex (
		x            [*] : numeric,  
		wanted_value [*] : numeric   
	)

	return_val  :  integer

Arguments

x

A one-dimensional array.

wanted_value

A one dimensional array of the same type as x containing the user specified values of x for which the subscripts [indices] are desired. Exact values only. It does not return the subscripts of the closest values.

Return value

A scalar or one dimensional array containing integer subscripts corresponding to wanted_value.

Description

Finds the indices in a one-dimensional array which equal a user specified list of values. The values must exist in the array to be checked. If the value does not exist, try using closest_val
Differs from ind in that an array of wanted values can be checked versus only a single value. Also, the input to ind must be made into a logical expression.

The input arguments should contain only unique values. Duplicate entries will lead to a fatal error.

Examples

Example 1

Find the subscript indices corresponding to years specified by the user.

  load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
       ;
       ;
  year      = ispan(1870,2006,1)

  year_want = (/1870,1900, 1948, 1957, 1964, 1965, 1989, 2005, 2006/)
  i         = get1Dindex(year,year_want)
     
  print(i)
The output would be:
     
Variable: i
Type: integer
Total Size: 28 bytes
            9 values
[snip]
(0)     0
(1)     30
(2)     78
(3)     87
(4)     94
(5)     95
(6)     119
(7)     135
(8)     136