Skip to the navigation links
Last modified: December 2009

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

read_file

Context: sl.crates

Synopsis

Read FITS or ASCII data into a crate.

Syntax

read_file(filename);

Description

  • filename - name of the input file; FITS or ASCII format

The read_file command loads the specified file into the appropriate crate, either a TABLECrate or an IMAGECrate. The input file may be in FITS or ASCII format.

The read_pha, read_arf, and read_rmf routines can be used when the type of the dataset is known.

Users familiar with the CIAO Data Model should note that:

  • Crates reads one extension of the input file, not the whole dataset. The file that is written out will only contain the block which was read.
  • Crates does not retain the data subspace of the file.
  • Crates does not retain HISTORY or COMMENT blocks from the input file.

Example 1

slsh> cr = read_file("image.fits");
slsh> get_crate_type(cr);
Image

A file is read into the crate "cr", then the get_crate_type command is used to confirm it is an IMAGECrate.

Example 2

slsh> cr = read_file("table.fits");
slsh> get_crate_type(cr);
Table

Read a file and create a TABLECrate.

Example 3

slsh> phacr = read_file("src.pi");
slsh> get_crate_type(phacr);
Table
slsh> resp = read_file("src.arf");
slsh> get_crate_type(resp);
Table
slsh> resp2 = read_file("src.arf");
slsh> get_crate_type(resp2);
Table

Using the read_file command to read a PHA, ARF, or RMF file reads it in as a TABLECrate. The read_pha, read_arf, and read_rmf routines should be used to create a PHACrate, ARFCrate, or RMFCrate.

Example 4

slsh> f = "evt2.fits[energy=500:7000,sky=region(src.reg)][bin sky=::1]";
slsh> cr = read_file(f);
slsh> s = sum (get_piximgvals (cr));
slsh> message ("Pixel sum=$s"$);
Pixel sum=2361

File names can include CIAO Data Model filtering and binning commands (e.g. see "ahelp dm"). In this case an energy and spatial filter are applied to an event file before being binned into an image. The pixel values are read in and then summed up.

Example 5

>>> a=read_file("myfile.dat");
>>> print(get_col_names(a));
>>> s=get_colvals(a,"col1");

The read_file command is used to read the contents of the ASCII file myfile.dat into the TABLEcrate "a", which is then input to the get_col_names command to print the column names read from the file. The get_colvals command is used to store the "col1" data array to the variable "s".

Example 6

>>> a = read_file("myfile.dat[opt colnames=none]");

In this case, the ASCII kernel option 'opt colnames=none' tells the read_file command to skip the header information when reading the contents of the ASCII file myfile.dat into the TABLEcrate "a" (see "ahelp dmascii" for more information).

Bugs

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

See Also

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

Last modified: December 2009