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

Home » Public Forums » archive » Programming style
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: Programming style [message #11732 is a reply to message #3375] Sat, 16 May 1998 00:00 Go to previous messageGo to previous message
steinhh is currently offline  steinhh
Messages: 260
Registered: June 1994
Senior Member
J.D. Smith wrote:

> z=findgen(nx*ny*nz)
> x2=((z mod (nx*ny)) mod nx-nx/2)^2
> y2=((z mod (nx*ny))/nx-ny/2)^2
> z2=((temporary(z)/(nx*ny)) - nz/2)^2
> array=bytarr(nx,ny,nz)
> array[where(z2+x2/e11^2+y2/e21^2 le c1^2 AND z2+x2/e12^2+y2/e22^2 ge
> c2^2)]=1b
>
> Note the two ellipses are centered on the midpoint of the array and are
> concentric. This can be modified by changing the subtracted value in
> each of x2,y2,z2. Definitely faster than loops. Elegance is in the eye
> of the beholder, though.

My $0.02 modification (speed/elegance?)

x2 = rebin((findgen(nx,1,1)-nx/2)^2,nx,ny,nz)
y2 = rebin((findgen(1,ny,1)-ny/2)^2,nx,ny,nz)
z2 = rebin((findgen(1,1,nz)-nz/2)^2,nx,ny,nz)
array = z2 + x2/e11^2 + y2/e21^2 LE c1^2 AND $
z2 + x2/e12^2 + y2/e22^2 GE c2^2

In case nx/ny/nz are large, this should save considerable time..

Since we're not using such huge indices any longer, we could
also substitute FINDGEN with INDGEN (if you don't need fractional
pixel positioning of the zero point (center) of the x2,y2,z2
arrays).


Stein Vidar
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: PS_FORM, other new IDL programs available
Next Topic: Re: spawning to my dir, not IDL dir !DIR

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

Current Time: Sat Oct 11 08:09:43 PDT 2025

Total time taken to generate the page: 1.44877 seconds