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

Home » Public Forums » archive » Re: Counting the number of iregular value in regular grid
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: Counting the number of iregular value in regular grid [message #54207] Sun, 27 May 2007 04:25
jkj is currently offline  jkj
Messages: 48
Registered: April 2007
Member
On May 26, 1:04 am, Nick <jungbin...@hotmail.com> wrote:
> I was trying to count the number of irregular data in regular grid.
> I made code but it's too slow to calculate my lots of data.
> Could you give me some advice to make this code more faster?
> Thank you, Jungbin
>
> ;1 X 1 Grid
> glon = -179.5 + findgen(360)
> glat = 89.5 - findgen(180)
>
> for j = 0, 359 do begin
> if [ (lon(x)-0.5 ge glon(j)) and (lon(x)+0.5 lt glon(j)) ]
> then begin
> for k = 0, 179 do begin
> if [ (lat(x)+0.5 le glat(k)) and (lat(x)-0.5 gt
> glat(k)) ] then begin
> if ( finite( value(j,k) ) eq 1 ) then nn(j,k) = nn(j,k)
> + 1
> endif
> endfor ;k
> endif

I think your comparison logic is backwards (won't you always end up
with a null set?), so I changed the comparisons, so my suggestion:

lowlon = lon - 0.5
highlon = lon + 0.5
lowlat = lat - 0.5
highlat = lat + 0.5
j_loop = where(lowlon[x] le glon and highlon[x] gt glon)
if(j_loop[0] ge 0)then begin
k_loop = where(lowlat[x] le glat and highlat[x] gt glat)
if(k_loop[0] ge 0)then begin
; ...now you have a list of j and k indices which
; meet your criteria
endif
endif

...I'm actually not certain how to gracefully use the resulting j_loop
and k_loop arrays to index the value and nn arrays... there must be
some slick array method to do that, however

-Kevin
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: object graphics: any similar tools already written?
Next Topic: difference between external programming and bridge

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

Current Time: Sat Oct 11 02:16:41 PDT 2025

Total time taken to generate the page: 0.48219 seconds