Re: IDL: Structure of Structures? [message #13903] |
Tue, 05 January 1999 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Scott Norton (norton@optics.rochester.edu) writes:
> Is it possible to create structure of structures?
I'm not sure this question goes with the following example. :-(
> If I have
> NAMEADDRESS = CREATE_STRUCT('name','', 'address', 0.0)
> NAMEADDRESSARRAY= replicate(NAMEADDRESS,100)
> and then wanted a structure that, for instance, that had US states with
> related fields and the above structure as a sub-structure, how would it
> appear?
>
> For instance,
>
> locationUSstate = CREATE_STRUCT(USstate,' ', numberOfvisits,0.0,
> NAMEADRESSARRAY, XX)
>
> so basically there would be a name-address list for each US state...
>
> What should XX be?
I'm going to guess that XX should be what you are calling
NAMEADDRESSARRY, a vector of structures:
locationUSstate = CREATE_STRUCT(USstate,' ', numberOfvisits,0.0, $
NAMEADRESSARRAY, NAMEADRESSARRAY)
(locationUSstate.nameaddressarray[4]).name = 'David'
(locationUSstate.nameaddressarray[4]).address = 4.0
> Is it possible to do this?
Well ... yes.
> Is there a better way of doing this?
Probably. Have you thought about pointers and named structures?
That would be my first thought. Then you wouldn't have to decide
ahead of time how many names and addresses you would have to have
for each state location. You could have a field that is a pointer
to a variable-length array of structures.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Progamming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|