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

Home » Public Forums » archive » Re: Having trouble stopping a loop (or loop de loop de loop)
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: Having trouble stopping a loop (or loop de loop de loop) [message #62146] Tue, 26 August 2008 09:46 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
> 1.) I'm not sure how to start and more importantly, end this loop. I
> chose: while e_t lt 2 do begin to start it. The problem is that this
> loop will never be greater than 2 so it will never end and it just
> keeps repeating values ad nauseum in the output file.
>
> I don't want it repeating but I'm not certain how to start it and stop
> it to allow for no repeated values.

If I understand you right, you want to work with different values of
e_t, but not with the same value twice. In this case, using "if" instead
of "while" will NOT help you, as it will process your code only once, no
matter what is the value of e_t.
So, you can keep your "while" loop, but you must also keep a copy of the
previous e_t value.

e_t_previous = -999 ;(a value you will NEVER get in your code)
e_t = 1.4
...

while e_t lt 2 and e_t_previous ne e_t do ...
e_t_previous= e_t
... ;change e_t
endWhile

Now, with this, you will still have the problem of comparing floats...
which you don't want to. Try
if 0.3+0.6 ne 0.9 then print, 'What??? 0.9 is not 0.9???'
then
print, 0.3+0.6, format = '(F20.10)'
0.9000000358
So basically you would do insteand: e_t - 2 le epsilon, epsilon being
small enough.

> 2.) for for c=0.006, 0.01, 0.004 do begin, I watch the output, but I
> don't see it change.

Of course it will not.
You INCREASE 0.006, by 0.01, UP to 0.004 ... 0.004<0.006 so this loop is
never executed.

> 3.) i must of screwed something up in this segment:
> if e_t ge 0.45 && e_t le 0.9 then openw,1,'g:\Mars_tectonics
> \IDL_programs\paper_m_data\alba_eflank.txt',
> printf,1,x,c,o,e_t,format='(3f9.3)'
>
> because it worked before, but know I keep getting an error about
> unable to close 1, or somesuch thing (just switched to compilation
> error).

Yes, if e_t does not satisfy this condition, the file will not be
open... but you try to close it after that. You can't close what is not
open.
do a "then begin", end put the "endif" after the "close" statement.

> As always, I appreciate any help that you may provide. After all I
> wouldn't be asking this question if it weren't for all your help :)

A good way to debug your program is to manually run it (or step by step
if you prefer). Use it with different values and check if it behave as
you have expected. You would have noticed much of the problem in your
code by doing that!

Jean

> Thanks,
> ~Matt
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Matching Lats and Lons from two arrays
Next Topic: Re: heap_free fatal error

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

Current Time: Wed Oct 08 17:04:15 PDT 2025

Total time taken to generate the page: 0.00403 seconds