CCfits
2.6
|
The program cookbook.cxx, analogous to the cookbook.c program supplied with cfitsio, was generated to test the correct functioning of the parts of the library and to provide a demonstration of its usage.
The code for cookbook is reproduced here with commentary as worked example of the usage of the library.
The simple driver program illustrates the setting of verbose mode for the library, which makes all internal exceptions visible to the programmer. This is primarily for debugging purposes; exceptions are in some cases used to transfer control in common circumstances (e.g. testing whether a file should be created or appended to in write operations). Most of the exceptions will not produce a message unless this flag is set.
Nearly all of the exceptions thrown by CCfits are derived from FitsException, which is caught by reference in the above example. This includes all nonzero status codes returned by cfitsio by the following construct (recall that in the cfitsio library, nearly all functions return a non-zero status code on error, and have a final argument status of type int):
FitsError, derived from FitsException, uses a cfitsio library call to convert the status code to a string message.
The few exceptions that are not derived from FitsException indicate fatal conditions implying bugs in the library. These print a message suggesting the user contact HEASARC to report the problem.
Note also the lack of statements for closing files in any of the following routines, The destructor (dtor) for the FITS object does this when it falls out of scope. A call
is provided for closing files explicitly; destroy() is also responsible for cleaning up the FITS object and deallocating its resources.
When the data are being read instead of written, the user is expected to copy the data into other program variables [rather than use references to the data contained in the FITS object].
The routines in this program test the following functionality: