Commit 3fb167e4ea7cb88bc958ba13ed3fa401397a257b
1 parent
5e0835f7
implement table column format definition for saving and new column constructor interface
Showing
21 changed files
with
696 additions
and
237 deletions
include/GException.hpp
| ... | ... | @@ -84,7 +84,8 @@ public: |
| 84 | 84 | // Matrix dimensions mismatch |
| 85 | 85 | class matrix_mismatch : public GExceptionHandler { |
| 86 | 86 | public: |
| 87 | - matrix_mismatch(string origin, int rows1, int cols1, int rows2, int cols2); | |
| 87 | + matrix_mismatch(string origin, int rows1, int cols1, int rows2, | |
| 88 | + int cols2); | |
| 88 | 89 | }; |
| 89 | 90 | |
| 90 | 91 | // Matrix not rectangular |
| ... | ... | @@ -190,6 +191,12 @@ public: |
| 190 | 191 | fits_invalid_type(string origin, string message); |
| 191 | 192 | }; |
| 192 | 193 | |
| 194 | + // FITS unknown table type | |
| 195 | + class fits_unknown_tabtype : public GExceptionHandler { | |
| 196 | + public: | |
| 197 | + fits_unknown_tabtype(string origin, int type); | |
| 198 | + }; | |
| 199 | + | |
| 193 | 200 | // FITS unknown column type |
| 194 | 201 | class fits_unknown_coltype : public GExceptionHandler { |
| 195 | 202 | public: | ... | ... |
include/GFitsCfitsio.hpp
| ... | ... | @@ -51,6 +51,7 @@ |
| 51 | 51 | #define __ffinit(A, B, C) ffinit(A, B, C) |
| 52 | 52 | #define __ffopen(A, B, C, D) ffopen(A, B, C, D) |
| 53 | 53 | #define __ffmahd(A, B, C, D) ffmahd(A, B, C, D) |
| 54 | +#define __ffpcn(A, B, C, D, E, F, G, H, I) ffpcn(A, B, C, D, E, F, G, H, I) | |
| 54 | 55 | #define __ffpcom(A, B, C) ffpcom(A, B, C) |
| 55 | 56 | #define __ffphis(A, B, C) ffphis(A, B, C) |
| 56 | 57 | #define __ffpss(A, B, C, D, E, F) ffpss(A, B, C, D, E, F) |
| ... | ... | @@ -101,6 +102,7 @@ typedef fitsfile __fitsfile; |
| 101 | 102 | #define __fficol(A, B, C, D, E) __dummy() |
| 102 | 103 | #define __ffinit(A, B, C) __dummy() |
| 103 | 104 | #define __ffmahd(A, B, C, D) __dummy() |
| 105 | +#define __ffpcn(A, B, C, D, E, F, G, H, I) __dummy() | |
| 104 | 106 | #define __ffopen(A, B, C, D) __dummy() |
| 105 | 107 | #define __ffpcom(A, B, C) __dummy() |
| 106 | 108 | #define __ffphis(A, B, C) __dummy() | ... | ... |
include/GFitsTableCol.hpp
| ... | ... | @@ -38,12 +38,13 @@ class GFitsTableCol { |
| 38 | 38 | friend class GFitsTable; |
| 39 | 39 | |
| 40 | 40 | // I/O friends |
| 41 | - friend ostream& operator<< (ostream& os, const GFitsTableCol& column); | |
| 41 | +// friend ostream& operator<< (ostream& os, const GFitsTableCol& column); | |
| 42 | 42 | |
| 43 | 43 | public: |
| 44 | 44 | // Constructors and destructors |
| 45 | 45 | GFitsTableCol(); |
| 46 | - GFitsTableCol(const int& length, const int& size = 1); | |
| 46 | + GFitsTableCol(const std::string& name, const int& length, | |
| 47 | + const int& number, const int& width); | |
| 47 | 48 | GFitsTableCol(const GFitsTableCol& column); |
| 48 | 49 | virtual ~GFitsTableCol(); |
| 49 | 50 | |
| ... | ... | @@ -64,24 +65,30 @@ public: |
| 64 | 65 | int type(void); |
| 65 | 66 | int repeat(void); |
| 66 | 67 | int width(void); |
| 68 | + int number(void); | |
| 67 | 69 | int length(void); |
| 68 | 70 | |
| 69 | 71 | protected: |
| 70 | 72 | // Protected data area |
| 71 | 73 | std::string m_name; //!< Column name |
| 72 | - std::string m_format; //!< Column format | |
| 73 | 74 | std::string m_unit; //!< Column unit |
| 74 | - int m_colnum; //!< Column number (starting from 1). | |
| 75 | + int m_colnum; //!< @brief Column number (starting from 1). | |
| 75 | 76 | //!< This parameter is used to signal if a |
| 76 | 77 | //!< table column corresponds to a FITS file |
| 77 | 78 | //!< column. If it is set to 0 there is no |
| 78 | 79 | //!< correspondance. |
| 79 | 80 | int m_type; //!< Column type |
| 80 | 81 | int m_repeat; //!< Repeat value of column |
| 81 | - int m_width; //!< Width of column | |
| 82 | + int m_width; //!< Width of single column element | |
| 83 | + int m_number; //!< Number of elements in column | |
| 84 | + //!< m_number = m_repeat / m_width | |
| 82 | 85 | int m_length; //!< Length of column |
| 83 | 86 | __fitsfile m_fitsfile; //!< FITS file associated with column |
| 84 | 87 | |
| 88 | + // Protected methods | |
| 89 | + virtual std::string ascii_format(void) const = 0; | |
| 90 | + virtual std::string binary_format(void) const = 0; | |
| 91 | + | |
| 85 | 92 | private: |
| 86 | 93 | // Private methods |
| 87 | 94 | void init_members(void); | ... | ... |
include/GFitsTableDblCol.hpp
| ... | ... | @@ -38,10 +38,14 @@ |
| 38 | 38 | ***************************************************************************/ |
| 39 | 39 | class GFitsTableDblCol : public GFitsTableCol { |
| 40 | 40 | |
| 41 | + // I/O friends | |
| 42 | + friend ostream& operator<< (ostream& os, const GFitsTableDblCol& column); | |
| 43 | + | |
| 41 | 44 | public: |
| 42 | 45 | // Constructors and destructors |
| 43 | 46 | GFitsTableDblCol(); |
| 44 | - GFitsTableDblCol(const int& length, const int& size = 1); | |
| 47 | + GFitsTableDblCol(const std::string& name, const int& length, | |
| 48 | + const int& size = 1); | |
| 45 | 49 | GFitsTableDblCol(const GFitsTableDblCol& column); |
| 46 | 50 | virtual ~GFitsTableDblCol(); |
| 47 | 51 | |
| ... | ... | @@ -61,13 +65,15 @@ public: |
| 61 | 65 | |
| 62 | 66 | private: |
| 63 | 67 | // Private methods |
| 64 | - void init_members(void); | |
| 65 | - void copy_members(const GFitsTableDblCol& column); | |
| 66 | - void free_members(void); | |
| 67 | - void fetch_data(void); | |
| 68 | + void init_members(void); | |
| 69 | + void copy_members(const GFitsTableDblCol& column); | |
| 70 | + void free_members(void); | |
| 71 | + void fetch_data(void); | |
| 72 | + std::string ascii_format(void) const; | |
| 73 | + std::string binary_format(void) const; | |
| 68 | 74 | |
| 69 | 75 | // Private data area |
| 70 | - int m_size; //!< Size of data area | |
| 76 | + int m_size; //!< Size of allocated data area (0 if offline) | |
| 71 | 77 | double* m_data; //!< Data area |
| 72 | 78 | double* m_nulval; //!< NULL value |
| 73 | 79 | int m_anynul; //!< Number of NULLs encountered | ... | ... |
include/GFitsTableFltCol.hpp
| ... | ... | @@ -41,6 +41,8 @@ class GFitsTableFltCol : public GFitsTableCol { |
| 41 | 41 | public: |
| 42 | 42 | // Constructors and destructors |
| 43 | 43 | GFitsTableFltCol(); |
| 44 | + GFitsTableFltCol(const std::string& name, const int& length, | |
| 45 | + const int& size = 1); | |
| 44 | 46 | GFitsTableFltCol(const GFitsTableFltCol& column); |
| 45 | 47 | virtual ~GFitsTableFltCol(); |
| 46 | 48 | |
| ... | ... | @@ -58,10 +60,12 @@ public: |
| 58 | 60 | |
| 59 | 61 | private: |
| 60 | 62 | // Private methods |
| 61 | - void init_members(void); | |
| 62 | - void copy_members(const GFitsTableFltCol& column); | |
| 63 | - void free_members(void); | |
| 64 | - void load(void); | |
| 63 | + void init_members(void); | |
| 64 | + void copy_members(const GFitsTableFltCol& column); | |
| 65 | + void free_members(void); | |
| 66 | + void load(void); | |
| 67 | + std::string ascii_format(void) const; | |
| 68 | + std::string binary_format(void) const; | |
| 65 | 69 | |
| 66 | 70 | // Private data area |
| 67 | 71 | int m_size; //!< Size of data area | ... | ... |
include/GFitsTableLngCol.hpp
| ... | ... | @@ -41,6 +41,8 @@ class GFitsTableLngCol : public GFitsTableCol { |
| 41 | 41 | public: |
| 42 | 42 | // Constructors and destructors |
| 43 | 43 | GFitsTableLngCol(); |
| 44 | + GFitsTableLngCol(const std::string& name, const int& length, | |
| 45 | + const int& size = 1); | |
| 44 | 46 | GFitsTableLngCol(const GFitsTableLngCol& column); |
| 45 | 47 | virtual ~GFitsTableLngCol(); |
| 46 | 48 | |
| ... | ... | @@ -60,10 +62,12 @@ public: |
| 60 | 62 | |
| 61 | 63 | private: |
| 62 | 64 | // Private methods |
| 63 | - void init_members(void); | |
| 64 | - void copy_members(const GFitsTableLngCol& column); | |
| 65 | - void free_members(void); | |
| 66 | - void fetch_data(void); | |
| 65 | + void init_members(void); | |
| 66 | + void copy_members(const GFitsTableLngCol& column); | |
| 67 | + void free_members(void); | |
| 68 | + void fetch_data(void); | |
| 69 | + std::string ascii_format(void) const; | |
| 70 | + std::string binary_format(void) const; | |
| 67 | 71 | |
| 68 | 72 | // Private data area |
| 69 | 73 | int m_size; //!< Size of data area | ... | ... |
include/GFitsTableShtCol.hpp
| ... | ... | @@ -32,6 +32,8 @@ class GFitsTableShtCol : public GFitsTableCol { |
| 32 | 32 | public: |
| 33 | 33 | // Constructors and destructors |
| 34 | 34 | GFitsTableShtCol(); |
| 35 | + GFitsTableShtCol(const std::string& name, const int& length, | |
| 36 | + const int& size = 1); | |
| 35 | 37 | GFitsTableShtCol(const GFitsTableShtCol& column); |
| 36 | 38 | virtual ~GFitsTableShtCol(); |
| 37 | 39 | |
| ... | ... | @@ -53,10 +55,12 @@ public: |
| 53 | 55 | |
| 54 | 56 | private: |
| 55 | 57 | // Private methods |
| 56 | - void init_members(void); | |
| 57 | - void copy_members(const GFitsTableShtCol& column); | |
| 58 | - void free_members(void); | |
| 59 | - void load(void); | |
| 58 | + void init_members(void); | |
| 59 | + void copy_members(const GFitsTableShtCol& column); | |
| 60 | + void free_members(void); | |
| 61 | + void load(void); | |
| 62 | + std::string ascii_format(void) const; | |
| 63 | + std::string binary_format(void) const; | |
| 60 | 64 | |
| 61 | 65 | // Private data area |
| 62 | 66 | int m_size; // Size of data area | ... | ... |
include/GFitsTableStrCol.hpp
| ... | ... | @@ -32,6 +32,8 @@ class GFitsTableStrCol : public GFitsTableCol { |
| 32 | 32 | public: |
| 33 | 33 | // Constructors and destructors |
| 34 | 34 | GFitsTableStrCol(); |
| 35 | + GFitsTableStrCol(const std::string& name, const int& length, | |
| 36 | + const int& size = 1); | |
| 35 | 37 | GFitsTableStrCol(const GFitsTableStrCol& column); |
| 36 | 38 | ~GFitsTableStrCol(); |
| 37 | 39 | |
| ... | ... | @@ -53,14 +55,15 @@ public: |
| 53 | 55 | |
| 54 | 56 | private: |
| 55 | 57 | // Private methods |
| 56 | - void init_members(void); | |
| 57 | - void copy_members(const GFitsTableStrCol& column); | |
| 58 | - void free_members(void); | |
| 59 | - void load(void); | |
| 58 | + void init_members(void); | |
| 59 | + void copy_members(const GFitsTableStrCol& column); | |
| 60 | + void free_members(void); | |
| 61 | + void load(void); | |
| 62 | + std::string ascii_format(void) const; | |
| 63 | + std::string binary_format(void) const; | |
| 60 | 64 | |
| 61 | 65 | // Private data area |
| 62 | 66 | int m_size; // Total number of strings |
| 63 | - int m_num_subs; // Number of substrings | |
| 64 | 67 | char** m_data; // Data area |
| 65 | 68 | char* m_nulstr; // NULL string |
| 66 | 69 | int m_anynul; // Number of NULLs encountered | ... | ... |
src/GException.cpp
| ... | ... | @@ -413,6 +413,20 @@ GException::fits_invalid_type::fits_invalid_type(string origin, |
| 413 | 413 | |
| 414 | 414 | |
| 415 | 415 | /***********************************************************************//** |
| 416 | + * @brief FITS error: Table type is unknow | |
| 417 | + * | |
| 418 | + * @param[in] origin Method that throws the error. | |
| 419 | + * @param[in] type Specified table type. | |
| 420 | + ***************************************************************************/ | |
| 421 | +GException::fits_unknown_tabtype::fits_unknown_tabtype(string origin, | |
| 422 | + int type) | |
| 423 | +{ | |
| 424 | + m_origin = origin; | |
| 425 | + m_message = "Table type '" + str(type) + "' is unknown"; | |
| 426 | +} | |
| 427 | + | |
| 428 | + | |
| 429 | +/***********************************************************************//** | |
| 416 | 430 | * @brief FITS error: Column type is unknown |
| 417 | 431 | * |
| 418 | 432 | * @param[in] origin Method that throws the error. | ... | ... |
src/GTools.cpp
| ... | ... | @@ -12,16 +12,18 @@ |
| 12 | 12 | ***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | /* __ Includes ___________________________________________________________ */ |
| 15 | +#include <sstream> | |
| 15 | 16 | #include "GTools.hpp" |
| 16 | 17 | |
| 17 | 18 | /* __ Namespaces _________________________________________________________ */ |
| 18 | 19 | |
| 19 | 20 | |
| 20 | -/*************************************************************************** | |
| 21 | - * Strip leading and trailing whitespace from string * | |
| 22 | - * ----------------------------------------------------------------------- * | |
| 21 | +/***********************************************************************//** | |
| 22 | + * @brief Strip leading and trailing whitespace from string | |
| 23 | + * | |
| 24 | + * @param[in] arg String which should be stripped of whitespace. | |
| 23 | 25 | ***************************************************************************/ |
| 24 | -std::string strip_whitespace(const std::string arg) | |
| 26 | +std::string strip_whitespace(const std::string& arg) | |
| 25 | 27 | { |
| 26 | 28 | // Return empty string if argument is empty |
| 27 | 29 | if (arg.empty()) |
| ... | ... | @@ -40,3 +42,17 @@ std::string strip_whitespace(const std::string arg) |
| 40 | 42 | // Return result |
| 41 | 43 | return result; |
| 42 | 44 | } |
| 45 | + | |
| 46 | + | |
| 47 | +/***********************************************************************//** | |
| 48 | + * @brief Convert integer value into string | |
| 49 | + * | |
| 50 | + * @param[in] value Value to be converted into a string. | |
| 51 | + ***************************************************************************/ | |
| 52 | +std::string str(const int& value) | |
| 53 | +{ | |
| 54 | + std::ostringstream s_value; | |
| 55 | + s_value << value; | |
| 56 | + return s_value.str(); | |
| 57 | +} | |
| 58 | + | ... | ... |
src/GTools.hpp
| ... | ... | @@ -22,6 +22,7 @@ |
| 22 | 22 | /* __ Namespaces _________________________________________________________ */ |
| 23 | 23 | |
| 24 | 24 | /* __ Prototypes ________________________________________________________ */ |
| 25 | -std::string strip_whitespace(const std::string arg); | |
| 25 | +std::string strip_whitespace(const std::string& arg); | |
| 26 | +std::string str(const int& value); | |
| 26 | 27 | |
| 27 | 28 | #endif /* GTOOLS_HPP */ | ... | ... |
src/fits/GFitsBinTable.cpp
| ... | ... | @@ -15,13 +15,7 @@ |
| 15 | 15 | /* __ Includes ___________________________________________________________ */ |
| 16 | 16 | #include <iostream> |
| 17 | 17 | #include "GException.hpp" |
| 18 | -//#include "GTools.hpp" | |
| 19 | 18 | #include "GFitsBinTable.hpp" |
| 20 | -//#include "GFitsTableStrCol.hpp" | |
| 21 | -//#include "GFitsTableShtCol.hpp" | |
| 22 | -//#include "GFitsTableLngCol.hpp" | |
| 23 | -//#include "GFitsTableFltCol.hpp" | |
| 24 | -//#include "GFitsTableDblCol.hpp" | |
| 25 | 19 | |
| 26 | 20 | /* __ Namespaces _________________________________________________________ */ |
| 27 | 21 | |
| ... | ... | @@ -33,6 +27,8 @@ |
| 33 | 27 | |
| 34 | 28 | /* __ Debug definitions __________________________________________________ */ |
| 35 | 29 | |
| 30 | +/* __ Prototypes of local functions ______________________________________ */ | |
| 31 | + | |
| 36 | 32 | |
| 37 | 33 | /*========================================================================== |
| 38 | 34 | = = |
| ... | ... | @@ -57,7 +53,6 @@ GFitsBinTable::GFitsBinTable() : GFitsTable() |
| 57 | 53 | * @brief Constructor |
| 58 | 54 | * |
| 59 | 55 | * @param[in] nrows Number of rows in table |
| 60 | - * @param[in] ncols Number of columns in table | |
| 61 | 56 | ***************************************************************************/ |
| 62 | 57 | GFitsBinTable::GFitsBinTable(int nrows) : GFitsTable(nrows) |
| 63 | 58 | { |
| ... | ... | @@ -145,7 +140,7 @@ GFitsBinTable& GFitsBinTable::operator= (const GFitsBinTable& table) |
| 145 | 140 | /***********************************************************************//** |
| 146 | 141 | * @brief Clone binary table |
| 147 | 142 | ***************************************************************************/ |
| 148 | -GFitsBinTable* GFitsBinTable::clone(void) const | |
| 143 | +GFitsBinTable* GFitsBinTable::clone(void) const | |
| 149 | 144 | { |
| 150 | 145 | return new GFitsBinTable(*this); |
| 151 | 146 | } | ... | ... |
src/fits/GFitsTable.cpp
| ... | ... | @@ -32,6 +32,7 @@ |
| 32 | 32 | #define G_INSERT_COLUMN "GFitsTable::insert_column(int, GFitsTableCol*)" |
| 33 | 33 | #define G_COLUMN1 "GFitsTable::column(const std::string&)" |
| 34 | 34 | #define G_COLUMN2 "GFitsTable::column(const int&)" |
| 35 | +#define G_GET_TFORM "GFitsTable::get_tform(const int&)" | |
| 35 | 36 | |
| 36 | 37 | /* __ Macros _____________________________________________________________ */ |
| 37 | 38 | |
| ... | ... | @@ -258,6 +259,13 @@ void GFitsTable::open(__fitsfile* fptr) |
| 258 | 259 | m_columns[i]->m_length = m_rows; |
| 259 | 260 | m_columns[i]->connect(fptr); |
| 260 | 261 | |
| 262 | + // Extract column vector size | |
| 263 | + if (m_columns[i]->m_repeat == 1) // ASCII tables | |
| 264 | + m_columns[i]->m_number = 1; | |
| 265 | + else // Binary tables | |
| 266 | + m_columns[i]->m_number = m_columns[i]->m_repeat / | |
| 267 | + m_columns[i]->m_width; | |
| 268 | + | |
| 261 | 269 | } // endfor: looped over all columns |
| 262 | 270 | |
| 263 | 271 | // Return |
| ... | ... | @@ -283,6 +291,8 @@ void GFitsTable::open(__fitsfile* fptr) |
| 283 | 291 | * columns need to have identical lengths to be saved into a FITS table. |
| 284 | 292 | * All columns with a length of zero will be excluded from saving, and if |
| 285 | 293 | * they exist in the FITS file, they will be removed from the file. |
| 294 | + * | |
| 295 | + * IMPLEMENTION NOT YET COMPLETED (ROW ADDING/DELETION MISSING) | |
| 286 | 296 | ***************************************************************************/ |
| 287 | 297 | void GFitsTable::save(void) |
| 288 | 298 | { |
| ... | ... | @@ -387,7 +397,7 @@ void GFitsTable::save(void) |
| 387 | 397 | } |
| 388 | 398 | |
| 389 | 399 | // If the table length differs from number of rows in the FITS file |
| 390 | - // then ???? | |
| 400 | + // then re-adjust FITS table length | |
| 391 | 401 | // TBD |
| 392 | 402 | |
| 393 | 403 | // Update all columns. The 'm_colnum' field specifies where in the |
| ... | ... | @@ -403,7 +413,6 @@ void GFitsTable::save(void) |
| 403 | 413 | // FITS table and link column to table. |
| 404 | 414 | if (m_columns[i]->m_colnum == 0) { |
| 405 | 415 | |
| 406 | -cout << "needs appending of column to FITS file " << num_cols << endl; | |
| 407 | 416 | // Increment number of columns in FITS file |
| 408 | 417 | num_cols++; |
| 409 | 418 | |
| ... | ... | @@ -420,10 +429,8 @@ cout << "needs appending of column to FITS file " << num_cols << endl; |
| 420 | 429 | } // endif: column appended to FITS file |
| 421 | 430 | |
| 422 | 431 | // Now write column into FITS file (only if length is positive) |
| 423 | - if (m_columns[i]->length() > 0) { | |
| 424 | -cout << "write column into " << m_columns[i]->m_colnum << endl; | |
| 425 | - //m_columns[i]->save(); | |
| 426 | - } | |
| 432 | + if (m_columns[i]->length() > 0) | |
| 433 | + m_columns[i]->save(); | |
| 427 | 434 | |
| 428 | 435 | } // endif: column was valid |
| 429 | 436 | } // endfor: looped over all table columns |
| ... | ... | @@ -503,8 +510,6 @@ void GFitsTable::append_column(GFitsTableCol& column) |
| 503 | 510 | * @exception GException::fits_bad_col_length |
| 504 | 511 | * The length of the column is incompatible with the number of |
| 505 | 512 | * rows in the table. |
| 506 | - * @exception GException::fits_unknown_coltype | |
| 507 | - * FITS column is of unknown type. | |
| 508 | 513 | * |
| 509 | 514 | * A column will be inserted at position 'colnum' of the table. If the |
| 510 | 515 | * 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) |
| 573 | 578 | |
| 574 | 579 | } // endelse: we made space to insert a column |
| 575 | 580 | |
| 576 | - // Type dependent copy of column | |
| 577 | - switch (column.m_type) { | |
| 578 | - case __TSTRING: | |
| 579 | - m_columns[colnum] = new GFitsTableStrCol; | |
| 580 | - *m_columns[colnum] = column; | |
| 581 | - break; | |
| 582 | - case __TSHORT: | |
| 583 | - m_columns[colnum] = new GFitsTableShtCol; | |
| 584 | - *m_columns[colnum] = column; | |
| 585 | - break; | |
| 586 | - case __TLONG: | |
| 587 | - m_columns[colnum] = new GFitsTableLngCol; | |
| 588 | - *m_columns[colnum] = column; | |
| 589 | - break; | |
| 590 | - case __TFLOAT: | |
| 591 | - m_columns[colnum] = new GFitsTableFltCol; | |
| 592 | - *m_columns[colnum] = column; | |
| 593 | - break; | |
| 594 | - case __TDOUBLE: | |
| 595 | - m_columns[colnum] = new GFitsTableDblCol; | |
| 596 | - *m_columns[colnum] = column; | |
| 597 | - break; | |
| 598 | - default: | |
| 599 | - throw GException::fits_unknown_coltype(G_INSERT_COLUMN, column.m_type); | |
| 600 | - break; | |
| 601 | - } | |
| 581 | + // Copy column by cloning it | |
| 582 | + m_columns[colnum] = column.clone(); | |
| 602 | 583 | |
| 603 | - // Set column number (this is important to known from which column in the | |
| 604 | - // FITS file the data should be read | |
| 605 | - //// NO NO NO !!! Only for columns that exist in the FITS file !!! | |
| 606 | - //// m_columns[colnum]->m_colnum = colnum + 1; | |
| 607 | 584 | // Reset column number since column does not already exist in FITS |
| 608 | 585 | // file |
| 609 | 586 | m_columns[colnum]->m_colnum = 0; |
| ... | ... | @@ -836,6 +813,9 @@ char* GFitsTable::get_ttype(const int& colnum) const |
| 836 | 813 | * |
| 837 | 814 | * @param[in] colnum Column number for which format is to be returned |
| 838 | 815 | * |
| 816 | + * @exception GException::fits_unknown_tabtype | |
| 817 | + * Table is neither ASCII nor Binary. | |
| 818 | + * | |
| 839 | 819 | * This methods allocates memory for the character string that holds the |
| 840 | 820 | * column format. The client has to de-allocate this memory after usage. |
| 841 | 821 | * 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 |
| 846 | 826 | char* ptr = NULL; |
| 847 | 827 | |
| 848 | 828 | // Get type only if column exists |
| 849 | - if (m_columns != NULL && colnum >=0 && colnum < m_cols && | |
| 829 | + if (m_columns != NULL && colnum >=0 && colnum < m_cols && | |
| 850 | 830 | m_columns[colnum] != NULL) { |
| 851 | - int size = m_columns[colnum]->m_format.length(); | |
| 852 | - ptr = new char[size+1]; | |
| 853 | - strncpy(ptr, m_columns[colnum]->m_format.c_str(), size); | |
| 831 | + | |
| 832 | + // Get table type specific format | |
| 833 | + int size; | |
| 834 | + switch (m_type) { | |
| 835 | + case 1: | |
| 836 | + size = m_columns[colnum]->ascii_format().length(); | |
| 837 | + ptr = new char[size+1]; | |
| 838 | + strncpy(ptr, m_columns[colnum]->ascii_format().c_str(), size); | |
| 839 | + break; | |
| 840 | + case 2: | |
| 841 | + size = m_columns[colnum]->binary_format().length(); | |
| 842 | + ptr = new char[size+1]; | |
| 843 | + strncpy(ptr, m_columns[colnum]->binary_format().c_str(), size); | |
| 844 | + break; | |
| 845 | + default: | |
| 846 | + throw GException::fits_unknown_tabtype(G_GET_TFORM, m_type); | |
| 847 | + break; | |
| 848 | + } | |
| 854 | 849 | ptr[size] = '\0'; |
| 855 | 850 | } |
| 856 | 851 | |
| ... | ... | @@ -919,8 +914,28 @@ ostream& operator<< (ostream& os, const GFitsTable& table) |
| 919 | 914 | os << " Number of columns .........: " << table.m_cols << endl; |
| 920 | 915 | if (table.m_columns != NULL) { |
| 921 | 916 | for (int i = 0; i < table.m_cols; ++i) { |
| 922 | - if (table.m_columns[i] != NULL) | |
| 923 | - os << " " << *(table.m_columns[i]); | |
| 917 | + if (table.m_columns[i] != NULL) { | |
| 918 | + switch (table.m_columns[i]->type()) { | |
| 919 | + case __TSTRING: | |
| 920 | + os << " column " << i << " no << operator" << endl; | |
| 921 | + break; | |
| 922 | + case __TSHORT: | |
| 923 | + os << " column " << i << " no << operator" << endl; | |
| 924 | + break; | |
| 925 | + case __TLONG: | |
| 926 | + os << " column " << i << " no << operator" << endl; | |
| 927 | + break; | |
| 928 | + case __TFLOAT: | |
| 929 | + os << " column " << i << " no << operator" << endl; | |
| 930 | + break; | |
| 931 | + case __TDOUBLE: | |
| 932 | + os << " " << *((GFitsTableDblCol*)table.m_columns[i]) | |
| 933 | + << endl; | |
| 934 | + break; | |
| 935 | + default: | |
| 936 | + break; | |
| 937 | + } | |
| 938 | + } | |
| 924 | 939 | else |
| 925 | 940 | os << " column " << i << " undefined" << endl; |
| 926 | 941 | } | ... | ... |
src/fits/GFitsTableCol.cpp
| ... | ... | @@ -50,17 +50,30 @@ GFitsTableCol::GFitsTableCol() |
| 50 | 50 | /***********************************************************************//** |
| 51 | 51 | * @brief Constructor |
| 52 | 52 | * |
| 53 | + * @param[in] name Name of column. | |
| 53 | 54 | * @param[in] length Length of column. |
| 54 | - * @param[in] size Vector size of column. | |
| 55 | + * @param[in] number Vector size of column. | |
| 56 | + * @param[in] width Width of single column element. | |
| 57 | + * | |
| 58 | + * Construct column instance from name, length, vector size and column width. | |
| 59 | + * The repeat value, required for binary tables, is calculated internally. | |
| 55 | 60 | ***************************************************************************/ |
| 56 | -GFitsTableCol::GFitsTableCol(const int& length, const int& size) | |
| 61 | +GFitsTableCol::GFitsTableCol(const std::string& name, | |
| 62 | + const int& length, | |
| 63 | + const int& number, | |
| 64 | + const int& width) | |
| 57 | 65 | { |
| 58 | 66 | // Initialise class members for clean destruction |
| 59 | 67 | init_members(); |
| 60 | 68 | |
| 61 | - // Set column length and vector size | |
| 69 | + // Store attributes | |
| 70 | + m_name = name; | |
| 62 | 71 | m_length = length; |
| 63 | - m_repeat = size; | |
| 72 | + m_number = number; | |
| 73 | + m_width = width; | |
| 74 | + | |
| 75 | + // Calculate repeat value (only used for binary table!) | |
| 76 | + m_repeat = m_number * m_width; | |
| 64 | 77 | |
| 65 | 78 | // Return |
| 66 | 79 | return; |
| ... | ... | @@ -196,7 +209,7 @@ int GFitsTableCol::type(void) |
| 196 | 209 | |
| 197 | 210 | |
| 198 | 211 | /***********************************************************************//** |
| 199 | - * @brief Get column repeat value | |
| 212 | + * @brief Get column repeat value (only used for binary tables) | |
| 200 | 213 | ***************************************************************************/ |
| 201 | 214 | int GFitsTableCol::repeat(void) |
| 202 | 215 | { |
| ... | ... | @@ -206,16 +219,26 @@ int GFitsTableCol::repeat(void) |
| 206 | 219 | |
| 207 | 220 | |
| 208 | 221 | /***********************************************************************//** |
| 209 | - * @brief Get column width | |
| 222 | + * @brief Get width of one element in column | |
| 210 | 223 | ***************************************************************************/ |
| 211 | 224 | int GFitsTableCol::width(void) |
| 212 | 225 | { |
| 213 | - // Return column width | |
| 226 | + // Return width of one element in column | |
| 214 | 227 | return m_width; |
| 215 | 228 | } |
| 216 | 229 | |
| 217 | 230 | |
| 218 | 231 | /***********************************************************************//** |
| 232 | + * @brief Get number of elements in a column | |
| 233 | + ***************************************************************************/ | |
| 234 | +int GFitsTableCol::number(void) | |
| 235 | +{ | |
| 236 | + // Return number of elements in a column | |
| 237 | + return m_number; | |
| 238 | +} | |
| 239 | + | |
| 240 | + | |
| 241 | +/***********************************************************************//** | |
| 219 | 242 | * @brief Get column length |
| 220 | 243 | ***************************************************************************/ |
| 221 | 244 | int GFitsTableCol::length(void) |
| ... | ... | @@ -238,12 +261,12 @@ void GFitsTableCol::init_members(void) |
| 238 | 261 | { |
| 239 | 262 | // Initialise members |
| 240 | 263 | m_name.clear(); |
| 241 | - m_format.clear(); | |
| 242 | 264 | m_unit.clear(); |
| 243 | 265 | m_colnum = 0; |
| 244 | 266 | m_type = 0; |
| 245 | 267 | m_repeat = 0; |
| 246 | 268 | m_width = 0; |
| 269 | + m_number = 0; | |
| 247 | 270 | m_length = 0; |
| 248 | 271 | m_fitsfile.HDUposition = 0; |
| 249 | 272 | m_fitsfile.Fptr = NULL; |
| ... | ... | @@ -262,12 +285,12 @@ void GFitsTableCol::copy_members(const GFitsTableCol& column) |
| 262 | 285 | { |
| 263 | 286 | // Copy attributes |
| 264 | 287 | m_name = column.m_name; |
| 265 | - m_format = column.m_format; | |
| 266 | 288 | m_unit = column.m_unit; |
| 267 | 289 | m_colnum = column.m_colnum; |
| 268 | 290 | m_type = column.m_type; |
| 269 | 291 | m_repeat = column.m_repeat; |
| 270 | 292 | m_width = column.m_width; |
| 293 | + m_number = column.m_number; | |
| 271 | 294 | m_length = column.m_length; |
| 272 | 295 | m_fitsfile = column.m_fitsfile; |
| 273 | 296 | |
| ... | ... | @@ -312,74 +335,6 @@ void GFitsTableCol::connect(__fitsfile* fptr) |
| 312 | 335 | = = |
| 313 | 336 | ==========================================================================*/ |
| 314 | 337 | |
| 315 | -/***********************************************************************//** | |
| 316 | - * @brief Output operator | |
| 317 | - * | |
| 318 | - * @param[in] os Output stream | |
| 319 | - * @param[in] column Column to put in output stream | |
| 320 | - ***************************************************************************/ | |
| 321 | -ostream& operator<< (ostream& os, const GFitsTableCol& column) | |
| 322 | -{ | |
| 323 | - // Put header in stream | |
| 324 | - os << "'" << column.m_name << "'"; | |
| 325 | - os << " [" << column.m_colnum << "] "; | |
| 326 | - | |
| 327 | - // Set column type | |
| 328 | - switch (column.m_type) { | |
| 329 | - case 1: | |
| 330 | - os << "TBIT"; | |
| 331 | - break; | |
| 332 | - case 11: | |
| 333 | - os << "TBYTE"; | |
| 334 | - break; | |
| 335 | - case 14: | |
| 336 | - os << "TLOGICAL"; | |
| 337 | - break; | |
| 338 | - case 16: | |
| 339 | - os << "TSTRING"; | |
| 340 | - break; | |
| 341 | - case 21: | |
| 342 | - os << "TSHORT"; | |
| 343 | - break; | |
| 344 | - case 31: | |
| 345 | - os << "TINT"; | |
| 346 | - break; | |
| 347 | - case 41: | |
| 348 | - os << "TLONG"; | |
| 349 | - break; | |
| 350 | - case 42: | |
| 351 | - os << "TFLOAT"; | |
| 352 | - break; | |
| 353 | - case 81: | |
| 354 | - os << "TLONGLONG"; | |
| 355 | - break; | |
| 356 | - case 82: | |
| 357 | - os << "TDOUBLE"; | |
| 358 | - break; | |
| 359 | - case 83: | |
| 360 | - os << "TCOMPLEX"; | |
| 361 | - break; | |
| 362 | - case 163: | |
| 363 | - os << "TDBLCOMPLEX"; | |
| 364 | - break; | |
| 365 | - default: | |
| 366 | - os << "<unknown type>"; | |
| 367 | - break; | |
| 368 | - } | |
| 369 | - | |
| 370 | - // Set vector length | |
| 371 | - os << " repeat=" << column.m_repeat; | |
| 372 | - | |
| 373 | - // Set width | |
| 374 | - os << " width=" << column.m_width; | |
| 375 | - | |
| 376 | - // Set length | |
| 377 | - os << " length=" << column.m_length << endl; | |
| 378 | - | |
| 379 | - // Return output stream | |
| 380 | - return os; | |
| 381 | -} | |
| 382 | - | |
| 383 | 338 | |
| 384 | 339 | /*========================================================================== |
| 385 | 340 | = = | ... | ... |
src/fits/GFitsTableDblCol.cpp
| ... | ... | @@ -13,9 +13,10 @@ |
| 13 | 13 | ***************************************************************************/ |
| 14 | 14 | |
| 15 | 15 | /* __ Includes ___________________________________________________________ */ |
| 16 | +#include <iostream> | |
| 16 | 17 | #include "GException.hpp" |
| 18 | +#include "GTools.hpp" | |
| 17 | 19 | #include "GFitsTableDblCol.hpp" |
| 18 | -#include <iostream> | |
| 19 | 20 | |
| 20 | 21 | /* __ Namespaces _________________________________________________________ */ |
| 21 | 22 | |
| ... | ... | @@ -55,20 +56,18 @@ GFitsTableDblCol::GFitsTableDblCol() : GFitsTableCol() |
| 55 | 56 | /***********************************************************************//** |
| 56 | 57 | * @brief Constructor |
| 57 | 58 | * |
| 59 | + * @param[in] name Name of column. | |
| 58 | 60 | * @param[in] length Length of column. |
| 59 | 61 | * @param[in] size Vector size of column. |
| 60 | 62 | ***************************************************************************/ |
| 61 | -GFitsTableDblCol::GFitsTableDblCol(const int& length, const int& size) | |
| 62 | - : GFitsTableCol(length, size) | |
| 63 | +GFitsTableDblCol::GFitsTableDblCol(const std::string& name, | |
| 64 | + const int& length, | |
| 65 | + const int& size) | |
| 66 | + : GFitsTableCol(name, length, size, 8) | |
| 63 | 67 | { |
| 64 | 68 | // Initialise class members for clean destruction |
| 65 | 69 | init_members(); |
| 66 | 70 | |
| 67 | - // Setup format | |
| 68 | - //m_name = "Test"; | |
| 69 | - m_format = "1D"; | |
| 70 | - //m_unit = "deg"; | |
| 71 | - | |
| 72 | 71 | // Return |
| 73 | 72 | return; |
| 74 | 73 | } |
| ... | ... | @@ -205,11 +204,17 @@ const double& GFitsTableDblCol::operator() (const int& row, const int& inx) |
| 205 | 204 | * |
| 206 | 205 | * @exception GException::fits_hdu_not_found |
| 207 | 206 | * Specified HDU not found in FITS file. |
| 207 | + * @exception GException::fits_error | |
| 208 | + * Error occured during writing of the column data. | |
| 209 | + * | |
| 210 | + * The table column is only saved if it is linked to a FITS file and if the | |
| 211 | + * data are indeed present in the class instance. This avoids saving of data | |
| 212 | + * that have not been modified. | |
| 208 | 213 | ***************************************************************************/ |
| 209 | 214 | void GFitsTableDblCol::save(void) |
| 210 | 215 | { |
| 211 | - // Continue only if a FITS file is connected | |
| 212 | - if (m_fitsfile.Fptr != NULL) { | |
| 216 | + // Continue only if a FITS file is connected and data have been loaded | |
| 217 | + if (m_fitsfile.Fptr != NULL && m_colnum > 0 && m_data != NULL) { | |
| 213 | 218 | |
| 214 | 219 | // Move to the HDU |
| 215 | 220 | int status = 0; |
| ... | ... | @@ -219,12 +224,14 @@ void GFitsTableDblCol::save(void) |
| 219 | 224 | throw GException::fits_hdu_not_found(G_SAVE, |
| 220 | 225 | (m_fitsfile.HDUposition)+1, |
| 221 | 226 | status); |
| 222 | - | |
| 223 | 227 | // Save the column data |
| 224 | - // TBD | |
| 225 | - | |
| 228 | + status = __ffpcn(&m_fitsfile, __TDOUBLE, m_colnum, 1, 1, | |
| 229 | + (long)m_size, m_data, m_nulval, &status); | |
| 230 | + if (status != 0) | |
| 231 | + throw GException::fits_error(G_SAVE, status); | |
| 232 | + | |
| 226 | 233 | } // endif: FITS file was connected |
| 227 | - | |
| 234 | + | |
| 228 | 235 | // Return |
| 229 | 236 | return; |
| 230 | 237 | } |
| ... | ... | @@ -251,8 +258,8 @@ std::string GFitsTableDblCol::string(const int& row, const int& inx) |
| 251 | 258 | throw GException::out_of_range(G_STRING, row, 0, m_length-1); |
| 252 | 259 | |
| 253 | 260 | // Check inx value |
| 254 | - if (inx < 0 || inx >= m_repeat) | |
| 255 | - throw GException::out_of_range(G_STRING, inx, 0, m_repeat-1); | |
| 261 | + if (inx < 0 || inx >= m_number) | |
| 262 | + throw GException::out_of_range(G_STRING, inx, 0, m_number-1); | |
| 256 | 263 | |
| 257 | 264 | // Get index |
| 258 | 265 | int offset = row * m_repeat + inx; |
| ... | ... | @@ -287,8 +294,8 @@ double GFitsTableDblCol::real(const int& row, const int& inx) |
| 287 | 294 | throw GException::out_of_range(G_REAL, row, 0, m_length-1); |
| 288 | 295 | |
| 289 | 296 | // Check inx value |
| 290 | - if (inx < 0 || inx >= m_repeat) | |
| 291 | - throw GException::out_of_range(G_REAL, inx, 0, m_repeat-1); | |
| 297 | + if (inx < 0 || inx >= m_number) | |
| 298 | + throw GException::out_of_range(G_REAL, inx, 0, m_number-1); | |
| 292 | 299 | |
| 293 | 300 | // Get index |
| 294 | 301 | int offset = row * m_repeat + inx; |
| ... | ... | @@ -319,8 +326,8 @@ int GFitsTableDblCol::integer(const int& row, const int& inx) |
| 319 | 326 | throw GException::out_of_range(G_INTEGER, row, 0, m_length-1); |
| 320 | 327 | |
| 321 | 328 | // Check col value |
| 322 | - if (inx < 0 || inx >= m_repeat) | |
| 323 | - throw GException::out_of_range(G_INTEGER, inx, 0, m_repeat-1); | |
| 329 | + if (inx < 0 || inx >= m_number) | |
| 330 | + throw GException::out_of_range(G_INTEGER, inx, 0, m_number-1); | |
| 324 | 331 | |
| 325 | 332 | // Get index |
| 326 | 333 | int offset = row * m_repeat + inx; |
| ... | ... | @@ -470,7 +477,7 @@ void GFitsTableDblCol::free_members(void) |
| 470 | 477 | void GFitsTableDblCol::fetch_data(void) |
| 471 | 478 | { |
| 472 | 479 | // Calculate size of memory |
| 473 | - m_size = m_repeat * m_length; | |
| 480 | + m_size = m_number * m_length; | |
| 474 | 481 | |
| 475 | 482 | // Load only if the column has a positive size |
| 476 | 483 | if (m_size > 0) { |
| ... | ... | @@ -504,12 +511,96 @@ void GFitsTableDblCol::fetch_data(void) |
| 504 | 511 | } |
| 505 | 512 | |
| 506 | 513 | |
| 514 | +/***********************************************************************//** | |
| 515 | + * @brief Returns format string of ASCII table | |
| 516 | + ***************************************************************************/ | |
| 517 | +std::string GFitsTableDblCol::ascii_format(void) const | |
| 518 | +{ | |
| 519 | + // Initialize format string | |
| 520 | + std::string format; | |
| 521 | + | |
| 522 | + // Set type code | |
| 523 | + format.append("F"); | |
| 524 | + | |
| 525 | + // Set width | |
| 526 | + format.append(str(m_width)); | |
| 527 | + | |
| 528 | + // Return format | |
| 529 | + return format; | |
| 530 | +} | |
| 531 | + | |
| 532 | + | |
| 533 | +/***********************************************************************//** | |
| 534 | + * @brief Returns format string of binary table | |
| 535 | + ***************************************************************************/ | |
| 536 | +std::string GFitsTableDblCol::binary_format(void) const | |
| 537 | +{ | |
| 538 | + // Initialize format string | |
| 539 | + std::string format; | |
| 540 | + | |
| 541 | + // Set number of elements | |
| 542 | + format.append(str(m_number)); | |
| 543 | + | |
| 544 | + // Set type code | |
| 545 | + format.append("D"); | |
| 546 | + | |
| 547 | + // Return format | |
| 548 | + return format; | |
| 549 | +} | |
| 550 | + | |
| 551 | + | |
| 507 | 552 | /*========================================================================== |
| 508 | 553 | = = |
| 509 | 554 | = GFitsTableDblCol friends = |
| 510 | 555 | = = |
| 511 | 556 | ==========================================================================*/ |
| 512 | 557 | |
| 558 | +/***********************************************************************//** | |
| 559 | + * @brief Output operator | |
| 560 | + * | |
| 561 | + * @param[in] os Output stream | |
| 562 | + * @param[in] column Column to put in output stream | |
| 563 | + ***************************************************************************/ | |
| 564 | +ostream& operator<< (ostream& os, const GFitsTableDblCol& column) | |
| 565 | +{ | |
| 566 | + // Put column name in stream | |
| 567 | + os << "'" << column.m_name << "'"; | |
| 568 | + | |
| 569 | + // Put FITS column number in stream | |
| 570 | + if (column.m_colnum > 0) | |
| 571 | + os << " [fits_colnum=" << column.m_colnum << "]"; | |
| 572 | + else | |
| 573 | + os << " [not linked to FITS file]"; | |
| 574 | + | |
| 575 | + // Put column type in stream | |
| 576 | + os << " " << column.ascii_format(); | |
| 577 | + os << " " << column.binary_format(); | |
| 578 | + | |
| 579 | + // Put data loading in stream | |
| 580 | + if (column.m_data == NULL) | |
| 581 | + os << " (not loaded)"; | |
| 582 | + else | |
| 583 | + os << " (loaded in memory)"; | |
| 584 | + | |
| 585 | + // Set data area size | |
| 586 | + os << " size=" << column.m_size; | |
| 587 | + | |
| 588 | + // Set vector length | |
| 589 | + os << " repeat=" << column.m_repeat; | |
| 590 | + | |
| 591 | + // Set width | |
| 592 | + os << " width=" << column.m_width; | |
| 593 | + | |
| 594 | + // Set number | |
| 595 | + os << " number=" << column.m_number; | |
| 596 | + | |
| 597 | + // Set length | |
| 598 | + os << " length=" << column.m_length; | |
| 599 | + | |
| 600 | + // Return output stream | |
| 601 | + return os; | |
| 602 | +} | |
| 603 | + | |
| 513 | 604 | |
| 514 | 605 | /*========================================================================== |
| 515 | 606 | = = | ... | ... |
src/fits/GFitsTableFltCol.cpp
| ... | ... | @@ -13,13 +13,15 @@ |
| 13 | 13 | ***************************************************************************/ |
| 14 | 14 | |
| 15 | 15 | /* __ Includes ___________________________________________________________ */ |
| 16 | +#include <iostream> | |
| 16 | 17 | #include "GException.hpp" |
| 18 | +#include "GTools.hpp" | |
| 17 | 19 | #include "GFitsTableFltCol.hpp" |
| 18 | -#include <iostream> // cout, cerr | |
| 19 | 20 | |
| 20 | 21 | /* __ Namespaces _________________________________________________________ */ |
| 21 | 22 | |
| 22 | 23 | /* __ Method name definitions ____________________________________________ */ |
| 24 | +#define G_SAVE "GFitsTableFltCol::save()" | |
| 23 | 25 | #define G_STRING "GFitsTableFltCol::string(const int&, const int&)" |
| 24 | 26 | #define G_REAL "GFitsTableFltCol::real(const int&, const int&)" |
| 25 | 27 | #define G_INTEGER "GFitsTableFltCol::integer(const int&, const int&)" |
| ... | ... | @@ -57,6 +59,26 @@ GFitsTableFltCol::GFitsTableFltCol() : GFitsTableCol() |
| 57 | 59 | |
| 58 | 60 | |
| 59 | 61 | /***********************************************************************//** |
| 62 | + * @brief Constructor | |
| 63 | + * | |
| 64 | + * @param[in] name Name of column. | |
| 65 | + * @param[in] length Length of column. | |
| 66 | + * @param[in] size Vector size of column. | |
| 67 | + ***************************************************************************/ | |
| 68 | +GFitsTableFltCol::GFitsTableFltCol(const std::string& name, | |
| 69 | + const int& length, | |
| 70 | + const int& size) | |
| 71 | + : GFitsTableCol(name, length, size, 4) | |
| 72 | +{ | |
| 73 | + // Initialise class members for clean destruction | |
| 74 | + init_members(); | |
| 75 | + | |
| 76 | + // Return | |
| 77 | + return; | |
| 78 | +} | |
| 79 | + | |
| 80 | + | |
| 81 | +/***********************************************************************//** | |
| 60 | 82 | * @brief Copy constructor |
| 61 | 83 | * |
| 62 | 84 | * @param[in] column Column from which class instance should be built. |
| ... | ... | @@ -130,6 +152,36 @@ GFitsTableFltCol& GFitsTableFltCol::operator= (const GFitsTableFltCol& column) |
| 130 | 152 | ==========================================================================*/ |
| 131 | 153 | |
| 132 | 154 | /***********************************************************************//** |
| 155 | + * @brief Save table column into FITS file | |
| 156 | + * | |
| 157 | + * @exception GException::fits_hdu_not_found | |
| 158 | + * Specified HDU not found in FITS file. | |
| 159 | + ***************************************************************************/ | |
| 160 | +void GFitsTableFltCol::save(void) | |
| 161 | +{ | |
| 162 | + // Continue only if a FITS file is connected | |
| 163 | + if (m_fitsfile.Fptr != NULL) { | |
| 164 | + | |
| 165 | + // Move to the HDU | |
| 166 | + int status = 0; | |
| 167 | + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, | |
| 168 | + &status); | |
| 169 | + if (status != 0) | |
| 170 | + throw GException::fits_hdu_not_found(G_SAVE, | |
| 171 | + (m_fitsfile.HDUposition)+1, | |
| 172 | + status); | |
| 173 | + | |
| 174 | + // Save the column data | |
| 175 | + // TBD | |
| 176 | + | |
| 177 | + } // endif: FITS file was connected | |
| 178 | + | |
| 179 | + // Return | |
| 180 | + return; | |
| 181 | +} | |
| 182 | + | |
| 183 | + | |
| 184 | +/***********************************************************************//** | |
| 133 | 185 | * @brief Get string value |
| 134 | 186 | * |
| 135 | 187 | * @param[in] row Table row. |
| ... | ... | @@ -148,8 +200,8 @@ std::string GFitsTableFltCol::string(const int& row, const int& col) |
| 148 | 200 | throw GException::out_of_range(G_STRING, row, 0, m_length-1); |
| 149 | 201 | |
| 150 | 202 | // Check col value |
| 151 | - if (col < 0 || col >= m_repeat) | |
| 152 | - throw GException::out_of_range(G_STRING, col, 0, m_repeat-1); | |
| 203 | + if (col < 0 || col >= m_number) | |
| 204 | + throw GException::out_of_range(G_STRING, col, 0, m_number-1); | |
| 153 | 205 | |
| 154 | 206 | // Get index |
| 155 | 207 | int inx = row * m_repeat + col; |
| ... | ... | @@ -182,8 +234,8 @@ double GFitsTableFltCol::real(const int& row, const int& col) |
| 182 | 234 | throw GException::out_of_range(G_REAL, row, 0, m_length-1); |
| 183 | 235 | |
| 184 | 236 | // Check col value |
| 185 | - if (col < 0 || col >= m_repeat) | |
| 186 | - throw GException::out_of_range(G_REAL, col, 0, m_repeat-1); | |
| 237 | + if (col < 0 || col >= m_number) | |
| 238 | + throw GException::out_of_range(G_REAL, col, 0, m_number-1); | |
| 187 | 239 | |
| 188 | 240 | // Get index |
| 189 | 241 | int inx = row * m_repeat + col; |
| ... | ... | @@ -215,8 +267,8 @@ int GFitsTableFltCol::integer(const int& row, const int& col) |
| 215 | 267 | throw GException::out_of_range(G_INTEGER, row, 0, m_length-1); |
| 216 | 268 | |
| 217 | 269 | // Check col value |
| 218 | - if (col < 0 || col >= m_repeat) | |
| 219 | - throw GException::out_of_range(G_INTEGER, col, 0, m_repeat-1); | |
| 270 | + if (col < 0 || col >= m_number) | |
| 271 | + throw GException::out_of_range(G_INTEGER, col, 0, m_number-1); | |
| 220 | 272 | |
| 221 | 273 | // Get index |
| 222 | 274 | int inx = row * m_repeat + col; |
| ... | ... | @@ -360,7 +412,7 @@ void GFitsTableFltCol::free_members(void) |
| 360 | 412 | void GFitsTableFltCol::load(void) |
| 361 | 413 | { |
| 362 | 414 | // Calculate size of memory |
| 363 | - m_size = m_repeat * m_length; | |
| 415 | + m_size = m_number * m_length; | |
| 364 | 416 | |
| 365 | 417 | // Allocate memory |
| 366 | 418 | if (m_data != NULL) delete [] m_data; |
| ... | ... | @@ -379,6 +431,44 @@ void GFitsTableFltCol::load(void) |
| 379 | 431 | } |
| 380 | 432 | |
| 381 | 433 | |
| 434 | +/***********************************************************************//** | |
| 435 | + * @brief Returns format string of ASCII table | |
| 436 | + ***************************************************************************/ | |
| 437 | +std::string GFitsTableFltCol::ascii_format(void) const | |
| 438 | +{ | |
| 439 | + // Initialize format string | |
| 440 | + std::string format; | |
| 441 | + | |
| 442 | + // Set type code | |
| 443 | + format.append("F"); | |
| 444 | + | |
| 445 | + // Set width | |
| 446 | + format.append(str(m_width)); | |
| 447 | + | |
| 448 | + // Return format | |
| 449 | + return format; | |
| 450 | +} | |
| 451 | + | |
| 452 | + | |
| 453 | +/***********************************************************************//** | |
| 454 | + * @brief Returns format string of binary table | |
| 455 | + ***************************************************************************/ | |
| 456 | +std::string GFitsTableFltCol::binary_format(void) const | |
| 457 | +{ | |
| 458 | + // Initialize format string | |
| 459 | + std::string format; | |
| 460 | + | |
| 461 | + // Set number of elements | |
| 462 | + format.append(str(m_number)); | |
| 463 | + | |
| 464 | + // Set type code | |
| 465 | + format.append("E"); | |
| 466 | + | |
| 467 | + // Return format | |
| 468 | + return format; | |
| 469 | +} | |
| 470 | + | |
| 471 | + | |
| 382 | 472 | /*========================================================================== |
| 383 | 473 | = = |
| 384 | 474 | = GFitsTableFltCol friends = | ... | ... |
src/fits/GFitsTableLngCol.cpp
| ... | ... | @@ -13,13 +13,15 @@ |
| 13 | 13 | ***************************************************************************/ |
| 14 | 14 | |
| 15 | 15 | /* __ Includes ___________________________________________________________ */ |
| 16 | +#include <iostream> | |
| 16 | 17 | #include "GException.hpp" |
| 18 | +#include "GTools.hpp" | |
| 17 | 19 | #include "GFitsTableLngCol.hpp" |
| 18 | -#include <iostream> // cout, cerr | |
| 19 | 20 | |
| 20 | 21 | /* __ Namespaces _________________________________________________________ */ |
| 21 | 22 | |
| 22 | 23 | /* __ Method name definitions ____________________________________________ */ |
| 24 | +#define G_SAVE "GFitsTableLngCol::save()" | |
| 23 | 25 | #define G_STRING "GFitsTableLngCol::string(const int&, const int&)" |
| 24 | 26 | #define G_REAL "GFitsTableLngCol::real(const int&, const int&)" |
| 25 | 27 | #define G_INTEGER "GFitsTableLngCol::integer(const int&, const int&)" |
| ... | ... | @@ -52,6 +54,26 @@ GFitsTableLngCol::GFitsTableLngCol() : GFitsTableCol() |
| 52 | 54 | |
| 53 | 55 | |
| 54 | 56 | /***********************************************************************//** |
| 57 | + * @brief Constructor | |
| 58 | + * | |
| 59 | + * @param[in] name Name of column. | |
| 60 | + * @param[in] length Length of column. | |
| 61 | + * @param[in] size Vector size of column. | |
| 62 | + ***************************************************************************/ | |
| 63 | +GFitsTableLngCol::GFitsTableLngCol(const std::string& name, | |
| 64 | + const int& length, | |
| 65 | + const int& size) | |
| 66 | + : GFitsTableCol(name, length, size, 4) | |
| 67 | +{ | |
| 68 | + // Initialise class members for clean destruction | |
| 69 | + init_members(); | |
| 70 | + | |
| 71 | + // Return | |
| 72 | + return; | |
| 73 | +} | |
| 74 | + | |
| 75 | + | |
| 76 | +/***********************************************************************//** | |
| 55 | 77 | * @brief Copy constructor |
| 56 | 78 | * |
| 57 | 79 | * @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) |
| 178 | 200 | ==========================================================================*/ |
| 179 | 201 | |
| 180 | 202 | /***********************************************************************//** |
| 203 | + * @brief Save table column into FITS file | |
| 204 | + * | |
| 205 | + * @exception GException::fits_hdu_not_found | |
| 206 | + * Specified HDU not found in FITS file. | |
| 207 | + ***************************************************************************/ | |
| 208 | +void GFitsTableLngCol::save(void) | |
| 209 | +{ | |
| 210 | + // Continue only if a FITS file is connected | |
| 211 | + if (m_fitsfile.Fptr != NULL) { | |
| 212 | + | |
| 213 | + // Move to the HDU | |
| 214 | + int status = 0; | |
| 215 | + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, | |
| 216 | + &status); | |
| 217 | + if (status != 0) | |
| 218 | + throw GException::fits_hdu_not_found(G_SAVE, | |
| 219 | + (m_fitsfile.HDUposition)+1, | |
| 220 | + status); | |
| 221 | + | |
| 222 | + // Save the column data | |
| 223 | + // TBD | |
| 224 | + | |
| 225 | + } // endif: FITS file was connected | |
| 226 | + | |
| 227 | + // Return | |
| 228 | + return; | |
| 229 | +} | |
| 230 | + | |
| 231 | + | |
| 232 | +/***********************************************************************//** | |
| 181 | 233 | * @brief Get string value |
| 182 | 234 | * |
| 183 | 235 | * @param[in] row Table row. |
| ... | ... | @@ -198,8 +250,8 @@ std::string GFitsTableLngCol::string(const int& row, const int& inx) |
| 198 | 250 | throw GException::out_of_range(G_STRING, row, 0, m_length-1); |
| 199 | 251 | |
| 200 | 252 | // Check inx value |
| 201 | - if (inx < 0 || inx >= m_repeat) | |
| 202 | - throw GException::out_of_range(G_STRING, inx, 0, m_repeat-1); | |
| 253 | + if (inx < 0 || inx >= m_number) | |
| 254 | + throw GException::out_of_range(G_STRING, inx, 0, m_number-1); | |
| 203 | 255 | |
| 204 | 256 | // Get index |
| 205 | 257 | int offset = row * m_repeat + inx; |
| ... | ... | @@ -234,8 +286,8 @@ double GFitsTableLngCol::real(const int& row, const int& inx) |
| 234 | 286 | throw GException::out_of_range(G_REAL, row, 0, m_length-1); |
| 235 | 287 | |
| 236 | 288 | // Check inx value |
| 237 | - if (inx < 0 || inx >= m_repeat) | |
| 238 | - throw GException::out_of_range(G_REAL, inx, 0, m_repeat-1); | |
| 289 | + if (inx < 0 || inx >= m_number) | |
| 290 | + throw GException::out_of_range(G_REAL, inx, 0, m_number-1); | |
| 239 | 291 | |
| 240 | 292 | // Get index |
| 241 | 293 | int offset = row * m_repeat + inx; |
| ... | ... | @@ -269,8 +321,8 @@ int GFitsTableLngCol::integer(const int& row, const int& inx) |
| 269 | 321 | throw GException::out_of_range(G_INTEGER, row, 0, m_length-1); |
| 270 | 322 | |
| 271 | 323 | // Check inx value |
| 272 | - if (inx < 0 || inx >= m_repeat) | |
| 273 | - throw GException::out_of_range(G_INTEGER, inx, 0, m_repeat-1); | |
| 324 | + if (inx < 0 || inx >= m_number) | |
| 325 | + throw GException::out_of_range(G_INTEGER, inx, 0, m_number-1); | |
| 274 | 326 | |
| 275 | 327 | // Get index |
| 276 | 328 | int offset = row * m_repeat + inx; |
| ... | ... | @@ -421,7 +473,7 @@ void GFitsTableLngCol::free_members(void) |
| 421 | 473 | void GFitsTableLngCol::fetch_data(void) |
| 422 | 474 | { |
| 423 | 475 | // Calculate size of memory |
| 424 | - m_size = m_repeat * m_length; | |
| 476 | + m_size = m_number * m_length; | |
| 425 | 477 | |
| 426 | 478 | // Load only if the column has a positive size |
| 427 | 479 | if (m_size > 0) { |
| ... | ... | @@ -455,6 +507,44 @@ void GFitsTableLngCol::fetch_data(void) |
| 455 | 507 | } |
| 456 | 508 | |
| 457 | 509 | |
| 510 | +/***********************************************************************//** | |
| 511 | + * @brief Returns format string of ASCII table | |
| 512 | + ***************************************************************************/ | |
| 513 | +std::string GFitsTableLngCol::ascii_format(void) const | |
| 514 | +{ | |
| 515 | + // Initialize format string | |
| 516 | + std::string format; | |
| 517 | + | |
| 518 | + // Set type code | |
| 519 | + format.append("J"); | |
| 520 | + | |
| 521 | + // Set width | |
| 522 | + format.append(str(m_width)); | |
| 523 | + | |
| 524 | + // Return format | |
| 525 | + return format; | |
| 526 | +} | |
| 527 | + | |
| 528 | + | |
| 529 | +/***********************************************************************//** | |
| 530 | + * @brief Returns format string of binary table | |
| 531 | + ***************************************************************************/ | |
| 532 | +std::string GFitsTableLngCol::binary_format(void) const | |
| 533 | +{ | |
| 534 | + // Initialize format string | |
| 535 | + std::string format; | |
| 536 | + | |
| 537 | + // Set number of elements | |
| 538 | + format.append(str(m_number)); | |
| 539 | + | |
| 540 | + // Set type code | |
| 541 | + format.append("J"); | |
| 542 | + | |
| 543 | + // Return format | |
| 544 | + return format; | |
| 545 | +} | |
| 546 | + | |
| 547 | + | |
| 458 | 548 | /*========================================================================== |
| 459 | 549 | = = |
| 460 | 550 | = GFitsTableLngCol friends = | ... | ... |
src/fits/GFitsTableShtCol.cpp
| ... | ... | @@ -13,13 +13,15 @@ |
| 13 | 13 | ***************************************************************************/ |
| 14 | 14 | |
| 15 | 15 | /* __ Includes ___________________________________________________________ */ |
| 16 | +#include <iostream> | |
| 16 | 17 | #include "GException.hpp" |
| 18 | +#include "GTools.hpp" | |
| 17 | 19 | #include "GFitsTableShtCol.hpp" |
| 18 | -#include <iostream> // cout, cerr | |
| 19 | 20 | |
| 20 | 21 | /* __ Namespaces _________________________________________________________ */ |
| 21 | 22 | |
| 22 | 23 | /* __ Method name definitions ____________________________________________ */ |
| 24 | +#define G_SAVE "GFitsTableShtCol::save()" | |
| 23 | 25 | #define G_STRING "GFitsTableShtCol::string(const int&, const int&)" |
| 24 | 26 | #define G_REAL "GFitsTableShtCol::real(const int&, const int&)" |
| 25 | 27 | #define G_INTEGER "GFitsTableShtCol::integer(const int&, const int&)" |
| ... | ... | @@ -57,6 +59,26 @@ GFitsTableShtCol::GFitsTableShtCol() : GFitsTableCol() |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | 61 | |
| 62 | +/***********************************************************************//** | |
| 63 | + * @brief Constructor | |
| 64 | + * | |
| 65 | + * @param[in] name Name of column. | |
| 66 | + * @param[in] length Length of column. | |
| 67 | + * @param[in] size Vector size of column. | |
| 68 | + ***************************************************************************/ | |
| 69 | +GFitsTableShtCol::GFitsTableShtCol(const std::string& name, | |
| 70 | + const int& length, | |
| 71 | + const int& size) | |
| 72 | + : GFitsTableCol(name, length, size, 2) | |
| 73 | +{ | |
| 74 | + // Initialise class members for clean destruction | |
| 75 | + init_members(); | |
| 76 | + | |
| 77 | + // Return | |
| 78 | + return; | |
| 79 | +} | |
| 80 | + | |
| 81 | + | |
| 60 | 82 | /*************************************************************************** |
| 61 | 83 | * Copy constructor * |
| 62 | 84 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -128,6 +150,35 @@ GFitsTableShtCol& GFitsTableShtCol::operator= (const GFitsTableShtCol& column) |
| 128 | 150 | = = |
| 129 | 151 | ==========================================================================*/ |
| 130 | 152 | |
| 153 | +/***********************************************************************//** | |
| 154 | + * @brief Save table column into FITS file | |
| 155 | + * | |
| 156 | + * @exception GException::fits_hdu_not_found | |
| 157 | + * Specified HDU not found in FITS file. | |
| 158 | + ***************************************************************************/ | |
| 159 | +void GFitsTableShtCol::save(void) | |
| 160 | +{ | |
| 161 | + // Continue only if a FITS file is connected | |
| 162 | + if (m_fitsfile.Fptr != NULL) { | |
| 163 | + | |
| 164 | + // Move to the HDU | |
| 165 | + int status = 0; | |
| 166 | + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, | |
| 167 | + &status); | |
| 168 | + if (status != 0) | |
| 169 | + throw GException::fits_hdu_not_found(G_SAVE, | |
| 170 | + (m_fitsfile.HDUposition)+1, | |
| 171 | + status); | |
| 172 | + | |
| 173 | + // Save the column data | |
| 174 | + // TBD | |
| 175 | + | |
| 176 | + } // endif: FITS file was connected | |
| 177 | + | |
| 178 | + // Return | |
| 179 | + return; | |
| 180 | +} | |
| 181 | + | |
| 131 | 182 | /*************************************************************************** |
| 132 | 183 | * Get string value * |
| 133 | 184 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -143,8 +194,8 @@ std::string GFitsTableShtCol::string(const int& row, const int& col) |
| 143 | 194 | throw GException::out_of_range(G_STRING, row, 0, m_length-1); |
| 144 | 195 | |
| 145 | 196 | // Check col value |
| 146 | - if (col < 0 || col >= m_repeat) | |
| 147 | - throw GException::out_of_range(G_STRING, col, 0, m_repeat-1); | |
| 197 | + if (col < 0 || col >= m_number) | |
| 198 | + throw GException::out_of_range(G_STRING, col, 0, m_number-1); | |
| 148 | 199 | |
| 149 | 200 | // Get index |
| 150 | 201 | int inx = row * m_repeat + col; |
| ... | ... | @@ -173,8 +224,8 @@ double GFitsTableShtCol::real(const int& row, const int& col) |
| 173 | 224 | throw GException::out_of_range(G_REAL, row, 0, m_length-1); |
| 174 | 225 | |
| 175 | 226 | // Check col value |
| 176 | - if (col < 0 || col >= m_repeat) | |
| 177 | - throw GException::out_of_range(G_REAL, col, 0, m_repeat-1); | |
| 227 | + if (col < 0 || col >= m_number) | |
| 228 | + throw GException::out_of_range(G_REAL, col, 0, m_number-1); | |
| 178 | 229 | |
| 179 | 230 | // Get index |
| 180 | 231 | int inx = row * m_repeat + col; |
| ... | ... | @@ -202,8 +253,8 @@ int GFitsTableShtCol::integer(const int& row, const int& col) |
| 202 | 253 | throw GException::out_of_range(G_INTEGER, row, 0, m_length-1); |
| 203 | 254 | |
| 204 | 255 | // Check col value |
| 205 | - if (col < 0 || col >= m_repeat) | |
| 206 | - throw GException::out_of_range(G_INTEGER, col, 0, m_repeat-1); | |
| 256 | + if (col < 0 || col >= m_number) | |
| 257 | + throw GException::out_of_range(G_INTEGER, col, 0, m_number-1); | |
| 207 | 258 | |
| 208 | 259 | // Get index |
| 209 | 260 | int inx = row * m_repeat + col; |
| ... | ... | @@ -352,7 +403,7 @@ void GFitsTableShtCol::free_members(void) |
| 352 | 403 | void GFitsTableShtCol::load(void) |
| 353 | 404 | { |
| 354 | 405 | // Calculate size of memory |
| 355 | - m_size = m_repeat * m_length; | |
| 406 | + m_size = m_number * m_length; | |
| 356 | 407 | |
| 357 | 408 | // Allocate memory |
| 358 | 409 | if (m_data != NULL) delete [] m_data; |
| ... | ... | @@ -371,6 +422,44 @@ void GFitsTableShtCol::load(void) |
| 371 | 422 | } |
| 372 | 423 | |
| 373 | 424 | |
| 425 | +/***********************************************************************//** | |
| 426 | + * @brief Returns format string of ASCII table | |
| 427 | + ***************************************************************************/ | |
| 428 | +std::string GFitsTableShtCol::ascii_format(void) const | |
| 429 | +{ | |
| 430 | + // Initialize format string | |
| 431 | + std::string format; | |
| 432 | + | |
| 433 | + // Set type code | |
| 434 | + format.append("I"); | |
| 435 | + | |
| 436 | + // Set width | |
| 437 | + format.append(str(m_width)); | |
| 438 | + | |
| 439 | + // Return format | |
| 440 | + return format; | |
| 441 | +} | |
| 442 | + | |
| 443 | + | |
| 444 | +/***********************************************************************//** | |
| 445 | + * @brief Returns format string of binary table | |
| 446 | + ***************************************************************************/ | |
| 447 | +std::string GFitsTableShtCol::binary_format(void) const | |
| 448 | +{ | |
| 449 | + // Initialize format string | |
| 450 | + std::string format; | |
| 451 | + | |
| 452 | + // Set number of elements | |
| 453 | + format.append(str(m_number)); | |
| 454 | + | |
| 455 | + // Set type code | |
| 456 | + format.append("I"); | |
| 457 | + | |
| 458 | + // Return format | |
| 459 | + return format; | |
| 460 | +} | |
| 461 | + | |
| 462 | + | |
| 374 | 463 | /*========================================================================== |
| 375 | 464 | = = |
| 376 | 465 | = GFitsTableShtCol friends = | ... | ... |
src/fits/GFitsTableStrCol.cpp
| ... | ... | @@ -13,13 +13,15 @@ |
| 13 | 13 | ***************************************************************************/ |
| 14 | 14 | |
| 15 | 15 | /* __ Includes ___________________________________________________________ */ |
| 16 | +#include <iostream> | |
| 16 | 17 | #include "GException.hpp" |
| 18 | +#include "GTools.hpp" | |
| 17 | 19 | #include "GFitsTableStrCol.hpp" |
| 18 | -#include <iostream> // cout, cerr | |
| 19 | 20 | |
| 20 | 21 | /* __ Namespaces _________________________________________________________ */ |
| 21 | 22 | |
| 22 | 23 | /* __ Method name definitions ____________________________________________ */ |
| 24 | +#define G_SAVE "GFitsTableStrCol::save()" | |
| 23 | 25 | #define G_STRING "GFitsTableStrCol::string(const int&, const int&)" |
| 24 | 26 | #define G_REAL "GFitsTableStrCol::real(const int&, const int&)" |
| 25 | 27 | #define G_INTEGER "GFitsTableStrCol::integer(const int&, const int&)" |
| ... | ... | @@ -129,6 +131,35 @@ GFitsTableStrCol& GFitsTableStrCol::operator= (const GFitsTableStrCol& column) |
| 129 | 131 | = = |
| 130 | 132 | ==========================================================================*/ |
| 131 | 133 | |
| 134 | +/***********************************************************************//** | |
| 135 | + * @brief Save table column into FITS file | |
| 136 | + * | |
| 137 | + * @exception GException::fits_hdu_not_found | |
| 138 | + * Specified HDU not found in FITS file. | |
| 139 | + ***************************************************************************/ | |
| 140 | +void GFitsTableStrCol::save(void) | |
| 141 | +{ | |
| 142 | + // Continue only if a FITS file is connected | |
| 143 | + if (m_fitsfile.Fptr != NULL) { | |
| 144 | + | |
| 145 | + // Move to the HDU | |
| 146 | + int status = 0; | |
| 147 | + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, | |
| 148 | + &status); | |
| 149 | + if (status != 0) | |
| 150 | + throw GException::fits_hdu_not_found(G_SAVE, | |
| 151 | + (m_fitsfile.HDUposition)+1, | |
| 152 | + status); | |
| 153 | + | |
| 154 | + // Save the column data | |
| 155 | + // TBD | |
| 156 | + | |
| 157 | + } // endif: FITS file was connected | |
| 158 | + | |
| 159 | + // Return | |
| 160 | + return; | |
| 161 | +} | |
| 162 | + | |
| 132 | 163 | /*************************************************************************** |
| 133 | 164 | * Get string value * |
| 134 | 165 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -144,11 +175,11 @@ std::string GFitsTableStrCol::string(const int& row, const int& col) |
| 144 | 175 | throw GException::out_of_range(G_STRING, row, 0, m_length-1); |
| 145 | 176 | |
| 146 | 177 | // Check col value |
| 147 | - if (col < 0 || col >= m_num_subs) | |
| 148 | - throw GException::out_of_range(G_STRING, col, 0, m_num_subs-1); | |
| 178 | + if (col < 0 || col >= m_number) | |
| 179 | + throw GException::out_of_range(G_STRING, col, 0, m_number-1); | |
| 149 | 180 | |
| 150 | 181 | // Get string index |
| 151 | - int inx = row * m_num_subs + col; | |
| 182 | + int inx = row * m_repeat + col; | |
| 152 | 183 | |
| 153 | 184 | // Assign C string to C++ std::string |
| 154 | 185 | std::string value; |
| ... | ... | @@ -174,11 +205,11 @@ double GFitsTableStrCol::real(const int& row, const int& col) |
| 174 | 205 | throw GException::out_of_range(G_STRING, row, 0, m_length-1); |
| 175 | 206 | |
| 176 | 207 | // Check col value |
| 177 | - if (col < 0 || col >= m_num_subs) | |
| 178 | - throw GException::out_of_range(G_STRING, col, 0, m_num_subs-1); | |
| 208 | + if (col < 0 || col >= m_number) | |
| 209 | + throw GException::out_of_range(G_STRING, col, 0, m_number-1); | |
| 179 | 210 | |
| 180 | 211 | // Get string index |
| 181 | - int inx = row * m_num_subs + col; | |
| 212 | + int inx = row * m_repeat + col; | |
| 182 | 213 | |
| 183 | 214 | // Assign C string to double |
| 184 | 215 | double value = atof(m_data[inx]); |
| ... | ... | @@ -203,11 +234,11 @@ int GFitsTableStrCol::integer(const int& row, const int& col) |
| 203 | 234 | throw GException::out_of_range(G_STRING, row, 0, m_length-1); |
| 204 | 235 | |
| 205 | 236 | // Check col value |
| 206 | - if (col < 0 || col >= m_num_subs) | |
| 207 | - throw GException::out_of_range(G_STRING, col, 0, m_num_subs-1); | |
| 237 | + if (col < 0 || col >= m_number) | |
| 238 | + throw GException::out_of_range(G_STRING, col, 0, m_number-1); | |
| 208 | 239 | |
| 209 | 240 | // Get string index |
| 210 | - int inx = row * m_num_subs + col; | |
| 241 | + int inx = row * m_repeat + col; | |
| 211 | 242 | |
| 212 | 243 | // Assign C string to int |
| 213 | 244 | int value = atoi(m_data[inx]); |
| ... | ... | @@ -289,7 +320,6 @@ void GFitsTableStrCol::init_members(void) |
| 289 | 320 | // Initialise members |
| 290 | 321 | m_type = __TSTRING; |
| 291 | 322 | m_size = 0; |
| 292 | - m_num_subs = 0; | |
| 293 | 323 | m_data = NULL; |
| 294 | 324 | m_nulstr = NULL; |
| 295 | 325 | m_anynul = 0; |
| ... | ... | @@ -309,7 +339,6 @@ void GFitsTableStrCol::copy_members(const GFitsTableStrCol& column) |
| 309 | 339 | { |
| 310 | 340 | // Copy string size |
| 311 | 341 | m_size = column.m_size; |
| 312 | - m_num_subs = column.m_num_subs; | |
| 313 | 342 | m_anynul = column.m_anynul; |
| 314 | 343 | |
| 315 | 344 | // Copy column data |
| ... | ... | @@ -368,14 +397,8 @@ void GFitsTableStrCol::free_members(void) |
| 368 | 397 | ***************************************************************************/ |
| 369 | 398 | void GFitsTableStrCol::load(void) |
| 370 | 399 | { |
| 371 | - // Calculate number of substrings | |
| 372 | - if (m_repeat == 1) // ASCII tables | |
| 373 | - m_num_subs = 1; | |
| 374 | - else // Binary tables | |
| 375 | - m_num_subs = m_repeat / m_width; | |
| 376 | - | |
| 377 | 400 | // Calculate total number of strings |
| 378 | - m_size = m_num_subs * m_length; | |
| 401 | + m_size = m_number * m_length; | |
| 379 | 402 | |
| 380 | 403 | // Free memory |
| 381 | 404 | free_members(); |
| ... | ... | @@ -393,8 +416,9 @@ void GFitsTableStrCol::load(void) |
| 393 | 416 | |
| 394 | 417 | // Load column data |
| 395 | 418 | int status = 0; |
| 396 | - status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status); | |
| 397 | - status = __ffgcvs(&m_fitsfile, m_colnum, 1, 1, m_size, m_nulstr, m_data, | |
| 419 | + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, | |
| 420 | + &status); | |
| 421 | + status = __ffgcvs(&m_fitsfile, m_colnum, 1, 1, m_size, m_nulstr, m_data, | |
| 398 | 422 | &m_anynul, &status); |
| 399 | 423 | if (status != 0) |
| 400 | 424 | throw GException::fits_error(G_LOAD, status); |
| ... | ... | @@ -406,6 +430,48 @@ void GFitsTableStrCol::load(void) |
| 406 | 430 | } |
| 407 | 431 | |
| 408 | 432 | |
| 433 | +/***********************************************************************//** | |
| 434 | + * @brief Returns format string of ASCII table | |
| 435 | + ***************************************************************************/ | |
| 436 | +std::string GFitsTableStrCol::ascii_format(void) const | |
| 437 | +{ | |
| 438 | + // Initialize format string | |
| 439 | + std::string format; | |
| 440 | + | |
| 441 | + // Set type code | |
| 442 | + format.append("A"); | |
| 443 | + | |
| 444 | + // Set width | |
| 445 | + format.append(str(m_width)); | |
| 446 | + | |
| 447 | + // Return format | |
| 448 | + return format; | |
| 449 | +} | |
| 450 | + | |
| 451 | + | |
| 452 | +/***********************************************************************//** | |
| 453 | + * @brief Returns format string of binary table | |
| 454 | + ***************************************************************************/ | |
| 455 | +std::string GFitsTableStrCol::binary_format(void) const | |
| 456 | +{ | |
| 457 | + // Initialize format string | |
| 458 | + std::string format; | |
| 459 | + | |
| 460 | + // Set number of elements | |
| 461 | + format.append(str(m_repeat)); | |
| 462 | + | |
| 463 | + // Set type code | |
| 464 | + format.append("A"); | |
| 465 | + | |
| 466 | + // If there are substrings then add width of substring | |
| 467 | + if (m_repeat > m_width) | |
| 468 | + format.append(str(m_width)); | |
| 469 | + | |
| 470 | + // Return format | |
| 471 | + return format; | |
| 472 | +} | |
| 473 | + | |
| 474 | + | |
| 409 | 475 | /*========================================================================== |
| 410 | 476 | = = |
| 411 | 477 | = GFitsTableStrCol friends = | ... | ... |
src/rsp/GLATResponse.cpp
| ... | ... | @@ -707,7 +707,7 @@ GVector GLATResponse::get_fits_vector(const GFitsHDU* hdu, const std::string& co |
| 707 | 707 | throw GException::fits_column_not_found(G_GET_FITS_VECTOR, colname); |
| 708 | 708 | |
| 709 | 709 | // Determine number of entries |
| 710 | - int num = ptr->repeat(); | |
| 710 | + int num = ptr->number(); | |
| 711 | 711 | |
| 712 | 712 | // Load data into vector |
| 713 | 713 | GVector data(num); | ... | ... |
test/test_GFits.cpp
| ... | ... | @@ -372,28 +372,28 @@ void test_create(void) |
| 372 | 372 | cout << "."; |
| 373 | 373 | |
| 374 | 374 | // Attach binary table |
| 375 | -cout << "start" << endl; | |
| 376 | 375 | try { |
| 377 | 376 | // Re-open FITS file |
| 378 | 377 | GFits fits; |
| 379 | 378 | fits.open("test.fits"); |
| 380 | -cout << "1" << endl; | |
| 381 | 379 | |
| 382 | 380 | // Create binary Table with 10 rows |
| 383 | 381 | int nrows = 10; |
| 384 | 382 | GFitsBinTable table = GFitsBinTable(nrows); |
| 385 | - GFitsTableDblCol first = GFitsTableDblCol(nrows); | |
| 386 | - GFitsTableDblCol second = GFitsTableDblCol(nrows); | |
| 387 | -cout << "2" << endl; | |
| 383 | + GFitsTableDblCol first = GFitsTableDblCol("First", nrows); | |
| 384 | + GFitsTableDblCol second = GFitsTableDblCol("Second", nrows); | |
| 385 | + first(9) = 99.0; | |
| 386 | + second(0) = -99.0; | |
| 387 | + cout << endl << first << endl; | |
| 388 | + cout << second << endl; | |
| 388 | 389 | table.append_column(first); |
| 389 | -cout << "3" << endl; | |
| 390 | 390 | table.append_column(second); |
| 391 | 391 | cout << table; |
| 392 | 392 | |
| 393 | 393 | // Create HDU and append to FILE file |
| 394 | 394 | GFitsHDU hdu(table); |
| 395 | 395 | fits.append_hdu(hdu); |
| 396 | -// cout << fits; | |
| 396 | + // cout << fits; | |
| 397 | 397 | |
| 398 | 398 | // Save FITS file |
| 399 | 399 | fits.save(); | ... | ... |