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

Home » Public Forums » archive » Arrays of Structures
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Arrays of Structures [message #52464] Thu, 08 February 2007 09:03
Mick Brooks is currently offline  Mick Brooks
Messages: 4
Registered: February 2007
Junior Member
Hi,

Can anyone help my understanding of what happens when I apply a tag-
name to an array of structures? All of my previous questions have been
answered by searching on either www.dfanning.com or this newsgroup,
but this one has me stumped.

Take an array of (very boring, anonymous) structures:

IDL> structs = REPLICATE({a:1}, 50)

If I look-up a tag-name on this array, I see this:

IDL> HELP, structs.a
<Expression> INT = Array[50]

That looks like wonderful magic to me (I don't have much experience
with array-based languages) - IDL knew to apply the tag-name to each
structure in turn, and return me an array of the values - in this case
an array of INTs. Now what if I want the 3rd element of this array?
Let's try:

IDL> HELP, structs.a[2]
% Subscript range values of the form low:high must be >= 0, < size,
with low
<= high: <No name>.
% Execution halted at: $MAIN$

Not so good. I know of two workarounds for this. Either take the 3rd
element of the array of structures before looking up the tag-name (I
understand why this one works):

IDL> HELP, structs[2].a
<Expression> INT = 1

Or, put some extra parentheses in (I've no idea why this one fixes
it):

IDL> HELP, (structs.a)[2]
<Expression> INT = 1

Why does my first attempt fails, and why do the parentheses help?

For more confusion, look what happens if I try and lookup the 2nd, 4th
and 28th element all at once:

IDL> indices = [1, 3, 27]
IDL> HELP, structs.a[indices]
<Expression> INT = Array[3, 50]

Where did that extra dimension come from? What is the type of
structs.a? It seems that if I don't put parentheses around it, some of
the magic leaks out...

Cheers,

Mick Brooks
[Message index]
 
Read Message
Previous Topic: creating wrong TIFF file by ENVI_OUTPUT_TO_EXTERNAL_FORMAT
Next Topic: Re: What are the errors in the FFT?

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

Current Time: Fri Oct 10 04:49:05 PDT 2025

Total time taken to generate the page: 1.11378 seconds