comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: X/Y convert to lat/lon
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: X/Y convert to lat/lon [message #75635] Tue, 15 March 2011 09:53
Robert Moss, PhD is currently offline  Robert Moss, PhD
Messages: 29
Registered: November 2006
Junior Member
You might want to check out VALUE_LOCATE
Re: X/Y convert to lat/lon [message #75637 is a reply to message #75635] Tue, 15 March 2011 08:38 Go to previous message
Kenneth P. Bowman is currently offline  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
Re: X/Y convert to lat/lon [message #75647 is a reply to message #75637] Tue, 15 March 2011 02:36 Go to previous message
teddyallen is currently offline  teddyallen
Messages: 5
Registered: September 2010
Junior Member
On Mar 15, 3:33 am, Fabzou <fabien.mauss...@tu-berlin.de> wrote:
> On 03/15/2011 05:53 AM, teddyallen wrote:
>
>
>
>
>
>> longitude = findgen(144)*2.5 ;creates a 144 element array with values
>> evenly spaced between 0 ->  357.5
>> latitude = ((findgen(73)*2.5)-90.)*(-1.) ;creates a 73 element array
>> with values evenly spaced between -90 ->  +90
>> xlon = 342 ;this is the longitude value I would like to subset the
>> array with
>> xlat = 35; this is the latitude value I would like to subset the array
>> with
>> lon1= where(longitude eq xlon)  ; provides the longitude index
>> dimension for array
>> lat1=where(latitude eq xlat)
>> test = array[lon1,lat1]   ; results in the subset of the arry given
>> xlon and xlat
>
>> The xlon value should be associated with the nearest 2.5 multiple,
>> which in this case would be xlon=342.5.....obviously not -1.
>> Any suggestions?
>> Thank you
>
> Well, where() is really not supposed to do so. It looks for exact
> matches... where(longitude eq 342.5) MAY work, but only if the sky is
> not falling (http://www.idlcoyote.com/math_tips/sky_is_falling.html).
>
> One method would be:
> IDL> longitude = findgen(144)*2.5
> IDL> m = min(abs(longitude - 342), p)
> IDL> print, longitude[p]
>        342.500
>
> But this is not always exact and there are plenty of better methods,
> especially when you are located on the "sphere"- Hide quoted text -
>
> - Show quoted text -

Dear Fabzou,
THANK YOU so much! I knew the resolution would rest in a few short
lines. I can now add these lines to my growing tank of IDL knowledge.
Let me know if you are ever in Miami and lunch is one me!
cheers,
teddy
Re: X/Y convert to lat/lon [message #75648 is a reply to message #75647] Tue, 15 March 2011 00:33 Go to previous message
Fabzou is currently offline  Fabzou
Messages: 76
Registered: November 2010
Member
On 03/15/2011 05:53 AM, teddyallen wrote:
> longitude = findgen(144)*2.5 ;creates a 144 element array with values
> evenly spaced between 0 -> 357.5
> latitude = ((findgen(73)*2.5)-90.)*(-1.) ;creates a 73 element array
> with values evenly spaced between -90 -> +90
> xlon = 342 ;this is the longitude value I would like to subset the
> array with
> xlat = 35; this is the latitude value I would like to subset the array
> with
> lon1= where(longitude eq xlon) ; provides the longitude index
> dimension for array
> lat1=where(latitude eq xlat)
> test = array[lon1,lat1] ; results in the subset of the arry given
> xlon and xlat
>
> The xlon value should be associated with the nearest 2.5 multiple,
> which in this case would be xlon=342.5.....obviously not -1.
> Any suggestions?
> Thank you

Well, where() is really not supposed to do so. It looks for exact
matches... where(longitude eq 342.5) MAY work, but only if the sky is
not falling (http://www.idlcoyote.com/math_tips/sky_is_falling.html).

One method would be:
IDL> longitude = findgen(144)*2.5
IDL> m = min(abs(longitude - 342), p)
IDL> print, longitude[p]
342.500

But this is not always exact and there are plenty of better methods,
especially when you are located on the "sphere"
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: journal files
Next Topic: color and tvellipse

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:17:07 PDT 2025

Total time taken to generate the page: 0.00544 seconds