next up previous contents
Next: Contents Up: CFHT FITS Handling Library Previous: 1. Using `idx' Sorting   Contents

Subsections

2. Opening, Locking, Closing and Creating FITS files

2.1 fh_create()

Before calling fh_file() to read from a filename (or fh_read() to read from a file descriptor which you opened yourself) this function must be used to create a new HeaderUnit. The HeaderUnit will be empty, until fh_file(), fh_read(), fh_set*(), or fh_merge() functions are used to add cards to it.

2.2 fh_destroy()

For each HeaderUnit returned by fh_create(), don't forget to pass it to fh_destroy() when it is no longer needed. The following happens in fh_destroy()

  1. Any remaining advisory file locks are released.
  2. The file is closed, if and only if it was opened with fh_file().
  3. Any linked extension header units are fh_destroy()'d.
  4. All resources allocated to the list are freed.

The first two steps may have errors, so always check the return code from fh_destroy(). For example:
\begin{code}
\begin{verbatim}if (fh_destroy(hu) != FH_SUCCESS) rtn = FAIL;\end{verbatim}\end{code}

WARNING: fh_destroy() should not be used on HeaderUnit's returned by the fh_ehu*() functions. These are destroyed automatically when their parent header unit is fh_destroy'ed.

2.3 fh_read()

This is not needed if you use fh_file(). But if you open() your own file descriptor, pass it to this function, along with an empty HeaderUnit from fh_create() to read the header from a FITS file.

Whether you used fh_read() or fh_file(), at this point if the file happens to be an MEF file, you can find out using fh_extensions() and access each extension unit using fh_ehu*().

CFHT FITS Handling Library
Revision 1.2

Sidik Isani

2001 April 8th
Last revised: 2001 April 27th

Make sure you have the latest version of this document, http://software.cfht.hawaii.edu/libfh/
For printing, download the PostScript version of this document.

Abstract:

This library of C functions can be included in your code to simplify the task of manipulating FITS data in either basic FITS format, or Multi-Extension FITS (MEF) with IMAGE extensions.

References and related documents:


next up previous contents
Next: Contents Up: CFHT FITS Handling Library Previous: 1. Using `idx' Sorting   Contents
Sidik Isani
2001-04-27