do I need this IF statement? [message #43247] |
Thu, 24 March 2005 02:07  |
Margrethe
Messages: 4 Registered: March 2005
|
Junior Member |
|
|
I find that in some cases I really need an IF statement to make sure
that I don't address some arrays with index -1. In the example below I
have vectorized the inner loop over j, but have kept the loop over i.
Is there a way to avoid the IF statement? Grateful for help! -Margrethe
FOR i=0,N-1 DO BEGIN
d = sqrt ( x(i) ^2 + y (INDGEN(N)) ^2 )
indx = WHERE ( d LT 3.*sigma, ct )
IF (ct GT 0) THEN BEGIN
v = v1 + vr (i,indx)
p = some_function ( x(i), y(indx) )
profile = profile + TOTAL ( p * image(i,indx) )
ENDIF
ENDFOR
|
|
|
Re: do I need this IF statement? [message #43283 is a reply to message #43247] |
Fri, 25 March 2005 16:25  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Margrethe wrote:
>
> I find that in some cases I really need an IF statement to make sure
> that I don't address some arrays with index -1. In the example below I
> have vectorized the inner loop over j, but have kept the loop over i.
> Is there a way to avoid the IF statement? Grateful for help! -Margrethe
>
> FOR i=0,N-1 DO BEGIN
>
> d = sqrt ( x(i) ^2 + y (INDGEN(N)) ^2 )
> indx = WHERE ( d LT 3.*sigma, ct )
>
> IF (ct GT 0) THEN BEGIN
>
> v = v1 + vr (i,indx)
> p = some_function ( x(i), y(indx) )
> profile = profile + TOTAL ( p * image(i,indx) )
>
> ENDIF
>
> ENDFOR
My suggestions to your syntax and usage of WHERE.
If you write index operations please use []. At the moment I can't decide if
x,y,vr,image is an array or a function. I suppose they are arrays. In the
past only () were used by functions and arrays and we got a lot of
conflicts. Because idl doesn't know either what it should be. It could be
both but if once is recogniced it's impossible to have the other one in the
same code.
Whenever you use WHERE you should use an IF condition to test if you get a
result!
cheers
Reimar
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|