spacer link to MAST page spacer logo image spacer
link to STScI page

Using IDL Structures

Below are notes on using IDL structures. A structure can be thought of as a user-defined data type, and can be particularly useful when reading data from a binary table FITS file. To learn more about IDL structures (and recent changes), see the IDL documentation provided by RSI. For IDL version 5.2, documentation on structures can be found in Chapter 4 of "Building IDL Applications".

Generally the IUEDAC IDL software uses anonymous rather than named structures. The format of a named structure is defined once and can not be changed (although see "relaxed structure assignments" in IDL version 5.1 or higher). Anonymous structures can be redefined, but creating arrays of anonymous structures can be more difficult. In most cases, the two types of structures can be used in the same way. See the examples below.

Basic Structures:

  • To define an anonymous structure containing hdr,wav,flux,nu, & sigma vectors:
      A = {H: hdr, W: wav, F: flux, NU: nu, SIG: sigma}

  • To define a named structure called IUE containing hdr,wav,flux,nu, & sigma vectors
      A = {IUE, H: hdr, W: wav, F: flux, NU: nu, SIG: sigma}

  • To extract a vector W of wavelengths from structure A:
      W = A.W (or W = A.(1))

  • To plot W & F:
      plot,a.w,a.f or
      plot a.(1),a.(2)) or

  • To display format of structure:

  • To determine number of fields in structure:

  • To determine the length in bytes of a structure:

  • To determine names of fields in structure:

  • To determine whether a variable is a structure:
      if (s(s(0)+1) eq 8) then a is a structure

  • To sum images N, O, & P stored in a structure:
      B = {i1:N, i2:O, i3:P}
      sum = N
      for i=1,2 do sum = sum + B.(i)

  • To replace elements in B.(0) > 250 DN with same elements from B.(1):
      ind = where(B.(0) gt 250)
      B.(0)(ind) = B.(1)(ind)

Arrays of Structures:

  • To create an array of 4 A structures:
      cat = replicate(a,4)

  • To combine 3 identical NAMED structures A, B, C:
      cat = replicate(a,3)
      cat(1) = b
      cat(2) = c

  • To combine 3 identical ANONYMOUS structures A,B,C:
    (Note the commands above will generate a "conflicting data structure" error with anonymous structures. One possible solution is shown below.)
      cat = replicate(a,3)
      b = a
      b.h = hd2
      c = a
      c.w = w3
      cat(1) = b
      cat(2) = c

  • To get help on the 2nd structure in array:

  • To plot W & F from 3rd structure in array:

General Comments:

  • Fields of a structure may contain other structures or even arrays of structures.
  • If a vector in a structure is input to a routine without redefining it as a new vector, its values can not be changed. For example, a routine which modifiies an input flux array will not work if the input vector is specified as a.f. There is no problem if the parameter is strictly for input however, as in plot,a.w,a.f
  • The format of structures is fixed and must be redefined to be changed. For example, using the above structure A, setting A.F = 0 does not make A.F a scalar, it just sets all 640 floating point elements to 0. To set F to a 0 scalar, one must type A = {H: hdr, W: wav, F: 0, NU: nu, SIG: sigma}
  • Tags can be added to anonymous structures but not named structures.
  • Structures can not have more than 127 tags (is this still true?).