Jump to Content
Version 1.6.2-43  



The CFITSIO module distributed with isis (and chips and sherpa) provides a S-Lang scriptable interface to the CFITSIO subroutine library. To simplify handling of common FITS files, this module includes several high-level functions which automatically handle some of the low-level details of FITS file manipulations. For versatility, access to many low-level CFITSIO library functions is also provided.

To read all the data from a simple FITS bintable:

isis> x = fits_read_table ("data.fits");
isis> print(x);
    bin_lo = Double_Type[1000]
    bin_hi = Double_Type[1000]
    counts = Double_Type[1000]
    stat_err = Double_Type[1000]

To read selected columns:

isis> (bin_lo, counts) = fits_read_col ("data.fits", "bin_lo", "counts");

Here's a somewhat more extended example showing how to use functions in the CFITSIO module to write a simple FITS binary table.

    % This function summarizes the basics of writing a FITS bintable
    % with a single HDU
    define write_bintable (filename, extname, data_struct, keyword_struct, history)
       variable fp = fits_open_file (filename, "c");
       if (fp == NULL)
    	vmessage ("Failed to create file %s", filename);
    	return -1;

       fits_write_binary_table (fp, extname, data_struct, keyword_struct);
       () = _fits_write_history (fp, history);

       fp = NULL;
       return 0;

    % Create a struct to hold the bintable data
    % (each struct field defines a column of the same name)
    variable d = struct
       bin_lo, bin_hi, counts, stat_err
    d.bin_lo = [0.0:10.0:0.01];
    d.bin_hi = d.bin_lo + 0.01;
    d.counts = @d.bin_lo;
    d.counts[*] = 0.0;
    d.stat_err = @d.counts;

    % Create a struct to contain the header keywords
    % (each struct field defines a keyword of the same name)
    variable k = struct
       object, telescop, instrume, exposure

    k.object = "Cyg X-1";
    k.telescop = "CHANDRA";
    k.instrume = "HETG";
    k.exposure = 1.e5;

    variable filename, extname, history;
    filename = "data.fits";
    extname = "NONE";
    history = sprintf ("FITS bintable creation demo:  %S", time);

    () = write_bintable (filename, extname, d, k, history);

Made with JED  |  Best Viewed with a Browser  |  Valid HTML 4.01  |  Valid CSS ]
This page is maintained by John C. Houck.   Last updated: Feb 2, 2019