The IDL "=" operator is unable to assign a structure value to a structure of a different type. The STRUCT_ASSIGN procedure performs " relaxed structure assignment," which is a field-by-field copy of a structure to another structure. Fields are copied according to the following rules:
Relaxed structure assignment is especially useful when restoring structures from disk files into an environment where the structure definition has changed. See the description o f the RELAXED_STRUCTURE_ASSIGNMENT keyword to the RESTORE procedure for additional details. Relaxed Structure Assignment provides a more in-depth discussion of the structure-definition process.
The following example creates two anonymous structures, then uses STRUCT_ASSIGN to insert the contents of the first into the second.
source = { a:FINDGEN(4), b:12 }
STRUCT_ASSIGN, /VERBOSE, source, dest
% STRUCT_ASSIGN: <Anonymous> tag A is longer than destination.
% STRUCT_ASSIGN: Destination lacks <Anonymous> tag B. Not copied.
After assignment,
dest
contains a two-element integer array [0, 1] in its field A and the integer 0 in its field C. Since
dest
does not have a field B, field B from
source
is not copied.