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

Home » Public Forums » archive » Re: newbie question / concatenation of arrays of nested structure
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: newbie question / concatenation of arrays of nested structure [message #17045] Thu, 09 September 1999 00:00
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Colin Rosenthal (colinr@toliman.uio.no) writes:

> That ain't a newbie question.
> A newbie question is "How can I make my axes run exactly from my
> lowest to my highest data values". :-)

No, no. Newbie questions always start out "How come I can't
get any colors...."

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: newbie question / concatenation of arrays of nested structure [message #17046 is a reply to message #17045] Thu, 09 September 1999 00:00 Go to previous message
colinr is currently offline  colinr
Messages: 30
Registered: July 1999
Member
On Wed, 8 Sep 1999 18:16:51 +0900,
Thomas Launey <t_launey@brain.riken.go.jp> wrote:

> This question has probably been already posted many time.
> how can I concatenate 2 arrays of anonymous nested structures?

That ain't a newbie question.
A newbie question is "How can I make my axes run exactly from my
lowest to my highest data values". :-)

--
Colin Rosenthal
Astrophysics Institute
University of Oslo
Re: newbie question / concatenation of arrays of nested structure [message #17047 is a reply to message #17045] Wed, 08 September 1999 00:00 Go to previous message
Thomas A. McGlynn is currently offline  Thomas A. McGlynn
Messages: 23
Registered: March 1996
Junior Member
If you don't want to modify the code that is creating the structures
to be concatenated then neither of these approaches might be feasible. You
could then do something like:

first = replicate({...}, ...)
....
second = replicate({...}, ...)
....

temp = replicate(first[0], n_elements(second));
for i=0, n_tags(first[0])-1 do temp.(i) = second.(i)
first = [first,temp]

This still isn't too bad, just three lines for a reasonably generic solution.

So long as the types agree you don't even have to worry about the
structure tag names matching. One could make build this into a function
easily enough -- though a general routine would probably need to deal
with recursive structures intelligently (and maybe multi-dimensional
arrays of structures).

Regards,
Tom McGlynn

Liam Gumley wrote:
>
> Liam Gumley wrote:
>> The only way to create equivalent structures is to use named structures,
>> e.g.
>>
>> IDL> record = {z, a:0, b:'name', c:0}
>> IDL> first = replicate(record, 5)
>> IDL> second = replicate(record, 3)
>> IDL> combo = [first, second]
>
> Note to self: Any time you say "The only way" in this newsgroup, you're
> bound to be wrong.
>
> David's web page correctly points out that copies of an anonymous
> structure are equivalent, and thus can be concatenated, e.g.
>
> IDL> record = {a:0, b:'name', c:{d:0, e:0}}
> IDL> a = record
> IDL> b = record
> IDL> c = [a, b]
>
> Cheers,
> Liam.
>
> --
> Liam E. Gumley
> Space Science and Engineering Center, UW-Madison
> http://cimss.ssec.wisc.edu/~gumley
Re: newbie question / concatenation of arrays of nested structure [message #17048 is a reply to message #17047] Wed, 08 September 1999 00:00 Go to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
Thomas Launey wrote:
> how can I concatenate 2 arrays of anonymous nested structures?
> In other word, try to concatenate the two arrays below
>
> first=replicate({a:0,b:'name',c:{d:0,e:0}},5)
> second=replicate({a:0,b:'name',c:{d:0,e:0}},3)
> third=[first,second]
> % Conflicting data structures: B,concatenation.
> % Execution halted at: $MAIN$

Since first and second are anonymous structures, IDL has no way of
knowing that they contain the same fields, e.g.

IDL> first = replicate({a:0,b:'name',c:{d:0,e:0}},5)
IDL> second = replicate({a:0,b:'name',c:{d:0,e:0}},3)
IDL> help, first, /structure
** Structure <1373ab8>, 3 tags, length=16, refs=1:
A INT 0
B STRING 'name'
C STRUCT -> <Anonymous> Array[1]
IDL> help, second, /structure
** Structure <13734c8>, 3 tags, length=16, refs=1:
A INT 0
B STRING 'name'
C STRUCT -> <Anonymous> Array[1]

You can see that the structure ids are different (1373ab8 vs. 13734c8).
IDL uses the structure id to determine if structures are equivalent.

The only way to create equivalent structures is to use named structures,
e.g.

IDL> record = {z, a:0, b:'name', c:0}
IDL> first = replicate(record, 5)
IDL> second = replicate(record, 3)
IDL> combo = [first, second]
IDL> help, first, /structure
** Structure Z, 3 tags, length=16:
A INT 0
B STRING 'name'
C INT 0
IDL> help, second, /structure
** Structure Z, 3 tags, length=16:
A INT 0
B STRING 'name'
C INT 0

Now first and second have the same structure id (z), and they can be
concatenated. Note that IDL does not like nested anonymous structures
inside a named structure, e.g.

IDL> record = {x, a:0, b:'name', c:{d:0, e:0}}
% Structures can't have anonymous structure members
% Execution halted at: $MAIN$

so you may have to re-think your original record format.

Cheers,
Liam.

--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
Re: newbie question / concatenation of arrays of nested structure [message #17049 is a reply to message #17047] Wed, 08 September 1999 00:00 Go to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
Liam Gumley wrote:
> The only way to create equivalent structures is to use named structures,
> e.g.
>
> IDL> record = {z, a:0, b:'name', c:0}
> IDL> first = replicate(record, 5)
> IDL> second = replicate(record, 3)
> IDL> combo = [first, second]

Note to self: Any time you say "The only way" in this newsgroup, you're
bound to be wrong.

David's web page correctly points out that copies of an anonymous
structure are equivalent, and thus can be concatenated, e.g.

IDL> record = {a:0, b:'name', c:{d:0, e:0}}
IDL> a = record
IDL> b = record
IDL> c = [a, b]

Cheers,
Liam.

--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
Re: newbie question / concatenation of arrays of nested structure [message #17050 is a reply to message #17047] Wed, 08 September 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Thomas Launey (t_launey@brain.riken.go.jp) writes:

> This question has probably been already posted many time.
> how can I concatenate 2 arrays of anonymous nested structures?
> In other word, try to concatenate the two arrays below
>
> first=replicate({a:0,b:'name',c:{d:0,e:0}},5)
> second=replicate({a:0,b:'name',c:{d:0,e:0}},3)
> third=[first,second]
> % Conflicting data structures: B,concatenation.
> % Execution halted at: $MAIN$
>
> I have not been able to find a way to do that properly (without subscripting
> each field one after another) an there are no example in David Fanning's
> book (Hey David, I've bought your great book, please help :-))

Not everything is in the book. Sometimes you have to
visit my web page. :-)

http://www.dfanning.com/tips/concatenate_structs.html

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Nautical Miles to Lat/Lon Degrees
Next Topic: Updates to SAVEIMAGE and SHOWIMAGE

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

Current Time: Fri Oct 10 01:29:41 PDT 2025

Total time taken to generate the page: 1.43865 seconds