[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Arrays in structures; workarounds?
Ed Santiago <esm@lanl.gov> writes:
> >Does anybody know a way to work around this? [...] 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.
>
> Yep. Crappy indeed... but I couldn't find an alternative, either.
>
> Below is a copy of "esmsize", a function I wrote last year when I
> *absolutely needed* to obtain true dimensions within a struct.
>
> Hope it helps,
...
Yes, that's what I was afraid I might have to do. Unfortunately I'd
still like it to work for IDL 4, for which HELP, OUTPUT doesn't work.
Here was one trick I found to determine the size of a structure tag,
if it has *at least* two elements. Try this:
IDL> zz = {x:reform(dblarr(2,2,1),2,2,1)}
IDL> help, zz([0,0]).x
<Expression> DOUBLE = Array[2, 2, 1, 2]
In this case, I index the structure with the [0,0] list while at the
same time extracting the X tag. You get the correct dimensions, with
an extra "2" tacked on the end, which you can then hack off. You need
to handle the case of X being 8 dimensional (!), but it works.
Unfortunately this *doesn't* work if X has only element. Arghh!
A comment on your procedure. I believe that you are treating the
output of HELP too simply. When tag names are long enough, help will
wrap the type description to the next line. Consider this:
IDL> zz = {sdlfkjsdlkfjsdklfjslkfjsldkfjsdlkfjsljfsldkfjsdf:1}
IDL> help, /struct, zz
** Structure <40045788>, 1 tags, length=2, refs=1:
SDLFKJSDLKFJSDKLFJSLKFJSLDKFJSDLKFJSLJFSLDKFJSDF
INT = 1
This will affect both the first tag, and any of the following ones.
Maybe it's better to do a search for the tag you want.
Craig
--
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------