Commit 1f9b685e828bbe9e26d0bd27a023224181d6edb3
1 parent
dbb531bd
initial implementation of FITS table and column classes
Showing
31 changed files
with
2688 additions
and
281 deletions
configure
configure.ac
| ... | ... | @@ -79,8 +79,7 @@ dnl ============================== |
| 79 | 79 | RANGE_CHECK="no" |
| 80 | 80 | AC_ARG_ENABLE(range_check, |
| 81 | 81 | [ --enable-range-check performs index range checking], |
| 82 | - [ RANGE_CHECK="$enableval" | |
| 83 | - ]) | |
| 82 | + [ RANGE_CHECK="$enableval" ]) | |
| 84 | 83 | if test "x$RANGE_CHECK" = "xyes"; then |
| 85 | 84 | AC_DEFINE([G_RANGE_CHECK], [1], [Define if range checking should be performed]) |
| 86 | 85 | fi | ... | ... |
include/GException.hpp
| ... | ... | @@ -58,6 +58,7 @@ public: |
| 58 | 58 | // Out of range |
| 59 | 59 | class out_of_range : public GExceptionHandler { |
| 60 | 60 | public: |
| 61 | + out_of_range(string origin, int inx, int min, int max); | |
| 61 | 62 | out_of_range(string origin, int inx, int elements); |
| 62 | 63 | out_of_range(string origin, int row, int col, int rows, int cols); |
| 63 | 64 | }; |
| ... | ... | @@ -134,12 +135,36 @@ public: |
| 134 | 135 | fits_open_error(string origin, string filename, int status); |
| 135 | 136 | }; |
| 136 | 137 | |
| 138 | + // FITS file has already been opened | |
| 139 | + class fits_already_opened : public GExceptionHandler { | |
| 140 | + public: | |
| 141 | + fits_already_opened(string origin, string filename); | |
| 142 | + }; | |
| 143 | + | |
| 137 | 144 | // FITS keyword not found error |
| 138 | 145 | class fits_key_not_found : public GExceptionHandler { |
| 139 | 146 | public: |
| 140 | 147 | fits_key_not_found(string origin, string keyname, int status); |
| 141 | 148 | }; |
| 142 | 149 | |
| 150 | + // FITS unknown HDU type | |
| 151 | + class fits_unknown_HDU_type : public GExceptionHandler { | |
| 152 | + public: | |
| 153 | + fits_unknown_HDU_type(string origin, int type); | |
| 154 | + }; | |
| 155 | + | |
| 156 | + // FITS unknown HDU type | |
| 157 | + class fits_HDU_not_a_table : public GExceptionHandler { | |
| 158 | + public: | |
| 159 | + fits_HDU_not_a_table(string origin, int type); | |
| 160 | + }; | |
| 161 | + | |
| 162 | + // FITS invalid type | |
| 163 | + class fits_invalid_type : public GExceptionHandler { | |
| 164 | + public: | |
| 165 | + fits_invalid_type(string origin, string message); | |
| 166 | + }; | |
| 167 | + | |
| 143 | 168 | }; |
| 144 | 169 | |
| 145 | 170 | #endif /* GEXCEPTION_HPP */ | ... | ... |
include/GFits.hpp
| ... | ... | @@ -27,7 +27,6 @@ |
| 27 | 27 | ***************************************************************************/ |
| 28 | 28 | class GFits { |
| 29 | 29 | |
| 30 | -// Public methods | |
| 31 | 30 | public: |
| 32 | 31 | // Constructors and destructors |
| 33 | 32 | GFits(); |
| ... | ... | @@ -38,26 +37,39 @@ public: |
| 38 | 37 | GFits& operator= (const GFits& fits); |
| 39 | 38 | |
| 40 | 39 | // Methods |
| 41 | - void open(std::string filename); | |
| 42 | - void close(void); | |
| 43 | - //GFitsHDU* hdu(std::string extname); | |
| 44 | - //GFitsHDU* hdu(int extno); | |
| 40 | + void open(const std::string filename); | |
| 41 | + void save(void); | |
| 42 | + void saveto(const std::string filename, int clobber); | |
| 43 | + void close(void); | |
| 44 | + GFitsHDU* hdu(std::string extname); | |
| 45 | + GFitsHDU* hdu(int extno); | |
| 45 | 46 | |
| 46 | -// Methods and data that are available to derived classes | |
| 47 | -protected: | |
| 48 | - // Protected methods | |
| 47 | +private: | |
| 48 | + // Private methods | |
| 49 | + void init_members(void); | |
| 50 | + void copy_members(const GFits& fits); | |
| 51 | + void free_members(void); | |
| 49 | 52 | |
| 50 | - // Protected data area | |
| 53 | + // Private data area | |
| 51 | 54 | std::string m_filename; // FITS file name |
| 52 | 55 | __fitsfile* m_fitsfile; // FITS file pointer |
| 53 | 56 | int m_num_hdu; // Number of HDUs in file |
| 54 | 57 | GFitsHDU* m_hdu; // Pointers to HDUs |
| 55 | - | |
| 56 | -// Methods that are available to the base class only | |
| 57 | -private: | |
| 58 | - void init_members(void); | |
| 59 | - void copy_members(const GFits& fits); | |
| 60 | - void free_members(void); | |
| 61 | 58 | }; |
| 62 | 59 | |
| 60 | + | |
| 61 | +/*************************************************************************** | |
| 62 | + * Inline methods * | |
| 63 | + ***************************************************************************/ | |
| 64 | +inline | |
| 65 | +GFitsHDU* GFits::hdu(int extno) | |
| 66 | +{ | |
| 67 | + #if defined(G_RANGE_CHECK) | |
| 68 | + if (extno < 1 || extno > m_num_hdu) | |
| 69 | + throw GException::out_of_range("GFits::hdu(int)", extno, 1, m_num_hdu); | |
| 70 | + #endif | |
| 71 | + return &(m_hdu[extno+1]); | |
| 72 | +} | |
| 73 | + | |
| 74 | + | |
| 63 | 75 | #endif /* GFITS_HPP */ | ... | ... |
include/GFitsAsciiTable.hpp
0 โ 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GFitsAsciiTable.hpp - FITS ASCII table class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + ***************************************************************************/ | |
| 13 | + | |
| 14 | +#ifndef GFITSASCIITABLE_HPP | |
| 15 | +#define GFITSASCIITABLE_HPP | |
| 16 | + | |
| 17 | +/* __ Includes ___________________________________________________________ */ | |
| 18 | +#include "GFitsCfitsio.hpp" | |
| 19 | +#include "GFitsData.hpp" | |
| 20 | +#include "GFitsTableCol.hpp" | |
| 21 | + | |
| 22 | +/* __ Namespaces _________________________________________________________ */ | |
| 23 | + | |
| 24 | + | |
| 25 | +/*************************************************************************** | |
| 26 | + * GFitsAsciiTable class definition * | |
| 27 | + ***************************************************************************/ | |
| 28 | +class GFitsAsciiTable : public GFitsData { | |
| 29 | + | |
| 30 | +public: | |
| 31 | + // Constructors and destructors | |
| 32 | + GFitsAsciiTable(); | |
| 33 | + GFitsAsciiTable(const GFitsAsciiTable& table); | |
| 34 | + virtual ~GFitsAsciiTable(); | |
| 35 | + | |
| 36 | + // Operators | |
| 37 | + GFitsAsciiTable& operator= (const GFitsAsciiTable& table); | |
| 38 | + | |
| 39 | + // Methods | |
| 40 | + void open(__fitsfile* fptr); | |
| 41 | + void close(void); | |
| 42 | + GFitsAsciiTable* clone(void) const; | |
| 43 | + GFitsTableCol* column(const std::string colname); | |
| 44 | + GFitsTableCol* column(const int colnum); | |
| 45 | + | |
| 46 | +private: | |
| 47 | + // Private methods | |
| 48 | + void init_members(void); | |
| 49 | + void copy_members(const GFitsAsciiTable& table); | |
| 50 | + void free_members(void); | |
| 51 | + | |
| 52 | + // Private data area | |
| 53 | + int m_rows; | |
| 54 | + int m_cols; | |
| 55 | + GFitsTableCol** m_columns; | |
| 56 | +}; | |
| 57 | + | |
| 58 | + | |
| 59 | +/*************************************************************************** | |
| 60 | + * Inline methods * | |
| 61 | + ***************************************************************************/ | |
| 62 | +inline | |
| 63 | +GFitsAsciiTable* GFitsAsciiTable::clone(void) const | |
| 64 | +{ | |
| 65 | + return new GFitsAsciiTable(*this); | |
| 66 | +} | |
| 67 | + | |
| 68 | +#endif /* GFITSASCIITABLE_HPP */ | ... | ... |
include/GFitsBinTable.hpp
0 โ 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GFitsBinTable.hpp - FITS binary table class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + ***************************************************************************/ | |
| 13 | + | |
| 14 | +#ifndef GFITSBINTABLE_HPP | |
| 15 | +#define GFITSBINTABLE_HPP | |
| 16 | + | |
| 17 | +/* __ Includes ___________________________________________________________ */ | |
| 18 | +#include <vector> | |
| 19 | +#include "GFitsCfitsio.hpp" | |
| 20 | +#include "GFitsData.hpp" | |
| 21 | +#include "GFitsTableCol.hpp" | |
| 22 | + | |
| 23 | +/* __ Namespaces _________________________________________________________ */ | |
| 24 | + | |
| 25 | + | |
| 26 | +/* __ Structures _________________________________________________________ */ | |
| 27 | + | |
| 28 | + | |
| 29 | +/*************************************************************************** | |
| 30 | + * GFitsBinTable class definition * | |
| 31 | + ***************************************************************************/ | |
| 32 | +class GFitsBinTable : public GFitsData { | |
| 33 | + | |
| 34 | +public: | |
| 35 | + // Constructors and destructors | |
| 36 | + GFitsBinTable(); | |
| 37 | + GFitsBinTable(const GFitsBinTable& table); | |
| 38 | + virtual ~GFitsBinTable(); | |
| 39 | + | |
| 40 | + // Operators | |
| 41 | + GFitsBinTable& operator= (const GFitsBinTable& table); | |
| 42 | + | |
| 43 | + // Methods | |
| 44 | + void open(__fitsfile* fptr); | |
| 45 | + void close(void); | |
| 46 | + GFitsBinTable* clone(void) const; | |
| 47 | + GFitsTableCol* column(const std::string colname); | |
| 48 | + GFitsTableCol* column(const int colnum); | |
| 49 | + | |
| 50 | +private: | |
| 51 | + // Private methods | |
| 52 | + void init_members(void); | |
| 53 | + void copy_members(const GFitsBinTable& table); | |
| 54 | + void free_members(void); | |
| 55 | + | |
| 56 | + // Private data area | |
| 57 | + int m_rows; | |
| 58 | + int m_cols; | |
| 59 | + GFitsTableCol** m_columns; | |
| 60 | +}; | |
| 61 | + | |
| 62 | + | |
| 63 | +/*************************************************************************** | |
| 64 | + * Inline methods * | |
| 65 | + ***************************************************************************/ | |
| 66 | +inline | |
| 67 | +GFitsBinTable* GFitsBinTable::clone(void) const | |
| 68 | +{ | |
| 69 | + return new GFitsBinTable(*this); | |
| 70 | +} | |
| 71 | + | |
| 72 | +#endif /* GFITSBINTABLE_HPP */ | ... | ... |
include/GFitsCfitsio.hpp
| ... | ... | @@ -39,7 +39,13 @@ |
| 39 | 39 | #define __ffgkey(A, B, C, D, E) ffgkey(A, B, C, D, E) |
| 40 | 40 | #define __ffgkyn(A, B, C, D, E, F) ffgkyn(A, B, C, D, E, F) |
| 41 | 41 | #define __ffuky(A, B, C, D, E, F) ffuky(A, B, C, D, E, F) |
| 42 | -#define __TSTRING TSTRING | |
| 42 | +#define __ffgnrw(A, B, C) ffgnrw(A, B, C) | |
| 43 | +#define __ffgncl(A, B, C) ffgncl(A, B, C) | |
| 44 | +#define __ffgtcl(A, B, C, D, E, F) ffgtcl(A, B, C, D, E, F) | |
| 45 | +#define __ffgcv(A, B, C, D, E, F, G, H, I, J) ffgcv(A, B, C, D, E, F, G, H, I, J) | |
| 46 | +#define __TLOGICAL TLOGICAL | |
| 47 | +#define __TSTRING TSTRING | |
| 48 | +#define __TDOUBLE TDOUBLE | |
| 43 | 49 | |
| 44 | 50 | /* __ Type definition ____________________________________________________ */ |
| 45 | 51 | typedef fitsfile __fitsfile; |
| ... | ... | @@ -60,7 +66,21 @@ typedef fitsfile __fitsfile; |
| 60 | 66 | #define __ffgkey(A, B, C, D, E) __dummy() |
| 61 | 67 | #define __ffgkyn(A, B, C, D, E, F) __dummy() |
| 62 | 68 | #define __ffuky(A, B, C, D, E, F) __dummy() |
| 63 | -#define __TSTRING 0 | |
| 69 | +#define __ffgnrw(A, B, C) __dummy() | |
| 70 | +#define __ffgncl(A, B, C) __dummy() | |
| 71 | +#define __ffgtcl(A, B, C, D, E, F) __dummy() | |
| 72 | +#define __ffgcv(A, B, C, D, E, F, G, H, I, J) __dummy() | |
| 73 | +#define __TBIT 1 | |
| 74 | +#define __TSHORT 11 | |
| 75 | +#define __TLOGICAL 14 | |
| 76 | +#define __TSTRING 16 | |
| 77 | +#define __TSHORT 21 | |
| 78 | +#define __TLONG 41 | |
| 79 | +#define __TLONGLONG 81 | |
| 80 | +#define __TFLOAT 42 | |
| 81 | +#define __TDOUBLE 82 | |
| 82 | +#define __TCOMPLEX 83 | |
| 83 | +#define __TDBLCOMPLEX 163 | |
| 64 | 84 | |
| 65 | 85 | /* __ Type definition ____________________________________________________ */ |
| 66 | 86 | typedef int __fitsfile; | ... | ... |
include/GFitsData.hpp
| ... | ... | @@ -15,37 +15,37 @@ |
| 15 | 15 | #define GFITSDATA_HPP |
| 16 | 16 | |
| 17 | 17 | /* __ Includes ___________________________________________________________ */ |
| 18 | -//#include "GVector.hpp" | |
| 18 | +#include "GFitsCfitsio.hpp" | |
| 19 | 19 | |
| 20 | 20 | /* __ Namespaces _________________________________________________________ */ |
| 21 | -using namespace std; | |
| 22 | 21 | |
| 23 | 22 | |
| 24 | 23 | /*************************************************************************** |
| 25 | - * GFitsData class definition * | |
| 24 | + * GFitsData class definition * | |
| 26 | 25 | ***************************************************************************/ |
| 27 | 26 | class GFitsData { |
| 28 | 27 | |
| 29 | -// Public methods | |
| 30 | 28 | public: |
| 31 | 29 | // Constructors and destructors |
| 32 | - //GFitsData(); | |
| 33 | - //GFitsData(const GFitsData& data); | |
| 34 | - //virtual ~GFitsData(); | |
| 30 | + GFitsData(); | |
| 31 | + GFitsData(const GFitsData& data); | |
| 32 | + virtual ~GFitsData(); | |
| 35 | 33 | |
| 36 | 34 | // Operators |
| 35 | + virtual GFitsData& operator= (const GFitsData& data); | |
| 37 | 36 | |
| 38 | 37 | // Methods |
| 38 | + virtual void open(__fitsfile* fptr) = 0; | |
| 39 | + virtual void close(void) = 0; | |
| 40 | + virtual GFitsData* clone(void) const = 0; | |
| 39 | 41 | |
| 40 | -// Methods and data that are available to derived classes | |
| 41 | 42 | protected: |
| 42 | 43 | // Protected methods |
| 44 | + void init_members(void); | |
| 45 | + void copy_members(const GFitsData& data); | |
| 46 | + void free_members(void); | |
| 43 | 47 | |
| 44 | 48 | // Protected data area |
| 45 | - // this is a test | |
| 46 | - | |
| 47 | -// Methods that are available to the base class only | |
| 48 | -private: | |
| 49 | 49 | }; |
| 50 | 50 | |
| 51 | 51 | #endif /* GFITSDATA_HPP */ | ... | ... |
include/GFitsHDU.hpp
| ... | ... | @@ -17,6 +17,9 @@ |
| 17 | 17 | /* __ Includes ___________________________________________________________ */ |
| 18 | 18 | #include "GFitsHeader.hpp" |
| 19 | 19 | #include "GFitsData.hpp" |
| 20 | +#include "GFitsImage.hpp" | |
| 21 | +#include "GFitsAsciiTable.hpp" | |
| 22 | +#include "GFitsBinTable.hpp" | |
| 20 | 23 | |
| 21 | 24 | /* __ Namespaces _________________________________________________________ */ |
| 22 | 25 | |
| ... | ... | @@ -37,10 +40,14 @@ public: |
| 37 | 40 | GFitsHDU& operator= (const GFitsHDU& hdu); |
| 38 | 41 | |
| 39 | 42 | // Methods |
| 40 | - void open(__fitsfile* fptr, int hdunum); | |
| 41 | - void close(void); | |
| 42 | - GFitsHeader* header(void); | |
| 43 | - GFitsData* data(void); | |
| 43 | + void open(__fitsfile* fptr, int hdunum); | |
| 44 | + void save(void); | |
| 45 | + std::string extname(void) const; | |
| 46 | + int extno(void) const; | |
| 47 | + int exttype(void) const; | |
| 48 | + GFitsHeader* header(void) const; | |
| 49 | + GFitsData* data(void) const; | |
| 50 | + GFitsTableCol* column(const std::string colname) const; | |
| 44 | 51 | |
| 45 | 52 | private: |
| 46 | 53 | // Private methods |
| ... | ... | @@ -54,8 +61,18 @@ private: |
| 54 | 61 | std::string m_name; // HDU name |
| 55 | 62 | int m_num; // HDU number (starting from 1) |
| 56 | 63 | int m_type; // HDU type |
| 57 | - GFitsHeader m_header; // HDU header | |
| 58 | - GFitsData m_data; // HDU data | |
| 64 | + GFitsHeader* m_header; // HDU header | |
| 65 | + GFitsData* m_data; // HDU data | |
| 59 | 66 | }; |
| 60 | 67 | |
| 68 | + | |
| 69 | +/*************************************************************************** | |
| 70 | + * Inline methods * | |
| 71 | + ***************************************************************************/ | |
| 72 | +inline std::string GFitsHDU::extname(void) const { return m_name; } | |
| 73 | +inline int GFitsHDU::extno(void) const { return m_num; } | |
| 74 | +inline int GFitsHDU::exttype(void) const { return m_type; } | |
| 75 | +inline GFitsHeader* GFitsHDU::header(void) const { return m_header; } | |
| 76 | +inline GFitsData* GFitsHDU::data(void) const { return m_data; } | |
| 77 | + | |
| 61 | 78 | #endif /* GFITSHDU_HPP */ | ... | ... |
include/GFitsHeader.hpp
| ... | ... | @@ -15,6 +15,7 @@ |
| 15 | 15 | #define GFITSHEADER_HPP |
| 16 | 16 | |
| 17 | 17 | /* __ Includes ___________________________________________________________ */ |
| 18 | +#include "GFitsCfitsio.hpp" | |
| 18 | 19 | #include "GFitsHeaderCard.hpp" |
| 19 | 20 | |
| 20 | 21 | /* __ Namespaces _________________________________________________________ */ |
| ... | ... | @@ -37,9 +38,16 @@ public: |
| 37 | 38 | |
| 38 | 39 | // Methods |
| 39 | 40 | void open(__fitsfile* fptr); |
| 41 | + void close(void); | |
| 40 | 42 | GFitsHeaderCard* card(const std::string keyname); |
| 41 | 43 | GFitsHeaderCard* card(const int cardno); |
| 42 | - std::string value(const std::string keyname); | |
| 44 | + std::string string(const std::string keyname); | |
| 45 | + std::string string(const int cardno); | |
| 46 | + double real(const std::string keyname); | |
| 47 | + double real(const int cardno); | |
| 48 | + int integer(const std::string keyname); | |
| 49 | + int integer(const int cardno); | |
| 50 | + GFitsHeader* clone(void) const; | |
| 43 | 51 | |
| 44 | 52 | private: |
| 45 | 53 | // Private methods |
| ... | ... | @@ -53,4 +61,24 @@ private: |
| 53 | 61 | GFitsHeaderCard* m_card; |
| 54 | 62 | }; |
| 55 | 63 | |
| 64 | + | |
| 65 | +/*************************************************************************** | |
| 66 | + * Inline methods * | |
| 67 | + ***************************************************************************/ | |
| 68 | +inline | |
| 69 | +GFitsHeaderCard* GFitsHeader::card(const std::string keyname) | |
| 70 | +{ | |
| 71 | + return GFitsHeader::card_ptr(keyname); | |
| 72 | +} | |
| 73 | +inline | |
| 74 | +GFitsHeaderCard* GFitsHeader::card(const int cardno) | |
| 75 | +{ | |
| 76 | + return (cardno >= 0 && cardno < m_num_cards) ? &(m_card[cardno]) : NULL; | |
| 77 | +} | |
| 78 | +inline | |
| 79 | +GFitsHeader* GFitsHeader::clone(void) const | |
| 80 | +{ | |
| 81 | + return new GFitsHeader(*this); | |
| 82 | +} | |
| 83 | + | |
| 56 | 84 | #endif /* GFITSHEADER_HPP */ | ... | ... |
include/GFitsHeaderCard.hpp
| ... | ... | @@ -36,6 +36,10 @@ public: |
| 36 | 36 | // Methods |
| 37 | 37 | std::string keyname(void); |
| 38 | 38 | std::string value(void); |
| 39 | + int value_type(void); | |
| 40 | + std::string string(void); | |
| 41 | + double real(void); | |
| 42 | + int integer(void); | |
| 39 | 43 | std::string unit(void); |
| 40 | 44 | std::string comment(void); |
| 41 | 45 | void set_keyname(std::string& keyname); |
| ... | ... | @@ -51,12 +55,29 @@ private: |
| 51 | 55 | void init_members(void); |
| 52 | 56 | void copy_members(const GFitsHeaderCard& card); |
| 53 | 57 | void free_members(void); |
| 58 | + int get_value_type(void); | |
| 54 | 59 | |
| 55 | 60 | // Private data area |
| 56 | 61 | std::string m_keyname; |
| 57 | 62 | std::string m_value; |
| 63 | + int m_value_type; | |
| 58 | 64 | std::string m_unit; |
| 59 | 65 | std::string m_comment; |
| 60 | 66 | }; |
| 61 | 67 | |
| 68 | + | |
| 69 | +/*************************************************************************** | |
| 70 | + * Inline methods * | |
| 71 | + ***************************************************************************/ | |
| 72 | +inline std::string GFitsHeaderCard::keyname(void) { return m_keyname; } | |
| 73 | +inline std::string GFitsHeaderCard::value(void) { return m_value; } | |
| 74 | +inline int GFitsHeaderCard::value_type(void) { return m_value_type; } | |
| 75 | +inline std::string GFitsHeaderCard::unit(void) { return m_unit; } | |
| 76 | +inline std::string GFitsHeaderCard::comment(void) { return m_comment; } | |
| 77 | +inline void GFitsHeaderCard::set_keyname(std::string& keyname) { m_keyname = keyname; } | |
| 78 | +inline void GFitsHeaderCard::set_value(std::string& value) { m_value = value; } | |
| 79 | +inline void GFitsHeaderCard::set_unit(std::string& unit) { m_unit = unit; } | |
| 80 | +inline void GFitsHeaderCard::set_comment(std::string& comment) { m_comment = comment; } | |
| 81 | + | |
| 82 | + | |
| 62 | 83 | #endif /* GFITSHEADERCARD_HPP */ | ... | ... |
include/GFitsImage.hpp
0 โ 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GFitsImage.hpp - FITS image class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + ***************************************************************************/ | |
| 13 | + | |
| 14 | +#ifndef GFITSIMAGE_HPP | |
| 15 | +#define GFITSIMAGE_HPP | |
| 16 | + | |
| 17 | +/* __ Includes ___________________________________________________________ */ | |
| 18 | +#include "GFitsCfitsio.hpp" | |
| 19 | +#include "GFitsData.hpp" | |
| 20 | + | |
| 21 | +/* __ Namespaces _________________________________________________________ */ | |
| 22 | + | |
| 23 | + | |
| 24 | +/*************************************************************************** | |
| 25 | + * GFitsImage class definition * | |
| 26 | + ***************************************************************************/ | |
| 27 | +class GFitsImage : public GFitsData { | |
| 28 | + | |
| 29 | +public: | |
| 30 | + // Constructors and destructors | |
| 31 | + GFitsImage(); | |
| 32 | + GFitsImage(const GFitsImage& image); | |
| 33 | + ~GFitsImage(); | |
| 34 | + | |
| 35 | + // Operators | |
| 36 | + GFitsImage& operator= (const GFitsImage& image); | |
| 37 | + | |
| 38 | + // Methods | |
| 39 | + void open(__fitsfile* fptr); | |
| 40 | + void close(void); | |
| 41 | + GFitsImage* clone(void) const; | |
| 42 | + | |
| 43 | +private: | |
| 44 | + // Private methods | |
| 45 | + void init_members(void); | |
| 46 | + void copy_members(const GFitsImage& image); | |
| 47 | + void free_members(void); | |
| 48 | + | |
| 49 | + // Private data area | |
| 50 | +}; | |
| 51 | + | |
| 52 | + | |
| 53 | +/*************************************************************************** | |
| 54 | + * Inline methods * | |
| 55 | + ***************************************************************************/ | |
| 56 | +inline | |
| 57 | +GFitsImage* GFitsImage::clone(void) const | |
| 58 | +{ | |
| 59 | + return new GFitsImage(*this); | |
| 60 | +} | |
| 61 | + | |
| 62 | +#endif /* GFITSIMAGE_HPP */ | ... | ... |
include/GFitsTableCol.hpp
0 โ 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GFitsTableCol.hpp - FITS table column abstract base class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + ***************************************************************************/ | |
| 13 | + | |
| 14 | +#ifndef GFITSTABLECOL_HPP | |
| 15 | +#define GFITSTABLECOL_HPP | |
| 16 | + | |
| 17 | +/* __ Includes ___________________________________________________________ */ | |
| 18 | +#include "GFitsCfitsio.hpp" | |
| 19 | + | |
| 20 | +/* __ Namespaces _________________________________________________________ */ | |
| 21 | + | |
| 22 | + | |
| 23 | +/*************************************************************************** | |
| 24 | + * GFitsTableCol class definition * | |
| 25 | + ***************************************************************************/ | |
| 26 | +class GFitsTableCol { | |
| 27 | + | |
| 28 | +public: | |
| 29 | + // Constructors and destructors | |
| 30 | + GFitsTableCol(); | |
| 31 | + GFitsTableCol(const GFitsTableCol& column); | |
| 32 | + virtual ~GFitsTableCol(); | |
| 33 | + | |
| 34 | + // Operators | |
| 35 | + GFitsTableCol& operator= (const GFitsTableCol& column); | |
| 36 | + | |
| 37 | + // Virtual Methods | |
| 38 | + virtual std::string string(const int& row, const int& col = 0) = 0; | |
| 39 | + virtual double real(const int& row, const int& col = 0) = 0; | |
| 40 | + virtual int integer(const int& row, const int& col = 0) = 0; | |
| 41 | + virtual GFitsTableCol* clone(void) const = 0; | |
| 42 | + virtual std::string* ptr_string(void) = 0; | |
| 43 | + virtual double* ptr_double(void) = 0; | |
| 44 | + virtual float* ptr_float(void) = 0; | |
| 45 | + virtual short* ptr_short(void) = 0; | |
| 46 | + virtual long* ptr_long(void) = 0; | |
| 47 | + virtual int* ptr_int(void) = 0; | |
| 48 | + | |
| 49 | + // Base class Methods | |
| 50 | + void set_name(const std::string name); | |
| 51 | + void set_colnum(const int colnum); | |
| 52 | + void set_type(const int type); | |
| 53 | + void set_repeat(const int repeat); | |
| 54 | + void set_width(const int width); | |
| 55 | + void set_length(const int length); | |
| 56 | + void set_fitsfile(const __fitsfile* fptr); | |
| 57 | + std::string name(void); | |
| 58 | + int colnum(void); | |
| 59 | + int type(void); | |
| 60 | + int repeat(void); | |
| 61 | + int width(void); | |
| 62 | + int length(void); | |
| 63 | + | |
| 64 | +protected: | |
| 65 | + // Protected data area | |
| 66 | + std::string m_name; | |
| 67 | + int m_colnum; | |
| 68 | + int m_type; | |
| 69 | + int m_repeat; | |
| 70 | + int m_width; | |
| 71 | + int m_length; | |
| 72 | + __fitsfile* m_fitsfile; | |
| 73 | + | |
| 74 | +private: | |
| 75 | + // Private methods | |
| 76 | + void init_members(void); | |
| 77 | + void copy_members(const GFitsTableCol& column); | |
| 78 | + void free_members(void); | |
| 79 | +}; | |
| 80 | + | |
| 81 | + | |
| 82 | +/*************************************************************************** | |
| 83 | + * Inline methods * | |
| 84 | + ***************************************************************************/ | |
| 85 | +inline void GFitsTableCol::set_name(const std::string name) { m_name = name; } | |
| 86 | +inline void GFitsTableCol::set_colnum(const int colnum) { m_colnum = colnum; } | |
| 87 | +inline void GFitsTableCol::set_type(const int type) { m_type = type; } | |
| 88 | +inline void GFitsTableCol::set_repeat(const int repeat) { m_repeat = repeat; } | |
| 89 | +inline void GFitsTableCol::set_width(const int width) { m_width = width; } | |
| 90 | +inline void GFitsTableCol::set_length(const int length) { m_length = length; } | |
| 91 | +inline void GFitsTableCol::set_fitsfile(const __fitsfile* fptr) { m_fitsfile = (__fitsfile*)fptr; } | |
| 92 | +inline std::string GFitsTableCol::name(void) { return m_name; } | |
| 93 | +inline int GFitsTableCol::colnum(void) { return m_colnum; } | |
| 94 | +inline int GFitsTableCol::type(void) { return m_type; } | |
| 95 | +inline int GFitsTableCol::repeat(void) { return m_repeat; } | |
| 96 | +inline int GFitsTableCol::width(void) { return m_width; } | |
| 97 | +inline int GFitsTableCol::length(void) { return m_length; } | |
| 98 | + | |
| 99 | +#endif /* GFITSTABLECOL_HPP */ | ... | ... |
include/GFitsTableDblCol.hpp
0 โ 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GFitsTableDblCol.hpp - FITS table double column class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + ***************************************************************************/ | |
| 13 | + | |
| 14 | +#ifndef GFITSTABLEDBLCOL_HPP | |
| 15 | +#define GFITSTABLEDBLCOL_HPP | |
| 16 | + | |
| 17 | +/* __ Includes ___________________________________________________________ */ | |
| 18 | +#include "GFitsCfitsio.hpp" | |
| 19 | +#include "GFitsTableCol.hpp" | |
| 20 | + | |
| 21 | +/* __ Namespaces _________________________________________________________ */ | |
| 22 | + | |
| 23 | + | |
| 24 | +/* __ Structures _________________________________________________________ */ | |
| 25 | + | |
| 26 | + | |
| 27 | +/*************************************************************************** | |
| 28 | + * GFitsTableDblCol class definition * | |
| 29 | + ***************************************************************************/ | |
| 30 | +class GFitsTableDblCol : public GFitsTableCol { | |
| 31 | + | |
| 32 | +public: | |
| 33 | + // Constructors and destructors | |
| 34 | + GFitsTableDblCol(); | |
| 35 | + GFitsTableDblCol(const GFitsTableDblCol& column); | |
| 36 | + virtual ~GFitsTableDblCol(); | |
| 37 | + | |
| 38 | + // Operators | |
| 39 | + GFitsTableDblCol& operator= (const GFitsTableDblCol& column); | |
| 40 | + | |
| 41 | + // Methods | |
| 42 | + std::string string(const int& row, const int& col = 0); | |
| 43 | + double real(const int& row, const int& col = 0); | |
| 44 | + int integer(const int& row, const int& col = 0); | |
| 45 | + GFitsTableDblCol* clone(void) const; | |
| 46 | + std::string* ptr_string(void); | |
| 47 | + double* ptr_double(void); | |
| 48 | + float* ptr_float(void); | |
| 49 | + short* ptr_short(void); | |
| 50 | + long* ptr_long(void); | |
| 51 | + int* ptr_int(void); | |
| 52 | + | |
| 53 | +private: | |
| 54 | + // Private methods | |
| 55 | + void init_members(void); | |
| 56 | + void copy_members(const GFitsTableDblCol& column); | |
| 57 | + void free_members(void); | |
| 58 | + void load(void); | |
| 59 | + | |
| 60 | + // Private data area | |
| 61 | + int m_size; // Size of data area | |
| 62 | + double* m_data; // Data area | |
| 63 | + double m_nulval; // NULL value | |
| 64 | +}; | |
| 65 | + | |
| 66 | + | |
| 67 | +/*************************************************************************** | |
| 68 | + * Inline methods * | |
| 69 | + ***************************************************************************/ | |
| 70 | +inline double* GFitsTableDblCol::ptr_double(void) { return m_data; } | |
| 71 | +inline | |
| 72 | +GFitsTableDblCol* GFitsTableDblCol::clone(void) const | |
| 73 | +{ | |
| 74 | + return new GFitsTableDblCol(*this); | |
| 75 | +} | |
| 76 | + | |
| 77 | +#endif /* GFITSTABLEDBLCOL_HPP */ | ... | ... |
include/GammaLib.hpp
| ... | ... | @@ -32,6 +32,11 @@ |
| 32 | 32 | #include "GFitsHeader.hpp" |
| 33 | 33 | #include "GFitsHeaderCard.hpp" |
| 34 | 34 | #include "GFitsData.hpp" |
| 35 | +#include "GFitsImage.hpp" | |
| 36 | +#include "GFitsAsciiTable.hpp" | |
| 37 | +#include "GFitsBinTable.hpp" | |
| 38 | +#include "GFitsTableCol.hpp" | |
| 39 | +#include "GFitsTableDblCol.hpp" | |
| 35 | 40 | |
| 36 | 41 | #include "GVector.hpp" |
| 37 | 42 | #include "GMatrixBase.hpp" | ... | ... |
include/Makefile.am
| ... | ... | @@ -7,6 +7,11 @@ pkginclude_HEADERS = GammaLib.hpp \ |
| 7 | 7 | GFitsHeaderCard.hpp \ |
| 8 | 8 | GFitsHeader.hpp \ |
| 9 | 9 | GFitsData.hpp \ |
| 10 | + GFitsImage.hpp \ | |
| 11 | + GFitsAsciiTable.hpp \ | |
| 12 | + GFitsBinTable.hpp \ | |
| 13 | + GFitsTableCol.hpp \ | |
| 14 | + GFitsTableDblCol.hpp \ | |
| 10 | 15 | GFitsHDU.hpp \ |
| 11 | 16 | GFits.hpp \ |
| 12 | 17 | GFitPar.hpp \ | ... | ... |
include/Makefile.in
| ... | ... | @@ -113,6 +113,11 @@ pkginclude_HEADERS = GammaLib.hpp \ |
| 113 | 113 | GFitsHeaderCard.hpp \ |
| 114 | 114 | GFitsHeader.hpp \ |
| 115 | 115 | GFitsData.hpp \ |
| 116 | + GFitsImage.hpp \ | |
| 117 | + GFitsAsciiTable.hpp \ | |
| 118 | + GFitsBinTable.hpp \ | |
| 119 | + GFitsTableCol.hpp \ | |
| 120 | + GFitsTableDblCol.hpp \ | |
| 116 | 121 | GFitsHDU.hpp \ |
| 117 | 122 | GFits.hpp \ |
| 118 | 123 | GFitPar.hpp \ | ... | ... |
src/GException.cpp
| ... | ... | @@ -20,6 +20,23 @@ using namespace std; |
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | /*************************************************************************** |
| 23 | + * Private conversion functions * | |
| 24 | + ***************************************************************************/ | |
| 25 | +std::string str(int value) | |
| 26 | +{ | |
| 27 | + ostringstream s_value; | |
| 28 | + s_value << value; | |
| 29 | + return s_value.str(); | |
| 30 | +} | |
| 31 | +std::string str(double value) | |
| 32 | +{ | |
| 33 | + ostringstream s_value; | |
| 34 | + s_value << scientific << value; | |
| 35 | + return s_value.str(); | |
| 36 | +} | |
| 37 | + | |
| 38 | + | |
| 39 | +/*************************************************************************** | |
| 23 | 40 | * Exception handler base class definition * |
| 24 | 41 | ***************************************************************************/ |
| 25 | 42 | const char* GExceptionHandler::what() const throw() |
| ... | ... | @@ -34,10 +51,8 @@ const char* GExceptionHandler::what() const throw() |
| 34 | 51 | ***************************************************************************/ |
| 35 | 52 | GException::mem_alloc::mem_alloc(string origin, unsigned num) |
| 36 | 53 | { |
| 37 | - ostringstream s_num; | |
| 38 | - s_num << num; | |
| 39 | 54 | m_origin = origin; |
| 40 | - m_message = "Memory allocation error (" + s_num.str() + " elements)"; | |
| 55 | + m_message = "Memory allocation error (" + str((int)num) + " elements)"; | |
| 41 | 56 | } |
| 42 | 57 | |
| 43 | 58 | |
| ... | ... | @@ -52,18 +67,25 @@ GException::empty::empty(string origin) |
| 52 | 67 | |
| 53 | 68 | |
| 54 | 69 | /*************************************************************************** |
| 70 | + * Index out of range * | |
| 71 | + ***************************************************************************/ | |
| 72 | +GException::out_of_range::out_of_range(string origin, int inx, int min, int max) | |
| 73 | +{ | |
| 74 | + m_origin = origin; | |
| 75 | + m_message = "Index (" + str(inx) + ") out of range [" + str(min) + | |
| 76 | + "," + str(max) + "]"; | |
| 77 | +} | |
| 78 | + | |
| 79 | + | |
| 80 | +/*************************************************************************** | |
| 55 | 81 | * Vector index out of range * |
| 56 | 82 | ***************************************************************************/ |
| 57 | 83 | GException::out_of_range::out_of_range(string origin, int inx, int elements) |
| 58 | 84 | { |
| 59 | 85 | m_origin = origin; |
| 60 | 86 | if (elements > 0) { |
| 61 | - ostringstream s_inx; | |
| 62 | - ostringstream s_elements; | |
| 63 | - s_inx << inx; | |
| 64 | - s_elements << elements-1; | |
| 65 | - m_message = "Vector index (" + s_inx.str() + ") out of range [0," + | |
| 66 | - s_elements.str() + "]"; | |
| 87 | + m_message = "Vector index (" + str(inx) + ") out of range [0," + | |
| 88 | + str(elements-1) + "]"; | |
| 67 | 89 | } |
| 68 | 90 | else { |
| 69 | 91 | m_message = "Empty vector"; |
| ... | ... | @@ -71,24 +93,15 @@ GException::out_of_range::out_of_range(string origin, int inx, int elements) |
| 71 | 93 | } |
| 72 | 94 | |
| 73 | 95 | |
| 74 | - | |
| 75 | 96 | /*************************************************************************** |
| 76 | 97 | * Matrix row or column out of range * |
| 77 | 98 | ***************************************************************************/ |
| 78 | 99 | GException::out_of_range::out_of_range(string origin, int row, int col, int rows, int cols) |
| 79 | 100 | { |
| 80 | - m_origin = origin; | |
| 81 | - ostringstream s_row; | |
| 82 | - ostringstream s_col; | |
| 83 | - ostringstream s_rows; | |
| 84 | - ostringstream s_cols; | |
| 85 | - s_row << row; | |
| 86 | - s_col << col; | |
| 87 | - s_rows << rows-1; | |
| 88 | - s_cols << cols-1; | |
| 89 | - m_message = "Matrix element (" + s_row.str() + "," + s_col.str() + | |
| 90 | - ") out of range ([0," + s_rows.str() + "], [0," + | |
| 91 | - s_cols.str() + "])"; | |
| 101 | + m_origin = origin; | |
| 102 | + m_message = "Matrix element (" + str(row) + "," + str(col) + | |
| 103 | + ") out of range ([0," + str(rows) + "], [0," + | |
| 104 | + str(cols) + "])"; | |
| 92 | 105 | } |
| 93 | 106 | |
| 94 | 107 | |
| ... | ... | @@ -97,13 +110,9 @@ GException::out_of_range::out_of_range(string origin, int row, int col, int rows |
| 97 | 110 | ***************************************************************************/ |
| 98 | 111 | GException::vector_mismatch::vector_mismatch(string origin, int size1, int size2) |
| 99 | 112 | { |
| 100 | - m_origin = origin; | |
| 101 | - ostringstream s_size1; | |
| 102 | - ostringstream s_size2; | |
| 103 | - s_size1 << size1; | |
| 104 | - s_size2 << size2; | |
| 105 | - m_message = "Vector dimensions differ (" + s_size1.str() + " <-> " + | |
| 106 | - s_size2.str() + ")"; | |
| 113 | + m_origin = origin; | |
| 114 | + m_message = "Vector dimensions differ (" + str(size1) + " <-> " + | |
| 115 | + str(size2) + ")"; | |
| 107 | 116 | } |
| 108 | 117 | |
| 109 | 118 | |
| ... | ... | @@ -112,11 +121,9 @@ GException::vector_mismatch::vector_mismatch(string origin, int size1, int size2 |
| 112 | 121 | ***************************************************************************/ |
| 113 | 122 | GException::vector_bad_cross_dim::vector_bad_cross_dim(string origin, int elements) |
| 114 | 123 | { |
| 115 | - m_origin = origin; | |
| 116 | - ostringstream s_elements; | |
| 117 | - s_elements << elements; | |
| 124 | + m_origin = origin; | |
| 118 | 125 | m_message = "Vector cross product only defined for 3 dimensions but vector size is " + |
| 119 | - s_elements.str(); | |
| 126 | + str(elements); | |
| 120 | 127 | } |
| 121 | 128 | |
| 122 | 129 | |
| ... | ... | @@ -125,16 +132,10 @@ GException::vector_bad_cross_dim::vector_bad_cross_dim(string origin, int elemen |
| 125 | 132 | ***************************************************************************/ |
| 126 | 133 | GException::matrix_vector_mismatch::matrix_vector_mismatch(string origin, int num, int rows, int cols) |
| 127 | 134 | { |
| 128 | - m_origin = origin; | |
| 129 | - ostringstream s_num; | |
| 130 | - ostringstream s_rows; | |
| 131 | - ostringstream s_cols; | |
| 132 | - s_num << num; | |
| 133 | - s_rows << rows; | |
| 134 | - s_cols << cols; | |
| 135 | - m_message = "Vector dimension [" + s_num.str() + | |
| 135 | + m_origin = origin; | |
| 136 | + m_message = "Vector dimension [" + str(num) + | |
| 136 | 137 | "] is incompatible with matrix size [" + |
| 137 | - s_rows.str() + "," + s_cols.str() + "]"; | |
| 138 | + str(rows) + "," + str(cols) + "]"; | |
| 138 | 139 | } |
| 139 | 140 | |
| 140 | 141 | |
| ... | ... | @@ -143,18 +144,9 @@ GException::matrix_vector_mismatch::matrix_vector_mismatch(string origin, int nu |
| 143 | 144 | ***************************************************************************/ |
| 144 | 145 | GException::matrix_mismatch::matrix_mismatch(string origin, int rows1, int cols1, int rows2, int cols2) |
| 145 | 146 | { |
| 146 | - m_origin = origin; | |
| 147 | - ostringstream s_rows1; | |
| 148 | - ostringstream s_rows2; | |
| 149 | - ostringstream s_cols1; | |
| 150 | - ostringstream s_cols2; | |
| 151 | - s_rows1 << rows1; | |
| 152 | - s_cols1 << cols1; | |
| 153 | - s_rows2 << rows2; | |
| 154 | - s_cols2 << cols2; | |
| 155 | - m_message = "Matrix mismatch: M1(" + s_rows1.str() + "," + s_cols1.str() + | |
| 156 | - ") incompatible with M2(" + s_rows2.str() + "," + | |
| 157 | - s_cols2.str() + ")"; | |
| 147 | + m_origin = origin; | |
| 148 | + m_message = "Matrix mismatch: M1(" + str(rows1) + "," + str(cols1) + | |
| 149 | + ") incompatible with M2(" + str(rows2) + "," + str(cols2) + ")"; | |
| 158 | 150 | } |
| 159 | 151 | |
| 160 | 152 | |
| ... | ... | @@ -163,13 +155,8 @@ GException::matrix_mismatch::matrix_mismatch(string origin, int rows1, int cols1 |
| 163 | 155 | ***************************************************************************/ |
| 164 | 156 | GException::matrix_not_rectangular::matrix_not_rectangular(string origin, int rows, int cols) |
| 165 | 157 | { |
| 166 | - m_origin = origin; | |
| 167 | - ostringstream s_rows; | |
| 168 | - ostringstream s_cols; | |
| 169 | - s_rows << rows; | |
| 170 | - s_cols << cols; | |
| 171 | - m_message = "Matrix is not rectangular [" + s_rows.str() + "," + s_cols.str() + | |
| 172 | - "]"; | |
| 158 | + m_origin = origin; | |
| 159 | + m_message = "Matrix is not rectangular [" + str(rows) + "," + str(cols) + "]"; | |
| 173 | 160 | } |
| 174 | 161 | |
| 175 | 162 | |
| ... | ... | @@ -178,13 +165,9 @@ GException::matrix_not_rectangular::matrix_not_rectangular(string origin, int ro |
| 178 | 165 | ***************************************************************************/ |
| 179 | 166 | GException::matrix_not_pos_definite::matrix_not_pos_definite(string origin, int row, double sum) |
| 180 | 167 | { |
| 181 | - m_origin = origin; | |
| 182 | - ostringstream s_rows; | |
| 183 | - ostringstream s_sum; | |
| 184 | - s_rows << row; | |
| 185 | - s_sum << scientific << sum; | |
| 186 | - m_message = "Matrix is not positive definite (sum " + s_sum.str() + | |
| 187 | - " occured in row/column " + s_rows.str() + ")"; | |
| 168 | + m_origin = origin; | |
| 169 | + m_message = "Matrix is not positive definite (sum " + str(sum) + | |
| 170 | + " occured in row/column " + str(row) + ")"; | |
| 188 | 171 | } |
| 189 | 172 | |
| 190 | 173 | |
| ... | ... | @@ -193,13 +176,8 @@ GException::matrix_not_pos_definite::matrix_not_pos_definite(string origin, int |
| 193 | 176 | ***************************************************************************/ |
| 194 | 177 | GException::matrix_not_symmetric::matrix_not_symmetric(string origin, int cols, int rows) |
| 195 | 178 | { |
| 196 | - m_origin = origin; | |
| 197 | - ostringstream s_rows; | |
| 198 | - ostringstream s_cols; | |
| 199 | - s_rows << rows; | |
| 200 | - s_cols << cols; | |
| 201 | - m_message = "Matrix is not symmetric [" + s_rows.str() + "," + | |
| 202 | - s_cols.str() + "]"; | |
| 179 | + m_origin = origin; | |
| 180 | + m_message = "Matrix is not symmetric [" + str(rows) + "," + str(cols) + "]"; | |
| 203 | 181 | } |
| 204 | 182 | |
| 205 | 183 | |
| ... | ... | @@ -228,16 +206,10 @@ GException::matrix_zero::matrix_zero(string origin) |
| 228 | 206 | ***************************************************************************/ |
| 229 | 207 | GException::invalid_order::invalid_order(string origin, int order, int min_order, int max_order) |
| 230 | 208 | { |
| 231 | - m_origin = origin; | |
| 232 | - ostringstream s_order; | |
| 233 | - ostringstream s_min_order; | |
| 234 | - ostringstream s_max_order; | |
| 235 | - s_order << order; | |
| 236 | - s_min_order << min_order; | |
| 237 | - s_max_order << max_order; | |
| 238 | - m_message = "Invalid ordering type " + s_order.str() + | |
| 239 | - "requested; must be comprised in [" + s_min_order.str() + | |
| 240 | - "," + s_max_order.str() + "]"; | |
| 209 | + m_origin = origin; | |
| 210 | + m_message = "Invalid ordering type " + str(order) + | |
| 211 | + "requested; must be comprised in [" + str(min_order) + | |
| 212 | + "," + str(max_order) + "]"; | |
| 241 | 213 | } |
| 242 | 214 | |
| 243 | 215 | |
| ... | ... | @@ -266,6 +238,16 @@ GException::fits_open_error::fits_open_error(string origin, string filename, int |
| 266 | 238 | |
| 267 | 239 | |
| 268 | 240 | /*************************************************************************** |
| 241 | + * FITS file already opened * | |
| 242 | + ***************************************************************************/ | |
| 243 | +GException::fits_already_opened::fits_already_opened(string origin, string filename) | |
| 244 | +{ | |
| 245 | + m_origin = origin; | |
| 246 | + m_message = "GFits object has already the FITS file '" + filename + "' opened"; | |
| 247 | +} | |
| 248 | + | |
| 249 | + | |
| 250 | +/*************************************************************************** | |
| 269 | 251 | * FITS keyword not found error * |
| 270 | 252 | ***************************************************************************/ |
| 271 | 253 | GException::fits_key_not_found::fits_key_not_found(string origin, string keyname, int status) |
| ... | ... | @@ -273,3 +255,33 @@ GException::fits_key_not_found::fits_key_not_found(string origin, string keyname |
| 273 | 255 | m_origin = origin; |
| 274 | 256 | m_message = "Keyword '" + keyname + "' not found in header"; |
| 275 | 257 | } |
| 258 | + | |
| 259 | + | |
| 260 | +/*************************************************************************** | |
| 261 | + * Unknown HDU type found * | |
| 262 | + ***************************************************************************/ | |
| 263 | +GException::fits_unknown_HDU_type::fits_unknown_HDU_type(string origin, int type) | |
| 264 | +{ | |
| 265 | + m_origin = origin; | |
| 266 | + m_message = "HDU type " + str(type) + " is not known"; | |
| 267 | +} | |
| 268 | + | |
| 269 | + | |
| 270 | +/*************************************************************************** | |
| 271 | + * HDU is not a table * | |
| 272 | + ***************************************************************************/ | |
| 273 | +GException::fits_HDU_not_a_table::fits_HDU_not_a_table(string origin, int type) | |
| 274 | +{ | |
| 275 | + m_origin = origin; | |
| 276 | + m_message = "HDU is not a table (type " + str(type) + ")"; | |
| 277 | +} | |
| 278 | + | |
| 279 | + | |
| 280 | +/*************************************************************************** | |
| 281 | + * HDU is not a table * | |
| 282 | + ***************************************************************************/ | |
| 283 | +GException::fits_invalid_type::fits_invalid_type(string origin, string message) | |
| 284 | +{ | |
| 285 | + m_origin = origin; | |
| 286 | + m_message = message; | |
| 287 | +} | ... | ... |
src/Makefile.am
| ... | ... | @@ -15,6 +15,11 @@ files = GException.cpp \ |
| 15 | 15 | fits/GFitsHeaderCard.cpp \ |
| 16 | 16 | fits/GFitsHeader.cpp \ |
| 17 | 17 | fits/GFitsData.cpp \ |
| 18 | + fits/GFitsImage.cpp \ | |
| 19 | + fits/GFitsAsciiTable.cpp \ | |
| 20 | + fits/GFitsBinTable.cpp \ | |
| 21 | + fits/GFitsTableCol.cpp \ | |
| 22 | + fits/GFitsTableDblCol.cpp \ | |
| 18 | 23 | fits/GFitsHDU.cpp \ |
| 19 | 24 | fits/GFits.cpp \ |
| 20 | 25 | fit/GFitPar.cpp \ | ... | ... |
src/Makefile.in
| ... | ... | @@ -120,6 +120,11 @@ files = GException.cpp \ |
| 120 | 120 | fits/GFitsHeaderCard.cpp \ |
| 121 | 121 | fits/GFitsHeader.cpp \ |
| 122 | 122 | fits/GFitsData.cpp \ |
| 123 | + fits/GFitsImage.cpp \ | |
| 124 | + fits/GFitsAsciiTable.cpp \ | |
| 125 | + fits/GFitsBinTable.cpp \ | |
| 126 | + fits/GFitsTableCol.cpp \ | |
| 127 | + fits/GFitsTableDblCol.cpp \ | |
| 123 | 128 | fits/GFitsHDU.cpp \ |
| 124 | 129 | fits/GFits.cpp \ |
| 125 | 130 | fit/GFitPar.cpp \ |
| ... | ... | @@ -144,10 +149,11 @@ LTLIBRARIES = $(lib_LTLIBRARIES) |
| 144 | 149 | |
| 145 | 150 | libgamma_la_LIBADD = |
| 146 | 151 | am__objects_1 = GException.lo GData.lo GResponse.lo GObservation.lo \ |
| 147 | - GFitsHeaderCard.lo GFitsHeader.lo GFitsData.lo GFitsHDU.lo \ | |
| 148 | - GFits.lo GFitPar.lo GVector.lo GMatrixBase.lo GMatrix.lo \ | |
| 149 | - GSymMatrix.lo GSparseMatrix.lo GSparseSymbolic.lo \ | |
| 150 | - GSparseNumeric.lo | |
| 152 | + GFitsHeaderCard.lo GFitsHeader.lo GFitsData.lo GFitsImage.lo \ | |
| 153 | + GFitsAsciiTable.lo GFitsBinTable.lo GFitsTableCol.lo \ | |
| 154 | + GFitsTableDblCol.lo GFitsHDU.lo GFits.lo GFitPar.lo GVector.lo \ | |
| 155 | + GMatrixBase.lo GMatrix.lo GSymMatrix.lo GSparseMatrix.lo \ | |
| 156 | + GSparseSymbolic.lo GSparseNumeric.lo | |
| 151 | 157 | am_libgamma_la_OBJECTS = $(am__objects_1) |
| 152 | 158 | libgamma_la_OBJECTS = $(am_libgamma_la_OBJECTS) |
| 153 | 159 | |
| ... | ... | @@ -214,6 +220,11 @@ GObservation.lo: obs/GObservation.cpp |
| 214 | 220 | GFitsHeaderCard.lo: fits/GFitsHeaderCard.cpp |
| 215 | 221 | GFitsHeader.lo: fits/GFitsHeader.cpp |
| 216 | 222 | GFitsData.lo: fits/GFitsData.cpp |
| 223 | +GFitsImage.lo: fits/GFitsImage.cpp | |
| 224 | +GFitsAsciiTable.lo: fits/GFitsAsciiTable.cpp | |
| 225 | +GFitsBinTable.lo: fits/GFitsBinTable.cpp | |
| 226 | +GFitsTableCol.lo: fits/GFitsTableCol.cpp | |
| 227 | +GFitsTableDblCol.lo: fits/GFitsTableDblCol.cpp | |
| 217 | 228 | GFitsHDU.lo: fits/GFitsHDU.cpp |
| 218 | 229 | GFits.lo: fits/GFits.cpp |
| 219 | 230 | GFitPar.lo: fit/GFitPar.cpp |
| ... | ... | @@ -296,6 +307,51 @@ GFitsData.obj: fits/GFitsData.cpp |
| 296 | 307 | GFitsData.lo: fits/GFitsData.cpp |
| 297 | 308 | $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsData.lo `test -f 'fits/GFitsData.cpp' || echo '$(srcdir)/'`fits/GFitsData.cpp |
| 298 | 309 | |
| 310 | +GFitsImage.o: fits/GFitsImage.cpp | |
| 311 | + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsImage.o `test -f 'fits/GFitsImage.cpp' || echo '$(srcdir)/'`fits/GFitsImage.cpp | |
| 312 | + | |
| 313 | +GFitsImage.obj: fits/GFitsImage.cpp | |
| 314 | + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsImage.obj `cygpath -w fits/GFitsImage.cpp` | |
| 315 | + | |
| 316 | +GFitsImage.lo: fits/GFitsImage.cpp | |
| 317 | + $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsImage.lo `test -f 'fits/GFitsImage.cpp' || echo '$(srcdir)/'`fits/GFitsImage.cpp | |
| 318 | + | |
| 319 | +GFitsAsciiTable.o: fits/GFitsAsciiTable.cpp | |
| 320 | + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsAsciiTable.o `test -f 'fits/GFitsAsciiTable.cpp' || echo '$(srcdir)/'`fits/GFitsAsciiTable.cpp | |
| 321 | + | |
| 322 | +GFitsAsciiTable.obj: fits/GFitsAsciiTable.cpp | |
| 323 | + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsAsciiTable.obj `cygpath -w fits/GFitsAsciiTable.cpp` | |
| 324 | + | |
| 325 | +GFitsAsciiTable.lo: fits/GFitsAsciiTable.cpp | |
| 326 | + $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsAsciiTable.lo `test -f 'fits/GFitsAsciiTable.cpp' || echo '$(srcdir)/'`fits/GFitsAsciiTable.cpp | |
| 327 | + | |
| 328 | +GFitsBinTable.o: fits/GFitsBinTable.cpp | |
| 329 | + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsBinTable.o `test -f 'fits/GFitsBinTable.cpp' || echo '$(srcdir)/'`fits/GFitsBinTable.cpp | |
| 330 | + | |
| 331 | +GFitsBinTable.obj: fits/GFitsBinTable.cpp | |
| 332 | + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsBinTable.obj `cygpath -w fits/GFitsBinTable.cpp` | |
| 333 | + | |
| 334 | +GFitsBinTable.lo: fits/GFitsBinTable.cpp | |
| 335 | + $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsBinTable.lo `test -f 'fits/GFitsBinTable.cpp' || echo '$(srcdir)/'`fits/GFitsBinTable.cpp | |
| 336 | + | |
| 337 | +GFitsTableCol.o: fits/GFitsTableCol.cpp | |
| 338 | + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsTableCol.o `test -f 'fits/GFitsTableCol.cpp' || echo '$(srcdir)/'`fits/GFitsTableCol.cpp | |
| 339 | + | |
| 340 | +GFitsTableCol.obj: fits/GFitsTableCol.cpp | |
| 341 | + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsTableCol.obj `cygpath -w fits/GFitsTableCol.cpp` | |
| 342 | + | |
| 343 | +GFitsTableCol.lo: fits/GFitsTableCol.cpp | |
| 344 | + $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsTableCol.lo `test -f 'fits/GFitsTableCol.cpp' || echo '$(srcdir)/'`fits/GFitsTableCol.cpp | |
| 345 | + | |
| 346 | +GFitsTableDblCol.o: fits/GFitsTableDblCol.cpp | |
| 347 | + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsTableDblCol.o `test -f 'fits/GFitsTableDblCol.cpp' || echo '$(srcdir)/'`fits/GFitsTableDblCol.cpp | |
| 348 | + | |
| 349 | +GFitsTableDblCol.obj: fits/GFitsTableDblCol.cpp | |
| 350 | + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsTableDblCol.obj `cygpath -w fits/GFitsTableDblCol.cpp` | |
| 351 | + | |
| 352 | +GFitsTableDblCol.lo: fits/GFitsTableDblCol.cpp | |
| 353 | + $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsTableDblCol.lo `test -f 'fits/GFitsTableDblCol.cpp' || echo '$(srcdir)/'`fits/GFitsTableDblCol.cpp | |
| 354 | + | |
| 299 | 355 | GFitsHDU.o: fits/GFitsHDU.cpp |
| 300 | 356 | $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsHDU.o `test -f 'fits/GFitsHDU.cpp' || echo '$(srcdir)/'`fits/GFitsHDU.cpp |
| 301 | 357 | ... | ... |
src/fits/GFits.cpp
| ... | ... | @@ -20,6 +20,9 @@ |
| 20 | 20 | /* __ Namespaces _________________________________________________________ */ |
| 21 | 21 | |
| 22 | 22 | /* __ Method name definitions ____________________________________________ */ |
| 23 | +#define G_OPEN "GFits::open(std::string)" | |
| 24 | +#define G_SAVETO "GFits::saveto(const std::string, int)" | |
| 25 | +#define G_FREE_MEM "GFits::free_members()" | |
| 23 | 26 | |
| 24 | 27 | /* __ Macros _____________________________________________________________ */ |
| 25 | 28 | |
| ... | ... | @@ -121,23 +124,25 @@ GFits& GFits::operator= (const GFits& fits) |
| 121 | 124 | * Open FITS file * |
| 122 | 125 | * ----------------------------------------------------------------------- * |
| 123 | 126 | ***************************************************************************/ |
| 124 | -void GFits::open(std::string filename) | |
| 127 | +void GFits::open(const std::string filename) | |
| 125 | 128 | { |
| 129 | + // Don't allow opening if another file is already open | |
| 130 | + if (m_fitsfile != NULL) | |
| 131 | + throw GException::fits_already_opened(G_OPEN, m_filename); | |
| 132 | + | |
| 126 | 133 | // Open FITS file |
| 127 | 134 | int status = 0; |
| 128 | 135 | status = __ffopen(&m_fitsfile, filename.c_str(), 1, &status); |
| 129 | - if (status != 0) { | |
| 130 | - throw GException::fits_open_error("GFits::open(std::string)", filename, status); | |
| 131 | - } | |
| 136 | + if (status != 0) | |
| 137 | + throw GException::fits_open_error(G_OPEN, filename, status); | |
| 132 | 138 | |
| 133 | 139 | // Store FITS file attributes |
| 134 | 140 | m_filename = filename; |
| 135 | 141 | |
| 136 | 142 | // Determine number of HDUs |
| 137 | 143 | status = __ffthdu(m_fitsfile, &m_num_hdu, &status); |
| 138 | - if (status != 0) { | |
| 139 | - throw GException::fits_error("GFits::open(std::string)", status); | |
| 140 | - } | |
| 144 | + if (status != 0) | |
| 145 | + throw GException::fits_error(G_OPEN, status); | |
| 141 | 146 | |
| 142 | 147 | // Allocate HDUs |
| 143 | 148 | if (m_hdu != NULL) delete [] m_hdu; |
| ... | ... | @@ -153,25 +158,99 @@ void GFits::open(std::string filename) |
| 153 | 158 | |
| 154 | 159 | |
| 155 | 160 | /*************************************************************************** |
| 156 | - * Close FITS file * | |
| 161 | + * Save FITS file * | |
| 157 | 162 | * ----------------------------------------------------------------------- * |
| 158 | 163 | ***************************************************************************/ |
| 159 | -void GFits::close(void) | |
| 164 | +void GFits::save(void) | |
| 160 | 165 | { |
| 161 | - // Close FITS file | |
| 166 | + // Save all HDUs | |
| 167 | + for (int i = 0; i < m_num_hdu; ++i) | |
| 168 | + m_hdu[i].save(); | |
| 169 | + | |
| 170 | + // Return | |
| 171 | + return; | |
| 172 | +} | |
| 173 | + | |
| 174 | + | |
| 175 | +/*************************************************************************** | |
| 176 | + * Save to specified FITS file * | |
| 177 | + * ----------------------------------------------------------------------- * | |
| 178 | + ***************************************************************************/ | |
| 179 | +void GFits::saveto(const std::string filename, int clobber) | |
| 180 | +{ | |
| 181 | + // Create a copy of existing object. Recall that the copy does not | |
| 182 | + // carry over the FITS filename and pointer. Those will be automatically | |
| 183 | + // reset to the initial values in the new object. | |
| 184 | + GFits new_fits = *this; | |
| 185 | + | |
| 186 | + // Check if specified FITS file exists. If yes, saving will only be | |
| 187 | + // allowed if clobber is true ... | |
| 162 | 188 | int status = 0; |
| 163 | - status = __ffclos(m_fitsfile, &status); | |
| 189 | + status = __ffopen(&(new_fits.m_fitsfile), filename.c_str(), 1, &status); | |
| 190 | + if (status == 0) { | |
| 191 | + if (!clobber) { | |
| 192 | + throw GException::fits_open_error(G_SAVETO, filename, status); | |
| 193 | + //throw file_exists ... | |
| 194 | + } | |
| 195 | + //delete existing file | |
| 196 | + //... | |
| 197 | + } | |
| 164 | 198 | |
| 165 | - // Handle error | |
| 166 | - if (status != 0) { | |
| 167 | - throw GException::fits_error("GFits::close(std::string)", status); | |
| 199 | + // ... otherwise create a new FITS file now | |
| 200 | + else { | |
| 201 | + // ... | |
| 168 | 202 | } |
| 169 | 203 | |
| 204 | + // Save all HDUs | |
| 205 | + for (int i = 0; i < m_num_hdu; ++i) | |
| 206 | + new_fits.m_hdu[i].save(); | |
| 207 | + | |
| 170 | 208 | // Return |
| 171 | 209 | return; |
| 172 | 210 | } |
| 173 | 211 | |
| 174 | 212 | |
| 213 | +/*************************************************************************** | |
| 214 | + * Close FITS file * | |
| 215 | + * ----------------------------------------------------------------------- * | |
| 216 | + * Closing detaches a FITS file from the GFits object and returns a clean * | |
| 217 | + * empty object. * | |
| 218 | + ***************************************************************************/ | |
| 219 | +void GFits::close(void) | |
| 220 | +{ | |
| 221 | + // Close file and free all members | |
| 222 | + free_members(); | |
| 223 | + | |
| 224 | + // Initialise members | |
| 225 | + init_members(); | |
| 226 | + | |
| 227 | + // Return | |
| 228 | + return; | |
| 229 | +} | |
| 230 | + | |
| 231 | + | |
| 232 | +/*************************************************************************** | |
| 233 | + * Get pointer to HDU * | |
| 234 | + * ----------------------------------------------------------------------- * | |
| 235 | + ***************************************************************************/ | |
| 236 | +GFitsHDU* GFits::hdu(std::string extname) | |
| 237 | +{ | |
| 238 | + // Initialise result to NULL pointer | |
| 239 | + GFitsHDU* ptr = NULL; | |
| 240 | + | |
| 241 | + // Search for specified extension | |
| 242 | + for (int i = 0; i < m_num_hdu; ++i) { | |
| 243 | + if (m_hdu[i].extname() == extname) { | |
| 244 | + ptr = &(m_hdu[i]); | |
| 245 | + break; | |
| 246 | + } | |
| 247 | + } | |
| 248 | + | |
| 249 | + // Return pointer | |
| 250 | + return ptr; | |
| 251 | +} | |
| 252 | + | |
| 253 | + | |
| 175 | 254 | /*========================================================================== |
| 176 | 255 | = = |
| 177 | 256 | = GFits private methods = |
| ... | ... | @@ -198,12 +277,17 @@ void GFits::init_members(void) |
| 198 | 277 | /*************************************************************************** |
| 199 | 278 | * Copy class members * |
| 200 | 279 | * ----------------------------------------------------------------------- * |
| 280 | + * The function does not copy the FITS filename and FITS file pointer. * | |
| 281 | + * This prevents that several copies of the FITS file pointer exist in * | |
| 282 | + * different instances of GFits, which would lead to confusion since one * | |
| 283 | + * instance could close the file while for another it still would be * | |
| 284 | + * opened. The rule ONE INSTANCE - ONE FILE applies. * | |
| 201 | 285 | ***************************************************************************/ |
| 202 | 286 | void GFits::copy_members(const GFits& fits) |
| 203 | 287 | { |
| 204 | - // Copy GFits attributes | |
| 205 | - m_filename = fits.m_filename; | |
| 206 | - m_fitsfile = fits.m_fitsfile; | |
| 288 | + // Reset FITS file attributes | |
| 289 | + m_filename.clear(); | |
| 290 | + m_fitsfile = NULL; | |
| 207 | 291 | |
| 208 | 292 | // Copy HDUs |
| 209 | 293 | if (fits.m_hdu != NULL && fits.m_num_hdu > 0) { |
| ... | ... | @@ -224,6 +308,14 @@ void GFits::copy_members(const GFits& fits) |
| 224 | 308 | ***************************************************************************/ |
| 225 | 309 | void GFits::free_members(void) |
| 226 | 310 | { |
| 311 | + // If FITS file has been opened then close it now | |
| 312 | + if (m_fitsfile != NULL) { | |
| 313 | + int status = 0; | |
| 314 | + status = __ffclos(m_fitsfile, &status); | |
| 315 | + if (status != 0) | |
| 316 | + throw GException::fits_error(G_FREE_MEM, status); | |
| 317 | + } | |
| 318 | + | |
| 227 | 319 | // Free memory |
| 228 | 320 | if (m_hdu != NULL) delete [] m_hdu; |
| 229 | 321 | ... | ... |
src/fits/GFitsAsciiTable.cpp
0 โ 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GFitsAsciiTable.cpp - FITS ASCII table class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * ----------------------------------------------------------------------- * | |
| 13 | + ***************************************************************************/ | |
| 14 | + | |
| 15 | +/* __ Includes ___________________________________________________________ */ | |
| 16 | +#include "GException.hpp" | |
| 17 | +#include "GFitsAsciiTable.hpp" | |
| 18 | +#include <iostream> // cout, cerr | |
| 19 | + | |
| 20 | +/* __ Namespaces _________________________________________________________ */ | |
| 21 | + | |
| 22 | +/* __ Method name definitions ____________________________________________ */ | |
| 23 | + | |
| 24 | +/* __ Macros _____________________________________________________________ */ | |
| 25 | + | |
| 26 | +/* __ Coding definitions _________________________________________________ */ | |
| 27 | + | |
| 28 | +/* __ Debug definitions __________________________________________________ */ | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | +/*========================================================================== | |
| 33 | + = = | |
| 34 | + = GFitsAsciiTable constructors/destructors = | |
| 35 | + = = | |
| 36 | + ==========================================================================*/ | |
| 37 | + | |
| 38 | +/*************************************************************************** | |
| 39 | + * Constructor * | |
| 40 | + * ----------------------------------------------------------------------- * | |
| 41 | + ***************************************************************************/ | |
| 42 | +GFitsAsciiTable::GFitsAsciiTable() : GFitsData() | |
| 43 | +{ | |
| 44 | + // Initialise class members for clean destruction | |
| 45 | + init_members(); | |
| 46 | + | |
| 47 | + // Return | |
| 48 | + return; | |
| 49 | +} | |
| 50 | + | |
| 51 | + | |
| 52 | +/*************************************************************************** | |
| 53 | + * Copy constructor * | |
| 54 | + * ----------------------------------------------------------------------- * | |
| 55 | + ***************************************************************************/ | |
| 56 | +GFitsAsciiTable::GFitsAsciiTable(const GFitsAsciiTable& table) : GFitsData(table) | |
| 57 | +{ | |
| 58 | + // Initialise class members for clean destruction | |
| 59 | + init_members(); | |
| 60 | + | |
| 61 | + // Copy members | |
| 62 | + copy_members(table); | |
| 63 | + | |
| 64 | + // Return | |
| 65 | + return; | |
| 66 | +} | |
| 67 | + | |
| 68 | + | |
| 69 | +/*************************************************************************** | |
| 70 | + * Destructor * | |
| 71 | + * ----------------------------------------------------------------------- * | |
| 72 | + ***************************************************************************/ | |
| 73 | +GFitsAsciiTable::~GFitsAsciiTable() | |
| 74 | +{ | |
| 75 | + // Free members | |
| 76 | + free_members(); | |
| 77 | + | |
| 78 | + // Return | |
| 79 | + return; | |
| 80 | +} | |
| 81 | + | |
| 82 | + | |
| 83 | +/*========================================================================== | |
| 84 | + = = | |
| 85 | + = GFitsAsciiTable operators = | |
| 86 | + = = | |
| 87 | + ==========================================================================*/ | |
| 88 | + | |
| 89 | +/*************************************************************************** | |
| 90 | + * Assignment operator * | |
| 91 | + * ----------------------------------------------------------------------- * | |
| 92 | + ***************************************************************************/ | |
| 93 | +GFitsAsciiTable& GFitsAsciiTable::operator= (const GFitsAsciiTable& table) | |
| 94 | +{ | |
| 95 | + // Execute only if object is not identical | |
| 96 | + if (this != &table) { | |
| 97 | + | |
| 98 | + // Copy base class members | |
| 99 | + this->GFitsData::operator=(table); | |
| 100 | + | |
| 101 | + // Free members | |
| 102 | + free_members(); | |
| 103 | + | |
| 104 | + // Initialise private members for clean destruction | |
| 105 | + init_members(); | |
| 106 | + | |
| 107 | + // Copy members | |
| 108 | + copy_members(table); | |
| 109 | + | |
| 110 | + } // endif: object was not identical | |
| 111 | + | |
| 112 | + // Return this object | |
| 113 | + return *this; | |
| 114 | +} | |
| 115 | + | |
| 116 | + | |
| 117 | +/*========================================================================== | |
| 118 | + = = | |
| 119 | + = GFitsAsciiTable public methods = | |
| 120 | + = = | |
| 121 | + ==========================================================================*/ | |
| 122 | + | |
| 123 | +/*************************************************************************** | |
| 124 | + * Open Table * | |
| 125 | + * ----------------------------------------------------------------------- * | |
| 126 | + ***************************************************************************/ | |
| 127 | +void GFitsAsciiTable::open(__fitsfile* fptr) | |
| 128 | +{ | |
| 129 | + cout << "open ASCII table" << endl; | |
| 130 | + // Return | |
| 131 | + return; | |
| 132 | +} | |
| 133 | + | |
| 134 | + | |
| 135 | +/*************************************************************************** | |
| 136 | + * Close Table * | |
| 137 | + * ----------------------------------------------------------------------- * | |
| 138 | + ***************************************************************************/ | |
| 139 | +void GFitsAsciiTable::close(void) | |
| 140 | +{ | |
| 141 | + // Free members | |
| 142 | + free_members(); | |
| 143 | + | |
| 144 | + // Initialise members | |
| 145 | + init_members(); | |
| 146 | + | |
| 147 | + // Return | |
| 148 | + return; | |
| 149 | +} | |
| 150 | + | |
| 151 | + | |
| 152 | +/*************************************************************************** | |
| 153 | + * Return pointer to column with specified name * | |
| 154 | + * ----------------------------------------------------------------------- * | |
| 155 | + ***************************************************************************/ | |
| 156 | +GFitsTableCol* GFitsAsciiTable::column(const std::string colname) | |
| 157 | +{ | |
| 158 | + // Initialise pointer | |
| 159 | + GFitsTableCol* ptr = NULL; | |
| 160 | + | |
| 161 | + // If there are columns then search for the specified name | |
| 162 | + if (m_columns != NULL) { | |
| 163 | + for (int i = 0; i < m_cols; ++i) { | |
| 164 | + if (m_columns[i]->name() == colname) { | |
| 165 | + ptr = m_columns[i]; | |
| 166 | + break; | |
| 167 | + } | |
| 168 | + } | |
| 169 | + } | |
| 170 | + | |
| 171 | + // Return column pointer | |
| 172 | + return ptr; | |
| 173 | +} | |
| 174 | + | |
| 175 | + | |
| 176 | +/*************************************************************************** | |
| 177 | + * Return pointer to column with number * | |
| 178 | + * ----------------------------------------------------------------------- * | |
| 179 | + ***************************************************************************/ | |
| 180 | +GFitsTableCol* GFitsAsciiTable::column(const int colnum) | |
| 181 | +{ | |
| 182 | + // Initialise pointer | |
| 183 | + GFitsTableCol* ptr = NULL; | |
| 184 | + | |
| 185 | + // If there are columns then search for the specified name | |
| 186 | + if (m_columns != NULL) { | |
| 187 | + ptr = m_columns[colnum]; | |
| 188 | + } | |
| 189 | + | |
| 190 | + // Return column pointer | |
| 191 | + return ptr; | |
| 192 | +} | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | +/*========================================================================== | |
| 198 | + = = | |
| 199 | + = GFitsAsciiTable private methods = | |
| 200 | + = = | |
| 201 | + ==========================================================================*/ | |
| 202 | + | |
| 203 | +/*************************************************************************** | |
| 204 | + * Initialise class members * | |
| 205 | + * ----------------------------------------------------------------------- * | |
| 206 | + ***************************************************************************/ | |
| 207 | +void GFitsAsciiTable::init_members(void) | |
| 208 | +{ | |
| 209 | + // Initialise members | |
| 210 | + m_rows = 0; | |
| 211 | + m_cols = 0; | |
| 212 | + m_columns = NULL; | |
| 213 | + | |
| 214 | + // Return | |
| 215 | + return; | |
| 216 | +} | |
| 217 | + | |
| 218 | + | |
| 219 | +/*************************************************************************** | |
| 220 | + * Copy class members * | |
| 221 | + * ----------------------------------------------------------------------- * | |
| 222 | + ***************************************************************************/ | |
| 223 | +void GFitsAsciiTable::copy_members(const GFitsAsciiTable& table) | |
| 224 | +{ | |
| 225 | + // Copy attributes | |
| 226 | + m_rows = table.m_rows; | |
| 227 | + m_cols = table.m_cols; | |
| 228 | + | |
| 229 | + // Copy column definition | |
| 230 | + if (table.m_columns != NULL && m_cols > 0) { | |
| 231 | + m_columns = new GFitsTableCol*[m_cols]; | |
| 232 | + for (int i = 0; i < m_cols; ++i) | |
| 233 | + m_columns[i] = table.m_columns[i]->clone(); | |
| 234 | + } | |
| 235 | + | |
| 236 | + // Return | |
| 237 | + return; | |
| 238 | +} | |
| 239 | + | |
| 240 | + | |
| 241 | +/*************************************************************************** | |
| 242 | + * Delete class members * | |
| 243 | + * ----------------------------------------------------------------------- * | |
| 244 | + ***************************************************************************/ | |
| 245 | +void GFitsAsciiTable::free_members(void) | |
| 246 | +{ | |
| 247 | + // Free memory | |
| 248 | + for (int i = 0; i < m_cols; ++i) { | |
| 249 | + if (m_columns[i] != NULL) delete m_columns[i]; | |
| 250 | + } | |
| 251 | + if (m_columns != NULL) delete [] m_columns; | |
| 252 | + | |
| 253 | + // Mark memory as freed | |
| 254 | + m_columns = NULL; | |
| 255 | + | |
| 256 | + // Return | |
| 257 | + return; | |
| 258 | +} | |
| 259 | + | |
| 260 | + | |
| 261 | +/*========================================================================== | |
| 262 | + = = | |
| 263 | + = GFitsAsciiTable friends = | |
| 264 | + = = | |
| 265 | + ==========================================================================*/ | |
| 266 | + | |
| 267 | + | |
| 268 | +/*========================================================================== | |
| 269 | + = = | |
| 270 | + = Other functions used by GFitsAsciiTable = | |
| 271 | + = = | |
| 272 | + ==========================================================================*/ | ... | ... |
src/fits/GFitsBinTable.cpp
0 โ 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GFitsBinTable.cpp - FITS binary table class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * ----------------------------------------------------------------------- * | |
| 13 | + ***************************************************************************/ | |
| 14 | + | |
| 15 | +/* __ Includes ___________________________________________________________ */ | |
| 16 | +#include "GException.hpp" | |
| 17 | +#include "GFitsBinTable.hpp" | |
| 18 | +#include "GFitsTableDblCol.hpp" | |
| 19 | +#include <iostream> // cout, cerr | |
| 20 | + | |
| 21 | +/* __ Namespaces _________________________________________________________ */ | |
| 22 | + | |
| 23 | +/* __ Method name definitions ____________________________________________ */ | |
| 24 | +#define G_OPEN "GFitsBinTable::open(fitsfile*)" | |
| 25 | + | |
| 26 | +/* __ Macros _____________________________________________________________ */ | |
| 27 | + | |
| 28 | +/* __ Coding definitions _________________________________________________ */ | |
| 29 | + | |
| 30 | +/* __ Debug definitions __________________________________________________ */ | |
| 31 | + | |
| 32 | + | |
| 33 | +/*========================================================================== | |
| 34 | + = = | |
| 35 | + = GFitsBinTable constructors/destructors = | |
| 36 | + = = | |
| 37 | + ==========================================================================*/ | |
| 38 | + | |
| 39 | +/*************************************************************************** | |
| 40 | + * Constructor * | |
| 41 | + * ----------------------------------------------------------------------- * | |
| 42 | + ***************************************************************************/ | |
| 43 | +GFitsBinTable::GFitsBinTable() : GFitsData() | |
| 44 | +{ | |
| 45 | + // Initialise class members for clean destruction | |
| 46 | + init_members(); | |
| 47 | + | |
| 48 | + // Return | |
| 49 | + return; | |
| 50 | +} | |
| 51 | + | |
| 52 | + | |
| 53 | +/*************************************************************************** | |
| 54 | + * Copy constructor * | |
| 55 | + * ----------------------------------------------------------------------- * | |
| 56 | + ***************************************************************************/ | |
| 57 | +GFitsBinTable::GFitsBinTable(const GFitsBinTable& table) : GFitsData(table) | |
| 58 | +{ | |
| 59 | + // Initialise class members for clean destruction | |
| 60 | + init_members(); | |
| 61 | + | |
| 62 | + // Copy members | |
| 63 | + copy_members(table); | |
| 64 | + | |
| 65 | + // Return | |
| 66 | + return; | |
| 67 | +} | |
| 68 | + | |
| 69 | + | |
| 70 | +/*************************************************************************** | |
| 71 | + * Destructor * | |
| 72 | + * ----------------------------------------------------------------------- * | |
| 73 | + ***************************************************************************/ | |
| 74 | +GFitsBinTable::~GFitsBinTable() | |
| 75 | +{ | |
| 76 | + // Free members | |
| 77 | + free_members(); | |
| 78 | + | |
| 79 | + // Return | |
| 80 | + return; | |
| 81 | +} | |
| 82 | + | |
| 83 | + | |
| 84 | +/*========================================================================== | |
| 85 | + = = | |
| 86 | + = GFitsBinTable operators = | |
| 87 | + = = | |
| 88 | + ==========================================================================*/ | |
| 89 | + | |
| 90 | +/*************************************************************************** | |
| 91 | + * Assignment operator * | |
| 92 | + * ----------------------------------------------------------------------- * | |
| 93 | + ***************************************************************************/ | |
| 94 | +GFitsBinTable& GFitsBinTable::operator= (const GFitsBinTable& table) | |
| 95 | +{ | |
| 96 | + // Execute only if object is not identical | |
| 97 | + if (this != &table) { | |
| 98 | + | |
| 99 | + // Copy base class members | |
| 100 | + this->GFitsData::operator=(table); | |
| 101 | + | |
| 102 | + // Free members | |
| 103 | + free_members(); | |
| 104 | + | |
| 105 | + // Initialise private members for clean destruction | |
| 106 | + init_members(); | |
| 107 | + | |
| 108 | + // Copy members | |
| 109 | + copy_members(table); | |
| 110 | + | |
| 111 | + } // endif: object was not identical | |
| 112 | + | |
| 113 | + // Return this object | |
| 114 | + return *this; | |
| 115 | +} | |
| 116 | + | |
| 117 | + | |
| 118 | +/*========================================================================== | |
| 119 | + = = | |
| 120 | + = GFitsBinTable public methods = | |
| 121 | + = = | |
| 122 | + ==========================================================================*/ | |
| 123 | + | |
| 124 | +/*************************************************************************** | |
| 125 | + * Open Table * | |
| 126 | + * ----------------------------------------------------------------------- * | |
| 127 | + ***************************************************************************/ | |
| 128 | +void GFitsBinTable::open(__fitsfile* fptr) | |
| 129 | +{ | |
| 130 | + // Determine number of rows in table | |
| 131 | + int status = 0; | |
| 132 | + long nrows = 0; | |
| 133 | + status = __ffgnrw(fptr, &nrows, &status); | |
| 134 | + if (status != 0) | |
| 135 | + throw GException::fits_error(G_OPEN, status); | |
| 136 | + else | |
| 137 | + m_rows = (int)nrows; | |
| 138 | + | |
| 139 | + // Determine number of columns in table | |
| 140 | + status = __ffgncl(fptr, &m_cols, &status); | |
| 141 | + if (status != 0) | |
| 142 | + throw GException::fits_error(G_OPEN, status); | |
| 143 | + | |
| 144 | + // Allocate memory for column pointers | |
| 145 | + if (m_columns != NULL) delete [] m_columns; | |
| 146 | + m_columns = new GFitsTableCol*[m_cols]; | |
| 147 | + | |
| 148 | + // Get table column information | |
| 149 | + int typecode = 0; | |
| 150 | + long repeat = 0; | |
| 151 | + long width = 0; | |
| 152 | + for (int i = 0; i < m_cols; ++i) { | |
| 153 | + | |
| 154 | + // Get column name | |
| 155 | + char keyname[10]; | |
| 156 | + char value[80]; | |
| 157 | + sprintf(keyname, "TTYPE%d", i+1); | |
| 158 | + status = __ffgkey(fptr, keyname, value, NULL, &status); | |
| 159 | + if (status != 0) | |
| 160 | + throw GException::fits_error(G_OPEN, status); | |
| 161 | + value[strlen(value)-1] = '\0'; | |
| 162 | + | |
| 163 | + // Get column definition | |
| 164 | + status = __ffgtcl(fptr, i+1, &typecode, &repeat, &width, &status); | |
| 165 | + if (status != 0) | |
| 166 | + throw GException::fits_error(G_OPEN, status); | |
| 167 | + | |
| 168 | + // Allocate column | |
| 169 | + switch (typecode) { | |
| 170 | + case __TDOUBLE: | |
| 171 | + m_columns[i] = new GFitsTableDblCol(); | |
| 172 | + break; | |
| 173 | + default: | |
| 174 | + m_columns[i] = NULL; | |
| 175 | + m_columns[i] = new GFitsTableDblCol(); // TO BE REMOVED LATER AND REPLACED BY THROW !!! | |
| 176 | + break; | |
| 177 | + } | |
| 178 | + | |
| 179 | + // Store column definition | |
| 180 | + m_columns[i]->set_name(&(value[1])); | |
| 181 | + m_columns[i]->set_colnum(i+1); | |
| 182 | + m_columns[i]->set_type(typecode); | |
| 183 | + m_columns[i]->set_repeat(repeat); | |
| 184 | + m_columns[i]->set_width(width); | |
| 185 | + m_columns[i]->set_length(m_rows); | |
| 186 | + m_columns[i]->set_fitsfile(fptr); | |
| 187 | + | |
| 188 | + cout << m_columns[i]->name() << " : " | |
| 189 | + << m_columns[i]->colnum() << " : " | |
| 190 | + << m_columns[i]->repeat() << " : " | |
| 191 | + << m_columns[i]->width() << " : " | |
| 192 | + << m_columns[i]->length() << endl; | |
| 193 | + } | |
| 194 | + | |
| 195 | + // Return | |
| 196 | + return; | |
| 197 | +} | |
| 198 | + | |
| 199 | + | |
| 200 | +/*************************************************************************** | |
| 201 | + * Close Table * | |
| 202 | + * ----------------------------------------------------------------------- * | |
| 203 | + ***************************************************************************/ | |
| 204 | +void GFitsBinTable::close(void) | |
| 205 | +{ | |
| 206 | + // Free members | |
| 207 | + free_members(); | |
| 208 | + | |
| 209 | + // Initialise members | |
| 210 | + init_members(); | |
| 211 | + | |
| 212 | + // Return | |
| 213 | + return; | |
| 214 | +} | |
| 215 | + | |
| 216 | + | |
| 217 | +/*************************************************************************** | |
| 218 | + * Return pointer to column with specified name * | |
| 219 | + * ----------------------------------------------------------------------- * | |
| 220 | + ***************************************************************************/ | |
| 221 | +GFitsTableCol* GFitsBinTable::column(const std::string colname) | |
| 222 | +{ | |
| 223 | + // Initialise pointer | |
| 224 | + GFitsTableCol* ptr = NULL; | |
| 225 | + | |
| 226 | + // If there are columns then search for the specified name | |
| 227 | + if (m_columns != NULL) { | |
| 228 | + for (int i = 0; i < m_cols; ++i) { | |
| 229 | + if (m_columns[i]->name() == colname) { | |
| 230 | + ptr = m_columns[i]; | |
| 231 | + break; | |
| 232 | + } | |
| 233 | + } | |
| 234 | + } | |
| 235 | + | |
| 236 | + // Return column pointer | |
| 237 | + return ptr; | |
| 238 | +} | |
| 239 | + | |
| 240 | + | |
| 241 | +/*************************************************************************** | |
| 242 | + * Return pointer to column with number * | |
| 243 | + * ----------------------------------------------------------------------- * | |
| 244 | + ***************************************************************************/ | |
| 245 | +GFitsTableCol* GFitsBinTable::column(const int colnum) | |
| 246 | +{ | |
| 247 | + // Initialise pointer | |
| 248 | + GFitsTableCol* ptr = NULL; | |
| 249 | + | |
| 250 | + // If there are columns then search for the specified name | |
| 251 | + if (m_columns != NULL) { | |
| 252 | + ptr = m_columns[colnum]; | |
| 253 | + } | |
| 254 | + | |
| 255 | + // Return column pointer | |
| 256 | + return ptr; | |
| 257 | +} | |
| 258 | + | |
| 259 | + | |
| 260 | +/*========================================================================== | |
| 261 | + = = | |
| 262 | + = GFitsBinTable private methods = | |
| 263 | + = = | |
| 264 | + ==========================================================================*/ | |
| 265 | + | |
| 266 | +/*************************************************************************** | |
| 267 | + * Initialise class members * | |
| 268 | + * ----------------------------------------------------------------------- * | |
| 269 | + ***************************************************************************/ | |
| 270 | +void GFitsBinTable::init_members(void) | |
| 271 | +{ | |
| 272 | + // Initialise members | |
| 273 | + m_rows = 0; | |
| 274 | + m_cols = 0; | |
| 275 | + m_columns = NULL; | |
| 276 | + | |
| 277 | + // Return | |
| 278 | + return; | |
| 279 | +} | |
| 280 | + | |
| 281 | + | |
| 282 | +/*************************************************************************** | |
| 283 | + * Copy class members * | |
| 284 | + * ----------------------------------------------------------------------- * | |
| 285 | + ***************************************************************************/ | |
| 286 | +void GFitsBinTable::copy_members(const GFitsBinTable& table) | |
| 287 | +{ | |
| 288 | + // Copy attributes | |
| 289 | + m_rows = table.m_rows; | |
| 290 | + m_cols = table.m_cols; | |
| 291 | + | |
| 292 | + // Copy column definition | |
| 293 | + if (table.m_columns != NULL && m_cols > 0) { | |
| 294 | + m_columns = new GFitsTableCol*[m_cols]; | |
| 295 | + for (int i = 0; i < m_cols; ++i) | |
| 296 | + m_columns[i] = table.m_columns[i]->clone(); | |
| 297 | + } | |
| 298 | + | |
| 299 | + // Return | |
| 300 | + return; | |
| 301 | +} | |
| 302 | + | |
| 303 | + | |
| 304 | +/*************************************************************************** | |
| 305 | + * Delete class members * | |
| 306 | + * ----------------------------------------------------------------------- * | |
| 307 | + ***************************************************************************/ | |
| 308 | +void GFitsBinTable::free_members(void) | |
| 309 | +{ | |
| 310 | + // Free memory | |
| 311 | + for (int i = 0; i < m_cols; ++i) { | |
| 312 | + if (m_columns[i] != NULL) delete m_columns[i]; | |
| 313 | + } | |
| 314 | + if (m_columns != NULL) delete [] m_columns; | |
| 315 | + | |
| 316 | + // Mark memory as freed | |
| 317 | + m_columns = NULL; | |
| 318 | + | |
| 319 | + // Return | |
| 320 | + return; | |
| 321 | +} | |
| 322 | + | |
| 323 | + | |
| 324 | +/*========================================================================== | |
| 325 | + = = | |
| 326 | + = GFitsBinTable friends = | |
| 327 | + = = | |
| 328 | + ==========================================================================*/ | |
| 329 | + | |
| 330 | + | |
| 331 | +/*========================================================================== | |
| 332 | + = = | |
| 333 | + = Other functions used by GFitsBinTable = | |
| 334 | + = = | |
| 335 | + ==========================================================================*/ | ... | ... |
src/fits/GFitsData.cpp
| ... | ... | @@ -17,7 +17,6 @@ |
| 17 | 17 | #include "GFitsData.hpp" |
| 18 | 18 | |
| 19 | 19 | /* __ Namespaces _________________________________________________________ */ |
| 20 | -using namespace std; | |
| 21 | 20 | |
| 22 | 21 | /* __ Method name definitions ____________________________________________ */ |
| 23 | 22 | |
| ... | ... | @@ -35,6 +34,50 @@ using namespace std; |
| 35 | 34 | = = |
| 36 | 35 | ==========================================================================*/ |
| 37 | 36 | |
| 37 | +/*************************************************************************** | |
| 38 | + * Constructor * | |
| 39 | + * ----------------------------------------------------------------------- * | |
| 40 | + ***************************************************************************/ | |
| 41 | +GFitsData::GFitsData() | |
| 42 | +{ | |
| 43 | + // Initialise class members for clean destruction | |
| 44 | + init_members(); | |
| 45 | + | |
| 46 | + // Return | |
| 47 | + return; | |
| 48 | +} | |
| 49 | + | |
| 50 | + | |
| 51 | +/*************************************************************************** | |
| 52 | + * Copy constructor * | |
| 53 | + * ----------------------------------------------------------------------- * | |
| 54 | + ***************************************************************************/ | |
| 55 | +GFitsData::GFitsData(const GFitsData& data) | |
| 56 | +{ | |
| 57 | + // Initialise class members for clean destruction | |
| 58 | + init_members(); | |
| 59 | + | |
| 60 | + // Copy members | |
| 61 | + copy_members(data); | |
| 62 | + | |
| 63 | + // Return | |
| 64 | + return; | |
| 65 | +} | |
| 66 | + | |
| 67 | + | |
| 68 | +/*************************************************************************** | |
| 69 | + * Destructor * | |
| 70 | + * ----------------------------------------------------------------------- * | |
| 71 | + ***************************************************************************/ | |
| 72 | +GFitsData::~GFitsData() | |
| 73 | +{ | |
| 74 | + // Free members | |
| 75 | + free_members(); | |
| 76 | + | |
| 77 | + // Return | |
| 78 | + return; | |
| 79 | +} | |
| 80 | + | |
| 38 | 81 | |
| 39 | 82 | /*========================================================================== |
| 40 | 83 | = = |
| ... | ... | @@ -42,20 +85,111 @@ using namespace std; |
| 42 | 85 | = = |
| 43 | 86 | ==========================================================================*/ |
| 44 | 87 | |
| 88 | +/*************************************************************************** | |
| 89 | + * Assignment operator * | |
| 90 | + * ----------------------------------------------------------------------- * | |
| 91 | + ***************************************************************************/ | |
| 92 | +GFitsData& GFitsData::operator= (const GFitsData& data) | |
| 93 | +{ | |
| 94 | + // Execute only if object is not identical | |
| 95 | + if (this != &data) { | |
| 96 | + | |
| 97 | + // Free members | |
| 98 | + free_members(); | |
| 99 | + | |
| 100 | + // Initialise private members for clean destruction | |
| 101 | + init_members(); | |
| 102 | + | |
| 103 | + // Copy members | |
| 104 | + copy_members(data); | |
| 105 | + | |
| 106 | + } // endif: object was not identical | |
| 107 | + | |
| 108 | + // Return this object | |
| 109 | + return *this; | |
| 110 | +} | |
| 111 | + | |
| 45 | 112 | |
| 46 | 113 | /*========================================================================== |
| 47 | 114 | = = |
| 48 | - = GFitsData methods = | |
| 115 | + = GFitsData public methods = | |
| 49 | 116 | = = |
| 50 | 117 | ==========================================================================*/ |
| 51 | 118 | |
| 119 | +/*************************************************************************** | |
| 120 | + * Open Data * | |
| 121 | + * ----------------------------------------------------------------------- * | |
| 122 | + ***************************************************************************/ | |
| 123 | +void GFitsData::open(__fitsfile* fptr) | |
| 124 | +{ | |
| 125 | + // Return | |
| 126 | + return; | |
| 127 | +} | |
| 128 | + | |
| 129 | + | |
| 130 | +/*************************************************************************** | |
| 131 | + * Close Data * | |
| 132 | + * ----------------------------------------------------------------------- * | |
| 133 | + ***************************************************************************/ | |
| 134 | +void GFitsData::close(void) | |
| 135 | +{ | |
| 136 | + // Free members | |
| 137 | + free_members(); | |
| 138 | + | |
| 139 | + // Initialise members | |
| 140 | + init_members(); | |
| 141 | + | |
| 142 | + // Return | |
| 143 | + return; | |
| 144 | +} | |
| 145 | + | |
| 52 | 146 | |
| 53 | 147 | /*========================================================================== |
| 54 | 148 | = = |
| 55 | - = GFitsData private functions = | |
| 149 | + = GFitsData private methods = | |
| 56 | 150 | = = |
| 57 | 151 | ==========================================================================*/ |
| 58 | 152 | |
| 153 | +/*************************************************************************** | |
| 154 | + * Initialise class members * | |
| 155 | + * ----------------------------------------------------------------------- * | |
| 156 | + ***************************************************************************/ | |
| 157 | +void GFitsData::init_members(void) | |
| 158 | +{ | |
| 159 | + // Initialise members | |
| 160 | + | |
| 161 | + // Return | |
| 162 | + return; | |
| 163 | +} | |
| 164 | + | |
| 165 | + | |
| 166 | +/*************************************************************************** | |
| 167 | + * Copy class members * | |
| 168 | + * ----------------------------------------------------------------------- * | |
| 169 | + ***************************************************************************/ | |
| 170 | +void GFitsData::copy_members(const GFitsData& data) | |
| 171 | +{ | |
| 172 | + // Copy attributes | |
| 173 | + | |
| 174 | + // Copy data | |
| 175 | + | |
| 176 | + // Return | |
| 177 | + return; | |
| 178 | +} | |
| 179 | + | |
| 180 | + | |
| 181 | +/*************************************************************************** | |
| 182 | + * Delete class members * | |
| 183 | + * ----------------------------------------------------------------------- * | |
| 184 | + ***************************************************************************/ | |
| 185 | +void GFitsData::free_members(void) | |
| 186 | +{ | |
| 187 | + // Free memory | |
| 188 | + | |
| 189 | + // Return | |
| 190 | + return; | |
| 191 | +} | |
| 192 | + | |
| 59 | 193 | |
| 60 | 194 | /*========================================================================== |
| 61 | 195 | = = | ... | ... |
src/fits/GFitsHDU.cpp
| ... | ... | @@ -20,6 +20,9 @@ |
| 20 | 20 | /* __ Namespaces _________________________________________________________ */ |
| 21 | 21 | |
| 22 | 22 | /* __ Method name definitions ____________________________________________ */ |
| 23 | +#define G_OPEN "GFitsHDU::open(int)" | |
| 24 | +#define G_COLUMN "GFitsHDU::column(std::string)" | |
| 25 | +#define G_MOVE2HDU "GFitsHDU::move2hdu(void)" | |
| 23 | 26 | |
| 24 | 27 | /* __ Macros _____________________________________________________________ */ |
| 25 | 28 | |
| ... | ... | @@ -132,26 +135,40 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum) |
| 132 | 135 | // Get HDU type |
| 133 | 136 | int status = 0; |
| 134 | 137 | status = __ffghdt(m_fitsfile, &m_type, &status); |
| 135 | - if (status != 0) { | |
| 136 | - throw GException::fits_error("GFitsHDU::open(int)", status); | |
| 137 | - } | |
| 138 | - | |
| 139 | - // Open HDU header | |
| 140 | - m_header.open(m_fitsfile); | |
| 138 | + if (status != 0) | |
| 139 | + throw GException::fits_error(G_OPEN, status); | |
| 140 | + | |
| 141 | + // Allocate and open HDU header | |
| 142 | + if (m_header != NULL) delete m_header; | |
| 143 | + m_header = new GFitsHeader(); | |
| 144 | + m_header->open(m_fitsfile); | |
| 141 | 145 | |
| 142 | 146 | // Open HDU data area |
| 143 | - // | |
| 147 | + if (m_data != NULL) delete m_data; | |
| 148 | + switch (m_type) { | |
| 149 | + case 0: // Image HDU | |
| 150 | + m_data = new GFitsImage(); | |
| 151 | + break; | |
| 152 | + case 1: // ASCII Table HDU | |
| 153 | + m_data = new GFitsAsciiTable(); | |
| 154 | + break; | |
| 155 | + case 2: // Binary Table HDU | |
| 156 | + m_data = new GFitsBinTable(); | |
| 157 | + break; | |
| 158 | + default: | |
| 159 | + throw GException::fits_unknown_HDU_type(G_OPEN, m_type); | |
| 160 | + break; | |
| 161 | + } | |
| 162 | + m_data->open(m_fitsfile); | |
| 144 | 163 | |
| 145 | 164 | // Get HDU name from header |
| 146 | - GFitsHeaderCard* extname = m_header.card("EXTNAME"); | |
| 147 | - if (extname == NULL) { | |
| 165 | + m_name = m_header->string("EXTNAME"); | |
| 166 | + if (m_name.length() == 0) { | |
| 148 | 167 | if (hdunum == 1) |
| 149 | 168 | m_name = "Primary"; |
| 150 | 169 | else |
| 151 | 170 | m_name = "NoName"; |
| 152 | 171 | } |
| 153 | - else | |
| 154 | - m_name = extname->value(); | |
| 155 | 172 | |
| 156 | 173 | cout << "HDU #" << hdunum << ": " << m_type << " : " << m_name << endl; |
| 157 | 174 | |
| ... | ... | @@ -161,35 +178,51 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum) |
| 161 | 178 | |
| 162 | 179 | |
| 163 | 180 | /*************************************************************************** |
| 164 | - * Close HDU * | |
| 181 | + * Save HDU to FITS file * | |
| 165 | 182 | * ----------------------------------------------------------------------- * |
| 166 | 183 | ***************************************************************************/ |
| 167 | -void GFitsHDU::close(void) | |
| 184 | +void GFitsHDU::save(void) | |
| 168 | 185 | { |
| 186 | + // Move to HDU | |
| 187 | + move2hdu(); | |
| 188 | + | |
| 189 | + // Save header | |
| 190 | + //... | |
| 191 | + | |
| 192 | + // Save data | |
| 193 | + //... | |
| 194 | + | |
| 169 | 195 | // Return |
| 170 | 196 | return; |
| 171 | 197 | } |
| 172 | 198 | |
| 173 | - | |
| 174 | 199 | /*************************************************************************** |
| 175 | - * Return pointer to HDU header * | |
| 200 | + * Return pointer to column of table * | |
| 176 | 201 | * ----------------------------------------------------------------------- * |
| 177 | 202 | ***************************************************************************/ |
| 178 | -GFitsHeader* GFitsHDU::header(void) | |
| 203 | +GFitsTableCol* GFitsHDU::column(const std::string colname) const | |
| 179 | 204 | { |
| 180 | - // Return header pointer | |
| 181 | - return &m_header; | |
| 182 | -} | |
| 183 | - | |
| 184 | - | |
| 185 | -/*************************************************************************** | |
| 186 | - * Return pointer to HDU data * | |
| 187 | - * ----------------------------------------------------------------------- * | |
| 188 | - ***************************************************************************/ | |
| 189 | -GFitsData* GFitsHDU::data(void) | |
| 190 | -{ | |
| 191 | - // Return data pointer | |
| 192 | - return &m_data; | |
| 205 | + // Initialise pointer | |
| 206 | + GFitsTableCol* ptr = NULL; | |
| 207 | + | |
| 208 | + // Get pointer to table column | |
| 209 | + switch (m_type) { | |
| 210 | + case 0: // Image HDU | |
| 211 | + throw GException::fits_HDU_not_a_table(G_COLUMN, m_type); | |
| 212 | + break; | |
| 213 | + case 1: // ASCII Table HDU | |
| 214 | + ptr = ((GFitsAsciiTable*)this->data())->column(colname); | |
| 215 | + break; | |
| 216 | + case 2: // Binary Table HDU | |
| 217 | + ptr = ((GFitsBinTable*)this->data())->column(colname); | |
| 218 | + break; | |
| 219 | + default: | |
| 220 | + throw GException::fits_unknown_HDU_type(G_COLUMN, m_type); | |
| 221 | + break; | |
| 222 | + } | |
| 223 | + | |
| 224 | + // Return pointer | |
| 225 | + return ptr; | |
| 193 | 226 | } |
| 194 | 227 | |
| 195 | 228 | |
| ... | ... | @@ -208,8 +241,8 @@ void GFitsHDU::init_members(void) |
| 208 | 241 | // Initialise members |
| 209 | 242 | m_fitsfile = NULL; |
| 210 | 243 | m_type = 0; |
| 211 | - //m_header = NULL; | |
| 212 | - //m_data = NULL; | |
| 244 | + m_header = NULL; | |
| 245 | + m_data = NULL; | |
| 213 | 246 | |
| 214 | 247 | // Return |
| 215 | 248 | return; |
| ... | ... | @@ -219,14 +252,21 @@ void GFitsHDU::init_members(void) |
| 219 | 252 | /*************************************************************************** |
| 220 | 253 | * Copy class members * |
| 221 | 254 | * ----------------------------------------------------------------------- * |
| 255 | + * The function does not copy the FITS file pointer. This prevents that * | |
| 256 | + * several copies of the FITS file pointer exist in different instances of * | |
| 257 | + * GFitsHDU, which would lead to confusion since one instance could close * | |
| 258 | + * the file while for another it still would be opened. * | |
| 259 | + * The rule ONE INSTANCE - ONE FILE applies. * | |
| 222 | 260 | ***************************************************************************/ |
| 223 | 261 | void GFitsHDU::copy_members(const GFitsHDU& hdu) |
| 224 | 262 | { |
| 225 | - // Copy membres | |
| 226 | - m_fitsfile = hdu.m_fitsfile; | |
| 227 | - m_type = hdu.m_type; | |
| 228 | - m_header = hdu.m_header; | |
| 229 | - m_data = hdu.m_data; | |
| 263 | + // Reset FITS file attributes | |
| 264 | + m_fitsfile = NULL; | |
| 265 | + | |
| 266 | + // Copy other membres | |
| 267 | + m_type = hdu.m_type; | |
| 268 | + m_header = hdu.m_header->clone(); | |
| 269 | + m_data = hdu.m_data->clone(); | |
| 230 | 270 | |
| 231 | 271 | // Return |
| 232 | 272 | return; |
| ... | ... | @@ -239,6 +279,14 @@ void GFitsHDU::copy_members(const GFitsHDU& hdu) |
| 239 | 279 | ***************************************************************************/ |
| 240 | 280 | void GFitsHDU::free_members(void) |
| 241 | 281 | { |
| 282 | + // Free memory | |
| 283 | + if (m_header != NULL) delete m_header; | |
| 284 | + if (m_data != NULL) delete m_data; | |
| 285 | + | |
| 286 | + // Signal free pointers | |
| 287 | + m_header = NULL; | |
| 288 | + m_data = NULL; | |
| 289 | + | |
| 242 | 290 | // Return |
| 243 | 291 | return; |
| 244 | 292 | } |
| ... | ... | @@ -253,9 +301,8 @@ void GFitsHDU::move2hdu(void) |
| 253 | 301 | // Move FITS file pointer to HDU |
| 254 | 302 | int status = 0; |
| 255 | 303 | status = __ffmahd(m_fitsfile, m_num, NULL, &status); |
| 256 | - if (status != 0) { | |
| 257 | - throw GException::fits_error("GFitsHDU::move2hdu(void)", status); | |
| 258 | - } | |
| 304 | + if (status != 0) | |
| 305 | + throw GException::fits_error(G_MOVE2HDU, status); | |
| 259 | 306 | |
| 260 | 307 | // Return |
| 261 | 308 | return; | ... | ... |
src/fits/GFitsHeader.cpp
| ... | ... | @@ -20,6 +20,7 @@ |
| 20 | 20 | /* __ Namespaces _________________________________________________________ */ |
| 21 | 21 | |
| 22 | 22 | /* __ Method name definitions ____________________________________________ */ |
| 23 | +#define G_OPEN "GFitsHeader::open(int)" | |
| 23 | 24 | |
| 24 | 25 | /* __ Macros _____________________________________________________________ */ |
| 25 | 26 | |
| ... | ... | @@ -118,7 +119,7 @@ GFitsHeader& GFitsHeader::operator= (const GFitsHeader& header) |
| 118 | 119 | ==========================================================================*/ |
| 119 | 120 | |
| 120 | 121 | /*************************************************************************** |
| 121 | - * Open HDU * | |
| 122 | + * Open Header * | |
| 122 | 123 | * ----------------------------------------------------------------------- * |
| 123 | 124 | ***************************************************************************/ |
| 124 | 125 | void GFitsHeader::open(__fitsfile* fptr) |
| ... | ... | @@ -126,9 +127,8 @@ void GFitsHeader::open(__fitsfile* fptr) |
| 126 | 127 | // Determine number of cards in header |
| 127 | 128 | int status = 0; |
| 128 | 129 | status = __ffghsp(fptr, &m_num_cards, NULL, &status); |
| 129 | - if (status != 0) { | |
| 130 | - throw GException::fits_error("GFitsHeader::open(int)", status); | |
| 131 | - } | |
| 130 | + if (status != 0) | |
| 131 | + throw GException::fits_error(G_OPEN, status); | |
| 132 | 132 | |
| 133 | 133 | // Drop any old cards |
| 134 | 134 | if (m_card != NULL) delete [] m_card; |
| ... | ... | @@ -139,7 +139,15 @@ void GFitsHeader::open(__fitsfile* fptr) |
| 139 | 139 | // Read all cards |
| 140 | 140 | for (int i = 0; i < m_num_cards; ++i) { |
| 141 | 141 | m_card[i].read(fptr, i+1); |
| 142 | - //cout << m_card[i].keyname() << " " << m_card[i].value() << " " << m_card[i].comment() << endl; | |
| 142 | + /* | |
| 143 | + cout << m_card[i].keyname() << " " | |
| 144 | + << m_card[i].value() << " " | |
| 145 | + << m_card[i].value_type() << " " | |
| 146 | + << m_card[i].string() << " " | |
| 147 | + << m_card[i].real() << " " | |
| 148 | + << m_card[i].integer() << " " | |
| 149 | + << m_card[i].comment() << endl; | |
| 150 | + */ | |
| 143 | 151 | } |
| 144 | 152 | |
| 145 | 153 | // Return |
| ... | ... | @@ -148,29 +156,121 @@ void GFitsHeader::open(__fitsfile* fptr) |
| 148 | 156 | |
| 149 | 157 | |
| 150 | 158 | /*************************************************************************** |
| 151 | - * Get specified header card * | |
| 159 | + * Close Header * | |
| 152 | 160 | * ----------------------------------------------------------------------- * |
| 153 | 161 | ***************************************************************************/ |
| 154 | -GFitsHeaderCard* GFitsHeader::card(const std::string keyname) | |
| 162 | +void GFitsHeader::close(void) | |
| 155 | 163 | { |
| 156 | - // Return card pointer | |
| 157 | - return GFitsHeader::card_ptr(keyname); | |
| 164 | + // Free members | |
| 165 | + free_members(); | |
| 166 | + | |
| 167 | + // Initialise members | |
| 168 | + init_members(); | |
| 169 | + | |
| 170 | + // Return | |
| 171 | + return; | |
| 158 | 172 | } |
| 159 | 173 | |
| 160 | 174 | |
| 161 | 175 | /*************************************************************************** |
| 162 | - * Get specified header card * | |
| 176 | + * Get specified header card value as string * | |
| 163 | 177 | * ----------------------------------------------------------------------- * |
| 164 | 178 | ***************************************************************************/ |
| 165 | -GFitsHeaderCard* GFitsHeader::card(const int cardno) | |
| 179 | +std::string GFitsHeader::string(const std::string keyname) | |
| 166 | 180 | { |
| 167 | - // Set card pointer | |
| 168 | - GFitsHeaderCard* ptr = (cardno >= 0 && cardno < m_num_cards) | |
| 169 | - ? &(m_card[cardno]) : NULL; | |
| 181 | + // Get card pointer | |
| 182 | + GFitsHeaderCard* ptr = GFitsHeader::card(keyname); | |
| 170 | 183 | |
| 171 | - // Return card pointer | |
| 172 | - return ptr; | |
| 184 | + // Get string value | |
| 185 | + std::string value = (ptr != NULL) ? ptr->string() : ""; | |
| 186 | + | |
| 187 | + // Return string | |
| 188 | + return value; | |
| 189 | +} | |
| 190 | + | |
| 191 | + | |
| 192 | +/*************************************************************************** | |
| 193 | + * Get specified header card value as string * | |
| 194 | + * ----------------------------------------------------------------------- * | |
| 195 | + ***************************************************************************/ | |
| 196 | +std::string GFitsHeader::string(const int cardno) | |
| 197 | +{ | |
| 198 | + // Get card pointer | |
| 199 | + GFitsHeaderCard* ptr = GFitsHeader::card(cardno); | |
| 200 | + | |
| 201 | + // Get string value | |
| 202 | + std::string value = (ptr != NULL) ? ptr->string() : ""; | |
| 203 | + | |
| 204 | + // Return string | |
| 205 | + return value; | |
| 206 | +} | |
| 207 | + | |
| 208 | + | |
| 209 | +/*************************************************************************** | |
| 210 | + * Get specified header card value as double * | |
| 211 | + * ----------------------------------------------------------------------- * | |
| 212 | + ***************************************************************************/ | |
| 213 | +double GFitsHeader::real(const std::string keyname) | |
| 214 | +{ | |
| 215 | + // Get card pointer | |
| 216 | + GFitsHeaderCard* ptr = GFitsHeader::card(keyname); | |
| 217 | + | |
| 218 | + // Get string value | |
| 219 | + double value = (ptr != NULL) ? ptr->real() : 0.0; | |
| 220 | + | |
| 221 | + // Return double | |
| 222 | + return value; | |
| 223 | +} | |
| 224 | + | |
| 225 | + | |
| 226 | +/*************************************************************************** | |
| 227 | + * Get specified header card value as double * | |
| 228 | + * ----------------------------------------------------------------------- * | |
| 229 | + ***************************************************************************/ | |
| 230 | +double GFitsHeader::real(const int cardno) | |
| 231 | +{ | |
| 232 | + // Get card pointer | |
| 233 | + GFitsHeaderCard* ptr = GFitsHeader::card(cardno); | |
| 234 | + | |
| 235 | + // Get string value | |
| 236 | + double value = (ptr != NULL) ? ptr->real() : 0.0; | |
| 237 | + | |
| 238 | + // Return double | |
| 239 | + return value; | |
| 240 | +} | |
| 241 | + | |
| 242 | + | |
| 243 | +/*************************************************************************** | |
| 244 | + * Get specified header card value as int * | |
| 245 | + * ----------------------------------------------------------------------- * | |
| 246 | + ***************************************************************************/ | |
| 247 | +int GFitsHeader::integer(const std::string keyname) | |
| 248 | +{ | |
| 249 | + // Get card pointer | |
| 250 | + GFitsHeaderCard* ptr = GFitsHeader::card(keyname); | |
| 251 | + | |
| 252 | + // Get string value | |
| 253 | + int value = (ptr != NULL) ? ptr->integer() : 0; | |
| 254 | + | |
| 255 | + // Return double | |
| 256 | + return value; | |
| 257 | +} | |
| 258 | + | |
| 259 | + | |
| 260 | +/*************************************************************************** | |
| 261 | + * Get specified header card value as int * | |
| 262 | + * ----------------------------------------------------------------------- * | |
| 263 | + ***************************************************************************/ | |
| 264 | +int GFitsHeader::integer(const int cardno) | |
| 265 | +{ | |
| 266 | + // Get card pointer | |
| 267 | + GFitsHeaderCard* ptr = GFitsHeader::card(cardno); | |
| 268 | + | |
| 269 | + // Get string value | |
| 270 | + int value = (ptr != NULL) ? ptr->integer() : 0; | |
| 173 | 271 | |
| 272 | + // Return double | |
| 273 | + return value; | |
| 174 | 274 | } |
| 175 | 275 | |
| 176 | 276 | ... | ... |
src/fits/GFitsHeaderCard.cpp
| ... | ... | @@ -19,11 +19,26 @@ |
| 19 | 19 | /* __ Namespaces _________________________________________________________ */ |
| 20 | 20 | |
| 21 | 21 | /* __ Method name definitions ____________________________________________ */ |
| 22 | +#define G_READ_NUM "GFitsHeaderCard::read(fitsfile*, int)" | |
| 23 | +#define G_READ_STR "GFitsHeaderCard::read(fitsfile*, std::string)" | |
| 24 | +#define G_WRITE "GFitsHeaderCard::write(fitsfile*)" | |
| 25 | + | |
| 26 | +/* __ Definitions ________________________________________________________ */ | |
| 27 | +#define CT_UNKNOWN 0 | |
| 28 | +#define CT_INVALID 1 | |
| 29 | +#define CT_STRING 2 | |
| 30 | +#define CT_INT 3 | |
| 31 | +#define CT_FLOAT 4 | |
| 32 | +#define CT_BOOL 5 | |
| 33 | +#define CT_COMMENT 6 | |
| 34 | +#define CT_HISTORY 7 | |
| 22 | 35 | |
| 23 | 36 | /* __ Macros _____________________________________________________________ */ |
| 24 | 37 | |
| 25 | 38 | /* __ Coding definitions _________________________________________________ */ |
| 26 | 39 | |
| 40 | +/* __ Enumerations _______________________________________________________ */ | |
| 41 | + | |
| 27 | 42 | /* __ Debug definitions __________________________________________________ */ |
| 28 | 43 | |
| 29 | 44 | |
| ... | ... | @@ -115,86 +130,99 @@ GFitsHeaderCard& GFitsHeaderCard::operator= (const GFitsHeaderCard& card) |
| 115 | 130 | ==========================================================================*/ |
| 116 | 131 | |
| 117 | 132 | /*************************************************************************** |
| 118 | - * Get keyname * | |
| 133 | + * Return value as string * | |
| 119 | 134 | * ----------------------------------------------------------------------- * |
| 120 | 135 | ***************************************************************************/ |
| 121 | -std::string GFitsHeaderCard::keyname(void) | |
| 136 | +std::string GFitsHeaderCard::string(void) | |
| 122 | 137 | { |
| 123 | - return m_keyname; | |
| 124 | -} | |
| 125 | - | |
| 126 | - | |
| 127 | -/*************************************************************************** | |
| 128 | - * Get value * | |
| 129 | - * ----------------------------------------------------------------------- * | |
| 130 | - ***************************************************************************/ | |
| 131 | -std::string GFitsHeaderCard::value(void) | |
| 132 | -{ | |
| 133 | - return m_value; | |
| 134 | -} | |
| 135 | - | |
| 138 | + // Initialize return value to empty string | |
| 139 | + std::string result; | |
| 140 | + | |
| 141 | + // Type dependent conversion | |
| 142 | + switch (m_value_type) { | |
| 143 | + case CT_STRING: | |
| 144 | + int length = m_value.length() - 2; | |
| 145 | + if (length > 0) | |
| 146 | + result = m_value.substr(1, length); | |
| 147 | + break; | |
| 148 | + case CT_INT: | |
| 149 | + case CT_FLOAT: | |
| 150 | + case CT_BOOL: | |
| 151 | + result = m_value; | |
| 152 | + break; | |
| 153 | + default: | |
| 154 | + break; | |
| 155 | + } | |
| 156 | + | |
| 157 | + // Return string | |
| 158 | + return result; | |
| 136 | 159 | |
| 137 | -/*************************************************************************** | |
| 138 | - * Get unit * | |
| 139 | - * ----------------------------------------------------------------------- * | |
| 140 | - ***************************************************************************/ | |
| 141 | -std::string GFitsHeaderCard::unit(void) | |
| 142 | -{ | |
| 143 | - return m_unit; | |
| 144 | 160 | } |
| 145 | 161 | |
| 146 | 162 | |
| 147 | 163 | /*************************************************************************** |
| 148 | - * Get comment * | |
| 164 | + * Return value as double * | |
| 149 | 165 | * ----------------------------------------------------------------------- * |
| 150 | 166 | ***************************************************************************/ |
| 151 | -std::string GFitsHeaderCard::comment(void) | |
| 167 | +double GFitsHeaderCard::real(void) | |
| 152 | 168 | { |
| 153 | - return m_comment; | |
| 154 | -} | |
| 155 | - | |
| 169 | + // Initialize return value to 0.0 | |
| 170 | + double result = 0.0; | |
| 171 | + | |
| 172 | + // Type dependent conversion | |
| 173 | + switch (m_value_type) { | |
| 174 | + case CT_STRING: | |
| 175 | + int length = m_value.length() - 2; | |
| 176 | + if (length > 0) | |
| 177 | + result = atof(m_value.substr(1, length).c_str()); | |
| 178 | + break; | |
| 179 | + case CT_INT: | |
| 180 | + case CT_FLOAT: | |
| 181 | + result = atof(m_value.c_str()); | |
| 182 | + break; | |
| 183 | + case CT_BOOL: | |
| 184 | + result = (m_value == "T") ? 1.0 : 0.0; | |
| 185 | + break; | |
| 186 | + default: | |
| 187 | + break; | |
| 188 | + } | |
| 189 | + | |
| 190 | + // Return string | |
| 191 | + return result; | |
| 156 | 192 | |
| 157 | -/*************************************************************************** | |
| 158 | - * Set keyname * | |
| 159 | - * ----------------------------------------------------------------------- * | |
| 160 | - ***************************************************************************/ | |
| 161 | -void GFitsHeaderCard::set_keyname(std::string& keyname) | |
| 162 | -{ | |
| 163 | - m_keyname = keyname; | |
| 164 | - return; | |
| 165 | 193 | } |
| 166 | 194 | |
| 167 | 195 | |
| 168 | 196 | /*************************************************************************** |
| 169 | - * Set value * | |
| 197 | + * Return value as int * | |
| 170 | 198 | * ----------------------------------------------------------------------- * |
| 171 | 199 | ***************************************************************************/ |
| 172 | -void GFitsHeaderCard::set_value(std::string& value) | |
| 200 | +int GFitsHeaderCard::integer(void) | |
| 173 | 201 | { |
| 174 | - m_value = value; | |
| 175 | - return; | |
| 176 | -} | |
| 177 | - | |
| 178 | - | |
| 179 | -/*************************************************************************** | |
| 180 | - * Set unit * | |
| 181 | - * ----------------------------------------------------------------------- * | |
| 182 | - ***************************************************************************/ | |
| 183 | -void GFitsHeaderCard::set_unit(std::string& unit) | |
| 184 | -{ | |
| 185 | - m_unit = unit; | |
| 186 | - return; | |
| 187 | -} | |
| 188 | - | |
| 202 | + // Initialize return value to 0 | |
| 203 | + int result = 0; | |
| 204 | + | |
| 205 | + // Type dependent conversion | |
| 206 | + switch (m_value_type) { | |
| 207 | + case CT_STRING: | |
| 208 | + int length = m_value.length() - 2; | |
| 209 | + if (length > 0) | |
| 210 | + result = atoi(m_value.substr(1, length).c_str()); | |
| 211 | + break; | |
| 212 | + case CT_INT: | |
| 213 | + case CT_FLOAT: | |
| 214 | + result = atoi(m_value.c_str()); | |
| 215 | + break; | |
| 216 | + case CT_BOOL: | |
| 217 | + result = (m_value == "T") ? 1 : 0; | |
| 218 | + break; | |
| 219 | + default: | |
| 220 | + break; | |
| 221 | + } | |
| 222 | + | |
| 223 | + // Return string | |
| 224 | + return result; | |
| 189 | 225 | |
| 190 | -/*************************************************************************** | |
| 191 | - * Set comment * | |
| 192 | - * ----------------------------------------------------------------------- * | |
| 193 | - ***************************************************************************/ | |
| 194 | -void GFitsHeaderCard::set_comment(std::string& comment) | |
| 195 | -{ | |
| 196 | - m_comment = comment; | |
| 197 | - return; | |
| 198 | 226 | } |
| 199 | 227 | |
| 200 | 228 | |
| ... | ... | @@ -210,14 +238,16 @@ void GFitsHeaderCard::read(__fitsfile* fptr, int keynum) |
| 210 | 238 | char comment[80]; |
| 211 | 239 | int status = 0; |
| 212 | 240 | status = __ffgkyn(fptr, keynum, keyname, value, comment, &status); |
| 213 | - if (status != 0) { | |
| 214 | - throw GException::fits_error("GFitsHeaderCard::read(fitsfile*, int)", status); | |
| 215 | - } | |
| 241 | + if (status != 0) | |
| 242 | + throw GException::fits_error(G_READ_NUM, status); | |
| 216 | 243 | |
| 217 | 244 | // Store result |
| 218 | 245 | m_keyname.assign(keyname); |
| 219 | 246 | m_value.assign(value); |
| 220 | 247 | m_comment.assign(comment); |
| 248 | + | |
| 249 | + // Determine card type | |
| 250 | + m_value_type = get_value_type(); | |
| 221 | 251 | |
| 222 | 252 | // Return |
| 223 | 253 | return; |
| ... | ... | @@ -237,18 +267,19 @@ void GFitsHeaderCard::read(__fitsfile* fptr, std::string keyname) |
| 237 | 267 | status = __ffgkey(fptr, (char*)keyname.c_str(), value, comment, &status); |
| 238 | 268 | |
| 239 | 269 | // Catch error |
| 240 | - if (status == 202) { // Keyword not found | |
| 241 | - throw GException::fits_key_not_found("GFitsHeaderCard::read(fitsfile*, std::string)", keyname, status); | |
| 242 | - } | |
| 243 | - else if (status != 0) { // Any other error | |
| 244 | - throw GException::fits_error("GFitsHeaderCard::read(fitsfile*, std::string)", status); | |
| 245 | - } | |
| 270 | + if (status == 202) // Keyword not found | |
| 271 | + throw GException::fits_key_not_found(G_READ_STR, keyname, status); | |
| 272 | + else if (status != 0) // Any other error | |
| 273 | + throw GException::fits_error(G_READ_STR, status); | |
| 246 | 274 | |
| 247 | 275 | // Store result |
| 248 | 276 | m_keyname = keyname; |
| 249 | 277 | m_value.assign(value); |
| 250 | 278 | m_comment.assign(comment); |
| 251 | 279 | |
| 280 | + // Determine card type | |
| 281 | + m_value_type = get_value_type(); | |
| 282 | + | |
| 252 | 283 | // Return |
| 253 | 284 | return; |
| 254 | 285 | } |
| ... | ... | @@ -264,17 +295,14 @@ void GFitsHeaderCard::write(__fitsfile* fptr) |
| 264 | 295 | int status = 0; |
| 265 | 296 | status = __ffuky(fptr, __TSTRING, (char*)m_keyname.c_str(), |
| 266 | 297 | (char*)m_value.c_str(), (char*)m_comment.c_str(), &status); |
| 267 | - if (status != 0) { | |
| 268 | - throw GException::fits_error("GFitsHeaderCard::write(fitsfile*", status); | |
| 269 | - } | |
| 298 | + if (status != 0) | |
| 299 | + throw GException::fits_error(G_WRITE, status); | |
| 270 | 300 | |
| 271 | 301 | // Return |
| 272 | 302 | return; |
| 273 | 303 | } |
| 274 | 304 | |
| 275 | 305 | |
| 276 | - | |
| 277 | - | |
| 278 | 306 | /*========================================================================== |
| 279 | 307 | = = |
| 280 | 308 | = GFitsHeaderCard private methods = |
| ... | ... | @@ -290,6 +318,7 @@ void GFitsHeaderCard::init_members(void) |
| 290 | 318 | // Initialise members |
| 291 | 319 | m_keyname.clear(); |
| 292 | 320 | m_value.clear(); |
| 321 | + m_value_type = CT_UNKNOWN; | |
| 293 | 322 | m_unit.clear(); |
| 294 | 323 | m_comment.clear(); |
| 295 | 324 | |
| ... | ... | @@ -305,10 +334,11 @@ void GFitsHeaderCard::init_members(void) |
| 305 | 334 | void GFitsHeaderCard::copy_members(const GFitsHeaderCard& card) |
| 306 | 335 | { |
| 307 | 336 | // Copy membres |
| 308 | - m_keyname = card.m_keyname; | |
| 309 | - m_value = card.m_value; | |
| 310 | - m_unit = card.m_unit; | |
| 311 | - m_comment = card.m_comment; | |
| 337 | + m_keyname = card.m_keyname; | |
| 338 | + m_value = card.m_value; | |
| 339 | + m_value_type = card.m_value_type; | |
| 340 | + m_unit = card.m_unit; | |
| 341 | + m_comment = card.m_comment; | |
| 312 | 342 | |
| 313 | 343 | // Return |
| 314 | 344 | return; |
| ... | ... | @@ -324,3 +354,59 @@ void GFitsHeaderCard::free_members(void) |
| 324 | 354 | // Return |
| 325 | 355 | return; |
| 326 | 356 | } |
| 357 | + | |
| 358 | + | |
| 359 | +/*************************************************************************** | |
| 360 | + * Determine card value type * | |
| 361 | + * ----------------------------------------------------------------------- * | |
| 362 | + ***************************************************************************/ | |
| 363 | +int GFitsHeaderCard::get_value_type(void) | |
| 364 | +{ | |
| 365 | + // Get index of last string element | |
| 366 | + int last = m_value.length() - 1; | |
| 367 | + | |
| 368 | + // If value is empty then we either have a COMMENT or HISTORY card or | |
| 369 | + // we don't know the type | |
| 370 | + if (last < 0) { | |
| 371 | + if (m_keyname == "COMMENT") | |
| 372 | + return CT_COMMENT; | |
| 373 | + if (m_keyname == "HISTORY") | |
| 374 | + return CT_HISTORY; | |
| 375 | + return CT_UNKNOWN; | |
| 376 | + } | |
| 377 | + | |
| 378 | + // If value is enclosed in parentheses we have a string | |
| 379 | + if (m_value[0] == '\x27' && m_value[last] == '\x27') | |
| 380 | + return CT_STRING; | |
| 381 | + | |
| 382 | + // If value has only one digit and is either 'F' or 'T' we have a | |
| 383 | + // Boolean | |
| 384 | + if (last == 0 && (m_value[0] == 'F' || m_value[0] == 'T')) | |
| 385 | + return CT_BOOL; | |
| 386 | + | |
| 387 | + // If value is composed only of numeric or '+' or '-' characters we | |
| 388 | + // have an integer. If in addition we have '.' or 'e' or 'E' we (may) | |
| 389 | + // have a float. | |
| 390 | + int found_int = 0; | |
| 391 | + int found_float = 0; | |
| 392 | + for (int i = 0; i <= last; ++i) { | |
| 393 | + if ((m_value[i] >= '0' && m_value[i] <= '9') || m_value[i] == '+' || m_value[i] == '-') | |
| 394 | + found_int = 1; | |
| 395 | + else if (m_value[i] == '.' || m_value[i] == 'e' || m_value[i] == 'E') | |
| 396 | + found_float = 1; | |
| 397 | + else | |
| 398 | + return CT_INVALID; | |
| 399 | + } | |
| 400 | + | |
| 401 | + // If we are still alive we should have now either a float or an integer | |
| 402 | + if (found_int) { | |
| 403 | + if (found_float) { | |
| 404 | + return CT_FLOAT; | |
| 405 | + } | |
| 406 | + else { | |
| 407 | + return CT_INT; | |
| 408 | + } | |
| 409 | + } | |
| 410 | + else | |
| 411 | + return CT_INVALID; | |
| 412 | +} | ... | ... |
src/fits/GFitsImage.cpp
0 โ 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GFitsImage.cpp - FITS image class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * ----------------------------------------------------------------------- * | |
| 13 | + ***************************************************************************/ | |
| 14 | + | |
| 15 | +/* __ Includes ___________________________________________________________ */ | |
| 16 | +#include "GException.hpp" | |
| 17 | +#include "GFitsImage.hpp" | |
| 18 | +#include <iostream> // cout, cerr | |
| 19 | + | |
| 20 | +/* __ Namespaces _________________________________________________________ */ | |
| 21 | + | |
| 22 | +/* __ Method name definitions ____________________________________________ */ | |
| 23 | + | |
| 24 | +/* __ Macros _____________________________________________________________ */ | |
| 25 | + | |
| 26 | +/* __ Coding definitions _________________________________________________ */ | |
| 27 | + | |
| 28 | +/* __ Debug definitions __________________________________________________ */ | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | +/*========================================================================== | |
| 33 | + = = | |
| 34 | + = GFitsImage constructors/destructors = | |
| 35 | + = = | |
| 36 | + ==========================================================================*/ | |
| 37 | + | |
| 38 | +/*************************************************************************** | |
| 39 | + * Constructor * | |
| 40 | + * ----------------------------------------------------------------------- * | |
| 41 | + ***************************************************************************/ | |
| 42 | +GFitsImage::GFitsImage() : GFitsData() | |
| 43 | +{ | |
| 44 | + // Initialise class members for clean destruction | |
| 45 | + init_members(); | |
| 46 | + | |
| 47 | + // Return | |
| 48 | + return; | |
| 49 | +} | |
| 50 | + | |
| 51 | + | |
| 52 | +/*************************************************************************** | |
| 53 | + * Copy constructor * | |
| 54 | + * ----------------------------------------------------------------------- * | |
| 55 | + ***************************************************************************/ | |
| 56 | +GFitsImage::GFitsImage(const GFitsImage& image) : GFitsData(image) | |
| 57 | +{ | |
| 58 | + // Initialise class members for clean destruction | |
| 59 | + init_members(); | |
| 60 | + | |
| 61 | + // Copy members | |
| 62 | + copy_members(image); | |
| 63 | + | |
| 64 | + // Return | |
| 65 | + return; | |
| 66 | +} | |
| 67 | + | |
| 68 | + | |
| 69 | +/*************************************************************************** | |
| 70 | + * Destructor * | |
| 71 | + * ----------------------------------------------------------------------- * | |
| 72 | + ***************************************************************************/ | |
| 73 | +GFitsImage::~GFitsImage() | |
| 74 | +{ | |
| 75 | + // Free members | |
| 76 | + free_members(); | |
| 77 | + | |
| 78 | + // Return | |
| 79 | + return; | |
| 80 | +} | |
| 81 | + | |
| 82 | + | |
| 83 | +/*========================================================================== | |
| 84 | + = = | |
| 85 | + = GFitsImage operators = | |
| 86 | + = = | |
| 87 | + ==========================================================================*/ | |
| 88 | + | |
| 89 | +/*************************************************************************** | |
| 90 | + * Assignment operator * | |
| 91 | + * ----------------------------------------------------------------------- * | |
| 92 | + ***************************************************************************/ | |
| 93 | +GFitsImage& GFitsImage::operator= (const GFitsImage& image) | |
| 94 | +{ | |
| 95 | + // Execute only if object is not identical | |
| 96 | + if (this != &image) { | |
| 97 | + | |
| 98 | + // Copy base class members | |
| 99 | + this->GFitsData::operator=(image); | |
| 100 | + | |
| 101 | + // Free members | |
| 102 | + free_members(); | |
| 103 | + | |
| 104 | + // Initialise private members for clean destruction | |
| 105 | + init_members(); | |
| 106 | + | |
| 107 | + // Copy members | |
| 108 | + copy_members(image); | |
| 109 | + | |
| 110 | + } // endif: object was not identical | |
| 111 | + | |
| 112 | + // Return this object | |
| 113 | + return *this; | |
| 114 | +} | |
| 115 | + | |
| 116 | + | |
| 117 | +/*========================================================================== | |
| 118 | + = = | |
| 119 | + = GFitsImage public methods = | |
| 120 | + = = | |
| 121 | + ==========================================================================*/ | |
| 122 | + | |
| 123 | +/*************************************************************************** | |
| 124 | + * Open Image * | |
| 125 | + * ----------------------------------------------------------------------- * | |
| 126 | + ***************************************************************************/ | |
| 127 | +void GFitsImage::open(__fitsfile* fptr) | |
| 128 | +{ | |
| 129 | + cout << "open image" << endl; | |
| 130 | + // Return | |
| 131 | + return; | |
| 132 | +} | |
| 133 | + | |
| 134 | + | |
| 135 | +/*************************************************************************** | |
| 136 | + * Close Image * | |
| 137 | + * ----------------------------------------------------------------------- * | |
| 138 | + ***************************************************************************/ | |
| 139 | +void GFitsImage::close(void) | |
| 140 | +{ | |
| 141 | + // Free members | |
| 142 | + free_members(); | |
| 143 | + | |
| 144 | + // Initialise members | |
| 145 | + init_members(); | |
| 146 | + | |
| 147 | + // Return | |
| 148 | + return; | |
| 149 | +} | |
| 150 | + | |
| 151 | + | |
| 152 | +/*========================================================================== | |
| 153 | + = = | |
| 154 | + = GFitsImage private methods = | |
| 155 | + = = | |
| 156 | + ==========================================================================*/ | |
| 157 | + | |
| 158 | +/*************************************************************************** | |
| 159 | + * Initialise class members * | |
| 160 | + * ----------------------------------------------------------------------- * | |
| 161 | + ***************************************************************************/ | |
| 162 | +void GFitsImage::init_members(void) | |
| 163 | +{ | |
| 164 | + // Initialise members | |
| 165 | + | |
| 166 | + // Return | |
| 167 | + return; | |
| 168 | +} | |
| 169 | + | |
| 170 | + | |
| 171 | +/*************************************************************************** | |
| 172 | + * Copy class members * | |
| 173 | + * ----------------------------------------------------------------------- * | |
| 174 | + ***************************************************************************/ | |
| 175 | +void GFitsImage::copy_members(const GFitsImage& image) | |
| 176 | +{ | |
| 177 | + // Copy attributes | |
| 178 | + | |
| 179 | + // Copy data | |
| 180 | + | |
| 181 | + // Return | |
| 182 | + return; | |
| 183 | +} | |
| 184 | + | |
| 185 | + | |
| 186 | +/*************************************************************************** | |
| 187 | + * Delete class members * | |
| 188 | + * ----------------------------------------------------------------------- * | |
| 189 | + ***************************************************************************/ | |
| 190 | +void GFitsImage::free_members(void) | |
| 191 | +{ | |
| 192 | + // Free memory | |
| 193 | + | |
| 194 | + // Return | |
| 195 | + return; | |
| 196 | +} | |
| 197 | + | |
| 198 | + | |
| 199 | +/*========================================================================== | |
| 200 | + = = | |
| 201 | + = GFitsImage friends = | |
| 202 | + = = | |
| 203 | + ==========================================================================*/ | |
| 204 | + | |
| 205 | + | |
| 206 | +/*========================================================================== | |
| 207 | + = = | |
| 208 | + = Other functions used by GFitsImage = | |
| 209 | + = = | |
| 210 | + ==========================================================================*/ | ... | ... |
src/fits/GFitsTableCol.cpp
0 โ 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GFitsTableCol.cpp - FITS table column abstract base class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * ----------------------------------------------------------------------- * | |
| 13 | + ***************************************************************************/ | |
| 14 | + | |
| 15 | +/* __ Includes ___________________________________________________________ */ | |
| 16 | +#include "GException.hpp" | |
| 17 | +#include "GFitsTableCol.hpp" | |
| 18 | +#include <iostream> // cout, cerr | |
| 19 | + | |
| 20 | +/* __ Namespaces _________________________________________________________ */ | |
| 21 | + | |
| 22 | +/* __ Method name definitions ____________________________________________ */ | |
| 23 | + | |
| 24 | +/* __ Macros _____________________________________________________________ */ | |
| 25 | + | |
| 26 | +/* __ Coding definitions _________________________________________________ */ | |
| 27 | + | |
| 28 | +/* __ Debug definitions __________________________________________________ */ | |
| 29 | + | |
| 30 | + | |
| 31 | +/*========================================================================== | |
| 32 | + = = | |
| 33 | + = GFitsTableCol constructors/destructors = | |
| 34 | + = = | |
| 35 | + ==========================================================================*/ | |
| 36 | + | |
| 37 | +/*************************************************************************** | |
| 38 | + * Constructor * | |
| 39 | + * ----------------------------------------------------------------------- * | |
| 40 | + ***************************************************************************/ | |
| 41 | +GFitsTableCol::GFitsTableCol() | |
| 42 | +{ | |
| 43 | + // Initialise class members for clean destruction | |
| 44 | + init_members(); | |
| 45 | + | |
| 46 | + // Return | |
| 47 | + return; | |
| 48 | +} | |
| 49 | + | |
| 50 | + | |
| 51 | +/*************************************************************************** | |
| 52 | + * Copy constructor * | |
| 53 | + * ----------------------------------------------------------------------- * | |
| 54 | + ***************************************************************************/ | |
| 55 | +GFitsTableCol::GFitsTableCol(const GFitsTableCol& column) | |
| 56 | +{ | |
| 57 | + // Initialise class members for clean destruction | |
| 58 | + init_members(); | |
| 59 | + | |
| 60 | + // Copy members | |
| 61 | + copy_members(column); | |
| 62 | + | |
| 63 | + // Return | |
| 64 | + return; | |
| 65 | +} | |
| 66 | + | |
| 67 | + | |
| 68 | +/*************************************************************************** | |
| 69 | + * Destructor * | |
| 70 | + * ----------------------------------------------------------------------- * | |
| 71 | + ***************************************************************************/ | |
| 72 | +GFitsTableCol::~GFitsTableCol() | |
| 73 | +{ | |
| 74 | + // Free members | |
| 75 | + free_members(); | |
| 76 | + | |
| 77 | + // Return | |
| 78 | + return; | |
| 79 | +} | |
| 80 | + | |
| 81 | + | |
| 82 | +/*========================================================================== | |
| 83 | + = = | |
| 84 | + = GFitsTableCol operators = | |
| 85 | + = = | |
| 86 | + ==========================================================================*/ | |
| 87 | + | |
| 88 | +/*************************************************************************** | |
| 89 | + * Assignment operator * | |
| 90 | + * ----------------------------------------------------------------------- * | |
| 91 | + ***************************************************************************/ | |
| 92 | +GFitsTableCol& GFitsTableCol::operator= (const GFitsTableCol& column) | |
| 93 | +{ | |
| 94 | + // Execute only if object is not identical | |
| 95 | + if (this != &column) { | |
| 96 | + | |
| 97 | + // Free members | |
| 98 | + free_members(); | |
| 99 | + | |
| 100 | + // Initialise private members for clean destruction | |
| 101 | + init_members(); | |
| 102 | + | |
| 103 | + // Copy members | |
| 104 | + copy_members(column); | |
| 105 | + | |
| 106 | + } // endif: object was not identical | |
| 107 | + | |
| 108 | + // Return this object | |
| 109 | + return *this; | |
| 110 | +} | |
| 111 | + | |
| 112 | + | |
| 113 | +/*========================================================================== | |
| 114 | + = = | |
| 115 | + = GFitsTableCol public methods = | |
| 116 | + = = | |
| 117 | + ==========================================================================*/ | |
| 118 | + | |
| 119 | + | |
| 120 | +/*========================================================================== | |
| 121 | + = = | |
| 122 | + = GFitsTableCol private methods = | |
| 123 | + = = | |
| 124 | + ==========================================================================*/ | |
| 125 | + | |
| 126 | +/*************************************************************************** | |
| 127 | + * Initialise class members * | |
| 128 | + * ----------------------------------------------------------------------- * | |
| 129 | + ***************************************************************************/ | |
| 130 | +void GFitsTableCol::init_members(void) | |
| 131 | +{ | |
| 132 | + // Initialise members | |
| 133 | + m_name.clear(); | |
| 134 | + m_colnum = 0; | |
| 135 | + m_type = 0; | |
| 136 | + m_repeat = 0; | |
| 137 | + m_width = 0; | |
| 138 | + m_length = 0; | |
| 139 | + m_fitsfile = NULL; | |
| 140 | + | |
| 141 | + // Return | |
| 142 | + return; | |
| 143 | +} | |
| 144 | + | |
| 145 | + | |
| 146 | +/*************************************************************************** | |
| 147 | + * Copy class members * | |
| 148 | + * ----------------------------------------------------------------------- * | |
| 149 | + ***************************************************************************/ | |
| 150 | +void GFitsTableCol::copy_members(const GFitsTableCol& column) | |
| 151 | +{ | |
| 152 | + // Copy attributes | |
| 153 | + m_name = column.m_name; | |
| 154 | + m_colnum = column.m_colnum; | |
| 155 | + m_type = column.m_type; | |
| 156 | + m_repeat = column.m_repeat; | |
| 157 | + m_width = column.m_width; | |
| 158 | + m_length = column.m_length; | |
| 159 | + m_fitsfile = column.m_fitsfile; | |
| 160 | + | |
| 161 | + // Return | |
| 162 | + return; | |
| 163 | +} | |
| 164 | + | |
| 165 | + | |
| 166 | +/*************************************************************************** | |
| 167 | + * Delete class members * | |
| 168 | + * ----------------------------------------------------------------------- * | |
| 169 | + ***************************************************************************/ | |
| 170 | +void GFitsTableCol::free_members(void) | |
| 171 | +{ | |
| 172 | + // Free memory | |
| 173 | + | |
| 174 | + // Mark memory as freed | |
| 175 | + | |
| 176 | + // Return | |
| 177 | + return; | |
| 178 | +} | |
| 179 | + | |
| 180 | + | |
| 181 | +/*========================================================================== | |
| 182 | + = = | |
| 183 | + = GFitsTableCol friends = | |
| 184 | + = = | |
| 185 | + ==========================================================================*/ | |
| 186 | + | |
| 187 | + | |
| 188 | +/*========================================================================== | |
| 189 | + = = | |
| 190 | + = Other functions used by GFitsTableCol = | |
| 191 | + = = | |
| 192 | + ==========================================================================*/ | ... | ... |
src/fits/GFitsTableDblCol.cpp
0 โ 100644
| 1 | +/*************************************************************************** | |
| 2 | + * GFitsTableDblCol.cpp - FITS table double column class * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software; you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * ----------------------------------------------------------------------- * | |
| 13 | + ***************************************************************************/ | |
| 14 | + | |
| 15 | +/* __ Includes ___________________________________________________________ */ | |
| 16 | +#include "GException.hpp" | |
| 17 | +#include "GFitsTableDblCol.hpp" | |
| 18 | +#include <iostream> // cout, cerr | |
| 19 | + | |
| 20 | +/* __ Namespaces _________________________________________________________ */ | |
| 21 | + | |
| 22 | +/* __ Method name definitions ____________________________________________ */ | |
| 23 | +#define G_STRING "GFitsTableDblCol::string(const int&, const int&)" | |
| 24 | +#define G_REAL "GFitsTableDblCol::real(const int&, const int&)" | |
| 25 | +#define G_INTEGER "GFitsTableDblCol::integer(const int&, const int&)" | |
| 26 | +#define G_PTR_STRING "GFitsTableDblCol::ptr_string()" | |
| 27 | +#define G_PTR_FLOAT "GFitsTableDblCol::ptr_float()" | |
| 28 | +#define G_PTR_SHORT "GFitsTableDblCol::ptr_short()" | |
| 29 | +#define G_PTR_LONG "GFitsTableDblCol::ptr_long()" | |
| 30 | +#define G_PTR_INT "GFitsTableDblCol::ptr_int()" | |
| 31 | +#define G_LOAD "GFitsTableDblCol::load()" | |
| 32 | + | |
| 33 | +/* __ Macros _____________________________________________________________ */ | |
| 34 | + | |
| 35 | +/* __ Coding definitions _________________________________________________ */ | |
| 36 | + | |
| 37 | +/* __ Debug definitions __________________________________________________ */ | |
| 38 | + | |
| 39 | + | |
| 40 | +/*========================================================================== | |
| 41 | + = = | |
| 42 | + = GFitsTableDblCol constructors/destructors = | |
| 43 | + = = | |
| 44 | + ==========================================================================*/ | |
| 45 | + | |
| 46 | +/*************************************************************************** | |
| 47 | + * Constructor * | |
| 48 | + * ----------------------------------------------------------------------- * | |
| 49 | + ***************************************************************************/ | |
| 50 | +GFitsTableDblCol::GFitsTableDblCol() : GFitsTableCol() | |
| 51 | +{ | |
| 52 | + // Initialise class members for clean destruction | |
| 53 | + init_members(); | |
| 54 | + | |
| 55 | + // Return | |
| 56 | + return; | |
| 57 | +} | |
| 58 | + | |
| 59 | + | |
| 60 | +/*************************************************************************** | |
| 61 | + * Copy constructor * | |
| 62 | + * ----------------------------------------------------------------------- * | |
| 63 | + ***************************************************************************/ | |
| 64 | +GFitsTableDblCol::GFitsTableDblCol(const GFitsTableDblCol& column) : GFitsTableCol(column) | |
| 65 | +{ | |
| 66 | + // Initialise class members for clean destruction | |
| 67 | + init_members(); | |
| 68 | + | |
| 69 | + // Copy members | |
| 70 | + copy_members(column); | |
| 71 | + | |
| 72 | + // Return | |
| 73 | + return; | |
| 74 | +} | |
| 75 | + | |
| 76 | + | |
| 77 | +/*************************************************************************** | |
| 78 | + * Destructor * | |
| 79 | + * ----------------------------------------------------------------------- * | |
| 80 | + ***************************************************************************/ | |
| 81 | +GFitsTableDblCol::~GFitsTableDblCol() | |
| 82 | +{ | |
| 83 | + // Free members | |
| 84 | + free_members(); | |
| 85 | + | |
| 86 | + // Return | |
| 87 | + return; | |
| 88 | +} | |
| 89 | + | |
| 90 | + | |
| 91 | +/*========================================================================== | |
| 92 | + = = | |
| 93 | + = GFitsTableDblCol operators = | |
| 94 | + = = | |
| 95 | + ==========================================================================*/ | |
| 96 | + | |
| 97 | +/*************************************************************************** | |
| 98 | + * Assignment operator * | |
| 99 | + * ----------------------------------------------------------------------- * | |
| 100 | + ***************************************************************************/ | |
| 101 | +GFitsTableDblCol& GFitsTableDblCol::operator= (const GFitsTableDblCol& column) | |
| 102 | +{ | |
| 103 | + // Execute only if object is not identical | |
| 104 | + if (this != &column) { | |
| 105 | + | |
| 106 | + // Copy base class members | |
| 107 | + this->GFitsTableCol::operator=(column); | |
| 108 | + | |
| 109 | + // Free members | |
| 110 | + free_members(); | |
| 111 | + | |
| 112 | + // Initialise private members for clean destruction | |
| 113 | + init_members(); | |
| 114 | + | |
| 115 | + // Copy members | |
| 116 | + copy_members(column); | |
| 117 | + | |
| 118 | + } // endif: object was not identical | |
| 119 | + | |
| 120 | + // Return this object | |
| 121 | + return *this; | |
| 122 | +} | |
| 123 | + | |
| 124 | + | |
| 125 | +/*========================================================================== | |
| 126 | + = = | |
| 127 | + = GFitsTableDblCol public methods = | |
| 128 | + = = | |
| 129 | + ==========================================================================*/ | |
| 130 | + | |
| 131 | +/*************************************************************************** | |
| 132 | + * Get string value * | |
| 133 | + * ----------------------------------------------------------------------- * | |
| 134 | + ***************************************************************************/ | |
| 135 | +std::string GFitsTableDblCol::string(const int& row, const int& col) | |
| 136 | +{ | |
| 137 | + // Check row value | |
| 138 | + if (row < 0 || row >= m_length) | |
| 139 | + throw GException::out_of_range(G_STRING, row, 0, m_length-1); | |
| 140 | + | |
| 141 | + // Check col value | |
| 142 | + if (col < 0 || col >= m_repeat) | |
| 143 | + throw GException::out_of_range(G_STRING, col, 0, m_repeat-1); | |
| 144 | + | |
| 145 | + // Make sure that data are loaded | |
| 146 | + if (m_data == NULL) | |
| 147 | + load(); | |
| 148 | + | |
| 149 | + // Get index | |
| 150 | + int inx = row * m_repeat + col; | |
| 151 | + | |
| 152 | + // Convert double into string | |
| 153 | + ostringstream s_value; | |
| 154 | + s_value << scientific << m_data[inx]; | |
| 155 | + | |
| 156 | + // Return value | |
| 157 | + return s_value.str(); | |
| 158 | +} | |
| 159 | + | |
| 160 | + | |
| 161 | +/*************************************************************************** | |
| 162 | + * Get real value * | |
| 163 | + * ----------------------------------------------------------------------- * | |
| 164 | + ***************************************************************************/ | |
| 165 | +double GFitsTableDblCol::real(const int& row, const int& col) | |
| 166 | +{ | |
| 167 | + // Check row value | |
| 168 | + if (row < 0 || row >= m_length) | |
| 169 | + throw GException::out_of_range(G_REAL, row, 0, m_length-1); | |
| 170 | + | |
| 171 | + // Check col value | |
| 172 | + if (col < 0 || col >= m_repeat) | |
| 173 | + throw GException::out_of_range(G_REAL, col, 0, m_repeat-1); | |
| 174 | + | |
| 175 | + // Make sure that data are loaded | |
| 176 | + if (m_data == NULL) | |
| 177 | + load(); | |
| 178 | + | |
| 179 | + // Get index | |
| 180 | + int inx = row * m_repeat + col; | |
| 181 | + | |
| 182 | + // Return value | |
| 183 | + return m_data[inx]; | |
| 184 | +} | |
| 185 | + | |
| 186 | + | |
| 187 | +/*************************************************************************** | |
| 188 | + * Get int value * | |
| 189 | + * ----------------------------------------------------------------------- * | |
| 190 | + ***************************************************************************/ | |
| 191 | +int GFitsTableDblCol::integer(const int& row, const int& col) | |
| 192 | +{ | |
| 193 | + // Check row value | |
| 194 | + if (row < 0 || row >= m_length) | |
| 195 | + throw GException::out_of_range(G_INTEGER, row, 0, m_length-1); | |
| 196 | + | |
| 197 | + // Check col value | |
| 198 | + if (col < 0 || col >= m_repeat) | |
| 199 | + throw GException::out_of_range(G_INTEGER, col, 0, m_repeat-1); | |
| 200 | + | |
| 201 | + // Make sure that data are loaded | |
| 202 | + if (m_data == NULL) | |
| 203 | + load(); | |
| 204 | + | |
| 205 | + // Get index | |
| 206 | + int inx = row * m_repeat + col; | |
| 207 | + | |
| 208 | + // Convert double into int | |
| 209 | + int value = (int)m_data[inx]; | |
| 210 | + | |
| 211 | + // Return value | |
| 212 | + return value; | |
| 213 | +} | |
| 214 | + | |
| 215 | + | |
| 216 | +/*************************************************************************** | |
| 217 | + * Access to invalid data pointers * | |
| 218 | + * ----------------------------------------------------------------------- * | |
| 219 | + ***************************************************************************/ | |
| 220 | +std::string* GFitsTableDblCol::ptr_string(void) | |
| 221 | +{ | |
| 222 | + throw GException::fits_invalid_type(G_PTR_STRING, "No <string> pointer allowed to <double> array"); | |
| 223 | +} | |
| 224 | +float* GFitsTableDblCol::ptr_float(void) | |
| 225 | +{ | |
| 226 | + throw GException::fits_invalid_type(G_PTR_FLOAT, "No <float> pointer allowed to <double> array"); | |
| 227 | +} | |
| 228 | +short* GFitsTableDblCol::ptr_short(void) | |
| 229 | +{ | |
| 230 | + throw GException::fits_invalid_type(G_PTR_SHORT, "No <short> pointer allowed to <double> array"); | |
| 231 | +} | |
| 232 | +long* GFitsTableDblCol::ptr_long(void) | |
| 233 | +{ | |
| 234 | + throw GException::fits_invalid_type(G_PTR_LONG, "No <long> pointer allowed to <double> array"); | |
| 235 | +} | |
| 236 | +int* GFitsTableDblCol::ptr_int(void) | |
| 237 | +{ | |
| 238 | + throw GException::fits_invalid_type(G_PTR_INT, "No <int> pointer allowed to <double> array"); | |
| 239 | +} | |
| 240 | + | |
| 241 | + | |
| 242 | +/*========================================================================== | |
| 243 | + = = | |
| 244 | + = GFitsTableDblCol private methods = | |
| 245 | + = = | |
| 246 | + ==========================================================================*/ | |
| 247 | + | |
| 248 | +/*************************************************************************** | |
| 249 | + * Initialise class members * | |
| 250 | + * ----------------------------------------------------------------------- * | |
| 251 | + ***************************************************************************/ | |
| 252 | +void GFitsTableDblCol::init_members(void) | |
| 253 | +{ | |
| 254 | + // Initialise members | |
| 255 | + m_size = 0; | |
| 256 | + m_data = NULL; | |
| 257 | + m_nulval = 0.0; | |
| 258 | + | |
| 259 | + // Return | |
| 260 | + return; | |
| 261 | +} | |
| 262 | + | |
| 263 | + | |
| 264 | +/*************************************************************************** | |
| 265 | + * Copy class members * | |
| 266 | + * ----------------------------------------------------------------------- * | |
| 267 | + ***************************************************************************/ | |
| 268 | +void GFitsTableDblCol::copy_members(const GFitsTableDblCol& column) | |
| 269 | +{ | |
| 270 | + // Copy attributes | |
| 271 | + m_size = column.m_size; | |
| 272 | + m_nulval = column.m_nulval; | |
| 273 | + | |
| 274 | + // Copy column data | |
| 275 | + if (column.m_data != NULL && m_size > 0) { | |
| 276 | + if (m_data != NULL) delete [] m_data; | |
| 277 | + m_data = new double[m_size]; | |
| 278 | + memcpy(m_data, column.m_data, m_size*sizeof(double)); | |
| 279 | + } | |
| 280 | + | |
| 281 | + // Return | |
| 282 | + return; | |
| 283 | +} | |
| 284 | + | |
| 285 | + | |
| 286 | +/*************************************************************************** | |
| 287 | + * Delete class members * | |
| 288 | + * ----------------------------------------------------------------------- * | |
| 289 | + ***************************************************************************/ | |
| 290 | +void GFitsTableDblCol::free_members(void) | |
| 291 | +{ | |
| 292 | + // Free memory | |
| 293 | + if (m_data != NULL) delete [] m_data; | |
| 294 | + | |
| 295 | + // Mark memory as freed | |
| 296 | + m_data = NULL; | |
| 297 | + | |
| 298 | + // Return | |
| 299 | + return; | |
| 300 | +} | |
| 301 | + | |
| 302 | + | |
| 303 | +/*************************************************************************** | |
| 304 | + * Load column data * | |
| 305 | + * ----------------------------------------------------------------------- * | |
| 306 | + ***************************************************************************/ | |
| 307 | +void GFitsTableDblCol::load(void) | |
| 308 | +{ | |
| 309 | + // Calculate size of memory | |
| 310 | + m_size = m_repeat * m_length; | |
| 311 | + | |
| 312 | + // Allocate memory | |
| 313 | + if (m_data != NULL) delete [] m_data; | |
| 314 | + m_data = new double[m_size]; | |
| 315 | + | |
| 316 | + // Load column data | |
| 317 | + int status = 0; | |
| 318 | + status = __ffgcv(m_fitsfile, __TDOUBLE, m_colnum, 1, 1, m_size, | |
| 319 | + &m_nulval, m_data, NULL, &status); | |
| 320 | + if (status != 0) | |
| 321 | + throw GException::fits_error(G_LOAD, status); | |
| 322 | + | |
| 323 | + // Return | |
| 324 | + return; | |
| 325 | +} | |
| 326 | + | |
| 327 | + | |
| 328 | +/*========================================================================== | |
| 329 | + = = | |
| 330 | + = GFitsTableDblCol friends = | |
| 331 | + = = | |
| 332 | + ==========================================================================*/ | |
| 333 | + | |
| 334 | + | |
| 335 | +/*========================================================================== | |
| 336 | + = = | |
| 337 | + = Other functions used by GFitsTableDblCol = | |
| 338 | + = = | |
| 339 | + ==========================================================================*/ | ... | ... |
test/test_GFits.cpp
| ... | ... | @@ -28,6 +28,19 @@ void test_open(void) |
| 28 | 28 | try { |
| 29 | 29 | GFits fits; |
| 30 | 30 | fits.open("srcid.fits"); |
| 31 | + | |
| 32 | + // Access data via conversion functions | |
| 33 | + cout << fits.hdu("LAT_POINT_SOURCE_CATALOG")->column("ID_3EG_PROB_1")->string(0) << endl; | |
| 34 | + cout << fits.hdu("LAT_POINT_SOURCE_CATALOG")->column("ID_3EG_PROB_1")->real(0) << endl; | |
| 35 | + cout << fits.hdu("LAT_POINT_SOURCE_CATALOG")->column("ID_3EG_PROB_1")->integer(0) << endl; | |
| 36 | + | |
| 37 | + // Access data via pointer | |
| 38 | + double* ptr = fits.hdu("LAT_POINT_SOURCE_CATALOG")->column("ID_3EG_PROB_1")->ptr_double(); | |
| 39 | + cout << ptr[0] << endl; | |
| 40 | + | |
| 41 | + GFitsTableDblCol column = *((GFitsTableDblCol*)fits.hdu("LAT_POINT_SOURCE_CATALOG")->column("ID_3EG_PROB_1")); | |
| 42 | + cout << column.real(0) << endl; | |
| 43 | + | |
| 31 | 44 | } |
| 32 | 45 | catch (exception &e) { |
| 33 | 46 | std::cout << std::endl << "TEST ERROR: Unable to open FITS file." << std::endl; | ... | ... |