Skip to the navigation links
Last modified: December 2009

URL: http://cxc-newtest.cfa.harvard.edu/ciao4.2/write_file.py.html
AHELP for CIAO 4.2

write_file

Context: py.crates

Synopsis

Write a crate to an output file.

Syntax

write_file(crate, filename)

Description

  • crate - input crate
  • filename - name of the output file

The write_file command creates an output file for the input crate, overwriting any existing file with the same name. This command may be used with any type of crate. The command returns a "1" if the file is written successfully.

The write_arf, write_pha, and write_rmf routines can be used when the type of the dataset is known.

Example 1

chips> cr = read_file("evt2.fits")
chips> delete_key(cr, "FILTER")
1
chips> write_file(cr, "edit.fits")
1

Delete the FILTER keyword from the crate, then write the crate to file edit.fits.

Example 2

chips> cr = read_file("tbl.dat")
chips> x = copy_colvals(cr, "x")
chips> y = copy_colvals(cr, "y")
chips> z = np.sqrt(x**2 + y**2)
chips> cd = CrateData()
chips> cd.name = "z"
chips> cd.load(z, 1)
1
chips> add_col(cr, cd)
1
chips> write_file(cr, "tbl2.dat[opt kernel=text/simple]")
1

In this example we read in the file tbl.dat, extract the x and y columns and create a new column, called z, from these values. This new column is added to the crate and then the crate is written out to the file tbl2.dat. The addition of the Data Model option "[opt kernel=text/simple]" ensures that the output is a text file (see "ahelp dmopt" and "ahelp dmascii" for more information on options and the ASCII file support in CIAO).

If the input file looked like:

unix% cat tbl.dat
# x y
1 2
3 5
9 10

then the output file will look like:

unix% cat tbl2.dat
#TEXT/SIMPLE
# x y z
1.0 2.0 2.236067977500
3.0 5.0 5.830951894845
9.0 10.0 13.45362404707

Bugs

See the bug pages on the CIAO website for an up-to-date listing of known bugs.

See Also

py.crates
add_col, add_key, add_piximg, delete_col, delete_key, delete_piximg, read_arf, read_file, read_pha, read_rmf, write_arf, write_pha, write_rmf
py.crates_contrib
make_table_crate, scale_image_crate, write_columns

Last modified: December 2009