#include <FitsFile.h>
Public Types | |
enum | FitsHdr { Primary, Secondary, Catalogue } |
enum | ExpectKeys { UTDATE, MJD, PROJECT, FILTER, FLATCOR, CIRCPM, SKYSUB, ARC_MFID, ARC_TIME, OBSNUM, XTENSION, ZNAXIS, ZNAXIS1, ZNAXIS2, NAXIS, NAXIS1, NAXIS2, CRVAL1, CRVAL2, CD11, CD12, CD21, CD22, CAMNUM, TEXPTIME, cAMSTART, cAMEND, cMAGZPT, cMAGZRR, cEXTINCT, cEXP_TIME, cCRVAL1, cCRVAL2, cCTYPE1, cCTYPE2, cCRPIX1, cCRPIX2, cCD11, cCD12, cCD21, cCD22, cPV21, cPV22, cPV23, cPV24, cPV25, NumKeys } |
Public Member Functions | |
FitsFile () | |
Constructor - just initialises the expected keywords list. | |
FitsFile (const std::string &filename) | |
Constructor - opens the given FITS filename on disc. | |
~FitsFile () | |
void | openFile (const std::string &filename) |
Opens the given FITS filename on disc. | |
void | closeFile () |
Closes the opened FITS file. | |
const std::string & | getFileName () const |
Returns the filename associated with the FitsFile object. | |
bool | isTile () const |
Returns true if the file is a tile. | |
bool | testExpectedKeys (const std::string &fitsType) |
Check if any of the essential keywords is missing. | |
int | checkKeys (const std::string &aKeyname) |
bool | hasKey (const std::string &keyname) const |
Returns true if keyword exists in FITS header. | |
void | readKey (const std::string &keyname, int &value) const |
Read value of given header keyword into integer argument. | |
void | readKey (const std::string &keyname, float &value) const |
Read value of given header keyword into float argument. | |
void | readKey (const std::string &keyname, double &value) const |
Read value of given header keyword into double argument. | |
void | readKey (const std::string &keyname, std::string &value) const |
Read value of given header keyword into std::string argument. | |
template<typename AnyDataType > | |
void | readKey (ExpectKeys keyname, AnyDataType &value) const |
Read value of given header keyword. | |
void | readKeyUnit (const std::string &keyname, std::string &unit) |
void | readHistory (std::list< std::string > &values) |
Read all HISTORY cards and put their values in the list of std::strings. | |
int | getNumCards () |
Return the number of FITS header cards in this HDU. | |
void | readCard (int keyNo, char *card) |
Get the card for the given key number. | |
std::string | readKeyname (int keyNo) |
Get the keyword for this key number. | |
int | getNumHdus () const |
Return the number of HDU blocks in the FITS file. | |
int | getHduNum () |
int | movabsHdu (int hdunum) const |
Move to the given absolute HDU number in the file. | |
int | movrelHdu (int nmove) |
Move nmove HDU blocks from the currently positioned HDU. | |
int | getHduType () |
bool | isImageHdu () |
Returns true if the current HDU correspond to image (pixel) data. | |
bool | isAsciiTable () |
Returns true if the current HDU corresponds to an ASCII table. | |
bool | isBinaryTable () |
Returns true if the current HDU corresponds to a binary table. | |
int | getNumRows () |
Returns number of rows in the table in the current HDU. | |
int | getNumCols () |
Returns the number of columns in the table in the current HDU. | |
int | getColnum (const std::string &name) |
void | readColumn (const std::string &name, float *data) |
void | readColumn (const std::string &name, double *data) |
void | readColumn (const std::string &name, std::string *data) |
std::string | readColumnUnit (const std::string &name) |
Return the unit std::string associated with the given column name. | |
Private Types | |
typedef std::pair< std::string, FitsHdr > | FitsKeysPair |
typedef std::vector< FitsKeysPair > | FitsKeysList |
Private Member Functions | |
void | initExpectedKeysList () |
Initialises the list of expected keywords. | |
void | handleError (int status, bool throwException=true) const |
Forms and throws a FitsIOException using the given CFITSIO status. | |
Private Attributes | |
std::string | fileName |
Name of file currently open. | |
fitsfile * | fptr |
Pointer to CFISTIO data structure. | |
Static Private Attributes | |
static FitsKeysList | mExpectedKeys |
A list of the expected FITS keywords - common to all instances. |
Class to represent FITS files on disc. This acts as a wrapper to the cfitsio library. Each class object (ie instance) represents a FITS file opened on disc.
typedef std::vector<FitsKeysPair> FitsFile::FitsKeysList [private] |
typedef std::pair<std::string, FitsHdr> FitsFile::FitsKeysPair [private] |
enum FitsFile::ExpectKeys |
enum FitsFile::FitsHdr |
FitsFile::FitsFile | ( | ) |
Constructor - just initialises the expected keywords list.
References initExpectedKeysList().
FitsFile::FitsFile | ( | const std::string & | filename | ) |
Constructor - opens the given FITS filename on disc.
References initExpectedKeysList(), and openFile().
FitsFile::~FitsFile | ( | ) |
Destructor. Does nothing at the moment, but future versions should have it check for an open file in the object and close it.
int FitsFile::checkKeys | ( | const std::string & | aKeyname | ) |
References fptr, and handleError().
Referenced by testExpectedKeys().
void FitsFile::closeFile | ( | ) |
Closes the opened FITS file.
References fptr, and handleError().
Referenced by IndirectFrameID< DataType >::doit(), extractMetadata(), and extractSources().
int FitsFile::getColnum | ( | const std::string & | name | ) |
Returns the column number in the table associated with the given name of the column
References fptr, and handleError().
Referenced by readColumn(), and readColumnUnit().
const std::string & FitsFile::getFileName | ( | ) | const |
Returns the filename associated with the FitsFile object.
References fileName.
Referenced by Extension< DataType >::build(), TotalExpTime< DataType >::doit(), QuantitiesByAst< DataType >::doit(), HlRadii< DataType >::doit(), HlRadCirc< DataType >::doit(), CalibratedVSAMagnitude< DataType >::doit2(), RaDecByAst< DataType >::doit2(), CalibratedMagnitude< DataType >::doit2(), FileName< DataType >::FileName(), FrameType< DataType >::FrameType(), getFrameIDMethod(), insertKeywordValue(), isTile(), TelRunNum< DataType >::TelRunNum(), testExpectedKeys(), VersionNum< DataType >::VersionNum(), and VSAProject< DataType >::VSAProject().
int FitsFile::getHduNum | ( | ) |
Return HDU at which the object is currently positioned. Note the FITSIO convention where the primary header is HDU #1 and all extensions start at HDU #2
References fptr.
Referenced by insertKeywordValue().
int FitsFile::getHduType | ( | ) |
Return the CFISTIO constant that identifies the type of data (image, ascii table, binary table) in the current HDU
References fptr, and handleError().
Referenced by isAsciiTable(), isBinaryTable(), and isImageHdu().
int FitsFile::getNumCards | ( | ) |
Return the number of FITS header cards in this HDU.
References fptr, and handleError().
Referenced by Provenance< DataType >::build(), QuantitiesByAst< DataType >::doit(), HlRadii< DataType >::doit(), HlRadCirc< DataType >::doit(), and RaDecByAst< DataType >::doit2().
int FitsFile::getNumCols | ( | ) |
Returns the number of columns in the table in the current HDU.
References fptr, and handleError().
int FitsFile::getNumHdus | ( | ) | const |
Return the number of HDU blocks in the FITS file.
References fptr, and handleError().
Referenced by DataDumper::addDefaultRow(), Extension< DataType >::build(), QuantitiesByAst< DataType >::doit(), HlRadii< DataType >::doit(), HlRadCirc< DataType >::doit(), CalibratedVSAMagnitude< DataType >::doit2(), RaDecByAst< DataType >::doit2(), CalibratedMagnitude< DataType >::doit2(), insertExtNum(), and testExpectedKeys().
int FitsFile::getNumRows | ( | ) |
Returns number of rows in the table in the current HDU.
References fptr, and handleError().
Referenced by DataDumper::addDefaultRow(), insertExtNum(), insertFitsColumns(), TableData< Numeric >::loadFitsColumn(), and readColumn().
void FitsFile::handleError | ( | int | status, | |
bool | throwException = true | |||
) | const [private] |
Forms and throws a FitsIOException using the given CFITSIO status.
References fileName, and StringOps::NumToString().
Referenced by checkKeys(), closeFile(), getColnum(), getHduType(), getNumCards(), getNumCols(), getNumHdus(), getNumRows(), movabsHdu(), movrelHdu(), openFile(), readCard(), readColumn(), readHistory(), readKey(), readKeyname(), and readKeyUnit().
bool FitsFile::hasKey | ( | const std::string & | keyname | ) | const |
Returns true if keyword exists in FITS header.
References fptr.
Referenced by QuantitiesByAst< DataType >::doit().
void FitsFile::initExpectedKeysList | ( | ) | [private] |
Initialises the list of expected keywords.
References ARC_MFID, ARC_TIME, cAMEND, CAMNUM, cAMSTART, Catalogue, cCD11, cCD12, cCD21, cCD22, cCRPIX1, cCRPIX2, cCRVAL1, cCRVAL2, cCTYPE1, cCTYPE2, CD11, CD12, CD21, CD22, cEXP_TIME, cEXTINCT, CIRCPM, cMAGZPT, cMAGZRR, cPV21, cPV22, cPV23, cPV24, cPV25, CRVAL1, CRVAL2, FILTER, FLATCOR, Options::getArchive(), mExpectedKeys, MJD, NAXIS, NAXIS1, NAXIS2, OBSNUM, PROJECT, Secondary, SKYSUB, TEXPTIME, StringOps::ToLower(), UTDATE, XTENSION, ZNAXIS, ZNAXIS1, and ZNAXIS2.
Referenced by FitsFile().
bool FitsFile::isAsciiTable | ( | ) |
Returns true if the current HDU corresponds to an ASCII table.
References getHduType().
bool FitsFile::isBinaryTable | ( | ) |
Returns true if the current HDU corresponds to a binary table.
References getHduType().
Referenced by insertExtNum(), and insertFitsExtensionHeader().
bool FitsFile::isImageHdu | ( | ) |
Returns true if the current HDU correspond to image (pixel) data.
References getHduType().
Referenced by insertExtNum(), and insertFitsExtensionHeader().
bool FitsFile::isTile | ( | ) | const |
Returns true if the file is a tile.
References getFileName(), and PreSuffixNames::tileSuffix.
Referenced by TotalExpTime< DataType >::doit(), CalibratedVSAMagnitude< DataType >::doit2(), FilterIDByFits< DataType >::FilterIDByFits(), DataOps::getFileTimeStamp(), DataOps::getRunNoFromKey(), DataOps::makeFrameID(), and testExpectedKeys().
int FitsFile::movabsHdu | ( | int | hdunum | ) | const |
Move to the given absolute HDU number in the file.
References fptr, and handleError().
Referenced by DataDumper::addDefaultRow(), Provenance< DataType >::build(), Primary< DataType >::build(), Extension< DataType >::build(), TotalExpTime< DataType >::doit(), QuantitiesByAst< DataType >::doit(), HlRadii< DataType >::doit(), HlRadCirc< DataType >::doit(), CalibratedVSAMagnitude< DataType >::doit2(), RaDecByAst< DataType >::doit2(), CalibratedMagnitude< DataType >::doit2(), FilterIDByFits< DataType >::FilterIDByFits(), DataOps::getFileTimeStamp(), DataOps::getRunNoFromKey(), insertExtNum(), insertFitsPrimaryHeader(), insertKeywordValue(), DataOps::makeFrameID(), and testExpectedKeys().
int FitsFile::movrelHdu | ( | int | nmove | ) |
Move nmove HDU blocks from the currently positioned HDU.
References fptr, and handleError().
void FitsFile::openFile | ( | const std::string & | filename | ) |
Opens the given FITS filename on disc.
References fileName, fptr, and handleError().
Referenced by FitsFile().
void FitsFile::readCard | ( | int | keyNo, | |
char * | card | |||
) |
Get the card for the given key number.
References fptr, and handleError().
Referenced by QuantitiesByAst< DataType >::doit(), HlRadii< DataType >::doit(), HlRadCirc< DataType >::doit(), and RaDecByAst< DataType >::doit2().
void FitsFile::readColumn | ( | const std::string & | name, | |
std::string * | data | |||
) | [inline] |
Read all entries in the named column and place the results in the std::string data array which must point to enough memory. I seem to have deliberately coded it up so that it does nothing - I can't remember why
void FitsFile::readColumn | ( | const std::string & | name, | |
double * | data | |||
) |
Read all entries in the named column and place the results in the double data array which must point to enough memory
References fptr, getColnum(), getNumRows(), and handleError().
void FitsFile::readColumn | ( | const std::string & | name, | |
float * | data | |||
) |
Read all entries in the named column and place the results in the float data array which must point to enough memory
References fptr, getColnum(), getNumRows(), and handleError().
Referenced by TableData< Numeric >::loadFitsColumn().
std::string FitsFile::readColumnUnit | ( | const std::string & | name | ) |
Return the unit std::string associated with the given column name.
References getColnum(), StringOps::NumToString(), and readKey().
Referenced by insertFitsColumns().
void FitsFile::readHistory | ( | std::list< std::string > & | values | ) |
Read all HISTORY cards and put their values in the list of std::strings.
References fptr, and handleError().
void FitsFile::readKey | ( | ExpectKeys | keyname, | |
AnyDataType & | value | |||
) | const [inline] |
Read value of given header keyword.
References mExpectedKeys, and readKey().
void FitsFile::readKey | ( | const std::string & | keyname, | |
std::string & | value | |||
) | const |
Read value of given header keyword into std::string argument.
References fptr, and handleError().
void FitsFile::readKey | ( | const std::string & | keyname, | |
double & | value | |||
) | const |
Read value of given header keyword into double argument.
References fptr, and handleError().
void FitsFile::readKey | ( | const std::string & | keyname, | |
float & | value | |||
) | const |
Read value of given header keyword into float argument.
References fptr, and handleError().
void FitsFile::readKey | ( | const std::string & | keyname, | |
int & | value | |||
) | const |
Read value of given header keyword into integer argument.
References fptr, and handleError().
Referenced by Provenance< DataType >::build(), TotalExpTime< DataType >::doit(), QuantitiesByAst< DataType >::doit(), HlRadii< DataType >::doit(), HlRadCirc< DataType >::doit(), CalibratedVSAMagnitude< DataType >::doit2(), RaDecByAst< DataType >::doit2(), CalibratedMagnitude< DataType >::doit2(), FilterIDByFits< DataType >::FilterIDByFits(), DataOps::getFileTimeStamp(), DataOps::getRunNoFromKey(), insertKeywordValue(), DataOps::makeFrameID(), readColumnUnit(), readKey(), and testExpectedKeys().
std::string FitsFile::readKeyname | ( | int | keyNo | ) |
Get the keyword for this key number.
References fptr, and handleError().
Referenced by Provenance< DataType >::build().
void FitsFile::readKeyUnit | ( | const std::string & | keyname, | |
std::string & | unit | |||
) |
Read the [] unit in the comment std::string associated with the given keyword name
References fptr, and handleError().
bool FitsFile::testExpectedKeys | ( | const std::string & | fitsType | ) |
Check if any of the essential keywords is missing.
References Logger::addError(), cAMEND, CAMNUM, cAMSTART, PreSuffixNames::casuPrefix, Catalogue, cEXP_TIME, checkKeys(), CIRCPM, cPV21, cPV22, cPV23, cPV24, cPV25, PreSuffixNames::edinPrefix, ExpectNames::extNum, FLATCOR, Options::getArchive(), getFileName(), getNumHdus(), isTile(), mExpectedKeys, movabsHdu(), OBSNUM, readKey(), Secondary, SKYSUB, TEXPTIME, StringOps::ToLower(), PreSuffixNames::VirtuallyNoPhotons, PreSuffixNames::vistaPrefix, and XTENSION.
Referenced by extractMetadata(), and extractSources().
std::string FitsFile::fileName [private] |
Name of file currently open.
Referenced by getFileName(), handleError(), and openFile().
fitsfile* FitsFile::fptr [private] |
Pointer to CFISTIO data structure.
Referenced by checkKeys(), closeFile(), getColnum(), getHduNum(), getHduType(), getNumCards(), getNumCols(), getNumHdus(), getNumRows(), hasKey(), movabsHdu(), movrelHdu(), openFile(), readCard(), readColumn(), readHistory(), readKey(), readKeyname(), and readKeyUnit().
FitsFile::FitsKeysList FitsFile::mExpectedKeys [static, private] |
A list of the expected FITS keywords - common to all instances.
Referenced by initExpectedKeysList(), readKey(), and testExpectedKeys().