[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Indexing structures of different type
- Subject: Re: Indexing structures of different type
- From: Craig Markwardt <craigmnet(at)cow.physics.wisc.edu>
- Date: 17 Jun 1999 18:08:47 -0500
- Newsgroups: comp.lang.idl-pvwave
- Organization: U. Wisc. Madison Physics -- Compact Objects
- References: <37694F30.9505DF06@eden.rutgers.edu>
- Reply-To: craigmnet(at)cow.physics.wisc.edu
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:15255
Donglai Gong Rm3110 x1569 <donglai@eden.rutgers.edu> writes:
>
> 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.
If you are *really* trying to glue a bunch of different types
together, you should probably structures as you say.
How to loop over them? This is easily done with a little magic:
;; Initialize your structure
s = {u:0L, v:0D, w:intarr(5), x:{a:1, b:2}, y:'hello'}
n = n_tags(s)
for i = 0L, n-1 do begin
;; The magic is here:
f = s.(i)
;; Operate on f here:
print, f
endfor
However, you should be aware that IDL structures are pretty slow to
operate on, especially when you build large ones. [ Some versions of
IDL have a limit on the number of elements in a structure too. ]
Good luck,
Craig
--
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@astrog.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------