Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > IDL > Arrays of Struc...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 169 of 228
Post > Topic >>

Arrays of Structures

by "Mick Brooks" <mick.brooks@[EMAIL PROTECTED] > Feb 8, 2007 at 08:51 AM

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
 




 2 Posts in Topic:
Arrays of Structures
"Mick Brooks" &  2007-02-08 08:51:37 
Re: Arrays of Structures
"Mick Brooks" &  2007-02-08 09:01:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 22:47:25 CDT 2008.