From a235d9c77dcab8d0f86078045ff134e7ae2b3fd1 Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Tue, 4 Mar 2008 10:02:47 +0000 Subject: [PATCH] enhance FITS table and table column interfaces --- include/GException.hpp | 6 ++++++ include/GFitsAsciiTable.hpp | 2 +- include/GFitsBinTable.hpp | 2 +- include/GFitsCfitsio.hpp | 4 ++-- include/GFitsTable.hpp | 13 ++++++++++--- include/GFitsTableCol.hpp | 43 +++++++++++++++++++------------------------ src/GException.cpp | 18 ++++++++++++++++++ src/fits/GFitsAsciiTable.cpp | 2 +- src/fits/GFitsBinTable.cpp | 2 +- src/fits/GFitsHDU.cpp | 4 ++-- src/fits/GFitsTable.cpp | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------- src/fits/GFitsTableCol.cpp | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- src/rsp/GLATResponse.cpp | 19 ++++++++++++------- test/test_GFits.cpp | 25 +++---------------------- 14 files changed, 408 insertions(+), 134 deletions(-) diff --git a/include/GException.hpp b/include/GException.hpp index 7999760..d5f1262 100644 --- a/include/GException.hpp +++ b/include/GException.hpp @@ -195,6 +195,12 @@ public: fits_unknown_coltype(string origin, int type); }; + // FITS bad column length + class fits_bad_col_length : public GExceptionHandler { + public: + fits_bad_col_length(string origin, int length, int rows); + }; + // FITS bad bitpix value class fits_bad_bitpix : public GExceptionHandler { public: diff --git a/include/GFitsAsciiTable.hpp b/include/GFitsAsciiTable.hpp index 9b64a7f..9bf79f3 100644 --- a/include/GFitsAsciiTable.hpp +++ b/include/GFitsAsciiTable.hpp @@ -37,7 +37,7 @@ class GFitsAsciiTable : public GFitsTable { public: // Constructors and destructors GFitsAsciiTable(); - GFitsAsciiTable(int nrows, int ncols); + GFitsAsciiTable(int nrows); GFitsAsciiTable(const GFitsAsciiTable& table); virtual ~GFitsAsciiTable(); diff --git a/include/GFitsBinTable.hpp b/include/GFitsBinTable.hpp index a8c292e..ed4395f 100644 --- a/include/GFitsBinTable.hpp +++ b/include/GFitsBinTable.hpp @@ -37,7 +37,7 @@ class GFitsBinTable : public GFitsTable { public: // Constructors and destructors GFitsBinTable(); - GFitsBinTable(int nrows, int ncols); + GFitsBinTable(int nrows); GFitsBinTable(const GFitsBinTable& table); virtual ~GFitsBinTable(); diff --git a/include/GFitsCfitsio.hpp b/include/GFitsCfitsio.hpp index 0fc45c7..ca4fa89 100644 --- a/include/GFitsCfitsio.hpp +++ b/include/GFitsCfitsio.hpp @@ -66,8 +66,8 @@ #define __TSHORT TSHORT #define __TINT TINT #define __TLONG TLONG -#define __TLONGLONG TLONGLONG #define __TFLOAT TFLOAT +#define __TLONGLONG TLONGLONG #define __TDOUBLE TDOUBLE /* __ Type definition ____________________________________________________ */ @@ -116,8 +116,8 @@ typedef fitsfile __fitsfile; #define __TSHORT 21 #define __TINT 31 #define __TLONG 41 -#define __TLONGLONG 81 #define __TFLOAT 42 +#define __TLONGLONG 81 #define __TDOUBLE 82 #define __TCOMPLEX 83 #define __TDBLCOMPLEX 163 diff --git a/include/GFitsTable.hpp b/include/GFitsTable.hpp index 2625242..e038369 100644 --- a/include/GFitsTable.hpp +++ b/include/GFitsTable.hpp @@ -34,6 +34,9 @@ * @class GFitsTable * * @brief Abstract interface for FITS table + * + * This class implements a FITS table. A FITS table is a collection of + * columns with an identical number of rows. ***************************************************************************/ class GFitsTable : public GFitsData { @@ -43,7 +46,7 @@ class GFitsTable : public GFitsData { public: // Constructors and destructors GFitsTable(); - GFitsTable(int nrows, int ncols); + GFitsTable(int nrows); GFitsTable(const GFitsTable& table); virtual ~GFitsTable(); @@ -55,10 +58,14 @@ public: void save(void); void close(void); GFitsTable* clone(void) const = 0; + void append_column(GFitsTableCol* column); + void insert_column(int colnum, GFitsTableCol* column); + void append_rows(const int& nrows); + void insert_rows(const int& rownum, const int& nrows); GFitsTableCol* column(const std::string& colname); GFitsTableCol* column(const int& colnum); - int rows(void) const; - int cols(void) const; + int nrows(void) const; + int ncols(void) const; protected: // Protected methods diff --git a/include/GFitsTableCol.hpp b/include/GFitsTableCol.hpp index 4980e05..78c9d53 100644 --- a/include/GFitsTableCol.hpp +++ b/include/GFitsTableCol.hpp @@ -10,6 +10,11 @@ * (at your option) any later version. * * * ***************************************************************************/ +/** + * @file GFitsTableCol.hpp + * @brief GFitsTableCol class definition. + * @author J. Knodlseder + */ #ifndef GFITSTABLECOL_HPP #define GFITSTABLECOL_HPP @@ -20,14 +25,18 @@ /* __ Namespaces _________________________________________________________ */ -/*************************************************************************** - * GFitsTableCol class definition * +/***********************************************************************//** + * @class GFitsTableCol + * + * @brief Abstract interface for FITS table column + * + * This class implements a FITS table column. ***************************************************************************/ class GFitsTableCol { // Friend classes friend class GFitsTable; - + // I/O friends friend ostream& operator<< (ostream& os, const GFitsTableCol& column); @@ -52,13 +61,12 @@ public: virtual int* ptr_int(void) = 0; // Base class Methods - void set_name(const std::string name); - void set_colnum(const int colnum); - void set_type(const int type); - void set_repeat(const int repeat); - void set_width(const int width); - void set_length(const int length); - void set_fitsfile(const __fitsfile* fptr); + void name(const std::string& name); + //void colnum(const int& colnum); //!< DO WE REALLY NEED THIS??? + //void type(const int& type); //!< DO WE REALLY NEED THIS??? + //void repeat(const int repeat); //!< DO WE REALLY NEED THIS??? + //void width(const int width); //!< DO WE REALLY NEED THIS??? + //void length(const int& length); //!< DO WE REALLY NEED THIS??? std::string name(void); int colnum(void); int type(void); @@ -71,7 +79,7 @@ protected: std::string m_name; //!< Column name std::string m_format; //!< Column format std::string m_unit; //!< Column unit - int m_colnum; //!< Column number + int m_colnum; //!< Column number (starting from 1) int m_type; //!< Column type int m_repeat; //!< Repeat value of column int m_width; //!< Width of column @@ -90,18 +98,5 @@ private: /*************************************************************************** * Inline methods * ***************************************************************************/ -inline void GFitsTableCol::set_name(const std::string name) { m_name = name; } -inline void GFitsTableCol::set_colnum(const int colnum) { m_colnum = colnum; } -inline void GFitsTableCol::set_type(const int type) { m_type = type; } -inline void GFitsTableCol::set_repeat(const int repeat) { m_repeat = repeat; } -inline void GFitsTableCol::set_width(const int width) { m_width = width; } -inline void GFitsTableCol::set_length(const int length) { m_length = length; } -inline void GFitsTableCol::set_fitsfile(const __fitsfile* fptr) { m_fitsfile = *fptr; } -inline std::string GFitsTableCol::name(void) { return m_name; } -inline int GFitsTableCol::colnum(void) { return m_colnum; } -inline int GFitsTableCol::type(void) { return m_type; } -inline int GFitsTableCol::repeat(void) { return m_repeat; } -inline int GFitsTableCol::width(void) { return m_width; } -inline int GFitsTableCol::length(void) { return m_length; } #endif /* GFITSTABLECOL_HPP */ diff --git a/src/GException.cpp b/src/GException.cpp index c92b548..bb1fe3c 100644 --- a/src/GException.cpp +++ b/src/GException.cpp @@ -409,6 +409,24 @@ GException::fits_unknown_coltype::fits_unknown_coltype(string origin, /***********************************************************************//** + * @brief FITS error: Bad column length + * + * @param[in] origin Method that throws the error. + * @param[in] length Length of the column. + * @param[in] rows Number of rows in table. + ***************************************************************************/ +GException::fits_bad_col_length::fits_bad_col_length(string origin, + int length, + int rows) +{ + m_origin = origin; + m_message = "Column length '" + str(length) + "' is not compatible" + " with the number of rows '" + str(rows) + "' in the" + " table"; +} + + +/***********************************************************************//** * @brief FITS error: invalid number of bits per pixel * * @param[in] origin Method that throws the error. diff --git a/src/fits/GFitsAsciiTable.cpp b/src/fits/GFitsAsciiTable.cpp index bf5375a..4b1b697 100644 --- a/src/fits/GFitsAsciiTable.cpp +++ b/src/fits/GFitsAsciiTable.cpp @@ -59,7 +59,7 @@ GFitsAsciiTable::GFitsAsciiTable() : GFitsTable() * @param[in] nrows Number of rows in table * @param[in] ncols Number of columns in table ***************************************************************************/ -GFitsAsciiTable::GFitsAsciiTable(int nrows, int ncols) : GFitsTable(nrows, ncols) +GFitsAsciiTable::GFitsAsciiTable(int nrows) : GFitsTable(nrows) { // Initialise class members for clean destruction init_members(); diff --git a/src/fits/GFitsBinTable.cpp b/src/fits/GFitsBinTable.cpp index bf87cdd..366dc8a 100644 --- a/src/fits/GFitsBinTable.cpp +++ b/src/fits/GFitsBinTable.cpp @@ -59,7 +59,7 @@ GFitsBinTable::GFitsBinTable() : GFitsTable() * @param[in] nrows Number of rows in table * @param[in] ncols Number of columns in table ***************************************************************************/ -GFitsBinTable::GFitsBinTable(int nrows, int ncols) : GFitsTable(nrows, ncols) +GFitsBinTable::GFitsBinTable(int nrows) : GFitsTable(nrows) { // Initialise class members for clean destruction init_members(); diff --git a/src/fits/GFitsHDU.cpp b/src/fits/GFitsHDU.cpp index d10e4ae..1adfb0b 100644 --- a/src/fits/GFitsHDU.cpp +++ b/src/fits/GFitsHDU.cpp @@ -385,8 +385,8 @@ void GFitsHDU::save(void) // image. else { - // Special case: The first HDU does not exist. A FITS file needs at least - // one primary HDU. Thus an empty image is created. + // Special case: The first HDU does not exist. A FITS file needs at + // least one primary HDU. Thus an empty image is created. if (m_fitsfile.HDUposition == 0) { int status = 0; status = __ffcrim(&m_fitsfile, 8, 0, NULL, &status); diff --git a/src/fits/GFitsTable.cpp b/src/fits/GFitsTable.cpp index f0b1c4c..f004813 100644 --- a/src/fits/GFitsTable.cpp +++ b/src/fits/GFitsTable.cpp @@ -26,10 +26,12 @@ /* __ Namespaces _________________________________________________________ */ /* __ Method name definitions ____________________________________________ */ -#define G_OPEN "GFitsTable::open(fitsfile*)" -#define G_SAVE "GFitsTable::save()" -#define G_COLUMN1 "GFitsTable::column(const std::string&)" -#define G_COLUMN2 "GFitsTable::column(const int&)" +#define G_OPEN "GFitsTable::open(fitsfile*)" +#define G_SAVE "GFitsTable::save()" +#define G_APPEND_COLUMN "GFitsTable::append_column(GFitsTableCol*)" +#define G_INSERT_COLUMN "GFitsTable::insert_column(int, GFitsTableCol*)" +#define G_COLUMN1 "GFitsTable::column(const std::string&)" +#define G_COLUMN2 "GFitsTable::column(const int&)" /* __ Macros _____________________________________________________________ */ @@ -46,6 +48,13 @@ /***********************************************************************//** * @brief Constructor + * + * Construct an instance of GFitsTable with zero rows. + * Use the methods + * GFitsTable::append_column and GFitsTable::insert_column + * to add columns and + * GFitsTable::append_rows and GFitsTable::insert_rows + * to add rows to this table. ***************************************************************************/ GFitsTable::GFitsTable() : GFitsData() { @@ -61,28 +70,19 @@ GFitsTable::GFitsTable() : GFitsData() * @brief Constructor * * @param[in] nrows Number of rows in table - * @param[in] ncols Number of columns in table + * + * Construct an instance of GFitsTable with a given number of rows. + * Use the methods + * GFitsTable::append_column and GFitsTable::insert_column + * to add columns to this table. ***************************************************************************/ -GFitsTable::GFitsTable(int nrows, int ncols) : GFitsData() +GFitsTable::GFitsTable(int nrows) : GFitsData() { // Initialise class members for clean destruction init_members(); - // Store table dimension + // Store numnber of rows m_rows = nrows; - m_cols = ncols; - - // If there are columns then allocate memory for column pointers - if (m_cols > 0) { - - // Allocate pointer memory - m_columns = new GFitsTableCol*[m_cols]; - - // Initialise pointers - for (int i = 0; i < m_cols; ++i) - m_columns[i] = NULL; - - } // endfor: looped over all columns // Return return; @@ -166,9 +166,9 @@ GFitsTable& GFitsTable::operator= (const GFitsTable& table) * * @param[in] fptr FITS file pointer * - * Builds a description of the binary table in memory. Columns are not loaded - * but column descriptors are allocated. The column data will only be loaded - * once it needs to be accessed. + * Builds a description of the table in memory. + * Columns are not loaded but column descriptors are allocated. + * The column data will only be loaded once it needs to be accessed. ***************************************************************************/ void GFitsTable::open(__fitsfile* fptr) { @@ -214,7 +214,8 @@ void GFitsTable::open(__fitsfile* fptr) value[strlen(value)-1] = '\0'; // Get column definition - status = __ffgtcl(&m_fitsfile, i+1, &typecode, &repeat, &width, &status); + status = __ffgtcl(&m_fitsfile, i+1, &typecode, &repeat, &width, + &status); if (status != 0) throw GException::fits_error(G_OPEN, status); @@ -241,13 +242,13 @@ void GFitsTable::open(__fitsfile* fptr) } // Store column definition - m_columns[i]->set_name(strip_whitespace(&(value[1]))); - m_columns[i]->set_colnum(i+1); - m_columns[i]->set_type(typecode); - m_columns[i]->set_repeat(repeat); - m_columns[i]->set_width(width); - m_columns[i]->set_length(m_rows); - m_columns[i]->set_fitsfile(fptr); + m_columns[i]->name(strip_whitespace(&(value[1]))); + m_columns[i]->m_colnum = i+1; + m_columns[i]->m_type = typecode; + m_columns[i]->m_repeat = repeat; + m_columns[i]->m_width = width; + m_columns[i]->m_length = m_rows; + m_columns[i]->connect(fptr); } // endfor: looped over all columns @@ -264,14 +265,15 @@ void GFitsTable::save(void) //cout << "GFitsTable::save entry" << endl; // Move to HDU int status = 0; - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status); + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, + &status); // If HDU does not yet exist in file then create it now if (status == 107) { - + // Reset status status = 0; - + // Initialise number of fields int tfields = 0; @@ -297,13 +299,13 @@ void GFitsTable::save(void) tfields++; } } - + // Create FITS table status = __ffcrtb(&m_fitsfile, m_type, m_rows, tfields, ttype, tform, tunit, NULL, &status); if (status != 0) throw GException::fits_error(G_SAVE, status); - + // De-allocate column definition arrays if (m_cols > 0) { for (int i = 0; i < m_cols; ++i) { @@ -342,6 +344,128 @@ void GFitsTable::close(void) /***********************************************************************//** + * @brief Append column to the table + * + * @param[in] column Pointer to column which should be appended + * + * @exception GException::fits_no_data + * A NULL column pointer was passed to the method. + * This method requires a valid column pointer. + * + * A column will be appended at the end of the table. See + * GFitsTable::insert_column + * for more details on the method. + ***************************************************************************/ +void GFitsTable::append_column(GFitsTableCol* column) +{ + // Throw exception if column pointer is empty + if (column == NULL) + throw GException::fits_no_data(G_APPEND_COLUMN, + "Column pointer was NULL"); + + // Inserting at the end correspond to appending + insert_column(m_cols, column); + + // Return + return; +} + +/***********************************************************************//** + * @brief Insert column into the table + * + * @param[in] colnum Column number to be inserted + * @param[in] column Pointer to column which should be inserted + * + * @exception GException::fits_no_data + * A NULL column pointer was passed to the method. + * This method requires a valid column pointer. + * @exception GException::fits_bad_col_length + * The length of the column is incompatible with the number of + * rows in the table. + * + * A column will be inserted at position 'colnum' of the table. If the + * position is beyond the end of the table the column will be appended. + * Any 'colnum' value smaller than 0 will be set automatically to 0. + * + * If the table is empty and has 0 rows, the number of rows will be set to + * the length of the column. + * + * The length of the column to be inserted has to be identical to the number + * of rows in the table. + ***************************************************************************/ +void GFitsTable::insert_column(int colnum, GFitsTableCol* column) +{ + // Throw exception if column pointer is empty + if (column == NULL) + throw GException::fits_no_data(G_INSERT_COLUMN, + "Column pointer was NULL"); + + // Make sure that 'colnum' is valid. Since we add one column the total + // number of columns at return will be m_cols+1, hence the column + // index is comprised between [0,m_cols] + if (colnum < 0) colnum = 0; + if (colnum > m_cols) colnum = m_cols; + + // If the table is empty and has 0 rows then set the number of rows in + // the table to the length of the column + if (m_columns == NULL && m_rows == 0) + m_rows = column->length(); + + // Throw exception if the column length is incompatible with number of + // rows in the table + if (m_rows != column->length()) + throw GException::fits_bad_col_length(G_INSERT_COLUMN, + column->length(), m_rows); + + // If there are no rows in the table then set the number of rows to + // the length of the column + if (m_rows == 0 && column->length() > 0) + m_rows = column->length(); + + // If no column data exist then allocate them now + if (m_columns == NULL) { + m_columns = new GFitsTableCol*[1]; + m_cols = 1; + m_columns[0] = NULL; + colnum = 0; // We insert at the first place + } + + // ... otherwise make space to insert column + else { + + // Allocate fresh memory + GFitsTableCol** tmp = new GFitsTableCol*[m_cols+1]; + + // Copy over old column pointers. Leave some space at the position + // where we want to insert the column + int src; + int dst; + for (src = 0, dst = 0; dst < m_cols+1; ++dst) { + if (dst == colnum) + tmp[dst] = NULL; + else { + tmp[dst] = m_columns[src]; + src++; + } + } + + // Free old column pointer array + delete [] m_columns; + + // Connect new memory + m_columns = tmp; + + } // endelse: we made space to insert a column + + // Insert column pointer + m_columns[colnum] = column; + + // Return + return; +} + + +/***********************************************************************//** * @brief Return pointer to column with specified name * * @param[in] colname Name of column which should be accessed @@ -417,7 +541,7 @@ GFitsTableCol* GFitsTable::column(const int& colnum) /***********************************************************************//** * @brief Return number of rows in table ***************************************************************************/ -int GFitsTable::rows(void) const +int GFitsTable::nrows(void) const { // Return number of rows return m_rows; @@ -427,7 +551,7 @@ int GFitsTable::rows(void) const /***********************************************************************//** * @brief Return number of columns in table ***************************************************************************/ -int GFitsTable::cols(void) const +int GFitsTable::ncols(void) const { // Return number of columns return m_cols; diff --git a/src/fits/GFitsTableCol.cpp b/src/fits/GFitsTableCol.cpp index 9dbab5f..4c9dcd2 100644 --- a/src/fits/GFitsTableCol.cpp +++ b/src/fits/GFitsTableCol.cpp @@ -34,9 +34,8 @@ = = ==========================================================================*/ -/*************************************************************************** - * Constructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Constructor ***************************************************************************/ GFitsTableCol::GFitsTableCol() { @@ -48,9 +47,10 @@ GFitsTableCol::GFitsTableCol() } -/*************************************************************************** - * Copy constructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Copy constructor + * + * @param[in] column Column from which the class instance should be built ***************************************************************************/ GFitsTableCol::GFitsTableCol(const GFitsTableCol& column) { @@ -65,9 +65,8 @@ GFitsTableCol::GFitsTableCol(const GFitsTableCol& column) } -/*************************************************************************** - * Destructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Destructor ***************************************************************************/ GFitsTableCol::~GFitsTableCol() { @@ -85,24 +84,25 @@ GFitsTableCol::~GFitsTableCol() = = ==========================================================================*/ -/*************************************************************************** - * Assignment operator * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] column Column which will be assigned ***************************************************************************/ GFitsTableCol& GFitsTableCol::operator= (const GFitsTableCol& column) { // Execute only if object is not identical if (this != &column) { - + // Free members free_members(); - + // Initialise private members for clean destruction init_members(); // Copy members copy_members(column); - + } // endif: object was not identical // Return this object @@ -116,6 +116,142 @@ GFitsTableCol& GFitsTableCol::operator= (const GFitsTableCol& column) = = ==========================================================================*/ +/***********************************************************************//** + * @brief Set column name + * + * @param[in] name Name of the column. + ***************************************************************************/ +void GFitsTableCol::name(const std::string& name) +{ + // Set name + m_name = name; + + // Return + return; +} + + +/***********************************************************************//** + * @brief Set column number + * + * @param[in] colnum Number of column. + ***************************************************************************/ +/* +void GFitsTableCol::colnum(const int& colnum) +{ + // Set column number + m_colnum = colnum; + + // Return + return; +} +*/ + +/***********************************************************************//** + * @brief Set column type + * + * @param[in] type Type of column. + ***************************************************************************/ +/* +void GFitsTableCol::type(const int& type) +{ + // Set column type + m_type = type; + + // Return + return; +} +*/ + +/***********************************************************************//** + * @brief Set column length + * + * @param[in] length Length of column. + ***************************************************************************/ +/* +void GFitsTableCol::length(const int& length) +{ + // Set column length + m_length = length; + + // Return + return; +} +*/ + +/***********************************************************************//** + * @brief Get column name + ***************************************************************************/ +std::string GFitsTableCol::name(void) +{ + // Return Name + return m_name; +} + + +/***********************************************************************//** + * @brief Get number of column in FITS file (starting from 1) + ***************************************************************************/ +int GFitsTableCol::colnum(void) +{ + // Return column number + return m_colnum; +} + + +/***********************************************************************//** + * @brief Get CFITSIO column type + * + * Returns one of the following: + * 1 (TBIT) + * 11 (TBYTE) + * 14 (TLOGICAL) + * 16 (TSTRING) + * 21 (TSHORT) + * 31 (TINT) + * 41 (TLONG) + * 42 (TFLOAT) + * 81 (TLONGLONG) + * 82 (TDOUBLE) + * 83 (TCOMPLEX) + * 163 (TDBLCOMPLEX) + ***************************************************************************/ +int GFitsTableCol::type(void) +{ + // Return column type + return m_type; +} + + +/***********************************************************************//** + * @brief Get column repeat value + ***************************************************************************/ +int GFitsTableCol::repeat(void) +{ + // Return column repeat value + return m_repeat; +} + + +/***********************************************************************//** + * @brief Get column width + ***************************************************************************/ +int GFitsTableCol::width(void) +{ + // Return column width + return m_width; +} + + +/***********************************************************************//** + * @brief Get column length + ***************************************************************************/ +int GFitsTableCol::length(void) +{ + // Return column length + return m_length; +} + /*========================================================================== = = @@ -123,9 +259,8 @@ GFitsTableCol& GFitsTableCol::operator= (const GFitsTableCol& column) = = ==========================================================================*/ -/*************************************************************************** - * Initialise class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Initialise class members ***************************************************************************/ void GFitsTableCol::init_members(void) { @@ -146,9 +281,10 @@ void GFitsTableCol::init_members(void) } -/*************************************************************************** - * Copy class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] column Column to be copied ***************************************************************************/ void GFitsTableCol::copy_members(const GFitsTableCol& column) { @@ -162,22 +298,21 @@ void GFitsTableCol::copy_members(const GFitsTableCol& column) m_width = column.m_width; m_length = column.m_length; m_fitsfile = column.m_fitsfile; - + // Return return; } -/*************************************************************************** - * Delete class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Delete class members ***************************************************************************/ void GFitsTableCol::free_members(void) { // Free memory - + // Mark memory as freed - + // Return return; } @@ -186,13 +321,14 @@ void GFitsTableCol::free_members(void) /***********************************************************************//** * @brief Connect table column to FITS file * - * @param fptr FITS file pointer to which the table column should be connected + * @param[in] fptr FITS file pointer to which the table column should be + * connected ***************************************************************************/ void GFitsTableCol::connect(__fitsfile* fptr) { // Connect Image m_fitsfile = *fptr; - + // Return return; } @@ -204,9 +340,11 @@ void GFitsTableCol::connect(__fitsfile* fptr) = = ==========================================================================*/ -/*************************************************************************** - * Output operator * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Output operator + * + * @param[in] os Output stream + * @param[in] column Column to put in output stream ***************************************************************************/ ostream& operator<< (ostream& os, const GFitsTableCol& column) { diff --git a/src/rsp/GLATResponse.cpp b/src/rsp/GLATResponse.cpp index efe00cd..672dfa5 100644 --- a/src/rsp/GLATResponse.cpp +++ b/src/rsp/GLATResponse.cpp @@ -264,22 +264,27 @@ void GLATResponse::save(const std::string& rspname) const GFits fits; fits.open(rspname); - // Build PSF HDUs - GFitsBinTable table_psf_bounds(1,4); + // Build PSF tables and images + GFitsBinTable table_psf_bounds(1); int naxes_psf2[] = {m_psf_energy_num, m_psf_ctheta_num}; - int naxes_psf3[] = {m_psf_angle_num, m_psf_energy_num, m_psf_ctheta_num}; + int naxes_psf3[] = {m_psf_angle_num, m_psf_energy_num, + m_psf_ctheta_num}; GFitsDblImage image_psf_psf(3, naxes_psf3, m_psf); GFitsDblImage image_psf_norm(2, naxes_psf2, m_norm); GFitsDblImage image_psf_sigma(2, naxes_psf2, m_sigma); - //TBD GFitsHDU hdu_psf_bounds(table_psf_bounds); - GFitsHDU hdu_psf_psf(image_psf_psf); - GFitsHDU hdu_psf_norm(image_psf_norm); - GFitsHDU hdu_psf_sigma(image_psf_sigma); + + // Construct PSF HDUs + GFitsHDU hdu_psf_bounds(table_psf_bounds); + GFitsHDU hdu_psf_psf(image_psf_psf); + GFitsHDU hdu_psf_norm(image_psf_norm); + GFitsHDU hdu_psf_sigma(image_psf_sigma); + hdu_psf_bounds.extname("PBOUNDS"); hdu_psf_psf.extname("PSF"); hdu_psf_norm.extname("NORM"); hdu_psf_sigma.extname("SIGMA"); // Append HDUs to FITS file + fits.append(&hdu_psf_bounds); fits.append(&hdu_psf_psf); fits.append(&hdu_psf_norm); fits.append(&hdu_psf_sigma); diff --git a/test/test_GFits.cpp b/test/test_GFits.cpp index 1a3e192..537a894 100644 --- a/test/test_GFits.cpp +++ b/test/test_GFits.cpp @@ -377,7 +377,7 @@ void test_create(void) fits.open("test.fits"); int nrows = 10; int ncols = 5; - GFitsBinTable table(nrows,ncols); + GFitsBinTable table(nrows); GFitsHDU hdu(table); fits.append(&hdu); cout << fits; @@ -390,25 +390,6 @@ void test_create(void) } cout << "."; - // Attach ASCII table - try { - GFits fits; - fits.open("test.fits"); - int nrows = 10; - int ncols = 5; - GFitsAsciiTable table(nrows,ncols); - GFitsHDU hdu(table); - fits.append(&hdu); - cout << fits; - fits.save(); - } - catch (exception &e) { - cout << endl << "TEST ERROR: Unable to attach ASCII table." << endl; - cout << e.what() << endl; - throw; - } - cout << "."; - cout << ". ok." << endl; } @@ -421,7 +402,7 @@ void test_image_double(void) { // Dump header cout << "Test GFitsDblImage: "; - + // Test 1D Image try { int naxis = 1; @@ -429,7 +410,7 @@ void test_image_double(void) int naxes[] = {nx}; GFitsDblImage image(naxis, naxes); cout << "."; - + // Fill and read image try { for (int ix = 0; ix < nx; ++ix) -- libgit2 0.21.4