Indexing structures of different type [message #15921] |
Thu, 17 June 1999 00:00  |
Donglai Gong Rm3110 x
Messages: 2 Registered: June 1999
|
Junior Member |
|
|
Hi, does anyone know how to index structures of different types in IDL?
REPLICATE won't work since it creates an array of the same structure, so
I'm thinking of doing a structure of structures. However I don't know
how to index them for use in a loop. Thanks in advance.
Donglai Gong
|
|
|
Re: Indexing structures of different type [message #15999 is a reply to message #15921] |
Tue, 22 June 1999 00:00   |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
Donglai Gong Rm3110 x1569 wrote:
>
> Hi, does anyone know how to index structures of different types in IDL?
>
> REPLICATE won't work since it creates an array of the same structure, so
> I'm thinking of doing a structure of structures. However I don't know
> how to index them for use in a loop. Thanks in advance.
>
> Donglai Gong
Use an array of pointers and index that array:
struct_ptrs = ptrarr(10, /allocate_heap)
*struct_ptrs[0] = struct1
*struct_ptrs[1] = struct2
...
(*struct_ptrs[0]).tag1 = ...
Check out the docs for PTRARR, PTR_NEW, PTR_FREE, and PTR_VALID.
Also look at TAG_NAMES and the use of tag *numbers* instead of
names when accessing structure elements.
Dave Foster
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|
Re: Indexing structures of different type [message #16106 is a reply to message #15921] |
Mon, 28 June 1999 00:00  |
Pavel Romashkin
Messages: 166 Registered: April 1999
|
Senior Member |
|
|
Structure fields can be indexed similarly to arrays. Use syntax similar
to:
for i=0, n_elements(tag_names(My_struct))-1 do help, My_struct.(i), /struct
This will step through all sub-structures in My_struct. Notice that you
MUST use parenthesis, not [ ] brackets, when indexing structures.
Cheers,
Pavel
Donglai Gong Rm3110 x1569 wrote:
> Hi, does anyone know how to index structures of different types in IDL?
>
> REPLICATE won't work since it creates an array of the same structure, so
> I'm thinking of doing a structure of structures. However I don't know
> how to index them for use in a loop. Thanks in advance.
>
> Donglai Gong
|
|
|