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

Home » Public Forums » archive » Re: for loops for total newbies
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
Re: for loops for total newbies [message #54792] Fri, 13 July 2007 16:42 Go to next message
Anna is currently offline  Anna
Messages: 2
Registered: July 2007
Junior Member
Thank you both! That was really helpful.

I think I'll be having a lot of fun the coming week :)
(And now I've been reminded that I should change the name of the
variables that came from my advisors' code... I really can't imagine
why he named it 'kaas'. Which means 'cheese'.)

Thanks again,

Anna
Re: for loops for total newbies [message #54795 is a reply to message #54792] Fri, 13 July 2007 11:45 Go to previous messageGo to next message
Conor is currently offline  Conor
Messages: 138
Registered: February 2007
Senior Member
I'm afraid a lot of this you might just have to come up with
yourself. It's hard (for me anyway) to vectorize everything for you
because I'm just not that familiar with your code. I don't know the
dimensions of everything, and I don't really know what you're trying
to accomplish. However, I think I can provide some hints that should
help.

First of all, why do you have a wait inside a for loop??? Even if it
doesn't cost you that much time, it still has no purpose that I can
see.

Second, remember that if an operation doesn't have to be in the for
loop, don't put it in the for loop! So in your inner-most loop you
have these two lines:

k2=(k+1+ max_cor_shift) mod max_cor_shift
k1=(k-1+ max_cor_shift) mod max_cor_shift

However the loop itself is looping over f, and the loop above it is
looping over i, neither of which appear in either of these lines. It
seems to me that these two variables should be constants inside the
loop, so you should move them out of the loop entirely. That probably
won't make a huge difference, but it will help.

Now the important part. It might be very difficult to get rid of both
for loops, but it should be pretty easy to get rid of the innermost
one. The first trick you will have to do is use the dimensions
keyword to max(). You'll want to get rid of the for loop over f, and
instead try something like this:

crtot= fltarr(sz-1,(size(cor_array))[2],(size(cor_array))[3])
crtot(0:sz-3,*,*)= cor_array(0:sz-3,*,*)

meanarr = fltarr((size(cor_array))[2])
j= findgen(1000*max_cor_shift)/1000.0
avgz= fltarr(sz-2)
fit = fltarr(sz-2, max_cor_shift*1000)

k2=(k+1+max_cor_shift) mod max_cor_shift
k1=(k-1+ max_cor_shift) mod max_cor_shift

for i = 0, (size(cor_array))[2]-1 do begin
print, i

maxcrs = max(crtot,ks,dimension=1)
a = crtot(*,i,k2)/2 + crtot(*,i,k1)/2 - maxcrs
b = crtot(*,i,k2)/2 - crtot(*,i,k1)/2 - maxcrs
c = maxcrs

fit = a*(j-k)^2 + b*(j-k) + c
kaas = max(fit, s, dimension=1)
avgz = s/(float(sz)) - 10

meanarr(i)=mean(avgz)
endfor



Now I really doubt the above code will work, but that's essentially
what you want to do. By saying: maxcrs = max(crtot,ks,dimension=1)
you are returning not just the maximum of a row, but the maximum of
every row. Then, you calculate 'a' for every row, 'b' for every row,
'c' for every row, and 'fit' for every row. I'm not sure if I quite
did it right though, because I'm not very sure what the dimensions of
fit are, and whether or not everything matches up. You'll probably
have to adjust the code accordingly. Same with the calculation of
kaas and avgz. Hopefully though, this will give you an idea of what
needs to be done.

Actually, considering that very little is done in the outer loop, you
might be able to get rid of it as well and do the whole thing loop-
less. I'm not really sure though, you might have to play around with
that yourself.
Re: for loops for total newbies [message #54799 is a reply to message #54795] Fri, 13 July 2007 08:44 Go to previous messageGo to next message
Brian Larsen is currently offline  Brian Larsen
Messages: 270
Registered: June 2006
Senior Member
Anna, First thing to do is really familiarize yourself with http://dfanning.com/.
Everything in the IDL world is at least mentioned here if not solved
(or so it seems).

Be sure to read carefully "The IDL way" http://www.dfanning.com/documents/tips.html#IDLWAY
These articles will help get you thinking like IDL.

Then from my experience about the only thing that has to be in for
loop is file I/O. Other than that you can almost always get away w/o
them if you are clever enough (I am often not that clever either
however)

I am too busy to take a long whack at your code but it is possible.

Hope this helps,

Brian


------------------------------------------------------------ ---------------------
Brian Larsen
Boston University
Center for Space Physics
Re: for loops for total newbies [message #54874 is a reply to message #54792] Mon, 16 July 2007 06:31 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Anna wrote:
> Thank you both! That was really helpful.
>
> I think I'll be having a lot of fun the coming week :)
> (And now I've been reminded that I should change the name of the
> variables that came from my advisors' code... I really can't imagine
> why he named it 'kaas'. Which means 'cheese'.)

Maybe he thought his code was full of holes.... ?

:o)


cheers,

paulv

--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: fortran feasability
Next Topic: Re: fortran feasability

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

Current Time: Wed Oct 08 15:53:20 PDT 2025

Total time taken to generate the page: 0.00721 seconds