next up previous contents FITSIO Home
Next: CFITSIO Routines Up: CFITSIO Quick Start Guide Previous: Installing and Using CFITSIO   Contents

Example Programs

Before describing the individual CFITSIO routines in detail, it is instructive to first look at an actual program. The names of the CFITSIO routines are fairly descriptive (they all begin with fits_, so it should be reasonably clear what this program does:

----------------------------------------------------------------
#include <string.h>
#include <stdio.h>
#include "fitsio.h"

int main(int argc, char *argv[])
{
    fitsfile *fptr;         
    char card[FLEN_CARD]; 
    int  nkeys, ii, status = 0;  /* MUST initialize status */

    fits_open_file(&fptr, argv[1], READONLY, &status);

    fits_get_hdrspace(fptr, &nkeys, NULL, &status);

    for (ii = 1; ii <= nkeys; ii++)  { 
       fits_read_record(fptr, ii, card, &status); /* read keyword */
       printf("%s\n", card);
    }
    printf("END\n\n");  /* terminate listing with END */

    fits_close_file(fptr, &status);

    if (status)          /* print any error messages */
        fits_report_error(stderr, status);
    return(status);
}
----------------------------------------------------------------

This program opens the specified FITS file and prints out all the header keywords in the current HDU. Some other points to notice about the program are:

A set of example FITS utility programs are available from the CFITSIO web site at
http://heasarc.gsfc.nasa.gov/docs/software/fitsio/cexamples.html. These are real working programs which illustrate how to read, write, and modify FITS files using the CFITSIO library. Most of these programs are very short, containing only a few 10s of lines of executable code or less, yet they perform quite useful operations on FITS files. Running each program without any command line arguments will produce a short description of how to use the program. The currently available programs are:

fitscopy - copy a file
listhead - list header keywords
liststruc - show the structure of a FITS file.
modhead - write or modify a header keyword
imarith - add, subtract, multiply, or divide 2 images
imlist - list pixel values in an image
imstat - compute mean, min, and max pixel values in an image
tablist - display the contents of a FITS table
tabcalc - general table calculator


next up previous contents FITSIO Home
Next: CFITSIO Routines Up: CFITSIO Quick Start Guide Previous: Installing and Using CFITSIO   Contents