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

Home » Public Forums » archive » Re: Expensive loops... can they be avoided?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Expensive loops... can they be avoided? [message #59023 is a reply to message #58891] Tue, 04 March 2008 14:02 Go to previous message
Spon is currently offline  Spon
Messages: 178
Registered: September 2007
Senior Member
On Feb 26, 4:15 pm, Rainer <ren...@arcor.de> wrote:
> Thank you Allan. The TRIGRID solution works, and is amazingly fast,
> but unfortunately not quite what I want.
>
> Thanks again,
> Rainer

Rainer,

here's my version, I'd be interested to hear if it works. The keys are
to use WHERE in place of the IF statement (predictably), and the
combination of the DIMENSION keyword to MIN with the use of MOD to
bring the subscripts generated back to meaningful values.

Sorry it's been so long in coming, hopefully it'll make up for it by
being that much faster to run! :-)
Let me know how you get on please,

Good luck!
Chris

; --- Start of code ---

NX = N_ELEMENTS(X)
NY = N_ELEMENTS(Y)
NR = N_ELEMENTS(R)
NC = N_ELEMENTS(Chi)

XX = REBIN(X, NX, NY)
YY = TRANSPOSE(REBIN(Y, NY, NX))

RVals = SQRT(XX^2 + YY^2)
RIndex = WHERE(RVals GT RMax, RCount, $
NCOMPLEMENT = RCompCount)

ChiVals = ATAN(XX, YY)
ChiIndex = WHERE(ChiVals GT ChiMax, $
ChiCount, NCOMPLEMENT = ChiCompCount)

; No good data? Get out now!
IF (RCompCount + ChiCompCount) EQ 0 THEN $
RETURN, REPLICATE(Environment_Value, NX, NY)

; Locate bad data:
IF (RCount + ChiCount) NE 0 THEN BEGIN
IF RCount NE 0 THEN BEGIN
IF ChiCount NE 0 THEN BEGIN
BadIndex = [RIndex, ChiIndex]
BadIndex = BadIndex[UNIQ(BadIndex, $
SORT(BadIndex))] ; If bad R and Chi
ENDIF ELSE BadIndex = RIndex ; If only bad R
ENDIF ELSE BadIndex = ChiIndex ; If only bad Chi
ENDIF

RVals = REBIN(RVals, NX, NY, NR, /SAMPLE)
RVals = TRANSPOSE(RVals, [2, 0, 1])

ChiVals = REBIN(ChiVals, NX, NY, NC, /SAMPLE)
ChiVals = TRANSPOSE(ChiVals, [2, 0, 1])

RR = REBIN(R, NR, NX, NY, /SAMPLE)
CC = REBIN(Chi, NC, NX, NY, /SAMPLE)

RDiff = RVals - RR
RFoo = MIN(RDiff, LeastR, /ABSOLUTE, $
DIMENSION = 1) ; Calculate R subscripts.
LeastR = LeastR MOD NR ; Bring subscripts back
; to 0:(nr)-1 range.

CDiff = ChiVals - CC
ChiFoo = MIN(CDiff, LeastChi, /ABS, DIM = 1)
LeastChi = LeastChi MOD NC

; Define B array:
B = A[LeastR, LeastChi]

; Replace any out-of-bound subscripts:
IF N_ELEMENTS(BadIndex) NE 0 THEN $
B[BadIndex] = Environment_Value

; --- End of code ---
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Convenient IGRF in IDL
Next Topic: Re: using the WHERE function on a portion of an array

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

Current Time: Sat Oct 11 21:38:37 PDT 2025

Total time taken to generate the page: 0.87399 seconds