About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/dup_struct.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 dup_struct Context: varmm

Synopsis

S-Lang function to duplicate a structured variable.

Syntax

Struct_Type dup_struct( Struct_Type s )
Struct_Type dup_struct( Struct_Type s, selectedfields )

Description

A convenience function for duplicating a structured variable. A slice, i.e. some potentially reordered subset of fields, may optionally be created from the structure by specifying one of the following as the second parameter:

  • a comma-delimited list of field names to include
  • a similar list, but beginning with a single "!", for exclusion
  • an integer representing the first N fields
  • NULL, in which case only non-NULL fields in the input structure will be copied

Example 1

Given this structured type definition and variable instance,

  chips> typedef struct {first, middle, last} Name_Type;
  chips> variable mozart = @Name_Type;
  chips> mozart.first = "Wolfgang";
  chips> mozart.middle = "Amadeus";
  chips> mozart.last = "Mozart";

this will make an entire copy of the structure:

  chips> variable copy = dup_struct(mozart);

while the following is an example of one kind of slice:

  chips> variable slice = dup_struct(mozart,"!first");
  chips> print(slice);
  middle           =  Amadeus
  last             =  Mozart

Example 2

Structures can contain NULL fields:

  chips> s = @struct{ elem1, elem2, elem3 };
  chips> s.elem1 = "hello"
  chips> s.elem3 = "there!"
  chips> print(s)
  elem1            =  hello
  elem2            =  NULL
  elem3            =  there!

If NULL is supplied as the second parameter to dup_struct(), then these NULL fields - elem2 in this example - will not be copied (they are by default):

  chips> copy = dup_struct(s,NULL)
  chips> print(copy)
  elem1            =  hello
  elem3            =  there!

Bugs

See the bugs page for the Varmm library on the CIAO website for an up-to-date listing of known bugs.

Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.