Problem combining structures [message #26554] |
Fri, 07 September 2001 10:45 |
Jacco de Zwart
Messages: 4 Registered: May 1998
|
Junior Member |
|
|
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$
### I can however generate the result that I want manually
IDL>
dd=create_struct([tag_names(aa),tag_names(cc)],aa.(0),aa.(1) ,cc.(0))
IDL> help,dd,/str
** Structure <8238934>, 3 tags, length=44, refs=1:
A INT 1
B INT 2
C STRUCT -> <Anonymous> Array[10]
### Loopwise adding elements of one structure to the other also doesn't
work:
IDL>
dd=cc
IDL> for i=0,1 do dd=create_struct(dd,(tag_names(aa))[i],aa.(i))
% CREATE_STRUCT: Expression must be a scalar in this context: DD.
% Execution halted at: $MAIN$
This was done in IDL 5.3 under Linux. Does anyone know how to do this?
Thanks in advance for your help!
Jacco de Zwart
|
|
|