[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Indexing structures of different type



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
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~