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 
Return to the default flat view Create a new topic Submit Reply
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
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: Thu Oct 09 21:47:26 PDT 2025

Total time taken to generate the page: 1.79629 seconds