In article <3ius72$52g@hermod.uio.no>, steinhh@amon.uio.no (Stein Vidar Hagfors
Haugan) writes:
|>
|>
|> I have come across the following annoying "feature" of IDL through
|> a programming project: If you type e.g.,
|>
|> IDL> HELP, fltarr(10,1,1) ; you get:
|> <Expression> FLOAT = Array(10)
|>
|> But if you say
|>
|> IDL> HELP, fltarr(1,1,10) ; you get:
|> <Expression> FLOAT = Array(1, 1, 10)
|>
|> In our applications, it matters that the data arrays retain the
|> correct number of dimensions, as we have e.g., axis names for each
|> dimension. The above behaviour is clearly inconsistent, and IDL
|> is definitely doing something that is not intuitively obvious,
|> nor is it desirable at all times.
|>
|> The behaviour I would like is:
|>
|> Whenever I create an array with so and so many dimensions
|> (singular as well..), I'd like it to stay that way, until explicitly
|> told otherwise.
Although cumbersome, I think the solution below accomplishes what you want.
This may work when creating arrays with fltarr, etc., but it is easy to
conceive of cases where this would not work (i.e., when data arrays
are created through manipulations other than an initialization statement).
im=10 & jm=1 & km=1
a = reform( fltarr(im, jm, km), im, jm, km )
help, a
|>
|> When I'm indexing an array with a scalar, I'd like the dimension to
|> disappear ("reformed away"), e.g.:
|>
|> IDL> a=fltarr(10,10)
|> IDL> help,a(1,1)
|> <Expression> FLOAT = 0.00000
|>
|> This is OK, and it's what happens with today's version, but if I do
|> the following:
|>
|> IDL> help,a(1,*)
|> <Expression> FLOAT = Array(1, 10)
|>
|> or, to make the example complete, we try:
|>
|> IDL> help,a(*,1)
|> <Expression> FLOAT = Array(10)
|>
|> Here I would have liked both expressions (a(1,*) and a(*,1)) to
|> return the same thing (an Array(10)). I'd still like to be able to
|> retain a singular dimension by indexing with an array, e.g.:
|>
|> IDL> help,a(*,[1])
|> <Expression> FLOAT = Array(10, 1)
|>
Here is another solution that works, but would not be very useful for
writing general-purpose code unless maybe you wrote your own function.
a = fltarr(10,10)
sza = size(a)
help, reform( a(1,*), sza(2) )
help, reform( a(*,1), sza(1) )
--
Andrew F. Loughe email: afl@cdc.noaa.gov
University of Colorado, CIRES voice: (303) 492-0707
Campus Box 449 fax: (303) 497-7013
Boulder, CO 80309-0449 USA
|