Re: array of structure in IDL 4.0.1 ??? [message #7135] |
Fri, 27 September 1996 00:00 |
Peter Mason
Messages: 145 Registered: June 1996
|
Senior Member |
|
|
On 26 Sep 1996, Hendrik Roepcke wrote:
> i want to use a predefined stucture to make an array...
> like: dummy = record(10).name
>
> is that possible ?? how to programm it?
> rec = {structname,name: "John Doe",tel:5551234 }
> record= make_array(count,/{structname}
> or is there a workaround???
Here are two ways to do it:
1 Using make_array():
First define your structure by defining a scalar.
e.g., rec = {structname,name: "John Doe",tel:5551234}
(You could also use an anonymous structure scalar.)
Then do recs=make_array(N,val=rec), where N is the number of elements you
want in your array of structures. (Of course, you don't have to stick
to a 1D array.)
2 Using replicate()
Set up your structure scalar "rec" as in (1), then do recs=replicate(rec,N).
Peter Mason
|
|
|