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

Home » Public Forums » archive » Arrays in structures; workarounds?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Arrays in structures; workarounds? [message #19967] Thu, 04 May 2000 00:00 Go to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
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
------------------------------------------------------------ --------------
Re: Arrays in structures; workarounds? [message #20132 is a reply to message #19967] Mon, 22 May 2000 00:00 Go to previous messageGo to next message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
... although I agree with most of you that chopping of dimensions bears
more risks than virtues, here is an easy workaround:

help,

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
>
> 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 [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
Re: Arrays in structures; workarounds? [message #20201 is a reply to message #19967] Tue, 23 May 2000 00:00 Go to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Craig Markwardt wrote:
>
> Martin Schultz <martin.schultz@dkrz.de> writes:
>> ... although I agree with most of you that chopping of dimensions bears
>> more risks than virtues, here is an easy workaround:
>>
>> help,
>>
>> gives you the array back ;-)
>
> Heh. Assumes you know that it's an array. :-)
>
> Craig
>
not quite: assumes only that you want an array ;-)

Martin

--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ 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 [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
Re: Arrays in structures; workarounds? [message #20211 is a reply to message #19967] Mon, 22 May 2000 00:00 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Martin Schultz <martin.schultz@dkrz.de> writes:
> ... 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 ;-)

Heh. Assumes you know that it's an array. :-)

Craig


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: unexpected colors
Next Topic: circle plot symbol

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

Current Time: Wed Oct 08 15:34:53 PDT 2025

Total time taken to generate the page: 0.00683 seconds