[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
When you can't concatenate structures like you expect....
- To: Liam Gumley <liam.gumley(at)ssec.wisc.edu>
- Subject: When you can't concatenate structures like you expect....
- From: Paul van Delst <paul.vandelst(at)ssec.wisc.edu>
- Date: Fri, 21 May 1999 14:27:55 -0500
- Newsgroups: comp.lang.idl-pvwave
- Organization: Space Science and Engineering Center
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:14865
Figure this one out.
Create a structure:
IDL>
t={latitude:0.0,longitude:0.0,decimal_time:0.0,c_date:'21-May-1999'}
IDL> HELP, t, /STRUCT
** Structure <10375708>, 4 tags, length=20, refs=1:
LATITUDE FLOAT 0.00000
LONGITUDE FLOAT 0.00000
DECIMAL_TIME FLOAT 0.00000
C_DATE STRING '21-May-1999'
Now replicate it into some structure arrays:
IDL> t1=REPLICATE( t, 5 )
IDL> t2=REPLICATE( t, 10 )
IDL> HELP, t1, t2, /STRUCT
** Structure <10375708>, 4 tags, length=20, refs=3:
LATITUDE FLOAT 0.00000
LONGITUDE FLOAT 0.00000
DECIMAL_TIME FLOAT 0.00000
C_DATE STRING '21-May-1999'
** Structure <10375708>, 4 tags, length=20, refs=3:
LATITUDE FLOAT 0.00000
LONGITUDE FLOAT 0.00000
DECIMAL_TIME FLOAT 0.00000
C_DATE STRING '21-May-1999'
Concatenation is no problem:
IDL> HELP, [ t1, t2 ]
<Expression> STRUCT = -> <Anonymous> Array[15]
Now create a different structure with *exactly* the same fields and
*exactly* the same data types and dimensions, and replicate it:
IDL>
s={latitude:0.0,longitude:0.0,decimal_time:0.0,c_date:'21-May-1999'}
IDL> HELP, s, /STRUCT
** Structure <1031e108>, 4 tags, length=20, refs=1:
LATITUDE FLOAT 0.00000
LONGITUDE FLOAT 0.00000
DECIMAL_TIME FLOAT 0.00000
C_DATE STRING '21-May-1999'
IDL> s1=REPLICATE( s, 10 )
IDL> HELP, s1, /STRUCT
** Structure <1031e108>, 4 tags, length=20, refs=2:
LATITUDE FLOAT 0.00000
LONGITUDE FLOAT 0.00000
DECIMAL_TIME FLOAT 0.00000
C_DATE STRING '21-May-1999'
Can't concatenate those two structures now:
IDL> HELP, [ t1, s1 ]
% Conflicting data structures: S1,concatenation.
% Execution halted at: $MAIN$
IDL>
Bummer. If you note the structure names, the hex strings 10375708 and
1031e108, this seems to distinguish what structures you can and cannot
concatenate - is this what tells IDL about the strucutre *type*?
Anyway, my first workaround didn't work (as I expected, but..):
IDL> HELP, t1, s1
T1 STRUCT = -> <Anonymous> Array[5]
S1 STRUCT = -> <Anonymous> Array[10]
IDL> s2 = REPLICATE( s, 5 )
IDL> s3 = [ s1, s2 ]
IDL> HELP, s3
S3 STRUCT = -> <Anonymous> Array[15]
IDL> s3[10:14]=t1[*]
% Conflicting data structures: <STRUCT Array[5]>,S3.
% Execution halted at: $MAIN$
Using "relaxed" structure assignment:
IDL> STRUCT_ASSIGN, s3[10:14], t1
Works fine.
Still, it's a pain in the butt when the internal representation of
structures dictates what you can and cannot concatenate. The discussion
of relaxed structure assignment in the IDL online help explains why it
is needed but the examples are for different structures where the tag
names are the same, but the data types/sizes are all different. Seems to
me that the "relaxed" assignment capability is great for those
situations where structures are quite different, but not for the simple
concatenation of structure arrays.
Anyway,
cheers,
paulv
--
Paul van Delst
Space Science and Engineering Center | Ph/Fax: (608) 265-5357, 262-5974
University of Wisconsin-Madison | Email:
paul.vandelst@ssec.wisc.edu
1225 W. Dayton St., Madison WI 53706 | Web:
http://airs2.ssec.wisc.edu/~paulv