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

Home » Public Forums » archive » Please help me avoid loops and conditionals
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Please help me avoid loops and conditionals [message #36332] Tue, 09 September 2003 09:44 Go to previous message
pford is currently offline  pford
Messages: 33
Registered: September 1996
Member
Greetings,

I use IDL just frequently enough to know that my ingrained programming
style is sub optimal for IDL but not frequently enough to clearly see
how to improve it. What I want to do is have one object inside the
other, in this case two concentric ellipses, and fill them with
different values. This function will be invoked thousands of times if
not more, so any small improvement here will show significant..

In the example below I see 3 items that sould slow this down, the
array declaration, the loops and the conditional statements. (Note: I
have not tried running this yet since I don't currently have access to
the machine with IDL, so there are likely typo bugs, etc.)

function elp2, a, b, box_dim, vval, e_a,e_b, I_ratio
x_box = box_dim/2
box = intarr(box_dim,box_dim)
o_val = fix(vval / I_ratio)
v = fix(vval)
for i = 0, box_dim-1 do begin
for j = 0, box_dim-1 do begin
x = float(i - x_box)
y = float(j - x_box)
if( ((x/(a+e_a))^2 + (y/(b+e_b))^2) LE 1.0) then $
if( ((x/a)^2 + (y/b)^2) LE 1.0) then box(i,j) = o_val $
else box(i,j) = v
endfor; j = 0, box_dim-1 do
endfor; i = 0, box_dim-1 do
return, box
end


So how do I go about converting this into a Boolean matrix operation
that avoids all of this? Would it be faster to create a mask array
such as:

x = float((indgen(box_dim) � box_dim/2) # replicate(1, box_dim))
y = (transpose(x) / b)^2
x = (x / a)^2
mask = where((x + y) LE 1.0)

?

Thanks
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Work with ENVI vector layers
Next Topic: Re: What does an optimal scientific programming language/environmentneed?

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

Current Time: Sat Oct 11 05:37:26 PDT 2025

Total time taken to generate the page: 0.64106 seconds