Re: Append tag to an array of structures [message #34535] |
Wed, 26 March 2003 16:29 |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Wed, 26 Mar 2003 14:01:40 -0700, Wayne Landsman wrote:
> JD Smith wrote:
>> Anyone have a clever method for appending a tag to an array of
>> structures? For a single structure, it's easy:
>>
>> new_struct=create_struct(struct,'NewTag',1.21)
>
> Well, I would hardly call it clever or efficient but one way is to
> create a structure of the right size and then use the copy_struct.pro
> procedure in
> http://idlastro.gsfc.nasa.gov/ftp/pro/structure/copy_struct. pro to copy
> all the previous tag information
>
> n = N_elements(struct)
> new_struct = replicate(create_struct(struct[0],'NewTag',1.21),N)
> copy_struct, struct, new_struct
>
> --Wayne Landsman landsman@mpb.gsfc.nasa.gov
Thanks Wayne. I came up with something similar using the builtin
"struct_assign,struct,new_struct,/NOZERO". I was hoping not to use
replicate though.
JD
|
|
|
Re: Append tag to an array of structures [message #34539 is a reply to message #34535] |
Wed, 26 March 2003 13:01  |
Wayne Landsman
Messages: 117 Registered: January 1997
|
Senior Member |
|
|
JD Smith wrote:
> Anyone have a clever method for appending a tag to an array of
> structures? For a single structure, it's easy:
>
> new_struct=create_struct(struct,'NewTag',1.21)
Well, I would hardly call it clever or efficient but one way is to
create a structure of the right size and then use the copy_struct.pro
procedure in http://idlastro.gsfc.nasa.gov/ftp/pro/structure/copy_struct. pro
to copy all the previous tag information
n = N_elements(struct)
new_struct = replicate(create_struct(struct[0],'NewTag',1.21),N)
copy_struct, struct, new_struct
--Wayne Landsman landsman@mpb.gsfc.nasa.gov
|
|
|