diff --git a/include/GFitsDblImage.hpp b/include/GFitsDblImage.hpp index 7685a86..a99ac2b 100644 --- a/include/GFitsDblImage.hpp +++ b/include/GFitsDblImage.hpp @@ -50,9 +50,12 @@ public: double& operator() (const int& ix, const int& iy); const double& operator() (const int& ix, const int& iy) const; double& operator() (const int& ix, const int& iy, const int& iz); - const double& operator() (const int& ix, const int& iy, const int& iz) const; - double& operator() (const int& ix, const int& iy, const int& iz, const int& it); - const double& operator() (const int& ix, const int& iy, const int& iz, const int& it) const; + const double& operator() (const int& ix, const int& iy, const int& iz) + const; + double& operator() (const int& ix, const int& iy, const int& iz, + const int& it); + const double& operator() (const int& ix, const int& iy, const int& iz, + const int& it) const; // Methods diff --git a/include/GFitsTableCol.hpp b/include/GFitsTableCol.hpp index 78c9d53..256e10a 100644 --- a/include/GFitsTableCol.hpp +++ b/include/GFitsTableCol.hpp @@ -30,7 +30,7 @@ * * @brief Abstract interface for FITS table column * - * This class implements a FITS table column. + * This class implements a FITS table column. Vector columns are supported. ***************************************************************************/ class GFitsTableCol { @@ -43,6 +43,7 @@ class GFitsTableCol { public: // Constructors and destructors GFitsTableCol(); + GFitsTableCol(const int& length, const int& size = 1); GFitsTableCol(const GFitsTableCol& column); virtual ~GFitsTableCol(); @@ -50,23 +51,13 @@ public: GFitsTableCol& operator= (const GFitsTableCol& column); // Virtual Methods - virtual std::string string(const int& row, const int& col = 0) = 0; - virtual double real(const int& row, const int& col = 0) = 0; - virtual int integer(const int& row, const int& col = 0) = 0; + virtual std::string string(const int& row, const int& inx = 0) = 0; + virtual double real(const int& row, const int& inx = 0) = 0; + virtual int integer(const int& row, const int& inx = 0) = 0; virtual GFitsTableCol* clone(void) const = 0; - virtual double* ptr_double(void) = 0; - virtual float* ptr_float(void) = 0; - virtual short* ptr_short(void) = 0; - virtual long* ptr_long(void) = 0; - virtual int* ptr_int(void) = 0; // Base class Methods 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); @@ -94,9 +85,4 @@ private: void connect(__fitsfile* fptr); }; - -/*************************************************************************** - * Inline methods * - ***************************************************************************/ - #endif /* GFITSTABLECOL_HPP */ diff --git a/include/GFitsTableDblCol.hpp b/include/GFitsTableDblCol.hpp index 2fb75e6..9f2cb02 100644 --- a/include/GFitsTableDblCol.hpp +++ b/include/GFitsTableDblCol.hpp @@ -10,6 +10,11 @@ * (at your option) any later version. * * * ***************************************************************************/ +/** + * @file GFitsTableDblCol.hpp + * @brief GFitsTableDblCol class definition. + * @author J. Knodlseder + */ #ifndef GFITSTABLEDBLCOL_HPP #define GFITSTABLEDBLCOL_HPP @@ -24,30 +29,33 @@ /* __ Structures _________________________________________________________ */ -/*************************************************************************** - * GFitsTableDblCol class definition * +/***********************************************************************//** + * @class GFitsTableDblCol + * + * @brief Interface for FITS table double precision column + * + * This class implements a FITS table double precision column. ***************************************************************************/ class GFitsTableDblCol : public GFitsTableCol { public: // Constructors and destructors GFitsTableDblCol(); + GFitsTableDblCol(const int& length, const int& size = 1); GFitsTableDblCol(const GFitsTableDblCol& column); virtual ~GFitsTableDblCol(); // Operators GFitsTableDblCol& operator= (const GFitsTableDblCol& column); + double& operator() (const int& row, const int& inx = 0); + const double& operator() (const int& row, const int& inx = 0) const; // Methods - std::string string(const int& row, const int& col = 0); - double real(const int& row, const int& col = 0); - int integer(const int& row, const int& col = 0); + std::string string(const int& row, const int& inx = 0); + double real(const int& row, const int& inx = 0); + int integer(const int& row, const int& inx = 0); GFitsTableDblCol* clone(void) const; - double* ptr_double(void); - float* ptr_float(void); - short* ptr_short(void); - long* ptr_long(void); - int* ptr_int(void); + double* data(void); void set_nullval(const double* value); private: @@ -55,24 +63,13 @@ private: void init_members(void); void copy_members(const GFitsTableDblCol& column); void free_members(void); - void load(void); + void fetch_data(void); // Private data area - int m_size; // Size of data area - double* m_data; // Data area - double* m_nulval; // NULL value - int m_anynul; // Number of NULLs encountered + int m_size; //!< Size of data area + double* m_data; //!< Data area + double* m_nulval; //!< NULL value + int m_anynul; //!< Number of NULLs encountered }; - -/*************************************************************************** - * Inline methods * - ***************************************************************************/ -inline double* GFitsTableDblCol::ptr_double(void) { return m_data; } -inline -GFitsTableDblCol* GFitsTableDblCol::clone(void) const -{ - return new GFitsTableDblCol(*this); -} - #endif /* GFITSTABLEDBLCOL_HPP */ diff --git a/include/GFitsTableFltCol.hpp b/include/GFitsTableFltCol.hpp index fc6ee89..98902b1 100644 --- a/include/GFitsTableFltCol.hpp +++ b/include/GFitsTableFltCol.hpp @@ -10,6 +10,11 @@ * (at your option) any later version. * * * ***************************************************************************/ +/** + * @file GFitsTableFltCol.hpp + * @brief GFitsTableFltCol class definition. + * @author J. Knodlseder + */ #ifndef GFITSTABLEFLTCOL_HPP #define GFITSTABLEFLTCOL_HPP @@ -24,8 +29,12 @@ /* __ Structures _________________________________________________________ */ -/*************************************************************************** - * GFitsTableFltCol class definition * +/***********************************************************************//** + * @class GFitsTableFltCol + * + * @brief Interface for FITS table floating point column + * + * This class implements a FITS table floating point column. ***************************************************************************/ class GFitsTableFltCol : public GFitsTableCol { @@ -43,11 +52,7 @@ public: double real(const int& row, const int& col = 0); int integer(const int& row, const int& col = 0); GFitsTableFltCol* clone(void) const; - double* ptr_double(void); - float* ptr_float(void); - short* ptr_short(void); - long* ptr_long(void); - int* ptr_int(void); + float* data(void); void set_nullval(const float* value); private: @@ -58,21 +63,15 @@ private: void load(void); // Private data area - int m_size; // Size of data area - float* m_data; // Data area - float* m_nulval; // NULL value - int m_anynul; // Number of NULLs encountered + int m_size; //!< Size of data area + float* m_data; //!< Data area + float* m_nulval; //!< NULL value + int m_anynul; //!< Number of NULLs encountered }; /*************************************************************************** * Inline methods * ***************************************************************************/ -inline float* GFitsTableFltCol::ptr_float(void) { return m_data; } -inline -GFitsTableFltCol* GFitsTableFltCol::clone(void) const -{ - return new GFitsTableFltCol(*this); -} #endif /* GFITSTABLEFLTCOL_HPP */ diff --git a/include/GFitsTableLngCol.hpp b/include/GFitsTableLngCol.hpp index 69bb646..df9c558 100644 --- a/include/GFitsTableLngCol.hpp +++ b/include/GFitsTableLngCol.hpp @@ -10,6 +10,11 @@ * (at your option) any later version. * * * ***************************************************************************/ +/** + * @file GFitsTableLngCol.hpp + * @brief GFitsTableLngCol class definition. + * @author J. Knodlseder + */ #ifndef GFITSTABLELNGCOL_HPP #define GFITSTABLELNGCOL_HPP @@ -24,8 +29,12 @@ /* __ Structures _________________________________________________________ */ -/*************************************************************************** - * GFitsTableLngCol class definition * +/***********************************************************************//** + * @class GFitsTableLngCol + * + * @brief Interface for FITS table long integer column + * + * This class implements a FITS table long integer column. ***************************************************************************/ class GFitsTableLngCol : public GFitsTableCol { @@ -37,17 +46,15 @@ public: // Operators GFitsTableLngCol& operator= (const GFitsTableLngCol& column); + long& operator() (const int& row, const int& inx = 0); + const long& operator() (const int& row, const int& inx = 0) const; // Methods std::string string(const int& row, const int& col = 0); double real(const int& row, const int& col = 0); int integer(const int& row, const int& col = 0); GFitsTableLngCol* clone(void) const; - double* ptr_double(void); - float* ptr_float(void); - short* ptr_short(void); - long* ptr_long(void); - int* ptr_int(void); + long* data(void); void set_nullval(const long* value); private: @@ -55,24 +62,13 @@ private: void init_members(void); void copy_members(const GFitsTableLngCol& column); void free_members(void); - void load(void); + void fetch_data(void); // Private data area - int m_size; // Size of data area - long* m_data; // Data area - long* m_nulval; // NULL value - int m_anynul; // Number of NULLs encountered + int m_size; //!< Size of data area + long* m_data; //!< Data area + long* m_nulval; //!< NULL value + int m_anynul; //!< Number of NULLs encountered }; - -/*************************************************************************** - * Inline methods * - ***************************************************************************/ -inline long* GFitsTableLngCol::ptr_long(void) { return m_data; } -inline -GFitsTableLngCol* GFitsTableLngCol::clone(void) const -{ - return new GFitsTableLngCol(*this); -} - #endif /* GFITSTABLELNGCOL_HPP */ diff --git a/src/fits/GFitsHDU.cpp b/src/fits/GFitsHDU.cpp index 1adfb0b..928e281 100644 --- a/src/fits/GFitsHDU.cpp +++ b/src/fits/GFitsHDU.cpp @@ -337,41 +337,7 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum) ***************************************************************************/ void GFitsHDU::save(void) { -//cout << "GFitsHDU::save " << m_fitsfile.Fptr << " " << m_hdunum << endl; - // Move to HDU -// int status = 0; -// status = __ffmahd(&m_fitsfile, m_hdunum, NULL, &status); - - // If HDU does not yet exist in file then create it now. This works even - // in the case that the actual HDU has no associated header and/or data - // (these will be created automatically). However, to make this work we have - // to set the fitsfile HDU position to the position we want to go. In that - // was the save members will know that they have to create the HDU ... -/* - if (status == 107) { - m_fitsfile.HDUposition = m_hdunum-1; - status = 0; - if (m_data != NULL) { - switch (m_type) { - case HT_IMAGE: // Image HDU - m_data->connect(&m_fitsfile); - //m_data->save(); - break; - case HT_ASCII_TABLE: // ASCII Table HDU - m_data->connect(&m_fitsfile); - //m_data->save(); - break; - case HT_BIN_TABLE: // Binary Table HDU - m_data->connect(&m_fitsfile); - //m_data->save(); - break; - default: - throw GException::fits_unknown_HDU_type(G_SAVE, m_type); - break; - } - } - } -*/ +//cout << "GFitsHDU::save entry" << endl; // Save data and header if they exist if (m_data != NULL) { @@ -398,6 +364,7 @@ void GFitsHDU::save(void) } // endelse: no data were available +//cout << "GFitsHDU::save exit" << endl; // Return return; } diff --git a/src/fits/GFitsHeader.cpp b/src/fits/GFitsHeader.cpp index 44f928d..5f571d5 100644 --- a/src/fits/GFitsHeader.cpp +++ b/src/fits/GFitsHeader.cpp @@ -174,6 +174,7 @@ void GFitsHeader::open(__fitsfile* fptr) ***************************************************************************/ void GFitsHeader::save(__fitsfile* fptr) { +//cout << "GFitsHeader::save entry" << endl; // Move to HDU int status = 0; status = __ffmahd(fptr, (fptr->HDUposition)+1, NULL, &status); @@ -193,6 +194,7 @@ void GFitsHeader::save(__fitsfile* fptr) } } +//cout << "GFitsHeader::save exit" << endl; // Return return; } diff --git a/src/fits/GFitsTable.cpp b/src/fits/GFitsTable.cpp index f004813..13d374d 100644 --- a/src/fits/GFitsTable.cpp +++ b/src/fits/GFitsTable.cpp @@ -301,7 +301,7 @@ void GFitsTable::save(void) } // Create FITS table - status = __ffcrtb(&m_fitsfile, m_type, m_rows, tfields, ttype, tform, + status = __ffcrtb(&m_fitsfile, m_type, m_rows, tfields, ttype, tform, tunit, NULL, &status); if (status != 0) throw GException::fits_error(G_SAVE, status); @@ -322,6 +322,7 @@ void GFitsTable::save(void) else if (status != 0) throw GException::fits_error(G_SAVE, status); +//cout << "GFitsTable::save exit" << endl; // Return return; } @@ -370,6 +371,7 @@ void GFitsTable::append_column(GFitsTableCol* column) return; } + /***********************************************************************//** * @brief Insert column into the table * @@ -455,11 +457,17 @@ void GFitsTable::insert_column(int colnum, GFitsTableCol* column) // Connect new memory m_columns = tmp; + // Increment column counter + m_cols++; + } // endelse: we made space to insert a column // Insert column pointer m_columns[colnum] = column; + // Set column attributes + m_columns[colnum]->m_colnum = colnum + 1; // IS THIS REALLY NEEDED??? + // Return return; } @@ -613,10 +621,7 @@ void GFitsTable::copy_members(const GFitsTable& table) ***************************************************************************/ void GFitsTable::free_members(void) { - // Free memory - for (int i = 0; i < m_cols; ++i) { - if (m_columns[i] != NULL) delete m_columns[i]; - } + // Free memory (don't free associated column pointers explicitely!!!) if (m_columns != NULL) delete [] m_columns; // Mark memory as freed @@ -664,15 +669,16 @@ char* GFitsTable::get_ttype(const int& colnum) const { // Initialise result with NULL pointer char* ptr = NULL; - + // Get type only if column exists if (m_columns != NULL && colnum >=0 && colnum < m_cols && m_columns[colnum] != NULL) { - int size = m_columns[colnum]->m_name.length() + 1; - ptr = new char[size]; - strncpy(ptr, m_columns[colnum]->m_name.c_str(), size-1); - } - + int size = m_columns[colnum]->m_name.length(); + ptr = new char[size+1]; + strncpy(ptr, m_columns[colnum]->m_name.c_str(), size); + ptr[size] = '\0'; + } + // Return result return ptr; } @@ -691,15 +697,16 @@ char* GFitsTable::get_tform(const int& colnum) const { // Initialise result with NULL pointer char* ptr = NULL; - + // Get type only if column exists if (m_columns != NULL && colnum >=0 && colnum < m_cols && m_columns[colnum] != NULL) { - int size = m_columns[colnum]->m_format.length() + 1; - ptr = new char[size]; - strncpy(ptr, m_columns[colnum]->m_format.c_str(), size-1); + int size = m_columns[colnum]->m_format.length(); + ptr = new char[size+1]; + strncpy(ptr, m_columns[colnum]->m_format.c_str(), size); + ptr[size] = '\0'; } - + // Return result return ptr; } @@ -718,15 +725,16 @@ char* GFitsTable::get_tunit(const int& colnum) const { // Initialise result with NULL pointer char* ptr = NULL; - + // Get type only if column exists if (m_columns != NULL && colnum >=0 && colnum < m_cols && m_columns[colnum] != NULL) { - int size = m_columns[colnum]->m_unit.length() + 1; - ptr = new char[size]; - strncpy(ptr, m_columns[colnum]->m_unit.c_str(), size-1); + int size = m_columns[colnum]->m_unit.length(); + ptr = new char[size+1]; + strncpy(ptr, m_columns[colnum]->m_unit.c_str(), size); + ptr[size] = '\0'; } - + // Return result return ptr; } diff --git a/src/fits/GFitsTableCol.cpp b/src/fits/GFitsTableCol.cpp index 4c9dcd2..023f13a 100644 --- a/src/fits/GFitsTableCol.cpp +++ b/src/fits/GFitsTableCol.cpp @@ -48,6 +48,26 @@ GFitsTableCol::GFitsTableCol() /***********************************************************************//** + * @brief Constructor + * + * @param[in] length Length of column. + * @param[in] size Vector size of column. + ***************************************************************************/ +GFitsTableCol::GFitsTableCol(const int& length, const int& size) +{ + // Initialise class members for clean destruction + init_members(); + + // Set column length and vector size + m_length = length; + m_repeat = size; + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] column Column from which the class instance should be built diff --git a/src/fits/GFitsTableDblCol.cpp b/src/fits/GFitsTableDblCol.cpp index fe2a116..4fb4723 100644 --- a/src/fits/GFitsTableDblCol.cpp +++ b/src/fits/GFitsTableDblCol.cpp @@ -23,12 +23,7 @@ #define G_STRING "GFitsTableDblCol::string(const int&, const int&)" #define G_REAL "GFitsTableDblCol::real(const int&, const int&)" #define G_INTEGER "GFitsTableDblCol::integer(const int&, const int&)" -#define G_PTR_FLOAT "GFitsTableDblCol::ptr_float()" -#define G_PTR_DOUBLE "GFitsTableDblCol::ptr_double()" -#define G_PTR_SHORT "GFitsTableDblCol::ptr_short()" -#define G_PTR_LONG "GFitsTableDblCol::ptr_long()" -#define G_PTR_INT "GFitsTableDblCol::ptr_int()" -#define G_LOAD "GFitsTableDblCol::load()" +#define G_FETCH_DATA "GFitsTableDblCol::fetch_data()" /* __ Macros _____________________________________________________________ */ @@ -43,9 +38,8 @@ = = ==========================================================================*/ -/*************************************************************************** - * Constructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Constructor ***************************************************************************/ GFitsTableDblCol::GFitsTableDblCol() : GFitsTableCol() { @@ -57,11 +51,35 @@ GFitsTableDblCol::GFitsTableDblCol() : GFitsTableCol() } -/*************************************************************************** - * Copy constructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Constructor + * + * @param[in] length Length of column. + * @param[in] size Vector size of column. ***************************************************************************/ -GFitsTableDblCol::GFitsTableDblCol(const GFitsTableDblCol& column) : GFitsTableCol(column) +GFitsTableDblCol::GFitsTableDblCol(const int& length, const int& size) + : GFitsTableCol(length, size) +{ + // Initialise class members for clean destruction + init_members(); + + // Setup format + //m_name = "Test"; + m_format = "1D"; + //m_unit = "deg"; + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy constructor + * + * @param[in] column Column from which class instance should be built. + ***************************************************************************/ +GFitsTableDblCol::GFitsTableDblCol(const GFitsTableDblCol& column) : + GFitsTableCol(column) { // Initialise class members for clean destruction init_members(); @@ -74,9 +92,8 @@ GFitsTableDblCol::GFitsTableDblCol(const GFitsTableDblCol& column) : GFitsTableC } -/*************************************************************************** - * Destructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Destructor ***************************************************************************/ GFitsTableDblCol::~GFitsTableDblCol() { @@ -94,9 +111,10 @@ GFitsTableDblCol::~GFitsTableDblCol() = = ==========================================================================*/ -/*************************************************************************** - * Assignment operator * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] column Column which should be assigned ***************************************************************************/ GFitsTableDblCol& GFitsTableDblCol::operator= (const GFitsTableDblCol& column) { @@ -122,126 +140,193 @@ GFitsTableDblCol& GFitsTableDblCol::operator= (const GFitsTableDblCol& column) } +/***********************************************************************//** + * @brief Column data access operator + * + * @param[in] row Row of column to access. + * @param[in] inx Vector index in column row to access + * + * Provides access to data in a column. No range checking is performed. + * Use one of + * GFitsTableDblCol::string(ix,iy), + * GFitsTableDblCol::real(ix;iy) or + * GFitsTableDblCol::integer(ix;iy) + * if range checking is required. + ***************************************************************************/ +double& GFitsTableDblCol::operator() (const int& row, const int& inx) +{ + // If data are not available then load them now + if (m_data == NULL) fetch_data(); + + // Calculate pixel offset + int offset = row * m_repeat + inx; + + // Return image pixel + return m_data[offset]; +} + + +/***********************************************************************//** + * @brief Column data access operator (const variant) + * + * @param[in] row Row of column to access. + * @param[in] inx Vector index in column row to access + * + * Provides access to data in a column. No range checking is performed. + * Use one of + * GFitsTableDblCol::string(ix,iy), + * GFitsTableDblCol::real(ix;iy) or + * GFitsTableDblCol::integer(ix;iy) + * if range checking is required. + ***************************************************************************/ +const double& GFitsTableDblCol::operator() (const int& row, const int& inx) + const +{ + // If data are not available then load them now + if (m_data == NULL) ((GFitsTableDblCol*)this)->fetch_data(); + + // Calculate pixel offset + int offset = row * m_repeat + inx; + + // Return image pixel + return m_data[offset]; +} + + /*========================================================================== = = = GFitsTableDblCol public methods = = = ==========================================================================*/ -/*************************************************************************** - * Get string value * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Get string value + * + * @param[in] row Table row. + * @param[in] inx Table column vector index. + * + * @exception GException::out_of_range + * Table row or vector index are out of valid range. + * + * Returns value of specified row and vector index as string. ***************************************************************************/ -std::string GFitsTableDblCol::string(const int& row, const int& col) +std::string GFitsTableDblCol::string(const int& row, const int& inx) { - // Make sure that data are loaded - if (m_data == NULL) - load(); + // If data are not available then load them now + if (m_data == NULL) fetch_data(); // Check row value if (row < 0 || row >= m_length) throw GException::out_of_range(G_STRING, row, 0, m_length-1); - // Check col value - if (col < 0 || col >= m_repeat) - throw GException::out_of_range(G_STRING, col, 0, m_repeat-1); + // Check inx value + if (inx < 0 || inx >= m_repeat) + throw GException::out_of_range(G_STRING, inx, 0, m_repeat-1); // Get index - int inx = row * m_repeat + col; + int offset = row * m_repeat + inx; // Convert double into string ostringstream s_value; - s_value << scientific << m_data[inx]; + s_value << scientific << m_data[offset]; // Return value return s_value.str(); } -/*************************************************************************** - * Get real value * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Get double precision value + * + * @param[in] row Table row. + * @param[in] inx Table column vector index. + * + * @exception GException::out_of_range + * Table row or vector index are out of valid range. + * + * Returns value of specified row and vector index as double precision. ***************************************************************************/ -double GFitsTableDblCol::real(const int& row, const int& col) +double GFitsTableDblCol::real(const int& row, const int& inx) { - // Make sure that data are loaded - if (m_data == NULL) - load(); + // If data are not available then load them now + if (m_data == NULL) fetch_data(); // Check row value if (row < 0 || row >= m_length) throw GException::out_of_range(G_REAL, row, 0, m_length-1); - // Check col value - if (col < 0 || col >= m_repeat) - throw GException::out_of_range(G_REAL, col, 0, m_repeat-1); + // Check inx value + if (inx < 0 || inx >= m_repeat) + throw GException::out_of_range(G_REAL, inx, 0, m_repeat-1); // Get index - int inx = row * m_repeat + col; + int offset = row * m_repeat + inx; // Return value - return m_data[inx]; + return m_data[offset]; } -/*************************************************************************** - * Get int value * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Get integer value + * + * @param[in] row Table row. + * @param[in] inx Table column vector index. + * + * @exception GException::out_of_range + * Table row or vector index are out of valid range. + * + * Returns value of specified row and vector index as integer. ***************************************************************************/ -int GFitsTableDblCol::integer(const int& row, const int& col) +int GFitsTableDblCol::integer(const int& row, const int& inx) { - // Make sure that data are loaded - if (m_data == NULL) - load(); + // If data are not available then load them now + if (m_data == NULL) fetch_data(); // Check row value if (row < 0 || row >= m_length) throw GException::out_of_range(G_INTEGER, row, 0, m_length-1); // Check col value - if (col < 0 || col >= m_repeat) - throw GException::out_of_range(G_INTEGER, col, 0, m_repeat-1); + if (inx < 0 || inx >= m_repeat) + throw GException::out_of_range(G_INTEGER, inx, 0, m_repeat-1); // Get index - int inx = row * m_repeat + col; + int offset = row * m_repeat + inx; // Convert double into int - int value = (int)m_data[inx]; + int value = (int)m_data[offset]; // Return value return value; } -/*************************************************************************** - * Access to invalid data pointers * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Clone column ***************************************************************************/ -float* GFitsTableDblCol::ptr_float(void) -{ - throw GException::fits_invalid_type(G_PTR_FLOAT, - "No pointer allowed to array"); -} -short* GFitsTableDblCol::ptr_short(void) -{ - throw GException::fits_invalid_type(G_PTR_SHORT, - "No pointer allowed to array"); -} -long* GFitsTableDblCol::ptr_long(void) +GFitsTableDblCol* GFitsTableDblCol::clone(void) const { - throw GException::fits_invalid_type(G_PTR_LONG, - "No pointer allowed to array"); + return new GFitsTableDblCol(*this); } -int* GFitsTableDblCol::ptr_int(void) + + +/***********************************************************************//** + * @brief Return pointer to double precision column + ***************************************************************************/ +double* GFitsTableDblCol::data(void) { - throw GException::fits_invalid_type(G_PTR_INT, - "No pointer allowed to array"); + return m_data; } -/*************************************************************************** - * Set NULL value * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Set NULL value + * + * @param[in] value Pointer on NULL value + * + * Allows the specification of the FITS table NULL value. If value=NULL the + * data will not be screened for NULL values. ***************************************************************************/ void GFitsTableDblCol::set_nullval(const double* value) { @@ -258,13 +343,13 @@ void GFitsTableDblCol::set_nullval(const double* value) *m_nulval = *value; } - // Re-load column - // NOTE: THIS WILL LEAD TO A LOSS OF MODIFICATIONS; ISSUE SAVE BEFORE !!! + // Re-load column +/* if (m_data != NULL) { - //save(); + save(); load(); } - +*/ // Return return; } @@ -276,9 +361,8 @@ void GFitsTableDblCol::set_nullval(const double* value) = = ==========================================================================*/ -/*************************************************************************** - * Initialise class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Initialise class members ***************************************************************************/ void GFitsTableDblCol::init_members(void) { @@ -293,9 +377,10 @@ void GFitsTableDblCol::init_members(void) } -/*************************************************************************** - * Copy class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] column Column for which members should be copied. ***************************************************************************/ void GFitsTableDblCol::copy_members(const GFitsTableDblCol& column) { @@ -322,9 +407,8 @@ void GFitsTableDblCol::copy_members(const GFitsTableDblCol& column) } -/*************************************************************************** - * Delete class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Delete class members ***************************************************************************/ void GFitsTableDblCol::free_members(void) { @@ -341,26 +425,47 @@ void GFitsTableDblCol::free_members(void) } -/*************************************************************************** - * Load column data * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Fetch column data + * + * @exception GException::fits_error + * An error occured while loading column data from FITS file. + * + * If a FITS file is attached to the column the data are loaded into memory + * from the FITS file. If no FITS file is attached, memory is allocated + * to hold the column data and all cells are set to 0. ***************************************************************************/ -void GFitsTableDblCol::load(void) +void GFitsTableDblCol::fetch_data(void) { // Calculate size of memory m_size = m_repeat * m_length; - // Allocate memory - if (m_data != NULL) delete [] m_data; - m_data = new double[m_size]; - - // Load column data - int status = 0; - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status); - status = __ffgcv(&m_fitsfile, __TDOUBLE, m_colnum, 1, 1, m_size, - m_nulval, m_data, &m_anynul, &status); - if (status != 0) - throw GException::fits_error(G_LOAD, status); + // Load only if the column has a positive size + if (m_size > 0) { + + // Allocate fresh memory + if (m_data != NULL) delete [] m_data; + m_data = new double[m_size]; + + // If a FITS file is attached then load column data from the FITS + // file + if (m_fitsfile.Fptr != NULL) { + int status = 0; + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, + &status); + status = __ffgcv(&m_fitsfile, __TDOUBLE, m_colnum, 1, 1, m_size, + m_nulval, m_data, &m_anynul, &status); + if (status != 0) + throw GException::fits_error(G_FETCH_DATA, status); + } + + // ... otherwise initialise all column values to 0 + else { + for (int i = 0; i < m_size; ++i) + m_data[i] = 0.0; + } + + } // endif: column has a positive size // Return return; diff --git a/src/fits/GFitsTableFltCol.cpp b/src/fits/GFitsTableFltCol.cpp index ff37a89..b6a937b 100644 --- a/src/fits/GFitsTableFltCol.cpp +++ b/src/fits/GFitsTableFltCol.cpp @@ -43,9 +43,8 @@ = = ==========================================================================*/ -/*************************************************************************** - * Constructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Constructor ***************************************************************************/ GFitsTableFltCol::GFitsTableFltCol() : GFitsTableCol() { @@ -57,11 +56,13 @@ GFitsTableFltCol::GFitsTableFltCol() : GFitsTableCol() } -/*************************************************************************** - * Copy constructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Copy constructor + * + * @param[in] column Column from which class instance should be built. ***************************************************************************/ -GFitsTableFltCol::GFitsTableFltCol(const GFitsTableFltCol& column) : GFitsTableCol(column) +GFitsTableFltCol::GFitsTableFltCol(const GFitsTableFltCol& column) : + GFitsTableCol(column) { // Initialise class members for clean destruction init_members(); @@ -74,9 +75,8 @@ GFitsTableFltCol::GFitsTableFltCol(const GFitsTableFltCol& column) : GFitsTableC } -/*************************************************************************** - * Destructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Destructor ***************************************************************************/ GFitsTableFltCol::~GFitsTableFltCol() { @@ -94,9 +94,10 @@ GFitsTableFltCol::~GFitsTableFltCol() = = ==========================================================================*/ -/*************************************************************************** - * Assignment operator * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] column Column which should be assigned ***************************************************************************/ GFitsTableFltCol& GFitsTableFltCol::operator= (const GFitsTableFltCol& column) { @@ -128,9 +129,13 @@ GFitsTableFltCol& GFitsTableFltCol::operator= (const GFitsTableFltCol& column) = = ==========================================================================*/ -/*************************************************************************** - * Get string value * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Get string value + * + * @param[in] row Table row. + * @param[in] col Table column vector index. + * + * Returns value of specified row and vector index as string. ***************************************************************************/ std::string GFitsTableFltCol::string(const int& row, const int& col) { @@ -158,9 +163,13 @@ std::string GFitsTableFltCol::string(const int& row, const int& col) } -/*************************************************************************** - * Get real value * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Get double precision value + * + * @param[in] row Table row. + * @param[in] col Table column vector index. + * + * Returns value of specified row and vector index as double precision. ***************************************************************************/ double GFitsTableFltCol::real(const int& row, const int& col) { @@ -187,9 +196,13 @@ double GFitsTableFltCol::real(const int& row, const int& col) } -/*************************************************************************** - * Get int value * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Get integer value + * + * @param[in] row Table row. + * @param[in] col Table column vector index. + * + * Returns value of specified row and vector index as integer. ***************************************************************************/ int GFitsTableFltCol::integer(const int& row, const int& col) { @@ -216,35 +229,31 @@ int GFitsTableFltCol::integer(const int& row, const int& col) } -/*************************************************************************** - * Access to invalid data pointers * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Clone column ***************************************************************************/ -double* GFitsTableFltCol::ptr_double(void) +GFitsTableFltCol* GFitsTableFltCol::clone(void) const { - throw GException::fits_invalid_type(G_PTR_DOUBLE, - "No pointer allowed to array"); + return new GFitsTableFltCol(*this); } -short* GFitsTableFltCol::ptr_short(void) -{ - throw GException::fits_invalid_type(G_PTR_SHORT, - "No pointer allowed to array"); -} -long* GFitsTableFltCol::ptr_long(void) -{ - throw GException::fits_invalid_type(G_PTR_LONG, - "No pointer allowed to array"); -} -int* GFitsTableFltCol::ptr_int(void) + + +/***********************************************************************//** + * @brief Return pointer to floating point column + ***************************************************************************/ +float* GFitsTableFltCol::data(void) { - throw GException::fits_invalid_type(G_PTR_INT, - "No pointer allowed to array"); + return m_data; } -/*************************************************************************** - * Set NULL string * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Set NULL value + * + * @param[in] value Pointer on NULL value + * + * Allows the specification of the FITS table NULL value. If value=NULL the + * data will not be screened for NULL values. ***************************************************************************/ void GFitsTableFltCol::set_nullval(const float* value) { @@ -261,12 +270,13 @@ void GFitsTableFltCol::set_nullval(const float* value) *m_nulval = *value; } - // Re-load column - // NOTE: THIS WILL LEAD TO A LOSS OF MODIFICATIONS; ISSUE SAVE BEFORE !!! + // Re-load column +/* if (m_data != NULL) { - //save(); + save(); load(); } +*/ // Return return; @@ -279,9 +289,8 @@ void GFitsTableFltCol::set_nullval(const float* value) = = ==========================================================================*/ -/*************************************************************************** - * Initialise class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Initialise class members ***************************************************************************/ void GFitsTableFltCol::init_members(void) { @@ -296,9 +305,10 @@ void GFitsTableFltCol::init_members(void) } -/*************************************************************************** - * Copy class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] column Column for which members should be copied. ***************************************************************************/ void GFitsTableFltCol::copy_members(const GFitsTableFltCol& column) { @@ -325,9 +335,8 @@ void GFitsTableFltCol::copy_members(const GFitsTableFltCol& column) } -/*************************************************************************** - * Delete class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Delete class members ***************************************************************************/ void GFitsTableFltCol::free_members(void) { @@ -344,9 +353,8 @@ void GFitsTableFltCol::free_members(void) } -/*************************************************************************** - * Load column data * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Load column data ***************************************************************************/ void GFitsTableFltCol::load(void) { diff --git a/src/fits/GFitsTableLngCol.cpp b/src/fits/GFitsTableLngCol.cpp index 563aa6c..8d0c1e8 100644 --- a/src/fits/GFitsTableLngCol.cpp +++ b/src/fits/GFitsTableLngCol.cpp @@ -23,12 +23,7 @@ #define G_STRING "GFitsTableLngCol::string(const int&, const int&)" #define G_REAL "GFitsTableLngCol::real(const int&, const int&)" #define G_INTEGER "GFitsTableLngCol::integer(const int&, const int&)" -#define G_PTR_FLOAT "GFitsTableLngCol::ptr_float()" -#define G_PTR_DOUBLE "GFitsTableLngCol::ptr_double()" -#define G_PTR_SHORT "GFitsTableLngCol::ptr_short()" -#define G_PTR_LONG "GFitsTableLngCol::ptr_long()" -#define G_PTR_INT "GFitsTableLngCol::ptr_int()" -#define G_LOAD "GFitsTableLngCol::load()" +#define G_FETCH_DATA "GFitsTableLngCol::fetch_data()" /* __ Macros _____________________________________________________________ */ @@ -43,9 +38,8 @@ = = ==========================================================================*/ -/*************************************************************************** - * Constructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Constructor ***************************************************************************/ GFitsTableLngCol::GFitsTableLngCol() : GFitsTableCol() { @@ -57,11 +51,13 @@ GFitsTableLngCol::GFitsTableLngCol() : GFitsTableCol() } -/*************************************************************************** - * Copy constructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Copy constructor + * + * @param[in] column Column from which class instance should be built. ***************************************************************************/ -GFitsTableLngCol::GFitsTableLngCol(const GFitsTableLngCol& column) : GFitsTableCol(column) +GFitsTableLngCol::GFitsTableLngCol(const GFitsTableLngCol& column) : + GFitsTableCol(column) { // Initialise class members for clean destruction init_members(); @@ -74,9 +70,8 @@ GFitsTableLngCol::GFitsTableLngCol(const GFitsTableLngCol& column) : GFitsTableC } -/*************************************************************************** - * Destructor * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Destructor ***************************************************************************/ GFitsTableLngCol::~GFitsTableLngCol() { @@ -94,9 +89,10 @@ GFitsTableLngCol::~GFitsTableLngCol() = = ==========================================================================*/ -/*************************************************************************** - * Assignment operator * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] column Column which should be assigned ***************************************************************************/ GFitsTableLngCol& GFitsTableLngCol::operator= (const GFitsTableLngCol& column) { @@ -122,129 +118,196 @@ GFitsTableLngCol& GFitsTableLngCol::operator= (const GFitsTableLngCol& column) } +/***********************************************************************//** + * @brief Column data access operator + * + * @param[in] row Row of column to access. + * @param[in] inx Vector index in column row to access + * + * Provides access to data in a column. No range checking is performed. + * Use one of + * GFitsTableLngCol::string(ix,iy), + * GFitsTableLngCol::real(ix;iy) or + * GFitsTableLngCol::integer(ix;iy) + * if range checking is required. + ***************************************************************************/ +long& GFitsTableLngCol::operator() (const int& row, const int& inx) +{ + // If data are not available then load them now + if (m_data == NULL) fetch_data(); + + // Calculate pixel offset + int offset = row * m_repeat + inx; + + // Return image pixel + return m_data[offset]; +} + + +/***********************************************************************//** + * @brief Column data access operator (const variant) + * + * @param[in] row Row of column to access. + * @param[in] inx Vector index in column row to access + * + * Provides access to data in a column. No range checking is performed. + * Use one of + * GFitsTableLngCol::string(ix,iy), + * GFitsTableLngCol::real(ix;iy) or + * GFitsTableLngCol::integer(ix;iy) + * if range checking is required. + ***************************************************************************/ +const long& GFitsTableLngCol::operator() (const int& row, const int& inx) + const +{ + // If data are not available then load them now + if (m_data == NULL) ((GFitsTableLngCol*)this)->fetch_data(); + + // Calculate pixel offset + int offset = row * m_repeat + inx; + + // Return image pixel + return m_data[offset]; +} + + /*========================================================================== = = = GFitsTableLngCol public methods = = = ==========================================================================*/ -/*************************************************************************** - * Get string value * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Get string value + * + * @param[in] row Table row. + * @param[in] inx Table column vector index. + * + * @exception GException::out_of_range + * Table row or vector index are out of valid range. + * + * Returns value of specified row and vector index as string. ***************************************************************************/ -std::string GFitsTableLngCol::string(const int& row, const int& col) +std::string GFitsTableLngCol::string(const int& row, const int& inx) { - // Make sure that data are loaded - if (m_data == NULL) - load(); + // If data are not available then load them now + if (m_data == NULL) fetch_data(); // Check row value if (row < 0 || row >= m_length) throw GException::out_of_range(G_STRING, row, 0, m_length-1); - // Check col value - if (col < 0 || col >= m_repeat) - throw GException::out_of_range(G_STRING, col, 0, m_repeat-1); + // Check inx value + if (inx < 0 || inx >= m_repeat) + throw GException::out_of_range(G_STRING, inx, 0, m_repeat-1); // Get index - int inx = row * m_repeat + col; + int offset = row * m_repeat + inx; // Convert long into string ostringstream s_value; - s_value << m_data[inx]; + s_value << m_data[offset]; // Return value return s_value.str(); } -/*************************************************************************** - * Get real value * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Get double precision value + * + * @param[in] row Table row. + * @param[in] inx Table column vector index. + * + * @exception GException::out_of_range + * Table row or vector index are out of valid range. + * + * Returns value of specified row and vector index as double precision. ***************************************************************************/ -double GFitsTableLngCol::real(const int& row, const int& col) +double GFitsTableLngCol::real(const int& row, const int& inx) { - // Make sure that data are loaded - if (m_data == NULL) - load(); + // If data are not available then load them now + if (m_data == NULL) fetch_data(); // Check row value if (row < 0 || row >= m_length) throw GException::out_of_range(G_REAL, row, 0, m_length-1); - // Check col value - if (col < 0 || col >= m_repeat) - throw GException::out_of_range(G_REAL, col, 0, m_repeat-1); + // Check inx value + if (inx < 0 || inx >= m_repeat) + throw GException::out_of_range(G_REAL, inx, 0, m_repeat-1); // Get index - int inx = row * m_repeat + col; + int offset = row * m_repeat + inx; // Convert long into double - double value = (double)m_data[inx]; + double value = (double)m_data[offset]; // Return value return value; } -/*************************************************************************** - * Get int value * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Get integer value + * + * @param[in] row Table row. + * @param[in] inx Table column vector index. + * + * @exception GException::out_of_range + * Table row or vector index are out of valid range. + * + * Returns value of specified row and vector index as integer. ***************************************************************************/ -int GFitsTableLngCol::integer(const int& row, const int& col) +int GFitsTableLngCol::integer(const int& row, const int& inx) { - // Make sure that data are loaded - if (m_data == NULL) - load(); + // If data are not available then load them now + if (m_data == NULL) fetch_data(); // Check row value if (row < 0 || row >= m_length) throw GException::out_of_range(G_INTEGER, row, 0, m_length-1); - // Check col value - if (col < 0 || col >= m_repeat) - throw GException::out_of_range(G_INTEGER, col, 0, m_repeat-1); + // Check inx value + if (inx < 0 || inx >= m_repeat) + throw GException::out_of_range(G_INTEGER, inx, 0, m_repeat-1); // Get index - int inx = row * m_repeat + col; + int offset = row * m_repeat + inx; // Convert long into int - int value = (int)m_data[inx]; + int value = (int)m_data[offset]; // Return value return value; } -/*************************************************************************** - * Access to invalid data pointers * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Clone column ***************************************************************************/ -float* GFitsTableLngCol::ptr_float(void) +GFitsTableLngCol* GFitsTableLngCol::clone(void) const { - throw GException::fits_invalid_type(G_PTR_FLOAT, - "No pointer allowed to array"); + return new GFitsTableLngCol(*this); } -double* GFitsTableLngCol::ptr_double(void) -{ - throw GException::fits_invalid_type(G_PTR_DOUBLE, - "No pointer allowed to array"); -} -short* GFitsTableLngCol::ptr_short(void) -{ - throw GException::fits_invalid_type(G_PTR_SHORT, - "No pointer allowed to array"); -} -int* GFitsTableLngCol::ptr_int(void) + + +/***********************************************************************//** + * @brief Return pointer to long integer column + ***************************************************************************/ +long* GFitsTableLngCol::data(void) { - throw GException::fits_invalid_type(G_PTR_INT, - "No pointer allowed to array"); + return m_data; } -/*************************************************************************** - * Set NULL string * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Set NULL value + * + * @param[in] value Pointer on NULL value + * + * Allows the specification of the FITS table NULL value. If value=NULL the + * data will not be screened for NULL values. ***************************************************************************/ void GFitsTableLngCol::set_nullval(const long* value) { @@ -261,12 +324,13 @@ void GFitsTableLngCol::set_nullval(const long* value) *m_nulval = *value; } - // Re-load column - // NOTE: THIS WILL LEAD TO A LOSS OF MODIFICATIONS; ISSUE SAVE BEFORE !!! + // Re-load column +/* if (m_data != NULL) { - //save(); + save(); load(); } +*/ // Return return; @@ -279,9 +343,8 @@ void GFitsTableLngCol::set_nullval(const long* value) = = ==========================================================================*/ -/*************************************************************************** - * Initialise class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Initialise class members ***************************************************************************/ void GFitsTableLngCol::init_members(void) { @@ -296,9 +359,10 @@ void GFitsTableLngCol::init_members(void) } -/*************************************************************************** - * Copy class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] column Column for which members should be copied. ***************************************************************************/ void GFitsTableLngCol::copy_members(const GFitsTableLngCol& column) { @@ -325,9 +389,8 @@ void GFitsTableLngCol::copy_members(const GFitsTableLngCol& column) } -/*************************************************************************** - * Delete class members * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Delete class members ***************************************************************************/ void GFitsTableLngCol::free_members(void) { @@ -344,26 +407,47 @@ void GFitsTableLngCol::free_members(void) } -/*************************************************************************** - * Load column data * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Fetch column data + * + * @exception GException::fits_error + * An error occured while loading column data from FITS file. + * + * If a FITS file is attached to the column the data are loaded into memory + * from the FITS file. If no FITS file is attached, memory is allocated + * to hold the column data and all cells are set to 0. ***************************************************************************/ -void GFitsTableLngCol::load(void) +void GFitsTableLngCol::fetch_data(void) { // Calculate size of memory m_size = m_repeat * m_length; - // Allocate memory - if (m_data != NULL) delete [] m_data; - m_data = new long[m_size]; + // Load only if the column has a positive size + if (m_size > 0) { + + // Allocate fresh memory + if (m_data != NULL) delete [] m_data; + m_data = new long[m_size]; - // Load column data - int status = 0; - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status); - status = __ffgcv(&m_fitsfile, __TLONG, m_colnum, 1, 1, m_size, - m_nulval, m_data, &m_anynul, &status); - if (status != 0) - throw GException::fits_error(G_LOAD, status); + // If a FITS file is attached then load column data from the FITS + // file + if (m_fitsfile.Fptr != NULL) { + int status = 0; + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, + &status); + status = __ffgcv(&m_fitsfile, __TLONG, m_colnum, 1, 1, m_size, + m_nulval, m_data, &m_anynul, &status); + if (status != 0) + throw GException::fits_error(G_FETCH_DATA, status); + } + + // ... otherwise initialise all column values to 0 + else { + for (int i = 0; i < m_size; ++i) + m_data[i] = 0; + } + + } // endif: column has a positive size // Return return; @@ -372,13 +456,13 @@ void GFitsTableLngCol::load(void) /*========================================================================== = = - = GFitsTableShtCol friends = + = GFitsTableLngCol friends = = = ==========================================================================*/ /*========================================================================== = = - = Other functions used by GFitsTableShtCol = + = Other functions used by GFitsTableLngCol = = = ==========================================================================*/ diff --git a/src/rsp/GLATResponse.cpp b/src/rsp/GLATResponse.cpp index 672dfa5..159c7c6 100644 --- a/src/rsp/GLATResponse.cpp +++ b/src/rsp/GLATResponse.cpp @@ -425,10 +425,12 @@ void GLATResponse::psf_init(void) // Evaluate ntail double denom = psf_base_value(10.0, gtail); - double ntail = (denom != 0.0) ? ncore * psf_base_value(10.0, gcore) / denom : 0.0; + double ntail = (denom != 0.0) + ? ncore * psf_base_value(10.0, gcore) / denom : 0.0; // Calculate PSF dependence - GVector psf = ncore * psf_base_vector(u, gcore) + ntail * psf_base_vector(u, gtail); + GVector psf = ncore * psf_base_vector(u, gcore) + + ntail * psf_base_vector(u, gtail); // Normalize PSF vector to identical amplitudes at smallest angular // distance. This allows for accurate interpolation afterwards @@ -555,7 +557,7 @@ double GLATResponse::psf_base_value(const double& u, const double& gamma) double c0 = 1.0 - invgamma; double c1 = 1.0 + u * invgamma; double result = c0 * pow(c1,-gamma); - + // Return result return result; } @@ -567,7 +569,7 @@ GVector GLATResponse::psf_base_vector(const GVector& u, const double& gamma) double c0 = 1.0 - invgamma; GVector c1 = 1.0 + u * invgamma; GVector result = c0 * pow(c1,-gamma); - + // Return result return result; } @@ -631,7 +633,7 @@ void GLATResponse::init_members(void) //m_aeff_name.clear(); //m_psf_name.clear(); //m_edisp_name.clear(); - + // Initialise PSF members m_psf_angle_num = 0; m_psf_angle_min = 0.0; @@ -703,7 +705,7 @@ GVector GLATResponse::get_fits_vector(const GFitsHDU* hdu, const std::string& co GFitsTableCol* ptr = hdu->column(colname); if (ptr == NULL) throw GException::fits_column_not_found(G_GET_FITS_VECTOR, colname); - + // Determine number of entries int num = ptr->repeat(); diff --git a/test/test_GFits.cpp b/test/test_GFits.cpp index 537a894..5ff5ec6 100644 --- a/test/test_GFits.cpp +++ b/test/test_GFits.cpp @@ -373,14 +373,25 @@ void test_create(void) // Attach binary table try { + // Re-open FITS file GFits fits; fits.open("test.fits"); + + // Create binary Table with 10 rows int nrows = 10; - int ncols = 5; - GFitsBinTable table(nrows); + GFitsBinTable table = GFitsBinTable(nrows); + GFitsTableDblCol first = GFitsTableDblCol(nrows); + GFitsTableDblCol second = GFitsTableDblCol(nrows); + table.append_column(&first); + table.append_column(&second); + cout << table; + + // Create HDU and append to FILE file GFitsHDU hdu(table); fits.append(&hdu); - cout << fits; +// cout << fits; + + // Save FITS file fits.save(); } catch (exception &e) {