[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FOR statement



>Eli,
>
>No matter how look at it, your example shows you *are* using a loop to
>create an evenly spaced mesh vector. I guess I was trying to say that
>using a loop is not the best way to do this in IDL. One of the wisest
>pieces of advice I ever received about IDL programming was
>
>"Try to think like an IDL programmer, not a Fortran or C programmer".
>
>In this spirit, I submit that the following method is preferable:
>
>nx = 1000    ; number of values required
>dx = 0.25    ; step size
>x1 = 0.0     ; start value
>radius = lindgen(nx) * dx + x1
>
>You might try changing the number of values to 10,000,000 and seeing
>which method is faster.
>
>Cheers,
>Liam.

Well, here's my FOR loop with some background info... The radius
vector was what was hanging me up -- it was not what the FOR loop was FOR!

I can't reason out any way of doing this without the loop, but I
imagine it can be done...

dist = sqrt((x-xc)^2 + (y-yc)^2)    ;xc & yc are the center positions
bin = 0.25                          ;of a distribution of points
psf = histogram(dist,binsize=bin)   ;psf is the radial profile
norm = total(psf)
maxR = max(dist)

ee=fltarr((maxR/bin)+1)
rval=fltarr(maxR/bin)+1)

FOR i=0.0, maxR/bin DO BEGIN
   radius = i * bin
   insidecounts = n_elements(where(dist le radius)) 
   rval(i) = radius              
   ee(i) = insidecounts/norm        ;to establish the number of counts
                                    ;within a given radius
ENDFOR