[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: STRUCT_ASSIGN



In article <6rn2tk$nne$1@hammer.msfc.nasa.gov>, mallors@crazyhorse.msfc.nasa.gov (Robert S. Mallozzi) writes:

>I have a structure defined as follows:
>
>   a = { f1: 0, f2: { x: 0, y: 0}}
>
>I want to initialize the substructure f2 
>in a subroutine by having an instance of the f2
>structure, then copying it field-by-field to
>a.f2.  STRUCT_ASSIGN seemed ideal for this,
>except one problem - it doesn't work :-)
>
>Assuming I have initialized an instance of
>f2 (called data) with some values
>    
>    data = {x: 10, y: 20}

The problem is that data is NOT an instance of f2, but rather another anonymous
structure, which IDL does not realize is the same as f2.  If IDL did realize
this then you could simply type:
a.f2 = data

There are 2 ways to get this to work:
    1) Use named structures rather than anonymous ones. 
        a = { f1: 0, f2: {f2, x: 0, y:    0}}
        data = {f2, x: 10, y: 20}
        a.f2 = data
    2) Create data from a
         a = { f1: 0, f2: { x: 0, y: 0}}
         data = a.f2 & data.x=10 & data.y=20
         a.f2 = data

____________________________________________________________
Mark Rivers                             (773) 702-2279 (office)
CARS                                    (773) 702-9951 (secretary)
Univ. of Chicago                        (773) 702-5454 (FAX)
5640 S. Ellis Ave.                      (708) 922-0499 (home)
Chicago, IL 60637                       rivers@cars.uchicago.edu (e-mail)

or:
Argonne National Laboratory             (630) 252-0422 (office)
Building 434A                           (630) 252-0405 (lab)
9700 South Cass Avenue                  (630) 252-1713 (beamline)
Argonne, IL 60439                       (630) 252-0443 (FAX)