Re: Matching Lats and Lons from two arrays [message #62143 is a reply to message #62142] |
Tue, 26 August 2008 10:29   |
Juggernaut
Messages: 83 Registered: June 2008
|
Member |
|
|
On Aug 26, 1:07 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> pgri...@gmail.com wrote:
>> Would something like this work for sorted x (plus some fix for first
>> and last element)?
>> There's going to be an overhead for sorting x if not already sorted
>> however.
>
>> x=[3,3.5,4,6.5,7]
>> y=[3.4, 3.0, 6.8, 6.3]
>
>> a=value_locate(x,y)
>> result=a+( (y-x[a]) GT (x[a+1]-y))
>> print,result
>
>> Ciao,
>> Paolo
>
> this would work if you only have 1 coordinate (latitude), not with 2
> (lat,long)...
> Jean
>
>
>
>> Brian Larsen wrote:
>>> I have tried this on several occasions (for a little different
>>> application but I think its the same) and have had no luck eliminating
>>> the for loop, so I just wrote it in a function to hide it from
>>> myself. This is my try at this based on value locate:
>>> http://people.bu.edu/balarsen/Home/IDL/Entries/2008/1/7_roun d2array_(...
>
>>> If others know how to eliminate the for loop that would be fantastic.
>
>>> Cheers,
>
>>> Brian
>
>>> ------------------------------------------------------------ --------------
>>> Brian Larsen
>>> Boston University
>>> Center for Space Physics
>>> http://people.bu.edu/balarsen/Home/IDL
You could just do them simultaneously and only take the intersection
of the values....
for i = 0, ncols-1 do begin
x2 = rebin(reform(dlat[i,*],nrows),nrows,nels)
x3 = rebin(reform(CS_LATLON,1,nels), nrows,nels)
indices = where(abs(x3-x2) LT 1e-4)
vals = x2[indices]
x2 = rebin(reform(dlon[i,*],nrows),nrows,nels)
x3 = rebin(reform(CS_LATLON,1,nels), nrows,nels)
indices2 = where(abs(x3-x2) LT 1e-4)
vals = x2[indices2]
intersecting = setintersection(indices,indices2)
endfor
Couldn't you?
|
|
|