From 98b5d10c2d5effcaf4fdc1bcaa7a3c75b9b7d53a Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Fri, 14 Mar 2008 01:26:08 +0000 Subject: [PATCH] add table column access by column number --- include/GFitsHDU.hpp | 1 + src/fits/GFitsHDU.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-) diff --git a/include/GFitsHDU.hpp b/include/GFitsHDU.hpp index 6a479e7..2b5433d 100644 --- a/include/GFitsHDU.hpp +++ b/include/GFitsHDU.hpp @@ -68,6 +68,7 @@ public: GFitsHeader* header(void) const; GFitsData* data(void) const; GFitsTableCol* column(const std::string& colname) const; + GFitsTableCol* column(const int& colnum) const; void primary(void); private: diff --git a/src/fits/GFitsHDU.cpp b/src/fits/GFitsHDU.cpp index be9b83d..e856d54 100644 --- a/src/fits/GFitsHDU.cpp +++ b/src/fits/GFitsHDU.cpp @@ -316,6 +316,40 @@ GFitsTableCol* GFitsHDU::column(const std::string& colname) const /***********************************************************************//** + * @brief Return pointer to column of table + * + * @param[in] colnum Number FITS table column to be returned (starting from 1) + * + * If this method is called for an image a 'fits_HDU_not_a_table' exception + * will be thrown. + ***************************************************************************/ +GFitsTableCol* GFitsHDU::column(const int& colnum) const +{ + // Initialise pointer + GFitsTableCol* ptr = NULL; + + // Get pointer to table column + switch (m_type) { + case HT_IMAGE: // Image HDU + throw GException::fits_HDU_not_a_table(G_COLUMN, m_type); + break; + case HT_ASCII_TABLE: // ASCII Table HDU + ptr = ((GFitsAsciiTable*)this->data())->column(colnum); + break; + case HT_BIN_TABLE: // Binary Table HDU + ptr = ((GFitsBinTable*)this->data())->column(colnum); + break; + default: + throw GException::fits_unknown_HDU_type(G_COLUMN, m_type); + break; + } + + // Return pointer + return ptr; +} + + +/***********************************************************************//** * @brief Setup minimal primary HDU ***************************************************************************/ void GFitsHDU::primary(void) -- libgit2 0.21.4