Order of argument evaluation (Was: Re: making a checkerboard array?) [message #56018] |
Wed, 26 September 2007 06:01 |
Allan Whiteford
Messages: 117 Registered: June 2006
|
Senior Member |
|
|
JD Smith wrote:
> On Tue, 25 Sep 2007 09:27:17 -0700, Mike wrote:
>
>
>> I'm trying to make a checkerboard mask for an array, but I'm missing
>> something that is likely to be obvious to the IDL array masters.
>
>
>> Can anyone help me fill in the missing rectangles like this?
>> <snip>
>
>
>
> l=lindgen(nx,ny)
> l=(l mod (xside*2) lt xside) XOR (l/nx mod (yside*2) ge yside)
>
> JD
>
Another solution along similar lines (the point of this post is to ask
how valid it is) is:
((s=strarr(nx,ny) + '0'))[where((((l=lindgen(nx,ny)) mod (xside*2) lt
xside) XOR (l/nx mod (yside*2) ge yside)) eq 1)]='+'
In an example:
IDL> nx=30
IDL> ny=30
IDL> xside=5
IDL> yside=5
IDL> ((s=strarr(nx,ny) + '0'))[where((((l=lindgen(nx,ny)) mod (xside*2)
lt xside) XOR (l/nx mod (yside*2) ge yside)) eq 1)]='+'
IDL> print,s,format='('+strtrim(string(nx),2)+'A1)'
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
+++++00000+++++00000+++++00000
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
00000+++++00000+++++00000+++++
Anyway, the real point of my post is to ask if I'm allowed to do the
above. For a more reasonable example am I allowed to do:
plot,(x=findgen(11)),x^2
and rely on the first argument of plot being evaluated before the second
argument (and the side effect of creating 'x') similarly for creating an
array and editing in place, e.g.:
IDL> ((a=fltarr(3)))[1]=10
IDL> print,a
0.00000 10.0000 0.00000
Does anyone else do this or just me? I tend to only do things like this
at the command line and don't embed it in programs out of fear that
it's going to stop working one day. It also arguably makes the code less
readable but as a pattern it's probably not that bad. I'd like to know
what others think.
Thanks,
Allan
|
|
|