Re: Combing structures [message #71188] |
Mon, 07 June 2010 09:37 |
Steve[5]
Messages: 10 Registered: September 2007
|
Junior Member |
|
|
Michael Williams wrote:
> Hi,
>
> I have two structures. Each contains a unique set of tags whose values
> are floats or arrays of floats. E.g.
>
> xx = findgen(5)
> y = 1.0
> str1 = {one: xx, two:y}
>
> xx = findgen(3)
> y = -1.0
> str2 = {three: xx, four: y}
>
> I want to merge them into one flat structure of their elements. At the
> moment I am doing this manually:
>
> str = {one:str1.one, two:str1.two, three:str2.three, four:str2.four}
>
> This obviously becomes unwieldy and error-prone when my structures
> have several dozen tags. Is there a way of automating the merge step?
> I am happy to assume the tag names are unique (i.e. there is no danger
> of a collision).
>
> I have played around with the tag_names function, but I can't see a
> way of using this without using the EVALUATE function, which is
> generally a bad idea.
>
> -- Mike
Try...
str=create_struct(str1, str2)
|
|
|
|
Re: Combing structures [message #71192 is a reply to message #71190] |
Mon, 07 June 2010 08:29  |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
On Mon, 7 Jun 2010, Michael Williams wrote:
> Hi,
>
> I have two structures. Each contains a unique set of tags whose values
> are floats or arrays of floats. E.g.
>
> xx = findgen(5)
> y = 1.0
> str1 = {one: xx, two:y}
>
> xx = findgen(3)
> y = -1.0
> str2 = {three: xx, four: y}
>
> I want to merge them into one flat structure of their elements. At the
> moment I am doing this manually:
>
> str = {one:str1.one, two:str1.two, three:str2.three, four:str2.four}
>
> This obviously becomes unwieldy and error-prone when my structures
> have several dozen tags. Is there a way of automating the merge step?
> I am happy to assume the tag names are unique (i.e. there is no danger
> of a collision).
>
> I have played around with the tag_names function, but I can't see a
> way of using this without using the EVALUATE function, which is
> generally a bad idea.
>
> -- Mike
>
str=create_struct(str1, str2)
regards,
lajos
|
|
|
Re: Combing structures [message #71193 is a reply to message #71192] |
Mon, 07 June 2010 08:29  |
Brian Daniel
Messages: 80 Registered: July 2009
|
Member |
|
|
On Jun 7, 11:01 am, Michael Williams <mjwilli...@gmail.com> wrote:
> Hi,
>
> I have two structures. Each contains a unique set of tags whose values
> are floats or arrays of floats. E.g.
>
> xx = findgen(5)
> y = 1.0
> str1 = {one: xx, two:y}
>
> xx = findgen(3)
> y = -1.0
> str2 = {three: xx, four: y}
>
> I want to merge them into one flat structure of their elements. At the
> moment I am doing this manually:
>
> str = {one:str1.one, two:str1.two, three:str2.three, four:str2.four}
>
> This obviously becomes unwieldy and error-prone when my structures
> have several dozen tags. Is there a way of automating the merge step?
> I am happy to assume the tag names are unique (i.e. there is no danger
> of a collision).
>
> I have played around with the tag_names function, but I can't see a
> way of using this without using the EVALUATE function, which is
> generally a bad idea.
>
> -- Mike
I believe Create_Struct will do this.
IDL> xx = findgen(5)
IDL> y = 1.0
IDL> str1 = {one: xx, two:y}
IDL> xx = findgen(3)
IDL> y = -1.0
IDL> str2 = {three: xx, four: y}
IDL> str3 = create_struct(str1,str2,NAME='str3')
IDL> help,str3,/struct
** Structure STR3, 4 tags, length=40, data length=40:
ONE FLOAT Array[5]
TWO FLOAT 1.00000
THREE FLOAT Array[3]
FOUR FLOAT -1.00000
I don't think you need the NAME keyword, but i did it for
completeness.
Regards,
Brian
|
|
|