NCL Website header
NCL Home > Documentation > Functions > Array query

dim_maxind

Returns the index of the first occurrence of a maximum value within the specified dimension.

Available in version 6.4.0 and later.

Prototype

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

	function dim_maxind (
		arg     : numeric,  
		dim [1] : integer   
	)

	return_val  :  integer array containing first occurrence of a maximum value

Arguments

arg

An array of up to four dimensions.

dim

The dimension number of arg along which the first maximum is desired. Currently, this must be set to 0 which corresponds to the leftmost dimension.

Return value

integer array containing the index of first occurrence of a maximum value

Description

This function scans an array for the maximum value and returns the index of the first occurrence along the specified dimension. Missing values are ignored. Remember that in NCL, indexing starts at 0, not 1.

This function will return a long if on a 64-bit system and the index value is >= 2 GB.

This function is based upon a response by Dave Allured (NOAA Affiliate) to an question asked on ncl-talk@ucar.edu.

See Also

dim_maxind, maxind, minind, ind_resolve, min, max, dim_min, dim_max, dim_min_n, dim_max_n

Examples

Example 1: Trivial example. The results should be identical (i=>j=2)


   x = (/3.,2.,5.,1.,5.,2.,5.,1.,3.,2./)
   i = maxind(x)                           ; Should be 2.
   j = dim_maxind(x, 0) ; dim=0 

Example 2: Find the first index value correspnding to the minimum and maximum values along the specified dimension.

   z = (/ (/1, 2, 3, 4, 7/), \         ; a(4,5) ; dimension 0 is the leftmost dimension
          (/5, 6, 7, 8, 3/), \
          (/9, 1, 9, 8,10/), \
          (/7, 6, 1, 4, 3/)  /)

   nmin = dim_minind(z, 0)  ; nmim= (/0, 2, 3, 0, 1/)
   nmax = dim_maxind(z, 0)   ; nmax= (/2, 1, 2, 1, 2/)