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

Home » Public Forums » archive » Indexing structures of different type
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Indexing structures of different type [message #15921] Thu, 17 June 1999 00:00 Go to next message
Donglai Gong Rm3110 x is currently offline  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 Go to previous messageGo to next message
David Foster is currently offline  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 Go to previous message
Pavel Romashkin is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Passing info and destroying widgets...
Next Topic: Crazy use of MAX function.

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

Current Time: Wed Oct 08 17:47:17 PDT 2025

Total time taken to generate the page: 0.00475 seconds