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

Home » Public Forums » archive » do I need this IF statement?
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
do I need this IF statement? [message #43247] Thu, 24 March 2005 02:07 Go to next message
Margrethe is currently offline  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 Go to previous message
R.Bauer is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Displaying floating point values with user specified decimal places?
Next Topic: Great News Blog!

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

Current Time: Sat Oct 11 04:39:39 PDT 2025

Total time taken to generate the page: 1.92177 seconds