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

Re: Arrays in structures; workarounds?



... although I agree with most of you that chopping of dimensions bears
more risks than virtues, here is an easy workaround:

help,[z1.x]

gives you the array back ;-)

Cheers,
Martin


Craig Markwardt wrote:
> 
> We've seen this one before, but it still astounds me that it stays
> around from version to version of IDL.
> 
> IDL routinely drops the last dimension if the length is 1.  We know
> that and can deal with it for the most part.  For example, we can
> ensure the dimensions by REFORMing the array.  The thing that gets me
> is when a structure element is a one-element array, like this:
> 
>    IDL> z1 = {x:reform(dblarr(1,1),1,1)}
>    IDL> help, /struct, z1
>    ** Structure <40047208>, 1 tags, length=8, refs=1:
>       X               DOUBLE    Array[1, 1]
> 
> Sure enough, it's a 1x1 element array, containing just one value of
> course.  But when you try to extract that element, it comes out like
> this:
> 
>    IDL> help, z1.x
>    <Expression>    DOUBLE    =        0.0000000
> 
> Huh?  A scalar?  This is worse than IDL dropping the last dimensions.
> It's dropping *all* the dimensions.  This can be a problem, if for
> example, you will be passing the value to PLOT, which takes only
> arrays.  And it aggravates me to h*ll!
> 
> Does anybody know a way to work around this?  I've thought of some
> pretty wierd things to try, like passing the struct as _EXTRA.  The
> only thing I can come up with is to parse the result of HELP,
> OUTPUT=out, but that seems like the crappiest solution ever.
> 
> Any ideas?
> 
> Craig
> 
> P.S. ... and it goes without saying that I don't necessarily know the
> tag name ahead of time.
> 
> P.P.S.
>    IDL> print, !version
>    { alpha OSF unix 5.2 Oct 30 1998}
> 
> --
> --------------------------------------------------------------------------
> Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
> Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
> --------------------------------------------------------------------------

-- 
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
[[ Dr. Martin Schultz   Max-Planck-Institut fuer Meteorologie    [[
[[                      Bundesstr. 55, 20146 Hamburg             [[
[[                      phone: +49 40 41173-308                  [[
[[                      fax:   +49 40 41173-298                  [[
[[ martin.schultz@dkrz.de                                        [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[