From 3fb167e4ea7cb88bc958ba13ed3fa401397a257b Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Wed, 5 Mar 2008 17:47:19 +0000 Subject: [PATCH] implement table column format definition for saving and new column constructor interface --- include/GException.hpp | 9 ++++++++- include/GFitsCfitsio.hpp | 2 ++ include/GFitsTableCol.hpp | 17 ++++++++++++----- include/GFitsTableDblCol.hpp | 18 ++++++++++++------ include/GFitsTableFltCol.hpp | 12 ++++++++---- include/GFitsTableLngCol.hpp | 12 ++++++++---- include/GFitsTableShtCol.hpp | 12 ++++++++---- include/GFitsTableStrCol.hpp | 13 ++++++++----- src/GException.cpp | 14 ++++++++++++++ src/GTools.cpp | 24 ++++++++++++++++++++---- src/GTools.hpp | 3 ++- src/fits/GFitsBinTable.cpp | 11 +++-------- src/fits/GFitsTable.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------- src/fits/GFitsTableCol.cpp | 109 ++++++++++++++++++++++++++++++++----------------------------------------------------------------------------- src/fits/GFitsTableDblCol.cpp | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------- src/fits/GFitsTableFltCol.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/fits/GFitsTableLngCol.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/fits/GFitsTableShtCol.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/fits/GFitsTableStrCol.cpp | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------- src/rsp/GLATResponse.cpp | 2 +- test/test_GFits.cpp | 14 +++++++------- 21 files changed, 696 insertions(+), 237 deletions(-) diff --git a/include/GException.hpp b/include/GException.hpp index 1abea90..f3d3788 100644 --- a/include/GException.hpp +++ b/include/GException.hpp @@ -84,7 +84,8 @@ public: // Matrix dimensions mismatch class matrix_mismatch : public GExceptionHandler { public: - matrix_mismatch(string origin, int rows1, int cols1, int rows2, int cols2); + matrix_mismatch(string origin, int rows1, int cols1, int rows2, + int cols2); }; // Matrix not rectangular @@ -190,6 +191,12 @@ public: fits_invalid_type(string origin, string message); }; + // FITS unknown table type + class fits_unknown_tabtype : public GExceptionHandler { + public: + fits_unknown_tabtype(string origin, int type); + }; + // FITS unknown column type class fits_unknown_coltype : public GExceptionHandler { public: diff --git a/include/GFitsCfitsio.hpp b/include/GFitsCfitsio.hpp index 3e7ae0d..dd3d97c 100644 --- a/include/GFitsCfitsio.hpp +++ b/include/GFitsCfitsio.hpp @@ -51,6 +51,7 @@ #define __ffinit(A, B, C) ffinit(A, B, C) #define __ffopen(A, B, C, D) ffopen(A, B, C, D) #define __ffmahd(A, B, C, D) ffmahd(A, B, C, D) +#define __ffpcn(A, B, C, D, E, F, G, H, I) ffpcn(A, B, C, D, E, F, G, H, I) #define __ffpcom(A, B, C) ffpcom(A, B, C) #define __ffphis(A, B, C) ffphis(A, B, C) #define __ffpss(A, B, C, D, E, F) ffpss(A, B, C, D, E, F) @@ -101,6 +102,7 @@ typedef fitsfile __fitsfile; #define __fficol(A, B, C, D, E) __dummy() #define __ffinit(A, B, C) __dummy() #define __ffmahd(A, B, C, D) __dummy() +#define __ffpcn(A, B, C, D, E, F, G, H, I) __dummy() #define __ffopen(A, B, C, D) __dummy() #define __ffpcom(A, B, C) __dummy() #define __ffphis(A, B, C) __dummy() diff --git a/include/GFitsTableCol.hpp b/include/GFitsTableCol.hpp index 04620ef..9802575 100644 --- a/include/GFitsTableCol.hpp +++ b/include/GFitsTableCol.hpp @@ -38,12 +38,13 @@ class GFitsTableCol { friend class GFitsTable; // I/O friends - friend ostream& operator<< (ostream& os, const GFitsTableCol& column); +// friend ostream& operator<< (ostream& os, const GFitsTableCol& column); public: // Constructors and destructors GFitsTableCol(); - GFitsTableCol(const int& length, const int& size = 1); + GFitsTableCol(const std::string& name, const int& length, + const int& number, const int& width); GFitsTableCol(const GFitsTableCol& column); virtual ~GFitsTableCol(); @@ -64,24 +65,30 @@ public: int type(void); int repeat(void); int width(void); + int number(void); int length(void); protected: // Protected data area std::string m_name; //!< Column name - std::string m_format; //!< Column format std::string m_unit; //!< Column unit - int m_colnum; //!< Column number (starting from 1). + int m_colnum; //!< @brief Column number (starting from 1). //!< This parameter is used to signal if a //!< table column corresponds to a FITS file //!< column. If it is set to 0 there is no //!< correspondance. int m_type; //!< Column type int m_repeat; //!< Repeat value of column - int m_width; //!< Width of column + int m_width; //!< Width of single column element + int m_number; //!< Number of elements in column + //!< m_number = m_repeat / m_width int m_length; //!< Length of column __fitsfile m_fitsfile; //!< FITS file associated with column + // Protected methods + virtual std::string ascii_format(void) const = 0; + virtual std::string binary_format(void) const = 0; + private: // Private methods void init_members(void); diff --git a/include/GFitsTableDblCol.hpp b/include/GFitsTableDblCol.hpp index 2326c68..eca2f66 100644 --- a/include/GFitsTableDblCol.hpp +++ b/include/GFitsTableDblCol.hpp @@ -38,10 +38,14 @@ ***************************************************************************/ class GFitsTableDblCol : public GFitsTableCol { + // I/O friends + friend ostream& operator<< (ostream& os, const GFitsTableDblCol& column); + public: // Constructors and destructors GFitsTableDblCol(); - GFitsTableDblCol(const int& length, const int& size = 1); + GFitsTableDblCol(const std::string& name, const int& length, + const int& size = 1); GFitsTableDblCol(const GFitsTableDblCol& column); virtual ~GFitsTableDblCol(); @@ -61,13 +65,15 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableDblCol& column); - void free_members(void); - void fetch_data(void); + void init_members(void); + void copy_members(const GFitsTableDblCol& column); + void free_members(void); + void fetch_data(void); + std::string ascii_format(void) const; + std::string binary_format(void) const; // Private data area - int m_size; //!< Size of data area + int m_size; //!< Size of allocated data area (0 if offline) double* m_data; //!< Data area double* m_nulval; //!< NULL value int m_anynul; //!< Number of NULLs encountered diff --git a/include/GFitsTableFltCol.hpp b/include/GFitsTableFltCol.hpp index 5fb3e3d..2f605c0 100644 --- a/include/GFitsTableFltCol.hpp +++ b/include/GFitsTableFltCol.hpp @@ -41,6 +41,8 @@ class GFitsTableFltCol : public GFitsTableCol { public: // Constructors and destructors GFitsTableFltCol(); + GFitsTableFltCol(const std::string& name, const int& length, + const int& size = 1); GFitsTableFltCol(const GFitsTableFltCol& column); virtual ~GFitsTableFltCol(); @@ -58,10 +60,12 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableFltCol& column); - void free_members(void); - void load(void); + void init_members(void); + void copy_members(const GFitsTableFltCol& column); + void free_members(void); + void load(void); + std::string ascii_format(void) const; + std::string binary_format(void) const; // Private data area int m_size; //!< Size of data area diff --git a/include/GFitsTableLngCol.hpp b/include/GFitsTableLngCol.hpp index ad68c82..0a243d8 100644 --- a/include/GFitsTableLngCol.hpp +++ b/include/GFitsTableLngCol.hpp @@ -41,6 +41,8 @@ class GFitsTableLngCol : public GFitsTableCol { public: // Constructors and destructors GFitsTableLngCol(); + GFitsTableLngCol(const std::string& name, const int& length, + const int& size = 1); GFitsTableLngCol(const GFitsTableLngCol& column); virtual ~GFitsTableLngCol(); @@ -60,10 +62,12 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableLngCol& column); - void free_members(void); - void fetch_data(void); + void init_members(void); + void copy_members(const GFitsTableLngCol& column); + void free_members(void); + void fetch_data(void); + std::string ascii_format(void) const; + std::string binary_format(void) const; // Private data area int m_size; //!< Size of data area diff --git a/include/GFitsTableShtCol.hpp b/include/GFitsTableShtCol.hpp index c74f14e..f302b28 100644 --- a/include/GFitsTableShtCol.hpp +++ b/include/GFitsTableShtCol.hpp @@ -32,6 +32,8 @@ class GFitsTableShtCol : public GFitsTableCol { public: // Constructors and destructors GFitsTableShtCol(); + GFitsTableShtCol(const std::string& name, const int& length, + const int& size = 1); GFitsTableShtCol(const GFitsTableShtCol& column); virtual ~GFitsTableShtCol(); @@ -53,10 +55,12 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableShtCol& column); - void free_members(void); - void load(void); + void init_members(void); + void copy_members(const GFitsTableShtCol& column); + void free_members(void); + void load(void); + std::string ascii_format(void) const; + std::string binary_format(void) const; // Private data area int m_size; // Size of data area diff --git a/include/GFitsTableStrCol.hpp b/include/GFitsTableStrCol.hpp index d3a34a2..ed7f655 100644 --- a/include/GFitsTableStrCol.hpp +++ b/include/GFitsTableStrCol.hpp @@ -32,6 +32,8 @@ class GFitsTableStrCol : public GFitsTableCol { public: // Constructors and destructors GFitsTableStrCol(); + GFitsTableStrCol(const std::string& name, const int& length, + const int& size = 1); GFitsTableStrCol(const GFitsTableStrCol& column); ~GFitsTableStrCol(); @@ -53,14 +55,15 @@ public: private: // Private methods - void init_members(void); - void copy_members(const GFitsTableStrCol& column); - void free_members(void); - void load(void); + void init_members(void); + void copy_members(const GFitsTableStrCol& column); + void free_members(void); + void load(void); + std::string ascii_format(void) const; + std::string binary_format(void) const; // Private data area int m_size; // Total number of strings - int m_num_subs; // Number of substrings char** m_data; // Data area char* m_nulstr; // NULL string int m_anynul; // Number of NULLs encountered diff --git a/src/GException.cpp b/src/GException.cpp index 2c475a1..928eefc 100644 --- a/src/GException.cpp +++ b/src/GException.cpp @@ -413,6 +413,20 @@ GException::fits_invalid_type::fits_invalid_type(string origin, /***********************************************************************//** + * @brief FITS error: Table type is unknow + * + * @param[in] origin Method that throws the error. + * @param[in] type Specified table type. + ***************************************************************************/ +GException::fits_unknown_tabtype::fits_unknown_tabtype(string origin, + int type) +{ + m_origin = origin; + m_message = "Table type '" + str(type) + "' is unknown"; +} + + +/***********************************************************************//** * @brief FITS error: Column type is unknown * * @param[in] origin Method that throws the error. diff --git a/src/GTools.cpp b/src/GTools.cpp index d7e5092..9a32127 100644 --- a/src/GTools.cpp +++ b/src/GTools.cpp @@ -12,16 +12,18 @@ ***************************************************************************/ /* __ Includes ___________________________________________________________ */ +#include #include "GTools.hpp" /* __ Namespaces _________________________________________________________ */ -/*************************************************************************** - * Strip leading and trailing whitespace from string * - * ----------------------------------------------------------------------- * +/***********************************************************************//** + * @brief Strip leading and trailing whitespace from string + * + * @param[in] arg String which should be stripped of whitespace. ***************************************************************************/ -std::string strip_whitespace(const std::string arg) +std::string strip_whitespace(const std::string& arg) { // Return empty string if argument is empty if (arg.empty()) @@ -40,3 +42,17 @@ std::string strip_whitespace(const std::string arg) // Return result return result; } + + +/***********************************************************************//** + * @brief Convert integer value into string + * + * @param[in] value Value to be converted into a string. + ***************************************************************************/ +std::string str(const int& value) +{ + std::ostringstream s_value; + s_value << value; + return s_value.str(); +} + diff --git a/src/GTools.hpp b/src/GTools.hpp index 83ebaeb..ee1f787 100644 --- a/src/GTools.hpp +++ b/src/GTools.hpp @@ -22,6 +22,7 @@ /* __ Namespaces _________________________________________________________ */ /* __ Prototypes ________________________________________________________ */ -std::string strip_whitespace(const std::string arg); +std::string strip_whitespace(const std::string& arg); +std::string str(const int& value); #endif /* GTOOLS_HPP */ diff --git a/src/fits/GFitsBinTable.cpp b/src/fits/GFitsBinTable.cpp index 366dc8a..ace7f9c 100644 --- a/src/fits/GFitsBinTable.cpp +++ b/src/fits/GFitsBinTable.cpp @@ -15,13 +15,7 @@ /* __ Includes ___________________________________________________________ */ #include #include "GException.hpp" -//#include "GTools.hpp" #include "GFitsBinTable.hpp" -//#include "GFitsTableStrCol.hpp" -//#include "GFitsTableShtCol.hpp" -//#include "GFitsTableLngCol.hpp" -//#include "GFitsTableFltCol.hpp" -//#include "GFitsTableDblCol.hpp" /* __ Namespaces _________________________________________________________ */ @@ -33,6 +27,8 @@ /* __ Debug definitions __________________________________________________ */ +/* __ Prototypes of local functions ______________________________________ */ + /*========================================================================== = = @@ -57,7 +53,6 @@ GFitsBinTable::GFitsBinTable() : GFitsTable() * @brief Constructor * * @param[in] nrows Number of rows in table - * @param[in] ncols Number of columns in table ***************************************************************************/ GFitsBinTable::GFitsBinTable(int nrows) : GFitsTable(nrows) { @@ -145,7 +140,7 @@ GFitsBinTable& GFitsBinTable::operator= (const GFitsBinTable& table) /***********************************************************************//** * @brief Clone binary table ***************************************************************************/ -GFitsBinTable* GFitsBinTable::clone(void) const +GFitsBinTable* GFitsBinTable::clone(void) const { return new GFitsBinTable(*this); } diff --git a/src/fits/GFitsTable.cpp b/src/fits/GFitsTable.cpp index 922a011..2756f5a 100644 --- a/src/fits/GFitsTable.cpp +++ b/src/fits/GFitsTable.cpp @@ -32,6 +32,7 @@ #define G_INSERT_COLUMN "GFitsTable::insert_column(int, GFitsTableCol*)" #define G_COLUMN1 "GFitsTable::column(const std::string&)" #define G_COLUMN2 "GFitsTable::column(const int&)" +#define G_GET_TFORM "GFitsTable::get_tform(const int&)" /* __ Macros _____________________________________________________________ */ @@ -258,6 +259,13 @@ void GFitsTable::open(__fitsfile* fptr) m_columns[i]->m_length = m_rows; m_columns[i]->connect(fptr); + // Extract column vector size + if (m_columns[i]->m_repeat == 1) // ASCII tables + m_columns[i]->m_number = 1; + else // Binary tables + m_columns[i]->m_number = m_columns[i]->m_repeat / + m_columns[i]->m_width; + } // endfor: looped over all columns // Return @@ -283,6 +291,8 @@ void GFitsTable::open(__fitsfile* fptr) * columns need to have identical lengths to be saved into a FITS table. * All columns with a length of zero will be excluded from saving, and if * they exist in the FITS file, they will be removed from the file. + * + * IMPLEMENTION NOT YET COMPLETED (ROW ADDING/DELETION MISSING) ***************************************************************************/ void GFitsTable::save(void) { @@ -387,7 +397,7 @@ void GFitsTable::save(void) } // If the table length differs from number of rows in the FITS file - // then ???? + // then re-adjust FITS table length // TBD // Update all columns. The 'm_colnum' field specifies where in the @@ -403,7 +413,6 @@ void GFitsTable::save(void) // FITS table and link column to table. if (m_columns[i]->m_colnum == 0) { -cout << "needs appending of column to FITS file " << num_cols << endl; // Increment number of columns in FITS file num_cols++; @@ -420,10 +429,8 @@ cout << "needs appending of column to FITS file " << num_cols << endl; } // endif: column appended to FITS file // Now write column into FITS file (only if length is positive) - if (m_columns[i]->length() > 0) { -cout << "write column into " << m_columns[i]->m_colnum << endl; - //m_columns[i]->save(); - } + if (m_columns[i]->length() > 0) + m_columns[i]->save(); } // endif: column was valid } // endfor: looped over all table columns @@ -503,8 +510,6 @@ void GFitsTable::append_column(GFitsTableCol& column) * @exception GException::fits_bad_col_length * The length of the column is incompatible with the number of * rows in the table. - * @exception GException::fits_unknown_coltype - * FITS column is of unknown type. * * 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. @@ -573,37 +578,9 @@ void GFitsTable::insert_column(int colnum, GFitsTableCol& column) } // endelse: we made space to insert a column - // Type dependent copy of column - switch (column.m_type) { - case __TSTRING: - m_columns[colnum] = new GFitsTableStrCol; - *m_columns[colnum] = column; - break; - case __TSHORT: - m_columns[colnum] = new GFitsTableShtCol; - *m_columns[colnum] = column; - break; - case __TLONG: - m_columns[colnum] = new GFitsTableLngCol; - *m_columns[colnum] = column; - break; - case __TFLOAT: - m_columns[colnum] = new GFitsTableFltCol; - *m_columns[colnum] = column; - break; - case __TDOUBLE: - m_columns[colnum] = new GFitsTableDblCol; - *m_columns[colnum] = column; - break; - default: - throw GException::fits_unknown_coltype(G_INSERT_COLUMN, column.m_type); - break; - } + // Copy column by cloning it + m_columns[colnum] = column.clone(); - // Set column number (this is important to known from which column in the - // FITS file the data should be read - //// NO NO NO !!! Only for columns that exist in the FITS file !!! - //// m_columns[colnum]->m_colnum = colnum + 1; // Reset column number since column does not already exist in FITS // file m_columns[colnum]->m_colnum = 0; @@ -836,6 +813,9 @@ char* GFitsTable::get_ttype(const int& colnum) const * * @param[in] colnum Column number for which format is to be returned * + * @exception GException::fits_unknown_tabtype + * Table is neither ASCII nor Binary. + * * This methods allocates memory for the character string that holds the * column format. The client has to de-allocate this memory after usage. * In case that the column does not exist a NULL pointer is returned. @@ -846,11 +826,26 @@ char* GFitsTable::get_tform(const int& colnum) const char* ptr = NULL; // Get type only if column exists - if (m_columns != NULL && colnum >=0 && colnum < m_cols && + if (m_columns != NULL && colnum >=0 && colnum < m_cols && m_columns[colnum] != NULL) { - int size = m_columns[colnum]->m_format.length(); - ptr = new char[size+1]; - strncpy(ptr, m_columns[colnum]->m_format.c_str(), size); + + // Get table type specific format + int size; + switch (m_type) { + case 1: + size = m_columns[colnum]->ascii_format().length(); + ptr = new char[size+1]; + strncpy(ptr, m_columns[colnum]->ascii_format().c_str(), size); + break; + case 2: + size = m_columns[colnum]->binary_format().length(); + ptr = new char[size+1]; + strncpy(ptr, m_columns[colnum]->binary_format().c_str(), size); + break; + default: + throw GException::fits_unknown_tabtype(G_GET_TFORM, m_type); + break; + } ptr[size] = '\0'; } @@ -919,8 +914,28 @@ ostream& operator<< (ostream& os, const GFitsTable& table) os << " Number of columns .........: " << table.m_cols << endl; if (table.m_columns != NULL) { for (int i = 0; i < table.m_cols; ++i) { - if (table.m_columns[i] != NULL) - os << " " << *(table.m_columns[i]); + if (table.m_columns[i] != NULL) { + switch (table.m_columns[i]->type()) { + case __TSTRING: + os << " column " << i << " no << operator" << endl; + break; + case __TSHORT: + os << " column " << i << " no << operator" << endl; + break; + case __TLONG: + os << " column " << i << " no << operator" << endl; + break; + case __TFLOAT: + os << " column " << i << " no << operator" << endl; + break; + case __TDOUBLE: + os << " " << *((GFitsTableDblCol*)table.m_columns[i]) + << endl; + break; + default: + break; + } + } else os << " column " << i << " undefined" << endl; } diff --git a/src/fits/GFitsTableCol.cpp b/src/fits/GFitsTableCol.cpp index c143553..11067c0 100644 --- a/src/fits/GFitsTableCol.cpp +++ b/src/fits/GFitsTableCol.cpp @@ -50,17 +50,30 @@ GFitsTableCol::GFitsTableCol() /***********************************************************************//** * @brief Constructor * + * @param[in] name Name of column. * @param[in] length Length of column. - * @param[in] size Vector size of column. + * @param[in] number Vector size of column. + * @param[in] width Width of single column element. + * + * Construct column instance from name, length, vector size and column width. + * The repeat value, required for binary tables, is calculated internally. ***************************************************************************/ -GFitsTableCol::GFitsTableCol(const int& length, const int& size) +GFitsTableCol::GFitsTableCol(const std::string& name, + const int& length, + const int& number, + const int& width) { // Initialise class members for clean destruction init_members(); - // Set column length and vector size + // Store attributes + m_name = name; m_length = length; - m_repeat = size; + m_number = number; + m_width = width; + + // Calculate repeat value (only used for binary table!) + m_repeat = m_number * m_width; // Return return; @@ -196,7 +209,7 @@ int GFitsTableCol::type(void) /***********************************************************************//** - * @brief Get column repeat value + * @brief Get column repeat value (only used for binary tables) ***************************************************************************/ int GFitsTableCol::repeat(void) { @@ -206,16 +219,26 @@ int GFitsTableCol::repeat(void) /***********************************************************************//** - * @brief Get column width + * @brief Get width of one element in column ***************************************************************************/ int GFitsTableCol::width(void) { - // Return column width + // Return width of one element in column return m_width; } /***********************************************************************//** + * @brief Get number of elements in a column + ***************************************************************************/ +int GFitsTableCol::number(void) +{ + // Return number of elements in a column + return m_number; +} + + +/***********************************************************************//** * @brief Get column length ***************************************************************************/ int GFitsTableCol::length(void) @@ -238,12 +261,12 @@ void GFitsTableCol::init_members(void) { // Initialise members m_name.clear(); - m_format.clear(); m_unit.clear(); m_colnum = 0; m_type = 0; m_repeat = 0; m_width = 0; + m_number = 0; m_length = 0; m_fitsfile.HDUposition = 0; m_fitsfile.Fptr = NULL; @@ -262,12 +285,12 @@ void GFitsTableCol::copy_members(const GFitsTableCol& column) { // Copy attributes m_name = column.m_name; - m_format = column.m_format; m_unit = column.m_unit; m_colnum = column.m_colnum; m_type = column.m_type; m_repeat = column.m_repeat; m_width = column.m_width; + m_number = column.m_number; m_length = column.m_length; m_fitsfile = column.m_fitsfile; @@ -312,74 +335,6 @@ void GFitsTableCol::connect(__fitsfile* fptr) = = ==========================================================================*/ -/***********************************************************************//** - * @brief Output operator - * - * @param[in] os Output stream - * @param[in] column Column to put in output stream - ***************************************************************************/ -ostream& operator<< (ostream& os, const GFitsTableCol& column) -{ - // Put header in stream - os << "'" << column.m_name << "'"; - os << " [" << column.m_colnum << "] "; - - // Set column type - switch (column.m_type) { - case 1: - os << "TBIT"; - break; - case 11: - os << "TBYTE"; - break; - case 14: - os << "TLOGICAL"; - break; - case 16: - os << "TSTRING"; - break; - case 21: - os << "TSHORT"; - break; - case 31: - os << "TINT"; - break; - case 41: - os << "TLONG"; - break; - case 42: - os << "TFLOAT"; - break; - case 81: - os << "TLONGLONG"; - break; - case 82: - os << "TDOUBLE"; - break; - case 83: - os << "TCOMPLEX"; - break; - case 163: - os << "TDBLCOMPLEX"; - break; - default: - os << ""; - break; - } - - // Set vector length - os << " repeat=" << column.m_repeat; - - // Set width - os << " width=" << column.m_width; - - // Set length - os << " length=" << column.m_length << endl; - - // Return output stream - return os; -} - /*========================================================================== = = diff --git a/src/fits/GFitsTableDblCol.cpp b/src/fits/GFitsTableDblCol.cpp index 89ebfac..054f968 100644 --- a/src/fits/GFitsTableDblCol.cpp +++ b/src/fits/GFitsTableDblCol.cpp @@ -13,9 +13,10 @@ ***************************************************************************/ /* __ Includes ___________________________________________________________ */ +#include #include "GException.hpp" +#include "GTools.hpp" #include "GFitsTableDblCol.hpp" -#include /* __ Namespaces _________________________________________________________ */ @@ -55,20 +56,18 @@ GFitsTableDblCol::GFitsTableDblCol() : GFitsTableCol() /***********************************************************************//** * @brief Constructor * + * @param[in] name Name of column. * @param[in] length Length of column. * @param[in] size Vector size of column. ***************************************************************************/ -GFitsTableDblCol::GFitsTableDblCol(const int& length, const int& size) - : GFitsTableCol(length, size) +GFitsTableDblCol::GFitsTableDblCol(const std::string& name, + const int& length, + const int& size) + : GFitsTableCol(name, length, size, 8) { // Initialise class members for clean destruction init_members(); - // Setup format - //m_name = "Test"; - m_format = "1D"; - //m_unit = "deg"; - // Return return; } @@ -205,11 +204,17 @@ const double& GFitsTableDblCol::operator() (const int& row, const int& inx) * * @exception GException::fits_hdu_not_found * Specified HDU not found in FITS file. + * @exception GException::fits_error + * Error occured during writing of the column data. + * + * The table column is only saved if it is linked to a FITS file and if the + * data are indeed present in the class instance. This avoids saving of data + * that have not been modified. ***************************************************************************/ void GFitsTableDblCol::save(void) { - // Continue only if a FITS file is connected - if (m_fitsfile.Fptr != NULL) { + // Continue only if a FITS file is connected and data have been loaded + if (m_fitsfile.Fptr != NULL && m_colnum > 0 && m_data != NULL) { // Move to the HDU int status = 0; @@ -219,12 +224,14 @@ void GFitsTableDblCol::save(void) throw GException::fits_hdu_not_found(G_SAVE, (m_fitsfile.HDUposition)+1, status); - // Save the column data - // TBD - + status = __ffpcn(&m_fitsfile, __TDOUBLE, m_colnum, 1, 1, + (long)m_size, m_data, m_nulval, &status); + if (status != 0) + throw GException::fits_error(G_SAVE, status); + } // endif: FITS file was connected - + // Return return; } @@ -251,8 +258,8 @@ std::string GFitsTableDblCol::string(const int& row, const int& inx) throw GException::out_of_range(G_STRING, row, 0, m_length-1); // Check inx value - if (inx < 0 || inx >= m_repeat) - throw GException::out_of_range(G_STRING, inx, 0, m_repeat-1); + if (inx < 0 || inx >= m_number) + throw GException::out_of_range(G_STRING, inx, 0, m_number-1); // Get index int offset = row * m_repeat + inx; @@ -287,8 +294,8 @@ double GFitsTableDblCol::real(const int& row, const int& inx) throw GException::out_of_range(G_REAL, row, 0, m_length-1); // Check inx value - if (inx < 0 || inx >= m_repeat) - throw GException::out_of_range(G_REAL, inx, 0, m_repeat-1); + if (inx < 0 || inx >= m_number) + throw GException::out_of_range(G_REAL, inx, 0, m_number-1); // Get index int offset = row * m_repeat + inx; @@ -319,8 +326,8 @@ int GFitsTableDblCol::integer(const int& row, const int& inx) throw GException::out_of_range(G_INTEGER, row, 0, m_length-1); // Check col value - if (inx < 0 || inx >= m_repeat) - throw GException::out_of_range(G_INTEGER, inx, 0, m_repeat-1); + if (inx < 0 || inx >= m_number) + throw GException::out_of_range(G_INTEGER, inx, 0, m_number-1); // Get index int offset = row * m_repeat + inx; @@ -470,7 +477,7 @@ void GFitsTableDblCol::free_members(void) void GFitsTableDblCol::fetch_data(void) { // Calculate size of memory - m_size = m_repeat * m_length; + m_size = m_number * m_length; // Load only if the column has a positive size if (m_size > 0) { @@ -504,12 +511,96 @@ void GFitsTableDblCol::fetch_data(void) } +/***********************************************************************//** + * @brief Returns format string of ASCII table + ***************************************************************************/ +std::string GFitsTableDblCol::ascii_format(void) const +{ + // Initialize format string + std::string format; + + // Set type code + format.append("F"); + + // Set width + format.append(str(m_width)); + + // Return format + return format; +} + + +/***********************************************************************//** + * @brief Returns format string of binary table + ***************************************************************************/ +std::string GFitsTableDblCol::binary_format(void) const +{ + // Initialize format string + std::string format; + + // Set number of elements + format.append(str(m_number)); + + // Set type code + format.append("D"); + + // Return format + return format; +} + + /*========================================================================== = = = GFitsTableDblCol friends = = = ==========================================================================*/ +/***********************************************************************//** + * @brief Output operator + * + * @param[in] os Output stream + * @param[in] column Column to put in output stream + ***************************************************************************/ +ostream& operator<< (ostream& os, const GFitsTableDblCol& column) +{ + // Put column name in stream + os << "'" << column.m_name << "'"; + + // Put FITS column number in stream + if (column.m_colnum > 0) + os << " [fits_colnum=" << column.m_colnum << "]"; + else + os << " [not linked to FITS file]"; + + // Put column type in stream + os << " " << column.ascii_format(); + os << " " << column.binary_format(); + + // Put data loading in stream + if (column.m_data == NULL) + os << " (not loaded)"; + else + os << " (loaded in memory)"; + + // Set data area size + os << " size=" << column.m_size; + + // Set vector length + os << " repeat=" << column.m_repeat; + + // Set width + os << " width=" << column.m_width; + + // Set number + os << " number=" << column.m_number; + + // Set length + os << " length=" << column.m_length; + + // Return output stream + return os; +} + /*========================================================================== = = diff --git a/src/fits/GFitsTableFltCol.cpp b/src/fits/GFitsTableFltCol.cpp index 2bf2d98..ad37fdc 100644 --- a/src/fits/GFitsTableFltCol.cpp +++ b/src/fits/GFitsTableFltCol.cpp @@ -13,13 +13,15 @@ ***************************************************************************/ /* __ Includes ___________________________________________________________ */ +#include #include "GException.hpp" +#include "GTools.hpp" #include "GFitsTableFltCol.hpp" -#include // cout, cerr /* __ Namespaces _________________________________________________________ */ /* __ Method name definitions ____________________________________________ */ +#define G_SAVE "GFitsTableFltCol::save()" #define G_STRING "GFitsTableFltCol::string(const int&, const int&)" #define G_REAL "GFitsTableFltCol::real(const int&, const int&)" #define G_INTEGER "GFitsTableFltCol::integer(const int&, const int&)" @@ -57,6 +59,26 @@ GFitsTableFltCol::GFitsTableFltCol() : GFitsTableCol() /***********************************************************************//** + * @brief Constructor + * + * @param[in] name Name of column. + * @param[in] length Length of column. + * @param[in] size Vector size of column. + ***************************************************************************/ +GFitsTableFltCol::GFitsTableFltCol(const std::string& name, + const int& length, + const int& size) + : GFitsTableCol(name, length, size, 4) +{ + // Initialise class members for clean destruction + init_members(); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] column Column from which class instance should be built. @@ -130,6 +152,36 @@ GFitsTableFltCol& GFitsTableFltCol::operator= (const GFitsTableFltCol& column) ==========================================================================*/ /***********************************************************************//** + * @brief Save table column into FITS file + * + * @exception GException::fits_hdu_not_found + * Specified HDU not found in FITS file. + ***************************************************************************/ +void GFitsTableFltCol::save(void) +{ + // Continue only if a FITS file is connected + if (m_fitsfile.Fptr != NULL) { + + // Move to the HDU + int status = 0; + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, + &status); + if (status != 0) + throw GException::fits_hdu_not_found(G_SAVE, + (m_fitsfile.HDUposition)+1, + status); + + // Save the column data + // TBD + + } // endif: FITS file was connected + + // Return + return; +} + + +/***********************************************************************//** * @brief Get string value * * @param[in] row Table row. @@ -148,8 +200,8 @@ std::string GFitsTableFltCol::string(const int& row, const int& col) 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); + if (col < 0 || col >= m_number) + throw GException::out_of_range(G_STRING, col, 0, m_number-1); // Get index int inx = row * m_repeat + col; @@ -182,8 +234,8 @@ double GFitsTableFltCol::real(const int& row, const int& col) 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); + if (col < 0 || col >= m_number) + throw GException::out_of_range(G_REAL, col, 0, m_number-1); // Get index int inx = row * m_repeat + col; @@ -215,8 +267,8 @@ int GFitsTableFltCol::integer(const int& row, const int& col) 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 (col < 0 || col >= m_number) + throw GException::out_of_range(G_INTEGER, col, 0, m_number-1); // Get index int inx = row * m_repeat + col; @@ -360,7 +412,7 @@ void GFitsTableFltCol::free_members(void) void GFitsTableFltCol::load(void) { // Calculate size of memory - m_size = m_repeat * m_length; + m_size = m_number * m_length; // Allocate memory if (m_data != NULL) delete [] m_data; @@ -379,6 +431,44 @@ void GFitsTableFltCol::load(void) } +/***********************************************************************//** + * @brief Returns format string of ASCII table + ***************************************************************************/ +std::string GFitsTableFltCol::ascii_format(void) const +{ + // Initialize format string + std::string format; + + // Set type code + format.append("F"); + + // Set width + format.append(str(m_width)); + + // Return format + return format; +} + + +/***********************************************************************//** + * @brief Returns format string of binary table + ***************************************************************************/ +std::string GFitsTableFltCol::binary_format(void) const +{ + // Initialize format string + std::string format; + + // Set number of elements + format.append(str(m_number)); + + // Set type code + format.append("E"); + + // Return format + return format; +} + + /*========================================================================== = = = GFitsTableFltCol friends = diff --git a/src/fits/GFitsTableLngCol.cpp b/src/fits/GFitsTableLngCol.cpp index 7258f5d..7c6e091 100644 --- a/src/fits/GFitsTableLngCol.cpp +++ b/src/fits/GFitsTableLngCol.cpp @@ -13,13 +13,15 @@ ***************************************************************************/ /* __ Includes ___________________________________________________________ */ +#include #include "GException.hpp" +#include "GTools.hpp" #include "GFitsTableLngCol.hpp" -#include // cout, cerr /* __ Namespaces _________________________________________________________ */ /* __ Method name definitions ____________________________________________ */ +#define G_SAVE "GFitsTableLngCol::save()" #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&)" @@ -52,6 +54,26 @@ GFitsTableLngCol::GFitsTableLngCol() : GFitsTableCol() /***********************************************************************//** + * @brief Constructor + * + * @param[in] name Name of column. + * @param[in] length Length of column. + * @param[in] size Vector size of column. + ***************************************************************************/ +GFitsTableLngCol::GFitsTableLngCol(const std::string& name, + const int& length, + const int& size) + : GFitsTableCol(name, length, size, 4) +{ + // Initialise class members for clean destruction + init_members(); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] column Column from which class instance should be built. @@ -178,6 +200,36 @@ const long& GFitsTableLngCol::operator() (const int& row, const int& inx) ==========================================================================*/ /***********************************************************************//** + * @brief Save table column into FITS file + * + * @exception GException::fits_hdu_not_found + * Specified HDU not found in FITS file. + ***************************************************************************/ +void GFitsTableLngCol::save(void) +{ + // Continue only if a FITS file is connected + if (m_fitsfile.Fptr != NULL) { + + // Move to the HDU + int status = 0; + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, + &status); + if (status != 0) + throw GException::fits_hdu_not_found(G_SAVE, + (m_fitsfile.HDUposition)+1, + status); + + // Save the column data + // TBD + + } // endif: FITS file was connected + + // Return + return; +} + + +/***********************************************************************//** * @brief Get string value * * @param[in] row Table row. @@ -198,8 +250,8 @@ std::string GFitsTableLngCol::string(const int& row, const int& inx) throw GException::out_of_range(G_STRING, row, 0, m_length-1); // Check inx value - if (inx < 0 || inx >= m_repeat) - throw GException::out_of_range(G_STRING, inx, 0, m_repeat-1); + if (inx < 0 || inx >= m_number) + throw GException::out_of_range(G_STRING, inx, 0, m_number-1); // Get index int offset = row * m_repeat + inx; @@ -234,8 +286,8 @@ double GFitsTableLngCol::real(const int& row, const int& inx) throw GException::out_of_range(G_REAL, row, 0, m_length-1); // Check inx value - if (inx < 0 || inx >= m_repeat) - throw GException::out_of_range(G_REAL, inx, 0, m_repeat-1); + if (inx < 0 || inx >= m_number) + throw GException::out_of_range(G_REAL, inx, 0, m_number-1); // Get index int offset = row * m_repeat + inx; @@ -269,8 +321,8 @@ int GFitsTableLngCol::integer(const int& row, const int& inx) throw GException::out_of_range(G_INTEGER, row, 0, m_length-1); // Check inx value - if (inx < 0 || inx >= m_repeat) - throw GException::out_of_range(G_INTEGER, inx, 0, m_repeat-1); + if (inx < 0 || inx >= m_number) + throw GException::out_of_range(G_INTEGER, inx, 0, m_number-1); // Get index int offset = row * m_repeat + inx; @@ -421,7 +473,7 @@ void GFitsTableLngCol::free_members(void) void GFitsTableLngCol::fetch_data(void) { // Calculate size of memory - m_size = m_repeat * m_length; + m_size = m_number * m_length; // Load only if the column has a positive size if (m_size > 0) { @@ -455,6 +507,44 @@ void GFitsTableLngCol::fetch_data(void) } +/***********************************************************************//** + * @brief Returns format string of ASCII table + ***************************************************************************/ +std::string GFitsTableLngCol::ascii_format(void) const +{ + // Initialize format string + std::string format; + + // Set type code + format.append("J"); + + // Set width + format.append(str(m_width)); + + // Return format + return format; +} + + +/***********************************************************************//** + * @brief Returns format string of binary table + ***************************************************************************/ +std::string GFitsTableLngCol::binary_format(void) const +{ + // Initialize format string + std::string format; + + // Set number of elements + format.append(str(m_number)); + + // Set type code + format.append("J"); + + // Return format + return format; +} + + /*========================================================================== = = = GFitsTableLngCol friends = diff --git a/src/fits/GFitsTableShtCol.cpp b/src/fits/GFitsTableShtCol.cpp index 53cfb61..9f10168 100644 --- a/src/fits/GFitsTableShtCol.cpp +++ b/src/fits/GFitsTableShtCol.cpp @@ -13,13 +13,15 @@ ***************************************************************************/ /* __ Includes ___________________________________________________________ */ +#include #include "GException.hpp" +#include "GTools.hpp" #include "GFitsTableShtCol.hpp" -#include // cout, cerr /* __ Namespaces _________________________________________________________ */ /* __ Method name definitions ____________________________________________ */ +#define G_SAVE "GFitsTableShtCol::save()" #define G_STRING "GFitsTableShtCol::string(const int&, const int&)" #define G_REAL "GFitsTableShtCol::real(const int&, const int&)" #define G_INTEGER "GFitsTableShtCol::integer(const int&, const int&)" @@ -57,6 +59,26 @@ GFitsTableShtCol::GFitsTableShtCol() : GFitsTableCol() } +/***********************************************************************//** + * @brief Constructor + * + * @param[in] name Name of column. + * @param[in] length Length of column. + * @param[in] size Vector size of column. + ***************************************************************************/ +GFitsTableShtCol::GFitsTableShtCol(const std::string& name, + const int& length, + const int& size) + : GFitsTableCol(name, length, size, 2) +{ + // Initialise class members for clean destruction + init_members(); + + // Return + return; +} + + /*************************************************************************** * Copy constructor * * ----------------------------------------------------------------------- * @@ -128,6 +150,35 @@ GFitsTableShtCol& GFitsTableShtCol::operator= (const GFitsTableShtCol& column) = = ==========================================================================*/ +/***********************************************************************//** + * @brief Save table column into FITS file + * + * @exception GException::fits_hdu_not_found + * Specified HDU not found in FITS file. + ***************************************************************************/ +void GFitsTableShtCol::save(void) +{ + // Continue only if a FITS file is connected + if (m_fitsfile.Fptr != NULL) { + + // Move to the HDU + int status = 0; + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, + &status); + if (status != 0) + throw GException::fits_hdu_not_found(G_SAVE, + (m_fitsfile.HDUposition)+1, + status); + + // Save the column data + // TBD + + } // endif: FITS file was connected + + // Return + return; +} + /*************************************************************************** * Get string value * * ----------------------------------------------------------------------- * @@ -143,8 +194,8 @@ std::string GFitsTableShtCol::string(const int& row, const int& col) 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); + if (col < 0 || col >= m_number) + throw GException::out_of_range(G_STRING, col, 0, m_number-1); // Get index int inx = row * m_repeat + col; @@ -173,8 +224,8 @@ double GFitsTableShtCol::real(const int& row, const int& col) 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); + if (col < 0 || col >= m_number) + throw GException::out_of_range(G_REAL, col, 0, m_number-1); // Get index int inx = row * m_repeat + col; @@ -202,8 +253,8 @@ int GFitsTableShtCol::integer(const int& row, const int& col) 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 (col < 0 || col >= m_number) + throw GException::out_of_range(G_INTEGER, col, 0, m_number-1); // Get index int inx = row * m_repeat + col; @@ -352,7 +403,7 @@ void GFitsTableShtCol::free_members(void) void GFitsTableShtCol::load(void) { // Calculate size of memory - m_size = m_repeat * m_length; + m_size = m_number * m_length; // Allocate memory if (m_data != NULL) delete [] m_data; @@ -371,6 +422,44 @@ void GFitsTableShtCol::load(void) } +/***********************************************************************//** + * @brief Returns format string of ASCII table + ***************************************************************************/ +std::string GFitsTableShtCol::ascii_format(void) const +{ + // Initialize format string + std::string format; + + // Set type code + format.append("I"); + + // Set width + format.append(str(m_width)); + + // Return format + return format; +} + + +/***********************************************************************//** + * @brief Returns format string of binary table + ***************************************************************************/ +std::string GFitsTableShtCol::binary_format(void) const +{ + // Initialize format string + std::string format; + + // Set number of elements + format.append(str(m_number)); + + // Set type code + format.append("I"); + + // Return format + return format; +} + + /*========================================================================== = = = GFitsTableShtCol friends = diff --git a/src/fits/GFitsTableStrCol.cpp b/src/fits/GFitsTableStrCol.cpp index fb45a37..3d3787c 100644 --- a/src/fits/GFitsTableStrCol.cpp +++ b/src/fits/GFitsTableStrCol.cpp @@ -13,13 +13,15 @@ ***************************************************************************/ /* __ Includes ___________________________________________________________ */ +#include #include "GException.hpp" +#include "GTools.hpp" #include "GFitsTableStrCol.hpp" -#include // cout, cerr /* __ Namespaces _________________________________________________________ */ /* __ Method name definitions ____________________________________________ */ +#define G_SAVE "GFitsTableStrCol::save()" #define G_STRING "GFitsTableStrCol::string(const int&, const int&)" #define G_REAL "GFitsTableStrCol::real(const int&, const int&)" #define G_INTEGER "GFitsTableStrCol::integer(const int&, const int&)" @@ -129,6 +131,35 @@ GFitsTableStrCol& GFitsTableStrCol::operator= (const GFitsTableStrCol& column) = = ==========================================================================*/ +/***********************************************************************//** + * @brief Save table column into FITS file + * + * @exception GException::fits_hdu_not_found + * Specified HDU not found in FITS file. + ***************************************************************************/ +void GFitsTableStrCol::save(void) +{ + // Continue only if a FITS file is connected + if (m_fitsfile.Fptr != NULL) { + + // Move to the HDU + int status = 0; + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, + &status); + if (status != 0) + throw GException::fits_hdu_not_found(G_SAVE, + (m_fitsfile.HDUposition)+1, + status); + + // Save the column data + // TBD + + } // endif: FITS file was connected + + // Return + return; +} + /*************************************************************************** * Get string value * * ----------------------------------------------------------------------- * @@ -144,11 +175,11 @@ std::string GFitsTableStrCol::string(const int& row, const int& col) throw GException::out_of_range(G_STRING, row, 0, m_length-1); // Check col value - if (col < 0 || col >= m_num_subs) - throw GException::out_of_range(G_STRING, col, 0, m_num_subs-1); + if (col < 0 || col >= m_number) + throw GException::out_of_range(G_STRING, col, 0, m_number-1); // Get string index - int inx = row * m_num_subs + col; + int inx = row * m_repeat + col; // Assign C string to C++ std::string std::string value; @@ -174,11 +205,11 @@ double GFitsTableStrCol::real(const int& row, const int& col) throw GException::out_of_range(G_STRING, row, 0, m_length-1); // Check col value - if (col < 0 || col >= m_num_subs) - throw GException::out_of_range(G_STRING, col, 0, m_num_subs-1); + if (col < 0 || col >= m_number) + throw GException::out_of_range(G_STRING, col, 0, m_number-1); // Get string index - int inx = row * m_num_subs + col; + int inx = row * m_repeat + col; // Assign C string to double double value = atof(m_data[inx]); @@ -203,11 +234,11 @@ int GFitsTableStrCol::integer(const int& row, const int& col) throw GException::out_of_range(G_STRING, row, 0, m_length-1); // Check col value - if (col < 0 || col >= m_num_subs) - throw GException::out_of_range(G_STRING, col, 0, m_num_subs-1); + if (col < 0 || col >= m_number) + throw GException::out_of_range(G_STRING, col, 0, m_number-1); // Get string index - int inx = row * m_num_subs + col; + int inx = row * m_repeat + col; // Assign C string to int int value = atoi(m_data[inx]); @@ -289,7 +320,6 @@ void GFitsTableStrCol::init_members(void) // Initialise members m_type = __TSTRING; m_size = 0; - m_num_subs = 0; m_data = NULL; m_nulstr = NULL; m_anynul = 0; @@ -309,7 +339,6 @@ void GFitsTableStrCol::copy_members(const GFitsTableStrCol& column) { // Copy string size m_size = column.m_size; - m_num_subs = column.m_num_subs; m_anynul = column.m_anynul; // Copy column data @@ -368,14 +397,8 @@ void GFitsTableStrCol::free_members(void) ***************************************************************************/ void GFitsTableStrCol::load(void) { - // Calculate number of substrings - if (m_repeat == 1) // ASCII tables - m_num_subs = 1; - else // Binary tables - m_num_subs = m_repeat / m_width; - // Calculate total number of strings - m_size = m_num_subs * m_length; + m_size = m_number * m_length; // Free memory free_members(); @@ -393,8 +416,9 @@ void GFitsTableStrCol::load(void) // Load column data int status = 0; - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status); - status = __ffgcvs(&m_fitsfile, m_colnum, 1, 1, m_size, m_nulstr, m_data, + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, + &status); + status = __ffgcvs(&m_fitsfile, m_colnum, 1, 1, m_size, m_nulstr, m_data, &m_anynul, &status); if (status != 0) throw GException::fits_error(G_LOAD, status); @@ -406,6 +430,48 @@ void GFitsTableStrCol::load(void) } +/***********************************************************************//** + * @brief Returns format string of ASCII table + ***************************************************************************/ +std::string GFitsTableStrCol::ascii_format(void) const +{ + // Initialize format string + std::string format; + + // Set type code + format.append("A"); + + // Set width + format.append(str(m_width)); + + // Return format + return format; +} + + +/***********************************************************************//** + * @brief Returns format string of binary table + ***************************************************************************/ +std::string GFitsTableStrCol::binary_format(void) const +{ + // Initialize format string + std::string format; + + // Set number of elements + format.append(str(m_repeat)); + + // Set type code + format.append("A"); + + // If there are substrings then add width of substring + if (m_repeat > m_width) + format.append(str(m_width)); + + // Return format + return format; +} + + /*========================================================================== = = = GFitsTableStrCol friends = diff --git a/src/rsp/GLATResponse.cpp b/src/rsp/GLATResponse.cpp index 472f162..39c8ae7 100644 --- a/src/rsp/GLATResponse.cpp +++ b/src/rsp/GLATResponse.cpp @@ -707,7 +707,7 @@ GVector GLATResponse::get_fits_vector(const GFitsHDU* hdu, const std::string& co throw GException::fits_column_not_found(G_GET_FITS_VECTOR, colname); // Determine number of entries - int num = ptr->repeat(); + int num = ptr->number(); // Load data into vector GVector data(num); diff --git a/test/test_GFits.cpp b/test/test_GFits.cpp index 9caf478..be4576e 100644 --- a/test/test_GFits.cpp +++ b/test/test_GFits.cpp @@ -372,28 +372,28 @@ void test_create(void) cout << "."; // Attach binary table -cout << "start" << endl; try { // Re-open FITS file GFits fits; fits.open("test.fits"); -cout << "1" << endl; // Create binary Table with 10 rows int nrows = 10; GFitsBinTable table = GFitsBinTable(nrows); - GFitsTableDblCol first = GFitsTableDblCol(nrows); - GFitsTableDblCol second = GFitsTableDblCol(nrows); -cout << "2" << endl; + GFitsTableDblCol first = GFitsTableDblCol("First", nrows); + GFitsTableDblCol second = GFitsTableDblCol("Second", nrows); + first(9) = 99.0; + second(0) = -99.0; + cout << endl << first << endl; + cout << second << endl; table.append_column(first); -cout << "3" << endl; table.append_column(second); cout << table; // Create HDU and append to FILE file GFitsHDU hdu(table); fits.append_hdu(hdu); -// cout << fits; + // cout << fits; // Save FITS file fits.save(); -- libgit2 0.21.4