>  Docs Center  >  Libraries  >  Mankoff  >  NEAREST_ELEMENT
Libraries

NEAREST_ELEMENT

NEAREST_ELEMENT

Name


    NEAREST_ELEMENT.PRO

Purpose


    This function return the nearest element in a LIST to a provided VALUE

Warning/note


    Look at the IDL provided procedure VALUE_LOCATE, as it performs
    a similar function, and works with arrays, and is MUCH
    faster. However, it uses interpolation, so it provides the wrong
    answer sometimes, depending on the type of array passed to it
    IDL> a = [ 0, 1, 1.1, 1.2, 10, 11, 12 ]
    IDL> print, value_locate( a, 1.16 ) ; WRONG
    IDL> print, vaule_locate( a, 9.00 ) ; WRONG
   
    The input array must be fairly linear for VALUE_LOCATE to
    work. If it is not, or has data gaps, use this procedure
    (NEAREST_ELEMENT)

Category


    Vector

Calling Sequence


    result = NEAREST_ELEMENTS( value, list, position )

Inputs


    value: This is a scalar value.
    list: This is a vector of any type but 'string'
  OUTPUTS: This function returns the element from list that is
    closest to value
  OPTIONAL OUTPUTS: The position into list of the nearest value
    can optionally be returned
  SIDE EFFECTS: hopefully none

Restrictions


    value cannot be an array
    list must be sequentially increasing
  PROCEDURE: Perform a min(where()) and a max(where()). If multiple
    entries in das_list are equally close, the first entry is returned.

Example


    val = 42
    list = [ 40, 41, 44, 48 ] ; list = list[sort(list)]
    print, nearest_element( val, list, p ), p
        41 1

Modification History


    KDM; 2002-04-09; wrote procedure
    KDM; 2002-05-16; documented
    KDM; 2002-07-31; Changed name and code from Mariner 9 DAS
        specific to vector general
    KDM; 2002-08-16; Removed all but 1 where() statement for speed



© 2024 NV5 Geospatial Solutions, Inc. |  Legal
   Contact Us