Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Compound Members   Related Pages  

CCfits::FITS Class Reference

Memory object representation of a disk FITS file. More...

#include <FITS.h>

List of all members.

Public Methods

 FITS (const string &name, RWmode mode=Read, bool readDataFlag=false, const std::vector< string > &primaryKeys=std::vector< string >())
 FITS (const string &name, RWmode mode, const string &hduName, bool readDataFlag=false, const std::vector< string > &hduKeys=std::vector< string >(), const std::vector< string > &primaryKey=std::vector< string >(), int version=1)
 FITS (const string &name, RWmode mode, const std::vector< string > &hduNames, bool readDataFlag=false, const std::vector< string > &primaryKey=std::vector< string >())
 FITS (const string &fileName, const FITS &source)
 FITS (const string &name, RWmode mode, const std::vector< string > &hduNames, const std::vector< std::vector< string > > &hduKeys, bool readDataFlag=false, const std::vector< string > &primaryKeys=std::vector< string >(), const std::vector< int > &hduVersions=std::vector< int >())
 FITS (const string &name, int bitpix, int naxis, long *naxes)
 FITS (const string &name, RWmode mode, int hduIndex, bool readDataFlag=false, const std::vector< string > &hduKeys=std::vector< string >(), const std::vector< string > &primaryKey=std::vector< string >())
 FITS (const string &name, RWmode mode, const std::vector< string > &searchKeys, const std::vector< string > &searchValues, bool readDataFlag=false, const std::vector< string > &hduKeys=std::vector< string >(), const std::vector< string > &primaryKey=std::vector< string >(), int version=1)
 ~FITS ()
void deleteExtension (const std::string &doomed, int version=1)
void read (const string &hduName, bool readDataFlag=false, const std::vector< string > &keys=std::vector< string >(), int version=0)
void read (const std::vector< string > &hduNames, bool readDataFlag=false)
void read (const std::vector< string > &hduNames, const std::vector< std::vector< string > > &keys, bool readDataFlag=false, const std::vector< int > &hduVersions=std::vector< int >())
FITS* clone () const
const ExtHDUextension (int i) const
ExtHDUextension (int i)
const ExtHDUextension (const string &hduName, int version=1) const
const PHDUpHDU () const
PHDUpHDU ()
ExtHDUextension (const string &hduName, int version=1)
void read (int hduIndex, bool readDataFlag=false, const std::vector< string > &keys=std::vector< string >())
TableaddTable (string &hduName, int rows, const std::vector< string > &columnName=std::vector< string >(), const std::vector< string > &columnFmt=std::vector< string >(), const std::vector< string > &columnUnit=std::vector< string >(), HduType type=BinaryTbl, int version=1)
ExtHDUaddImage (const string &hduName, int bpix, std::vector< long > &naxes, int version=1)
void destroy () throw ()
void flush ()
const string& currentExtensionName () const
void read (const std::vector< string > &searchKeys, const std::vector< string > &searchValues, bool readDataFlag=false, const std::vector< string > &hduKeys=std::vector< string >(), int version=1)
const std::multimap<string,
ExtHDU*>& 
extension () const
void resetPosition ()
const string& name () const
void copy (const HDU &source)
Tablefilter (const string &expression, ExtHDU &inputTable, bool overwrite=true, bool readData=false)
ExtHDUcurrentExtension ()
void deleteExtension (int doomed)

Static Public Methods

void clearErrors ()
bool verboseMode ()
void setVerboseMode (bool value)


Detailed Description

Memory object representation of a disk FITS file.

Constructors are provided to get FITS data from an existing file or to create new FITS data sets. Overloaded versions allow the user to

a) read from one or more specified extensions, specified by EXTNAME and VERSION or by HDU number. b either just header information or data on construction c) to specify scalar keyword values to be read on construction d) to open and read an extension that has specified keyword values e) create a new FITS object and corresponding file, including an empty primary header.

The memory fits object as constructed is always an image of a valid FITS object, i.e. a primary HDU is created on construction.

calling the destructor closes the disk file, so that FITS files are automatically deleted at the end of scope unless other arrangements are made.


Constructor & Destructor Documentation

CCfits::FITS::FITS ( const string & name,
RWmode mode = Read,
bool readDataFlag = false,
const std::vector< string > & primaryKeys = std::vector<string>() )
 

basic constructor.

This basic constructor makes a FITS object from the given filename. The filename string is passed directly to the cfitsio library: thus all of the extended filename syntax described in the cfitsio manual should work as documented.

If the mode is Read [default], it will read all of the headers in the file, and all of the data if the readDataFlag is supplied as true. It will also read optional primary keys.

The file name is the only required argument. If the mode is Write and the file does not already exist, a default primary HDU will be created in the file with BITPIX=8 and NAXIS=0: this mode is designed for writing FITS files with table extensions only. For files with image data the constructor that specified the data type and number of axes should be called.

Parameters:
name   The name of the FITS file to be read/written
mode   The read/write mode: must be Read or Write
readDataFlag   boolean: read data on construction if true
primaryKeys   Allows optional reading of primary header keys on construction
Exceptions:
NoSuchHDU   thrown on HDU seek error either by index or {name,version}
FitsError   thrown on non-zero status code from cfitsio when not overriden by FitsException error to produce more illuminating message.

CCfits::FITS::FITS ( const string & name,
RWmode mode,
const string & hduName,
bool readDataFlag = false,
const std::vector< string > & hduKeys = std::vector<string>(),
const std::vector< string > & primaryKey = std::vector<string>(),
int version = 1 )
 

Open a FITS file and read a single specified HDU.

This and similar constructor variants support reading table data.

Optional arguments allow the reading of primary header keys and specified data from hduName, the HDU to be read. An object representing the primary HDU is always created: if it contains an image, that image may be read by subsequent calls.

Parameters:
name   The name of the FITS file to be read
mode   The read/write mode: takes values Read or Write
hduName   The name of the HDU to be read.
hduKeys   Optional array of keywords to be read from the HDU
version   Optional version number. If not supplied the first HDU with name hduName is read see above for other parameter definitions

CCfits::FITS::FITS ( const string & name,
RWmode mode,
const std::vector< string > & hduNames,
bool readDataFlag = false,
const std::vector< string > & primaryKey = std::vector<string>() )
 

This is intended as a convenience where the file consists of single versions of HDUs and data only, not keys are to be read.

Parameters:
hduNames   array of HDU names to be read. see above for other parameter definitions.

CCfits::FITS::FITS ( const string & fileName,
const FITS & source )
 

create a new FITS object and corresponding file with copy of the primary header of the source.

Parameters:
fileName   New file to be created.
source   A previously created FITS object to be copied.

see above for other parameter definitions.

CCfits::FITS::FITS ( const string & name,
RWmode mode,
const std::vector< string > & hduNames,
const std::vector< std::vector< string > > & hduKeys,
bool readDataFlag = false,
const std::vector< string > & primaryKeys = std::vector<string>(),
const std::vector< int > & hduVersions = std::vector<int>() )
 

FITS read constructor in full generality.

Parameters:
hduVersions   an optional version number for each HDU to be read
hduKeys   an array of keywords for each HDU to be read. see above for other parameter definitions.

CCfits::FITS::FITS ( const string & name,
int bitpix,
int naxis,
long * naxes )
 

Constructor for creating new FITS objects containing images.

This constructor is only called for creating new files (mode is not an argument) and creates a new primary HDU with the datatype & axes specified by bitpix, naxis, and naxes. The data are added to the new fits object and file by subsequent calls to FITS::pHDU().write( <arguments> )

Valid values of bitpix are given in the fitsio.h header. If the filename corresponds to an existing file and does not start with the '!' character the construction will fail with a CantCreate exception.

The arguments are:

Parameters:
name   The file to be written to disk
bitpix   the datatype of the primary image (see cfitsio documentation for allowed values.
naxis   the data dimension of the primary image
naxes   the array of axis lengths for the primary image. Ignored if naxis =0, i.e. the primary header is empty. extensions can be added arbitrarily to the file after this constructor is called. The constructors should write header information to disk:

CCfits::FITS::FITS ( const string & name,
RWmode mode,
int hduIndex,
bool readDataFlag = false,
const std::vector< string > & hduKeys = std::vector<string>(),
const std::vector< string > & primaryKey = std::vector<string>() )
 

read a single numbered HDU.

Constructor analogous to the version that reads by name. This is required since HDU extensions are not required to have the EXTNAME or HDUNAME keyword by the standard. If there is no name, a dummy name based on the HDU number is created and becomes the key.

Parameters:
hduIndex   The index of the HDU to be read. see above for other parameter definitions.

CCfits::FITS::FITS ( const string & name,
RWmode mode,
const std::vector< string > & searchKeys,
const std::vector< string > & searchValues,
bool readDataFlag = false,
const std::vector< string > & hduKeys = std::vector<string>(),
const std::vector< string > & primaryKey = std::vector<string>(),
int version = 1 )
 

open fits file and read HDU which contains supplied keywords with [optional] specified values (sometimes one just wants to know that the keyword is present).

Optional parameters allows the reading of specified primary HDU keys and specified columns and keywords in the HDU of interest.

Parameters:
name   The name of the FITS file to be read
mode   The read/write mode: must be Read or Write
searchKeys   A string vector of keywords to search for in each header
searchValues   A string vector of values those keywords are required to have for success. Note that the keys must be of type string. If any value does not need to be checked the corresponding searchValue element can be empty.
readDataFlag   boolean: if true, read data if HDU is found
hduKeys   Allows optional reading of keys in the HDU that is searched for if it is successfully found
primaryKeys   Allows optional reading of primary header keys on construction
version   Optional version number. If specified, checks the EXTVERS keyword.
Exceptions:
FitsError   thrown on non-zero status code from cfitsio when not overriden by FitsException error to produce more illuminating message.

CCfits::FITS::~FITS ( )
 

destructor.


Member Function Documentation

ExtHDU * CCfits::FITS::addImage ( const string & hduName,
int bpix,
std::vector< long > & naxes,
int version = 1 )
 

Add an image extension to an existing FITS object. (File with w or rw access).

Does not make primary images, which are built in the constructor for the FITS file. The image data is not added here: it can be added by a second call.

Todo:
Add a function for replacing the primary image

Table * CCfits::FITS::addTable ( string & hduName,
int rows,
const std::vector< string > & columnName = std::vector<string>(),
const std::vector< string > & columnFmt = std::vector<string>(),
const std::vector< string > & columnUnit = std::vector<string>(),
HduType type = BinaryTbl,
int version = 1 )
 

Add a table extension to an existing FITS object. Add extension to FITS object for file with w or rw access.

Parameters:
rows   The number of rows in the table to be created.
columnName   A vector containing the table column names
columnFmt   A vector containing the table column formats
columnUnit   (Optional) a vector giving the units of the columns.
HduType   The table type - AsciiTbl or BinaryTbl (defaults to BinaryTbl) the lists of columns are optional - one can create an empty table extension but if supplied, colType, columnName and colFmt must have equal dimensions.

Todo:
the code should one day check that the version keyword is higher than any other versions already added to the FITS object (although cfitsio doesn't do this either).

void CCfits::FITS::clearErrors ( ) [static]
 

clear the error stack and set status to zero.

FITS * CCfits::FITS::clone ( ) const
 

clone function: to allow implementation later of reference counting.

void CCfits::FITS::copy ( const HDU & source )
 

copy the HDU source into the FITS object.

This function adds a copy of an HDU from another file into *this. It does not create a duplicate of an HDU in the file associated with *this.

ExtHDU & CCfits::FITS::currentExtension ( )
 

return a non-const reference to whichever is the current extension.

const string & CCfits::FITS::currentExtensionName ( ) const
 

return the name of the extension that the fitsfile is currently addressing.

If the extension in question does not have an EXTNAME or HDUNAME keyword, then the function returns $HDU$n, where n is the sequential HDU index number (primary HDU = 0).

void CCfits::FITS::deleteExtension ( int doomed )
 

Delete extension specified by extension number.

\overload

void CCfits::FITS::deleteExtension ( const std::string & doomed,
int version = 1 )
 

Delete extension specified by name and version number.

Removes extension from FITS object and memory copy.

Parameters:
doomed   the name of the extension to be deleted
version   an optional version number, the EXTVER keyword, defaults to 1
Exceptions:
NoSuchHDU   Thrown if there is no extension with the specified version number
FitsError   Thrown if there is a non-zero status code from cfitsio, e.g. if the delete operation is applied to a FITS file opened for read only access.

void CCfits::FITS::destroy ( ) throw ()
 

Erase FITS object and close corresponding file.

Force deallocation and erase of elements of a FITS memory object. Allows a reset of everything inside the FITS object, and closes the file. The object is inaccessible after this call.

destroy is public to allow users to reuse a symbol for a new file, but it is identical in operation to the destructor.

const std::multimap< string, ExtHDU *> & CCfits::FITS::extension<string,ExtHDU*> ( ) const
 

return const reference to the extension container.

This is useful for such operations as extension().size() etc.

ExtHDU & CCfits::FITS::extension ( const string & hduName,
int version = 1 ) [inline]
 

return FITS extension by name and (optionally) version number.

const ExtHDU & CCfits::FITS::extension ( const string & hduName,
int version = 1 ) const
 

return FITS extension by name and (optionally) version number.

ExtHDU & CCfits::FITS::extension ( int i )
 

return FITS extension by index number. non-const version. see const version for details.

const ExtHDU & CCfits::FITS::extension ( int i ) const
 

return FITS extension by index number. N.B. The input index number is currently defined as enumerating extensions, so the extension(1) returns HDU number 2.

Table & CCfits::FITS::filter ( const string & expression,
ExtHDU & inputTable,
bool overwrite = true,
bool readData = false )
 

Filter the rows of the inputTable with the condition expression, and return a reference to the resulting Table.

This function provides an object oriented version of cfitsio's fits_select_rows call. The expression string is any boolean expression involving the names of the columns in the input table (e.g., if there were a column called "density", a valid expression might be "DENSITY > 3.5": see the cfitsio documentation for further details).

[N.B. the "append" functionality described below does not work when linked with cfitsio 2.202 or prior because of a known issue with that version of the library. This causes the output to be a new extension with a correct header copy and version number but without the filtered data]. If the inputTable is an Extension HDU of this FITS object, then if overwrite is true the operation will overwrite the inputTable with the filtered version, otherwise it will append a new HDU with the same extension name but the next highest version (EXTVER) number available.

void CCfits::FITS::flush ( )
 

flush buffer contents to disk.

Provides manual control of disk writing operation. Image data are flushed automatically to disk after the write operation is completed, but not column data.

const string & CCfits::FITS::name ( ) const
 

return filename of file corresponding to FITS object.

PHDU & CCfits::FITS::pHDU ( )
 

return a reference to the primary HDU.

const PHDU & CCfits::FITS::pHDU ( ) const
 

return a const reference to the primary HDU.

void CCfits::FITS::read ( const std::vector< string > & searchKeys,
const std::vector< string > & searchValues,
bool readDataFlag = false,
const std::vector< string > & hduKeys = std::vector<string>(),
int version = 1 )
 

read method for read header or HDU that contains specified keywords.

Parameters:
searchKeys   A string vector of keywords to search for in each header
searchValues   A string vector of values those keywords are required to have for success. Note that the keys must be of type string. If any value does not need to be checked the corresponding searchValue element can be empty.
readDataFlag   boolean: if true, read data if HDU is found
hduKeys   Allows optional reading of keys in the HDU that is searched for if it is successfully found
primaryKeys   Allows optional reading of primary header keys on construction
version   Optional version number. If specified, checks the EXTVERS keyword.

void CCfits::FITS::read ( int hduIndex,
bool readDataFlag = false,
const std::vector< string > & keys = std::vector<string>() )
 

read an HDU specified by index number.

This is provided to allow reading of HDUs after construction. see above for parameter definitions.

void CCfits::FITS::read ( const std::vector< string > & hduNames,
const std::vector< std::vector< string > > & keys,
bool readDataFlag = false,
const std::vector< int > & hduVersions = std::vector<int>() )
 

get data from a set of HDUs from disk file, specifying keys and version numbers.

This is provided to allow reading of HDUs after construction. see above for parameter definitions.

void CCfits::FITS::read ( const std::vector< string > & hduNames,
bool readDataFlag = false )
 

get data from a set of HDUs from disk file.

This is provided to allow reading of HDUs after construction. see above for parameter definitions.

void CCfits::FITS::read ( const string & hduName,
bool readDataFlag = false,
const std::vector< string > & keys = std::vector<string>(),
int version = 0 )
 

get data from single HDU from disk file.

This is provided to allow the adding of additional HDUs to the FITS object after construction of the FITS object. After the read() functions have been called for the FITS object, subsequent read method to the Primary, ExtHDU, and Column objects will retrieve data from the FITS object in memory (those methods can be called to read data in those HDU objects that was not read when the HDU objects were constructed.

All the read functions will throw NoSuchHDU exceptions on seek errors since they involve constructing HDU objects.

The parameter definitions are as documented for the corresponding constructor.

void CCfits::FITS::resetPosition ( )
 

explicit call to set the fits file pointer to the primary.

void CCfits::FITS::setVerboseMode ( bool value ) [inline, static]
 

set verbose setting for library.

bool CCfits::FITS::verboseMode ( ) [inline, static]
 

return verbose setting for library.

If true, all messages that are reported by exceptions are printed to std::cerr.


The documentation for this class was generated from the following files:
Generated at Fri Apr 11 16:05:10 2003 for CCfits by doxygen1.2.7 written by Dimitri van Heesch, © 1997-2001