next_group up previous contents
Up: CFHT FITS Handling Library Previous: 10. Recipes for Converting   Contents

Subsections

11. Examples

11.1 Display any Primary or Extension Header (fhlist.c)

This program will show the FITS header from any file, or any extension within the file (by using a feature of fh_file() which searches for an extension when the filename contains ``fitsfile[extname]''.)

This small program is also a good way to test the behavior of fh_file().


\begin{code}
\begin{verbatim}...


\begin{code}
\begin{verbatim}...

11.2 Loop through all extensions by EXTNAME (fhextname.c)

When there is a separate FITS file for each amplifier, finding the names of all the ``extensions'' is as easy as listing all the files in a subdirectory. Here's a utility which generates an equivalent list of names for MEF Files. The output from this program can be used as the arguments to a pipeline program which uses fh_file() to open one file or extension each time it is run. Multiple FITS files may be given on the command line. In this example, the `fhextname' program is used just as `ls' would have been with basic FITS files:


   #!/bin/sh
   for i in `fhextname *.fits`
   do
      reduce "$i"
   done

Note that this also works for split files, since `fhextname' just prints the name of the fits file itself, if there are no extensions.

Here is the source code for `fhextname':


\begin{code}
\begin{verbatim}...

11.3 Tool to Set any Keyword(s) (fhset.c)

Here is the source code for `fhset', a command line utility which sets arbitrary keywords and comment fields in a FITS file (and extension units, if it has any.) The following would cause this tool to update/add GAIN (a float value), OBSID (an integer), CCD (a string) and INHERIT (boolean).


\begin{code}
\begin{verbatim}...

Here is the source for the fhset.c program:


\begin{code}
\begin{verbatim}...

11.4 Tool for making Reserve Space (fhreserve.c)

This one still has to be written . . .

11.5 Update a Card with known Keyword

In this example, the keyword WEATHER may or may not exist.


\begin{code}
\begin{verbatim}...

11.6 Add set of COMMENT cards to already open file

This example is not a complete program, but a function within a larger program which has its own way of opening a file descriptor (and thus, does not want to use fh_file.)


\begin{code}
\begin{verbatim}PASSFAIL
add_some_comments(int fd)
{
HeaderUn...
...h_destroy(hu) != FH_SUCCESS) rtn = FAIL;
return rtn;
}\end{verbatim}\end{code}

11.7 Build a FITS File from Scratch

Here a complete FITS file is built from scratch, using routines in libfh. It demonstrates several other things which the examples above do not:

Source code follows:


\begin{code}
\begin{verbatim}...

11.8 Build an MEF File from Scratch

The fh_ehu*() functions are only used to access extensions within an already existing MEF. The are not used when building an MEF File for the first time. This task must be done by writing the appropriate interleaved header units and image data manually.

The following example constructs a very minimal MEF File with only two extensions. For a more comprehensive example, see the source code of DetCom, /cfht/src/medusa/detcom/detcom/det_data.c.


\begin{code}
\begin{verbatim}...


next_group up previous contents
Up: CFHT FITS Handling Library Previous: 10. Recipes for Converting   Contents
Sidik Isani
2001-04-27