comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Combing structures
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Combing structures [message #71188] Mon, 07 June 2010 09:37
Steve[5] is currently offline  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 #71190 is a reply to message #71188] Mon, 07 June 2010 08:39 Go to previous message
Michael Williams is currently offline  Michael Williams
Messages: 17
Registered: December 2008
Junior Member
Wow, that was quick (and I feel pretty silly!). Thanks guys!

-- Mike
Re: Combing structures [message #71192 is a reply to message #71190] Mon, 07 June 2010 08:29 Go to previous message
Foldy Lajos is currently offline  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 Go to previous message
Brian Daniel is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Testing if HDF5 file is corrupt
Next Topic: Vendor daemon is down

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:34:12 PDT 2025

Total time taken to generate the page: 0.00436 seconds