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

Home » Public Forums » archive » FOR loop question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
FOR loop question [message #12319] Mon, 13 July 1998 00:00
lbryan is currently offline  lbryan
Messages: 4
Registered: June 1998
Junior Member
Hello all,

I'm developing a developing a bottom / target detector for a ocean
LIDAR system and found a puzzle with a FOR loop that I don't
understand. Could someone tell me why this code runs:
=======================================================
range = 360
x = findgen(range)*!pi/180
y = sin(x) ;simulates my real data
minarray = where(y eq max(y))
maxpos = minarray(0)
window,0
plot,x,y

for rg = 0,range - 2 do begin
if (rg gt 0) then oplot,x,y(0:rg), psym = 2
if (y(rg) gt 0 and y(rg+1) lt 0) then begin $
bottdepth = float(x(rg))+!pi/180*y(rg)/(y(rg+1) + y(rg))
print,rg
rg = range ;end loop through range
endif else bottdepth = 0
endfor

print,bottdepth
end
========================================================
and this code doesn't:
========================================================
range = 360
x = findgen(range)*!pi/180
y = sin(x)
minarray = where(y eq max(y))
maxpos = minarray(0)
window,0
plot,x,y

for rg = maxpos,range - 2 do begin ;<===only difference is here
if (rg gt 0) then oplot,x,y(0:rg), psym = 2
if (y(rg) gt 0 and y(rg+1) lt 0) then begin $
bottdepth = float(x(rg))+!pi/180*y(rg)/(y(rg+1) + y(rg))
print,rg
rg = range ;end loop through range
endif else bottdepth = 0
endfor

print,bottdepth
end
==========================================================

I know changing the index value within a loop isn't slick programming,
but this is how I happened to write it and now I'm curious why one
works and one doesn't.

Lisa Bryan
Arete Associates
Tucson, AZ
lbryan@azstarnet.com
Arete Associates
Tucson, Arizona
[Message index]
 
Read Message
Previous Topic: Re: FOR loop question
Next Topic: OPENW using /XDR (crow recipe)

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

Current Time: Fri Oct 10 09:59:39 PDT 2025

Total time taken to generate the page: 0.95784 seconds