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

Home » Public Forums » archive » "infinite" nested for
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: "infinite" nested for [message #86643 is a reply to message #86642] Mon, 25 November 2013 08:37 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Chrisss writes:

Another way you can improve this code is to only calculate unchanging
variable once, and outside the loops. For example, you have this, in
which you calculate the number of elements of X, which never changes,
six times!

for i=0, dx-1 do begin
for j=0,dy-1 do begin
y=reform (Im[i,j,*],N_ELEMENTS(x)))
fitErrors=FLTARR(N_ELEMENTS(x))
T1values=FLTARR(N_ELEMENTS(x))
S0values=FLTARR(N_ELEMENTS(x))
fvalues=FLTARR(N_ELEMENTS(x))
for t=0,N_ELEMENTS(x)-1 do begin

This can be changed to this:

num_x = N_Elements(x)
fitErrors=FLTARR(num_x)
T1values=FLTARR(num_x)
S0values=FLTARR(num_x)
fvalues=FLTARR(num_x)
for i=0, dx-1 do begin
for j=0,dy-1 do begin
y=reform (Im[i,j,*],num_x)
for t=0,num_x-1 do begin

If you need to reinitialize your arrays inside the loop, then do this,
rather than re-allocating more memory. I think this is probably why your
program crashed after 12 hours. You ran out of dynamic memory on your
machine:

fitErrors=Temporary(fitErrors)*0.0
T1values=Temporary(T1values)*0.0
S0values=Temporary(S0values)*0.0
fvalues=Temporary(fvalues)*0.0

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: lamda default value in CURVEFIT function
Next Topic: Secret of Failed IDL Business Plan

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

Current Time: Wed Oct 08 15:14:26 PDT 2025

Total time taken to generate the page: 0.00426 seconds