Re: Problem combining structures [message #26543] |
Fri, 07 September 2001 15:56 |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Jacco de Zwart <effuh1@nih.gov> writes:
> Hi,
>
> I have a problem combining two structures, which contain different tag
> names, if one of them is a structure-array. Example:
>
> ### I make three structures: aa, bb and cc
> IDL> aa={a:1,b:2}
> IDL> bb={c:aa}
> IDL> cc=replicate(bb,10)
> IDL> help,aa,bb,cc
> AA STRUCT = -> <Anonymous> Array[1]
> BB STRUCT = -> <Anonymous> Array[1]
> CC STRUCT = -> <Anonymous> Array[10]
>
> ### Assume I want to make a structure which combines aa and bb
> IDL> dd=create_struct(aa,bb)
> IDL> help,dd,/str
> ** Structure <8237944>, 3 tags, length=8, refs=1:
> A INT 1
> B INT 2
> C STRUCT -> <Anonymous> Array[1]
> ### This obviously works fine
>
> ### However, combinging aa and cc in this way doesn't work
> IDL> dd=create_struct(aa,cc)
> % CREATE_STRUCT: Expression must be a scalar in this context: CC.
> % Execution halted at: $MAIN$
Short answer: you can't use CREATE_STRUCT to merge arrays of
structures. CREATE_STRUCT is only useful to merge scalar structures
together. Look at your first example, which is, when expressed
explicitly:
dd = create_struct({a:1,b:2},{c:aa})
which becomes:
dd = {a:1,b:2 , c:aa}
I just removed the extra punctuation from the line above to make it
clear. But in your second example, CC is an array, and I just don't
know what that means. For example:
dd = create_struct({a:1,b:2},[{c:a1},{c:a2},{c:a3}])
Now it's not so simple to just combine the structures together. What
is definitely not clear is that this should somehow end up being:
dd = {a:1,b:2,c:[a1,a2,a3]}
That is another beast entirely. You go through a lot of methods that
*did* produce what you wanted, so why don't you use one of those. :-)
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|