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

Home » Public Forums » archive » Array 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
Re: Array of Structures [message #38993 is a reply to message #19984] Thu, 15 April 2004 09:38 Go to previous messageGo to previous message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
"Dan Steinberg" wrote in message...

> I am wondering if it is possible to create an array of structures. I
> want to read multiple different anonymous structures into a single
> variable so I can reference each structure using the variable name and
> the array index. Is this possible?

Yes, but if when you say different, you mean that their lengths are
different, you need to create an array of pointers which point to your
structures.



You can have arrays of identical structures:

IDL> x=[{a:'one',b:1},{a:'two',b:2},{a:'three',b:3}]
IDL> help, x
X STRUCT = -> <Anonymous> Array[3]
IDL> print, x[2].a
three



You can have arrays of structs that are the same length but their *initial*
tags are different:

IDL> y=[{a:'one',b:1},{c:'two',d:2},{e:'three',f:3}]
IDL> help, y[0], /struct
** Structure <15b85b0>, 2 tags, length=16, data length=14, refs=2:
A STRING 'one'
B INT 1
IDL> help, y[1], /struct
** Structure <15b85b0>, 2 tags, length=16, data length=14, refs=2:
A STRING 'two'
B INT 2
IDL> help, y[2], /struct
** Structure <15b85b0>, 2 tags, length=16, data length=14, refs=2:
A STRING 'three'
B INT 3



But you can not have an array whose elements differ in length:

IDL> y=[{a:'one',b:1},{a:'two',b:2,c:2.2},{a:'three',b:3,d:0D}]
% Conflicting data structures: <STRUCT Array[1]>,<STRUCT Array[1]>.
% Execution halted at: $MAIN$


In this case you need to create an array of pointers which point to your
structs:

z =
PTR_NEW([PTR_NEW({a:'one',b:FLTARR(3)}),PTR_NEW({a:'two',b:D BLARR(10)})])

IDL> help, *(*z)[0], /struct
** Structure <1b20198>, 2 tags, length=24, data length=24, refs=1:
A STRING 'one'
B FLOAT Array[3]
IDL> help, *(*z)[1], /struct
** Structure <1bc3420>, 2 tags, length=96, data length=92, refs=1:
A STRING 'two'
B DOUBLE Array[10]


-Rick
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Array of Structures
Next Topic: Can IDL look after graphics in C++ code?

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

Current Time: Tue Dec 02 10:02:40 PST 2025

Total time taken to generate the page: 0.40251 seconds