Re: X/Y convert to lat/lon [message #75637 is a reply to message #75635] |
Tue, 15 March 2011 08:38   |
Kenneth P. Bowman
Messages: 585 Registered: May 2000
|
Senior Member |
|
|
In article
<887457ef-3c22-404a-a958-176714fa2053@s18g2000vbe.googlegroups.com>,
teddyallen <teddyallen@yahoo.com> wrote:
> I am reluctant to post this since it seems like a very easy task, but
> unfortunately, I cannot manage to figure it out on my own nor with any
> online search help. ( I am away from home and my trusty IDL books are
> not on pdf....bummer!)
I use this function frequently,
Ken Bowman
FUNCTION INDEX_OF_NEAREST, x, x0
;+
;NAME:
; INDEX_OF_NEAREST
;PURPOSE:
; This function finds the index of the element of x whose value is
; nearest to x0. This is primarily useful for finding the index of
; a point in an ordered 1-dimensional array. For example, if x is
; an array of latitudes, this function will return the index of the
; element of the array that is closest to the latitude x0.
; If there are multiple elements in x that are the same distance from
; x0, this function returns the first one.
;CATEGORY:
; Array utility.
;CALLING SEQUENCE:
; i = INDEX_OF_NEAREST(x, x0)
;INPUT:
; x : array of values to search.
; x0 : value to search for.
;KEYWORDS:
; None.
;OUTPUT:
; Index of element nearest to x0.
;MODIFICATION HISTORY:
; KPB, 1999-04.
;-
COMPILE_OPT IDL2
i = (WHERE(ABS(x - x0) EQ MIN(ABS(x - x0)), count))[0]
RETURN, i
END
|
|
|