Commit bf772c7391058b6fb6b9055cfe5f40e65fb9e4e4

Authored by knodlseder
1 parent a12d06bb

start implementing table writing

include/GFitsAsciiTable.hpp
... ... @@ -10,6 +10,11 @@
10 10 * (at your option) any later version. *
11 11 * *
12 12 ***************************************************************************/
  13 +/**
  14 + * @file GFitsAsciiTable.hpp
  15 + * @brief GFitsAsciiTable class definition.
  16 + * @author J. Knodlseder
  17 + */
13 18  
14 19 #ifndef GFITSASCIITABLE_HPP
15 20 #define GFITSASCIITABLE_HPP
... ... @@ -17,22 +22,22 @@
17 22 /* __ Includes ___________________________________________________________ */
18 23 #include "GFitsCfitsio.hpp"
19 24 #include "GFitsData.hpp"
20   -#include "GFitsTableCol.hpp"
  25 +#include "GFitsTable.hpp"
21 26  
22 27 /* __ Namespaces _________________________________________________________ */
23 28  
24 29  
25   -/***************************************************************************
26   - * GFitsAsciiTable class definition *
  30 +/***********************************************************************//**
  31 + * @class GFitsAsciiTable
  32 + *
  33 + * @brief Interface for FITS binary table
27 34 ***************************************************************************/
28   -class GFitsAsciiTable : public GFitsData {
29   -
30   - // I/O friends
31   - friend ostream& operator<< (ostream& os, const GFitsAsciiTable& table);
  35 +class GFitsAsciiTable : public GFitsTable {
32 36  
33 37 public:
34 38 // Constructors and destructors
35 39 GFitsAsciiTable();
  40 + GFitsAsciiTable(int nrows, int ncols);
36 41 GFitsAsciiTable(const GFitsAsciiTable& table);
37 42 virtual ~GFitsAsciiTable();
38 43  
... ... @@ -40,34 +45,20 @@ public:
40 45 GFitsAsciiTable& operator= (const GFitsAsciiTable& table);
41 46  
42 47 // Methods
43   - void open(__fitsfile* fptr);
44   - void save(void);
45   - void close(void);
46 48 GFitsAsciiTable* clone(void) const;
47   - GFitsTableCol* column(const std::string& colname);
48   - GFitsTableCol* column(const int& colnum);
49 49  
50 50 private:
51 51 // Private methods
52 52 void init_members(void);
53 53 void copy_members(const GFitsAsciiTable& table);
54 54 void free_members(void);
55   - void connect(__fitsfile* fptr);
56 55  
57 56 // Private data area
58   - int m_rows;
59   - int m_cols;
60   - GFitsTableCol** m_columns;
61 57 };
62 58  
63 59  
64 60 /***************************************************************************
65 61 * Inline methods *
66 62 ***************************************************************************/
67   -inline
68   -GFitsAsciiTable* GFitsAsciiTable::clone(void) const
69   -{
70   - return new GFitsAsciiTable(*this);
71   -}
72 63  
73 64 #endif /* GFITSASCIITABLE_HPP */
... ...
include/GFitsBinTable.hpp
... ... @@ -22,23 +22,17 @@
22 22 /* __ Includes ___________________________________________________________ */
23 23 #include "GFitsCfitsio.hpp"
24 24 #include "GFitsData.hpp"
25   -#include "GFitsTableCol.hpp"
  25 +#include "GFitsTable.hpp"
26 26  
27 27 /* __ Namespaces _________________________________________________________ */
28 28  
29 29  
30   -/* __ Structures _________________________________________________________ */
31   -
32   -
33 30 /***********************************************************************//**
34 31 * @class GFitsBinTable
35 32 *
36 33 * @brief Interface for FITS binary table
37 34 ***************************************************************************/
38   -class GFitsBinTable : public GFitsData {
39   -
40   - // I/O friends
41   - friend ostream& operator<< (ostream& os, const GFitsBinTable& table);
  35 +class GFitsBinTable : public GFitsTable {
42 36  
43 37 public:
44 38 // Constructors and destructors
... ... @@ -51,34 +45,20 @@ public:
51 45 GFitsBinTable& operator= (const GFitsBinTable& table);
52 46  
53 47 // Methods
54   - void open(__fitsfile* fptr);
55   - void save(void);
56   - void close(void);
57 48 GFitsBinTable* clone(void) const;
58   - GFitsTableCol* column(const std::string& colname);
59   - GFitsTableCol* column(const int& colnum);
60 49  
61 50 private:
62 51 // Private methods
63 52 void init_members(void);
64 53 void copy_members(const GFitsBinTable& table);
65 54 void free_members(void);
66   - void connect(__fitsfile* fptr);
67 55  
68 56 // Private data area
69   - int m_rows; //!< Number of rows in table
70   - int m_cols; //!< Number of columns in table
71   - GFitsTableCol** m_columns; //!< Array of column pointers
72 57 };
73 58  
74 59  
75 60 /***************************************************************************
76 61 * Inline methods *
77 62 ***************************************************************************/
78   -inline
79   -GFitsBinTable* GFitsBinTable::clone(void) const
80   -{
81   - return new GFitsBinTable(*this);
82   -}
83 63  
84 64 #endif /* GFITSBINTABLE_HPP */
... ...
include/GFitsCfitsio.hpp
... ... @@ -31,6 +31,7 @@
31 31 /* __ Macros _____________________________________________________________ */
32 32 #define __ffclos(A, B) ffclos(A, B)
33 33 #define __ffcrim(A, B, C, D, E) ffcrim(A, B, C, D, E)
  34 +#define __ffcrtb(A, B, C, D, E, F, G, H, I) ffcrtb(A, B, C, D, E, F, G, H, I)
34 35 #define __ffdelt(A, B) ffdelt(A, B)
35 36 #define __ffgcv(A, B, C, D, E, F, G, H, I, J) ffgcv(A, B, C, D, E, F, G, H, I, J)
36 37 #define __ffgcvs(A, B, C, D, E, F, G, H, I) ffgcvs(A, B, C, D, E, F, G, H, I)
... ... @@ -49,14 +50,21 @@
49 50 #define __ffinit(A, B, C) ffinit(A, B, C)
50 51 #define __ffopen(A, B, C, D) ffopen(A, B, C, D)
51 52 #define __ffmahd(A, B, C, D) ffmahd(A, B, C, D)
  53 +#define __ffpcom(A, B, C) ffpcom(A, B, C)
  54 +#define __ffphis(A, B, C) ffphis(A, B, C)
52 55 #define __ffpss(A, B, C, D, E, F) ffpss(A, B, C, D, E, F)
53 56 #define __ffthdu(A, B, C) ffthdu(A, B, C)
54 57 #define __ffuky(A, B, C, D, E, F) ffuky(A, B, C, D, E, F)
  58 +#define __ffukyd(A, B, C, D, E, F) ffukyd(A, B, C, D, E, F)
  59 +#define __ffukyj(A, B, C, D, E) ffukyj(A, B, C, D, E)
  60 +#define __ffukyl(A, B, C, D, E) ffukyl(A, B, C, D, E)
  61 +#define __ffukys(A, B, C, D, E) ffukys(A, B, C, D, E)
55 62 #define __TBIT TBIT
56 63 #define __TBYTE TBYTE
57 64 #define __TLOGICAL TLOGICAL
58 65 #define __TSTRING TSTRING
59 66 #define __TSHORT TSHORT
  67 +#define __TINT TINT
60 68 #define __TLONG TLONG
61 69 #define __TLONGLONG TLONGLONG
62 70 #define __TFLOAT TFLOAT
... ... @@ -73,6 +81,7 @@ typedef fitsfile __fitsfile;
73 81 /* __ Macros _____________________________________________________________ */
74 82 #define __ffclos(A, B) __dummy()
75 83 #define __ffcrim(A, B, C, D, E) __dummy()
  84 +#define __ffcrtb(A, B, C, D, E, F, G, H, I) __dummy()
76 85 #define __ffdelt(A, B) __dummy()
77 86 #define __ffgcv(A, B, C, D, E, F, G, H, I, J) __dummy()
78 87 #define __ffgcvs(A, B, C, D, E, F, G, H, I) __dummy()
... ... @@ -91,14 +100,21 @@ typedef fitsfile __fitsfile;
91 100 #define __ffinit(A, B, C) __dummy()
92 101 #define __ffmahd(A, B, C, D) __dummy()
93 102 #define __ffopen(A, B, C, D) __dummy()
  103 +#define __ffpcom(A, B, C) __dummy()
  104 +#define __ffphis(A, B, C) __dummy()
94 105 #define __ffpss(A, B, C, D, E, F) __dummy()
95 106 #define __ffthdu(A, B, C) __dummy()
96 107 #define __ffuky(A, B, C, D, E, F) __dummy()
  108 +#define __ffukyd(A, B, C, D, E, F) __dummy()
  109 +#define __ffukyj(A, B, C, D, E) __dummy()
  110 +#define __ffukyl(A, B, C, D, E) __dummy()
  111 +#define __ffukys(A, B, C, D, E) __dummy()
97 112 #define __TBIT 1
98 113 #define __TBYTE 11
99 114 #define __TLOGICAL 14
100 115 #define __TSTRING 16
101 116 #define __TSHORT 21
  117 +#define __TINT 31
102 118 #define __TLONG 41
103 119 #define __TLONGLONG 81
104 120 #define __TFLOAT 42
... ...
include/GFitsData.hpp
... ... @@ -45,7 +45,10 @@ public:
45 45  
46 46 protected:
47 47 // Protected methods
48   - virtual void connect(__fitsfile* fptr) = 0;
  48 + virtual void connect(__fitsfile* fptr);
  49 +
  50 + // Protected data area
  51 + __fitsfile m_fitsfile; //!< FITS file
49 52 };
50 53  
51 54 #endif /* GFITSDATA_HPP */
... ...
include/GFitsHDU.hpp
... ... @@ -51,6 +51,8 @@ public:
51 51 // Constructors and destructors
52 52 GFitsHDU();
53 53 GFitsHDU(const GFitsImage& image);
  54 + GFitsHDU(const GFitsAsciiTable& table);
  55 + GFitsHDU(const GFitsBinTable& table);
54 56 GFitsHDU(const GFitsHDU& hdu);
55 57 ~GFitsHDU();
56 58  
... ...
include/GFitsHeaderCard.hpp
... ... @@ -92,6 +92,7 @@ private:
92 92 int m_value_decimals; //!< Decimals of value (for float)
93 93 std::string m_unit; //!< Unit of the card value
94 94 std::string m_comment; //!< Card comment
  95 + int m_comment_write; //!< Signals that comment should be written
95 96 };
96 97  
97 98  
... ...
include/GFitsImage.hpp
... ... @@ -65,13 +65,11 @@ protected:
65 65 void init_members(void);
66 66 void copy_members(const GFitsImage& image);
67 67 void free_members(void);
68   - void connect(__fitsfile* fptr);
69 68 void open_image(__fitsfile* fptr);
70 69 void load_image(int datatype, const void* pixels, const void* nulval, int* anynul);
71 70 void save_image(int datatype, const void* pixels);
72 71  
73 72 // Private data area
74   - __fitsfile m_fitsfile; //!< FITS file
75 73 int m_bitpix; //!< Number of Bits/pixel
76 74 int m_naxis; //!< Image dimension
77 75 long* m_naxes; //!< Number of pixels in each dimension
... ...
include/GFitsTable.hpp 0 โ†’ 100644
  1 +/***************************************************************************
  2 + * GFitsTable.hpp - FITS table 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 + * @file GFitsTable.hpp
  15 + * @brief GFitsTable class definition.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef GFITSTABLE_HPP
  20 +#define GFITSTABLE_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include "GFitsCfitsio.hpp"
  24 +#include "GFitsData.hpp"
  25 +#include "GFitsTableCol.hpp"
  26 +
  27 +/* __ Namespaces _________________________________________________________ */
  28 +
  29 +
  30 +/* __ Structures _________________________________________________________ */
  31 +
  32 +
  33 +/***********************************************************************//**
  34 + * @class GFitsTable
  35 + *
  36 + * @brief Abstract interface for FITS table
  37 + ***************************************************************************/
  38 +class GFitsTable : public GFitsData {
  39 +
  40 + // I/O friends
  41 + friend ostream& operator<< (ostream& os, const GFitsTable& table);
  42 +
  43 +public:
  44 + // Constructors and destructors
  45 + GFitsTable();
  46 + GFitsTable(int nrows, int ncols);
  47 + GFitsTable(const GFitsTable& table);
  48 + virtual ~GFitsTable();
  49 +
  50 + // Operators
  51 + GFitsTable& operator= (const GFitsTable& table);
  52 +
  53 + // Methods
  54 + void open(__fitsfile* fptr);
  55 + void save(void);
  56 + void close(void);
  57 + GFitsTable* clone(void) const = 0;
  58 + GFitsTableCol* column(const std::string& colname);
  59 + GFitsTableCol* column(const int& colnum);
  60 + int rows(void) const;
  61 + int cols(void) const;
  62 +
  63 +protected:
  64 + // Protected methods
  65 + void init_members(void);
  66 + void copy_members(const GFitsTable& table);
  67 + void free_members(void);
  68 + void connect(__fitsfile* fptr);
  69 + char* get_ttype(const int& colnum) const;
  70 + char* get_tform(const int& colnum) const;
  71 + char* get_tunit(const int& colnum) const;
  72 +
  73 + // Protected data area
  74 + int m_type; //!< Table type (1=ASCII, 2=Binary)
  75 + int m_rows; //!< Number of rows in table
  76 + int m_cols; //!< Number of columns in table
  77 + GFitsTableCol** m_columns; //!< Array of column pointers
  78 +};
  79 +
  80 +
  81 +/***************************************************************************
  82 + * Inline methods *
  83 + ***************************************************************************/
  84 +
  85 +#endif /* GFITSTABLE_HPP */
... ...
include/GFitsTableCol.hpp
... ... @@ -26,8 +26,7 @@
26 26 class GFitsTableCol {
27 27  
28 28 // Friend classes
29   - friend class GFitsAsciiTable;
30   - friend class GFitsBinTable;
  29 + friend class GFitsTable;
31 30  
32 31 // I/O friends
33 32 friend ostream& operator<< (ostream& os, const GFitsTableCol& column);
... ... @@ -69,13 +68,15 @@ public:
69 68  
70 69 protected:
71 70 // Protected data area
72   - std::string m_name;
73   - int m_colnum;
74   - int m_type;
75   - int m_repeat;
76   - int m_width;
77   - int m_length;
78   - __fitsfile m_fitsfile;
  71 + std::string m_name; //!< Column name
  72 + std::string m_format; //!< Column format
  73 + std::string m_unit; //!< Column unit
  74 + int m_colnum; //!< Column number
  75 + int m_type; //!< Column type
  76 + int m_repeat; //!< Repeat value of column
  77 + int m_width; //!< Width of column
  78 + int m_length; //!< Length of column
  79 + __fitsfile m_fitsfile; //!< FITS file associated with column
79 80  
80 81 private:
81 82 // Private methods
... ...
include/Makefile.am
... ... @@ -11,6 +11,7 @@ pkginclude_HEADERS = GammaLib.hpp \
11 11 GFitsData.hpp \
12 12 GFitsImage.hpp \
13 13 GFitsDblImage.hpp \
  14 + GFitsTable.hpp \
14 15 GFitsAsciiTable.hpp \
15 16 GFitsBinTable.hpp \
16 17 GFitsTableCol.hpp \
... ...
include/Makefile.in
... ... @@ -117,6 +117,7 @@ pkginclude_HEADERS = GammaLib.hpp \
117 117 GFitsData.hpp \
118 118 GFitsImage.hpp \
119 119 GFitsDblImage.hpp \
  120 + GFitsTable.hpp \
120 121 GFitsAsciiTable.hpp \
121 122 GFitsBinTable.hpp \
122 123 GFitsTableCol.hpp \
... ...
src/Makefile.am
... ... @@ -20,6 +20,7 @@ files = GException.cpp \
20 20 fits/GFitsData.cpp \
21 21 fits/GFitsImage.cpp \
22 22 fits/GFitsDblImage.cpp \
  23 + fits/GFitsTable.cpp \
23 24 fits/GFitsAsciiTable.cpp \
24 25 fits/GFitsBinTable.cpp \
25 26 fits/GFitsTableCol.cpp \
... ...
src/Makefile.in
... ... @@ -125,6 +125,7 @@ files = GException.cpp \
125 125 fits/GFitsData.cpp \
126 126 fits/GFitsImage.cpp \
127 127 fits/GFitsDblImage.cpp \
  128 + fits/GFitsTable.cpp \
128 129 fits/GFitsAsciiTable.cpp \
129 130 fits/GFitsBinTable.cpp \
130 131 fits/GFitsTableCol.cpp \
... ... @@ -159,11 +160,12 @@ libgamma_la_LIBADD =
159 160 am__objects_1 = GException.lo GTools.lo GSkyDir.lo GData.lo GResponse.lo \
160 161 GLATResponse.lo GObservation.lo GFitsHeaderCard.lo \
161 162 GFitsHeader.lo GFitsData.lo GFitsImage.lo GFitsDblImage.lo \
162   - GFitsAsciiTable.lo GFitsBinTable.lo GFitsTableCol.lo \
163   - GFitsTableStrCol.lo GFitsTableShtCol.lo GFitsTableLngCol.lo \
164   - GFitsTableFltCol.lo GFitsTableDblCol.lo GFitsHDU.lo GFits.lo \
165   - GFitPar.lo GVector.lo GMatrixBase.lo GMatrix.lo GSymMatrix.lo \
166   - GSparseMatrix.lo GSparseSymbolic.lo GSparseNumeric.lo
  163 + GFitsTable.lo GFitsAsciiTable.lo GFitsBinTable.lo \
  164 + GFitsTableCol.lo GFitsTableStrCol.lo GFitsTableShtCol.lo \
  165 + GFitsTableLngCol.lo GFitsTableFltCol.lo GFitsTableDblCol.lo \
  166 + GFitsHDU.lo GFits.lo GFitPar.lo GVector.lo GMatrixBase.lo \
  167 + GMatrix.lo GSymMatrix.lo GSparseMatrix.lo GSparseSymbolic.lo \
  168 + GSparseNumeric.lo
167 169 am_libgamma_la_OBJECTS = $(am__objects_1)
168 170 libgamma_la_OBJECTS = $(am_libgamma_la_OBJECTS)
169 171  
... ... @@ -233,6 +235,7 @@ GFitsHeader.lo: fits/GFitsHeader.cpp
233 235 GFitsData.lo: fits/GFitsData.cpp
234 236 GFitsImage.lo: fits/GFitsImage.cpp
235 237 GFitsDblImage.lo: fits/GFitsDblImage.cpp
  238 +GFitsTable.lo: fits/GFitsTable.cpp
236 239 GFitsAsciiTable.lo: fits/GFitsAsciiTable.cpp
237 240 GFitsBinTable.lo: fits/GFitsBinTable.cpp
238 241 GFitsTableCol.lo: fits/GFitsTableCol.cpp
... ... @@ -350,6 +353,15 @@ GFitsDblImage.obj: fits/GFitsDblImage.cpp
350 353 GFitsDblImage.lo: fits/GFitsDblImage.cpp
351 354 $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsDblImage.lo `test -f 'fits/GFitsDblImage.cpp' || echo '$(srcdir)/'`fits/GFitsDblImage.cpp
352 355  
  356 +GFitsTable.o: fits/GFitsTable.cpp
  357 + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsTable.o `test -f 'fits/GFitsTable.cpp' || echo '$(srcdir)/'`fits/GFitsTable.cpp
  358 +
  359 +GFitsTable.obj: fits/GFitsTable.cpp
  360 + $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsTable.obj `cygpath -w fits/GFitsTable.cpp`
  361 +
  362 +GFitsTable.lo: fits/GFitsTable.cpp
  363 + $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o GFitsTable.lo `test -f 'fits/GFitsTable.cpp' || echo '$(srcdir)/'`fits/GFitsTable.cpp
  364 +
353 365 GFitsAsciiTable.o: fits/GFitsAsciiTable.cpp
354 366 $(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
355 367  
... ...
src/fits/GFitsAsciiTable.cpp
... ... @@ -16,11 +16,11 @@
16 16 #include <iostream>
17 17 #include "GException.hpp"
18 18 #include "GFitsAsciiTable.hpp"
19   -#include "GFitsTableStrCol.hpp"
20   -#include "GFitsTableShtCol.hpp"
21   -#include "GFitsTableLngCol.hpp"
22   -#include "GFitsTableFltCol.hpp"
23   -#include "GFitsTableDblCol.hpp"
  19 +//#include "GFitsTableStrCol.hpp"
  20 +//#include "GFitsTableShtCol.hpp"
  21 +//#include "GFitsTableLngCol.hpp"
  22 +//#include "GFitsTableFltCol.hpp"
  23 +//#include "GFitsTableDblCol.hpp"
24 24  
25 25 /* __ Namespaces _________________________________________________________ */
26 26  
... ... @@ -43,7 +43,23 @@
43 43 /***********************************************************************//**
44 44 * @brief Constructor
45 45 ***************************************************************************/
46   -GFitsAsciiTable::GFitsAsciiTable() : GFitsData()
  46 +GFitsAsciiTable::GFitsAsciiTable() : GFitsTable()
  47 +{
  48 + // Initialise class members for clean destruction
  49 + init_members();
  50 +
  51 + // Return
  52 + return;
  53 +}
  54 +
  55 +
  56 +/***********************************************************************//**
  57 + * @brief Constructor
  58 + *
  59 + * @param[in] nrows Number of rows in table
  60 + * @param[in] ncols Number of columns in table
  61 + ***************************************************************************/
  62 +GFitsAsciiTable::GFitsAsciiTable(int nrows, int ncols) : GFitsTable(nrows, ncols)
47 63 {
48 64 // Initialise class members for clean destruction
49 65 init_members();
... ... @@ -58,7 +74,7 @@ GFitsAsciiTable::GFitsAsciiTable() : GFitsData()
58 74 *
59 75 * @param table Table to be used to initialise instance
60 76 ***************************************************************************/
61   -GFitsAsciiTable::GFitsAsciiTable(const GFitsAsciiTable& table) : GFitsData(table)
  77 +GFitsAsciiTable::GFitsAsciiTable(const GFitsAsciiTable& table) : GFitsTable(table)
62 78 {
63 79 // Initialise class members for clean destruction
64 80 init_members();
... ... @@ -101,7 +117,7 @@ GFitsAsciiTable&amp; GFitsAsciiTable::operator= (const GFitsAsciiTable&amp; table)
101 117 if (this != &table) {
102 118  
103 119 // Copy base class members
104   - this->GFitsData::operator=(table);
  120 + this->GFitsTable::operator=(table);
105 121  
106 122 // Free members
107 123 free_members();
... ... @@ -126,88 +142,11 @@ GFitsAsciiTable&amp; GFitsAsciiTable::operator= (const GFitsAsciiTable&amp; table)
126 142 ==========================================================================*/
127 143  
128 144 /***********************************************************************//**
129   - * @brief Open Table
130   - *
131   - * NOT YET IMPLEMENTED
  145 + * @brief Clone ASCII table
132 146 ***************************************************************************/
133   -void GFitsAsciiTable::open(__fitsfile* fptr)
  147 +GFitsAsciiTable* GFitsAsciiTable::clone(void) const
134 148 {
135   - // Return
136   - return;
137   -}
138   -
139   -
140   -/***********************************************************************//**
141   - * @brief Save ASCII table
142   - *
143   - * NOT YET IMPLEMENTED
144   - ***************************************************************************/
145   -void GFitsAsciiTable::save(void)
146   -{
147   - cout << "GFitsAsciiTable::save entry" << endl;
148   - // Return
149   - return;
150   -}
151   -
152   -
153   -/***********************************************************************//**
154   - * @brief Close Table
155   - ***************************************************************************/
156   -void GFitsAsciiTable::close(void)
157   -{
158   - // Free members
159   - free_members();
160   -
161   - // Initialise members
162   - init_members();
163   -
164   - // Return
165   - return;
166   -}
167   -
168   -
169   -/***********************************************************************//**
170   - * @brief Return pointer to column with specified name
171   - *
172   - * @param colname Name of ASCII table column
173   - ***************************************************************************/
174   -GFitsTableCol* GFitsAsciiTable::column(const std::string& colname)
175   -{
176   - // Initialise pointer
177   - GFitsTableCol* ptr = NULL;
178   -
179   - // If there are columns then search for the specified name
180   - if (m_columns != NULL) {
181   - for (int i = 0; i < m_cols; ++i) {
182   - if (m_columns[i]->name() == colname) {
183   - ptr = m_columns[i];
184   - break;
185   - }
186   - }
187   - }
188   -
189   - // Return column pointer
190   - return ptr;
191   -}
192   -
193   -
194   -/***********************************************************************//**
195   - * @brief Return pointer to column with number
196   - *
197   - * @param colnum Number of ASCII column (starting from 0)
198   - ***************************************************************************/
199   -GFitsTableCol* GFitsAsciiTable::column(const int& colnum)
200   -{
201   - // Initialise pointer
202   - GFitsTableCol* ptr = NULL;
203   -
204   - // If there are columns then search for the specified name
205   - if (m_columns != NULL) {
206   - ptr = m_columns[colnum];
207   - }
208   -
209   - // Return column pointer
210   - return ptr;
  149 + return new GFitsAsciiTable(*this);
211 150 }
212 151  
213 152  
... ... @@ -223,9 +162,7 @@ GFitsTableCol* GFitsAsciiTable::column(const int&amp; colnum)
223 162 void GFitsAsciiTable::init_members(void)
224 163 {
225 164 // Initialise members
226   - m_rows = 0;
227   - m_cols = 0;
228   - m_columns = NULL;
  165 + m_type = 1;
229 166  
230 167 // Return
231 168 return;
... ... @@ -239,18 +176,7 @@ void GFitsAsciiTable::init_members(void)
239 176 ***************************************************************************/
240 177 void GFitsAsciiTable::copy_members(const GFitsAsciiTable& table)
241 178 {
242   - // Copy attributes
243   - m_rows = table.m_rows;
244   - m_cols = table.m_cols;
245   -
246   - // Copy column definition
247   - if (table.m_columns != NULL && m_cols > 0) {
248   - m_columns = new GFitsTableCol*[m_cols];
249   - for (int i = 0; i < m_cols; ++i) {
250   - if (table.m_columns[i] != NULL)
251   - m_columns[i] = table.m_columns[i]->clone();
252   - }
253   - }
  179 + // Copy members
254 180  
255 181 // Return
256 182 return;
... ... @@ -263,34 +189,8 @@ void GFitsAsciiTable::copy_members(const GFitsAsciiTable&amp; table)
263 189 void GFitsAsciiTable::free_members(void)
264 190 {
265 191 // Free memory
266   - for (int i = 0; i < m_cols; ++i) {
267   - if (m_columns[i] != NULL) delete m_columns[i];
268   - }
269   - if (m_columns != NULL) delete [] m_columns;
270 192  
271 193 // Mark memory as freed
272   - m_columns = NULL;
273   -
274   - // Return
275   - return;
276   -}
277   -
278   -
279   -/***********************************************************************//**
280   - * @brief Connect ASCII table to FITS file
281   - *
282   - * @param fptr FITS file pointer to which the binary table should be connected
283   - *
284   - * The connection of the ASCII table is done by connecting all columns.
285   - ***************************************************************************/
286   -void GFitsAsciiTable::connect(__fitsfile* fptr)
287   -{
288   - // First connect ASCII table
289   -
290   - // Then connect all columns
291   - for (int i = 0; i < m_cols; ++i) {
292   - if (m_columns[i] != NULL) m_columns[i]->connect(fptr);
293   - }
294 194  
295 195 // Return
296 196 return;
... ... @@ -303,25 +203,6 @@ void GFitsAsciiTable::connect(__fitsfile* fptr)
303 203 = =
304 204 ==========================================================================*/
305 205  
306   -/***********************************************************************//**
307   - * @brief Output operator
308   - *
309   - * @param os Stream into which the output is done
310   - * @param table Table to be dumped
311   - ***************************************************************************/
312   -ostream& operator<< (ostream& os, const GFitsAsciiTable& table)
313   -{
314   - // Put header in stream
315   - os << "=== GFitsAsciiTable ===" << endl;
316   - os << " Number of rows ............: " << table.m_rows << endl;
317   - os << " Number of columns .........: " << table.m_cols << endl;
318   - for (int i = 0; i < table.m_cols; ++i)
319   - os << " " << *(table.m_columns[i]);
320   -
321   - // Return output stream
322   - return os;
323   -}
324   -
325 206  
326 207 /*==========================================================================
327 208 = =
... ...
src/fits/GFitsBinTable.cpp
... ... @@ -15,20 +15,17 @@
15 15 /* __ Includes ___________________________________________________________ */
16 16 #include <iostream>
17 17 #include "GException.hpp"
18   -#include "GTools.hpp"
  18 +//#include "GTools.hpp"
19 19 #include "GFitsBinTable.hpp"
20   -#include "GFitsTableStrCol.hpp"
21   -#include "GFitsTableShtCol.hpp"
22   -#include "GFitsTableLngCol.hpp"
23   -#include "GFitsTableFltCol.hpp"
24   -#include "GFitsTableDblCol.hpp"
  20 +//#include "GFitsTableStrCol.hpp"
  21 +//#include "GFitsTableShtCol.hpp"
  22 +//#include "GFitsTableLngCol.hpp"
  23 +//#include "GFitsTableFltCol.hpp"
  24 +//#include "GFitsTableDblCol.hpp"
25 25  
26 26 /* __ Namespaces _________________________________________________________ */
27 27  
28 28 /* __ Method name definitions ____________________________________________ */
29   -#define G_OPEN "GFitsBinTable::open(fitsfile*)"
30   -#define G_COLUMN1 "GFitsBinTable::column(const std::string&)"
31   -#define G_COLUMN2 "GFitsBinTable::column(const int&)"
32 29  
33 30 /* __ Macros _____________________________________________________________ */
34 31  
... ... @@ -46,7 +43,7 @@
46 43 /***********************************************************************//**
47 44 * @brief Constructor
48 45 ***************************************************************************/
49   -GFitsBinTable::GFitsBinTable() : GFitsData()
  46 +GFitsBinTable::GFitsBinTable() : GFitsTable()
50 47 {
51 48 // Initialise class members for clean destruction
52 49 init_members();
... ... @@ -62,27 +59,11 @@ GFitsBinTable::GFitsBinTable() : GFitsData()
62 59 * @param[in] nrows Number of rows in table
63 60 * @param[in] ncols Number of columns in table
64 61 ***************************************************************************/
65   -GFitsBinTable::GFitsBinTable(int nrows, int ncols) : GFitsData()
  62 +GFitsBinTable::GFitsBinTable(int nrows, int ncols) : GFitsTable(nrows, ncols)
66 63 {
67 64 // Initialise class members for clean destruction
68 65 init_members();
69 66  
70   - // Store table dimension
71   - m_rows = nrows;
72   - m_cols = ncols;
73   -
74   - // If there are columns then allocate memory for column pointers
75   - if (m_cols > 0) {
76   -
77   - // Allocate pointer memory
78   - m_columns = new GFitsTableCol*[m_cols];
79   -
80   - // Initialise pointers
81   - for (int i = 0; i < m_cols; ++i)
82   - m_columns[i] = NULL;
83   -
84   - } // endfor: looped over all columns
85   -
86 67 // Return
87 68 return;
88 69 }
... ... @@ -94,7 +75,7 @@ GFitsBinTable::GFitsBinTable(int nrows, int ncols) : GFitsData()
94 75 * @param[in] table Table which will be used to construct GFitsBinTable
95 76 * instance
96 77 ***************************************************************************/
97   -GFitsBinTable::GFitsBinTable(const GFitsBinTable& table) : GFitsData(table)
  78 +GFitsBinTable::GFitsBinTable(const GFitsBinTable& table) : GFitsTable(table)
98 79 {
99 80 // Initialise class members for clean destruction
100 81 init_members();
... ... @@ -137,7 +118,7 @@ GFitsBinTable&amp; GFitsBinTable::operator= (const GFitsBinTable&amp; table)
137 118 if (this != &table) {
138 119  
139 120 // Copy base class members
140   - this->GFitsData::operator=(table);
  121 + this->GFitsTable::operator=(table);
141 122  
142 123 // Free members
143 124 free_members();
... ... @@ -162,197 +143,11 @@ GFitsBinTable&amp; GFitsBinTable::operator= (const GFitsBinTable&amp; table)
162 143 ==========================================================================*/
163 144  
164 145 /***********************************************************************//**
165   - * @brief Open Table
166   - *
167   - * @param[in] fptr FITS file pointer
168   - *
169   - * Builds a description of the binary table in memory. Columns are not loaded
170   - * but column descriptors are allocated. The column data will only be loaded
171   - * once it needs to be accessed.
172   - ***************************************************************************/
173   -void GFitsBinTable::open(__fitsfile* fptr)
174   -{
175   - // Move to HDU
176   - int status = 0;
177   - status = __ffmahd(fptr, (fptr->HDUposition)+1, NULL, &status);
178   - if (status != 0)
179   - throw GException::fits_error(G_OPEN, status);
180   -
181   - // Determine number of rows in table
182   - long nrows = 0;
183   - status = __ffgnrw(fptr, &nrows, &status);
184   - if (status != 0)
185   - throw GException::fits_error(G_OPEN, status);
186   - else
187   - m_rows = (int)nrows;
188   -
189   - // Determine number of columns in table
190   - status = __ffgncl(fptr, &m_cols, &status);
191   - if (status != 0)
192   - throw GException::fits_error(G_OPEN, status);
193   -
194   - // Allocate memory for column pointers
195   - if (m_columns != NULL) delete [] m_columns;
196   - m_columns = new GFitsTableCol*[m_cols];
197   -
198   - // Get table column information
199   - int typecode = 0;
200   - long repeat = 0;
201   - long width = 0;
202   - for (int i = 0; i < m_cols; ++i) {
203   -
204   - // Get column name
205   - char keyname[10];
206   - char value[80];
207   - sprintf(keyname, "TTYPE%d", i+1);
208   - status = __ffgkey(fptr, keyname, value, NULL, &status);
209   - if (status != 0)
210   - throw GException::fits_error(G_OPEN, status);
211   - value[strlen(value)-1] = '\0';
212   -
213   - // Get column definition
214   - status = __ffgtcl(fptr, i+1, &typecode, &repeat, &width, &status);
215   - if (status != 0)
216   - throw GException::fits_error(G_OPEN, status);
217   -
218   - // Allocate column
219   - switch (typecode) {
220   - case __TSTRING:
221   - m_columns[i] = new GFitsTableStrCol();
222   - break;
223   - case __TSHORT:
224   - m_columns[i] = new GFitsTableShtCol();
225   - break;
226   - case __TLONG:
227   - m_columns[i] = new GFitsTableLngCol();
228   - break;
229   - case __TFLOAT:
230   - m_columns[i] = new GFitsTableFltCol();
231   - break;
232   - case __TDOUBLE:
233   - m_columns[i] = new GFitsTableDblCol();
234   - break;
235   - default:
236   - throw GException::fits_unknown_coltype(G_OPEN, typecode);
237   - break;
238   - }
239   -
240   - // Store column definition
241   - m_columns[i]->set_name(strip_whitespace(&(value[1])));
242   - m_columns[i]->set_colnum(i+1);
243   - m_columns[i]->set_type(typecode);
244   - m_columns[i]->set_repeat(repeat);
245   - m_columns[i]->set_width(width);
246   - m_columns[i]->set_length(m_rows);
247   - m_columns[i]->set_fitsfile(fptr);
248   -
249   - } // endfor: looped over all columns
250   -
251   - // Return
252   - return;
253   -}
254   -
255   -
256   -/***********************************************************************//**
257   - * @brief Save binary table
258   - *
259   - * NOT YET IMPLEMENTED
260   - ***************************************************************************/
261   -void GFitsBinTable::save(void)
262   -{
263   - cout << "GFitsBinTable::save entry" << endl;
264   -
265   - // Return
266   - return;
267   -}
268   -
269   -
270   -/***********************************************************************//**
271   - * @brief Close binary table
272   - ***************************************************************************/
273   -void GFitsBinTable::close(void)
274   -{
275   - // Free members
276   - free_members();
277   -
278   - // Initialise members
279   - init_members();
280   -
281   - // Return
282   - return;
283   -}
284   -
285   -
286   -/***********************************************************************//**
287   - * @brief Return pointer to column with specified name
288   - *
289   - * @param[in] colname Name of column which should be accessed
290   - *
291   - * @exception GException::fits_no_data
292   - * There are no column data in the table or there is not data
293   - * for this column
294   - * @exception GException::fits_column_not_found
295   - * Requested column has not been found in table.
296   - ***************************************************************************/
297   -GFitsTableCol* GFitsBinTable::column(const std::string& colname)
298   -{
299   - // If there is no data then throw an exception
300   - if (m_columns == NULL)
301   - throw GException::fits_no_data(G_COLUMN1, "No column data in table");
302   -
303   - // Initialise pointer
304   - GFitsTableCol* ptr = NULL;
305   -
306   - // If there are columns then search for the specified name
307   - if (m_columns != NULL) {
308   - for (int i = 0; i < m_cols; ++i) {
309   - if (m_columns[i]->name() == colname) {
310   - ptr = m_columns[i];
311   - if (ptr == NULL)
312   - throw GException::fits_no_data(G_COLUMN1,
313   - "No data for this column");
314   - break;
315   - }
316   - }
317   - }
318   -
319   - // If column has not been found throw an exception
320   - if (ptr == NULL)
321   - throw GException::fits_column_not_found(G_COLUMN1, colname);
322   -
323   - // Return column pointer
324   - return ptr;
325   -}
326   -
327   -
328   -/***********************************************************************//**
329   - * @brief Return pointer to column with number
330   - *
331   - * @param[in] colnum Number of requested column (starting from 0)
332   - *
333   - * @exception GException::fits_no_data
334   - * There are no column data in the table or there is not data
335   - * for this column
336   - * @exception GException::out_of_range
337   - * Requested column has not been found in table.
  146 + * @brief Clone binary table
338 147 ***************************************************************************/
339   -GFitsTableCol* GFitsBinTable::column(const int& colnum)
  148 +GFitsBinTable* GFitsBinTable::clone(void) const
340 149 {
341   - // If there is no data then throw an exception
342   - if (m_columns == NULL)
343   - throw GException::fits_no_data(G_COLUMN2, "No column data in table");
344   -
345   - // If column number is out of range then throw an exception
346   - if (colnum < 0 || colnum >= m_cols)
347   - throw GException::out_of_range(G_COLUMN2, colnum, 0, m_cols-1);
348   -
349   - // Get column pointer
350   - GFitsTableCol* ptr = ptr = m_columns[colnum];
351   - if (ptr == NULL)
352   - throw GException::fits_no_data(G_COLUMN2, "No data for this column");
353   -
354   - // Return column pointer
355   - return ptr;
  150 + return new GFitsBinTable(*this);
356 151 }
357 152  
358 153  
... ... @@ -368,9 +163,7 @@ GFitsTableCol* GFitsBinTable::column(const int&amp; colnum)
368 163 void GFitsBinTable::init_members(void)
369 164 {
370 165 // Initialise members
371   - m_rows = 0;
372   - m_cols = 0;
373   - m_columns = NULL;
  166 + m_type = 2;
374 167  
375 168 // Return
376 169 return;
... ... @@ -384,18 +177,7 @@ void GFitsBinTable::init_members(void)
384 177 ***************************************************************************/
385 178 void GFitsBinTable::copy_members(const GFitsBinTable& table)
386 179 {
387   - // Copy attributes
388   - m_rows = table.m_rows;
389   - m_cols = table.m_cols;
390   -
391   - // Copy column definition
392   - if (table.m_columns != NULL && m_cols > 0) {
393   - m_columns = new GFitsTableCol*[m_cols];
394   - for (int i = 0; i < m_cols; ++i) {
395   - if (table.m_columns[i] != NULL)
396   - m_columns[i] = table.m_columns[i]->clone();
397   - }
398   - }
  180 + // Copy members
399 181  
400 182 // Return
401 183 return;
... ... @@ -408,35 +190,8 @@ void GFitsBinTable::copy_members(const GFitsBinTable&amp; table)
408 190 void GFitsBinTable::free_members(void)
409 191 {
410 192 // Free memory
411   - for (int i = 0; i < m_cols; ++i) {
412   - if (m_columns[i] != NULL) delete m_columns[i];
413   - }
414   - if (m_columns != NULL) delete [] m_columns;
415 193  
416 194 // Mark memory as freed
417   - m_columns = NULL;
418   -
419   - // Return
420   - return;
421   -}
422   -
423   -
424   -/***********************************************************************//**
425   - * @brief Connect binary table to FITS file
426   - *
427   - * @param[in] fptr FITS file pointer to which the binary table should be
428   - * connected
429   - *
430   - * The connection of the binary table is done by connecting all columns.
431   - ***************************************************************************/
432   -void GFitsBinTable::connect(__fitsfile* fptr)
433   -{
434   - // First connect binary table
435   -
436   - // Then connect all columns
437   - for (int i = 0; i < m_cols; ++i) {
438   - if (m_columns[i] != NULL) m_columns[i]->connect(fptr);
439   - }
440 195  
441 196 // Return
442 197 return;
... ... @@ -449,25 +204,6 @@ void GFitsBinTable::connect(__fitsfile* fptr)
449 204 = =
450 205 ==========================================================================*/
451 206  
452   -/***********************************************************************//**
453   - * @brief Output operator
454   - *
455   - * @param[in] os Output stream
456   - * @param[in] table Table to put in output stream
457   - ***************************************************************************/
458   -ostream& operator<< (ostream& os, const GFitsBinTable& table)
459   -{
460   - // Put header in stream
461   - os << "=== GFitsBinTable ===" << endl;
462   - os << " Number of rows ............: " << table.m_rows << endl;
463   - os << " Number of columns .........: " << table.m_cols << endl;
464   - for (int i = 0; i < table.m_cols; ++i)
465   - os << " " << *(table.m_columns[i]);
466   -
467   - // Return output stream
468   - return os;
469   -}
470   -
471 207  
472 208 /*==========================================================================
473 209 = =
... ...
src/fits/GFitsData.cpp
... ... @@ -103,6 +103,20 @@ GFitsData&amp; GFitsData::operator= (const GFitsData&amp; data)
103 103 = =
104 104 ==========================================================================*/
105 105  
  106 +/***********************************************************************//**
  107 + * @brief Connect data to FITS file
  108 + *
  109 + * @param[in] fptr FITS file pointer to which the data should be connected
  110 + ***************************************************************************/
  111 +void GFitsData::connect(__fitsfile* fptr)
  112 +{
  113 + // Connect data
  114 + m_fitsfile = *fptr;
  115 +
  116 + // Return
  117 + return;
  118 +}
  119 +
106 120  
107 121 /*==========================================================================
108 122 = =
... ...
src/fits/GFitsHDU.cpp
... ... @@ -27,6 +27,11 @@
27 27 #define G_COLUMN "GFitsHDU::column(const std::string&)"
28 28 #define G_NEW_IMAGE "GFitsHDU::new_image()"
29 29  
  30 +/* __ Definitions ________________________________________________________ */
  31 +#define HT_IMAGE 0
  32 +#define HT_ASCII_TABLE 1
  33 +#define HT_BIN_TABLE 2
  34 +
30 35 /* __ Macros _____________________________________________________________ */
31 36  
32 37 /* __ Coding definitions _________________________________________________ */
... ... @@ -67,8 +72,9 @@ GFitsHDU::GFitsHDU(const GFitsImage&amp; image)
67 72 // Initialise class members for clean destruction
68 73 init_members();
69 74  
70   - // Copy image into HDU data
  75 + // Copy image into HDU data and set data type
71 76 m_data = image.clone();
  77 + m_type = HT_IMAGE;
72 78  
73 79 // Allocate new header
74 80 m_header = new GFitsHeader();
... ... @@ -99,9 +105,91 @@ GFitsHDU::GFitsHDU(const GFitsImage&amp; image)
99 105  
100 106  
101 107 /***********************************************************************//**
  108 + * @brief ASCII Table HDU Constructor
  109 + *
  110 + * @param[in] table Table from which the HDU should be constructed
  111 + ***************************************************************************/
  112 +GFitsHDU::GFitsHDU(const GFitsAsciiTable& table)
  113 +{
  114 + // Initialise class members for clean destruction
  115 + init_members();
  116 +
  117 + // Copy table into HDU data and set data type
  118 + m_data = table.clone();
  119 + m_type = HT_ASCII_TABLE;
  120 +
  121 + // Allocate new header
  122 + m_header = new GFitsHeader();
  123 +
  124 + // Set image header keywords
  125 + /*
  126 + m_header->update(GFitsHeaderCard("XTENSION", "'BINTABLE'",
  127 + "binary table extension"));
  128 + m_header->update(GFitsHeaderCard("BITPIX", 8,
  129 + "8-bit bytes"));
  130 + m_header->update(GFitsHeaderCard("NAXIS", 2,
  131 + "2-dimensional binary table"));
  132 + m_header->update(GFitsHeaderCard("NAXIS1", 0,
  133 + "width of table in bytes"));
  134 + m_header->update(GFitsHeaderCard("NAXIS2", table.rows(),
  135 + "number of rows in table"));
  136 + m_header->update(GFitsHeaderCard("PCOUNT", 0,
  137 + "size of special data area"));
  138 + m_header->update(GFitsHeaderCard("GCOUNT", 1,
  139 + "one data group (required keyword)"));
  140 + m_header->update(GFitsHeaderCard("TFIELDS", 1,
  141 + "number of fields in each row"));
  142 +*/
  143 + // Return
  144 + return;
  145 +}
  146 +
  147 +
  148 +/***********************************************************************//**
  149 + * @brief Binary Table HDU Constructor
  150 + *
  151 + * @param[in] table Table from which the HDU should be constructed
  152 + ***************************************************************************/
  153 +GFitsHDU::GFitsHDU(const GFitsBinTable& table)
  154 +{
  155 + // Initialise class members for clean destruction
  156 + init_members();
  157 +
  158 + // Copy table into HDU data and set data type
  159 + m_data = table.clone();
  160 + m_type = HT_BIN_TABLE;
  161 +
  162 + // Allocate new header
  163 + m_header = new GFitsHeader();
  164 +
  165 + // Set image header keywords
  166 + /*
  167 + m_header->update(GFitsHeaderCard("XTENSION", "'BINTABLE'",
  168 + "binary table extension"));
  169 + m_header->update(GFitsHeaderCard("BITPIX", 8,
  170 + "8-bit bytes"));
  171 + m_header->update(GFitsHeaderCard("NAXIS", 2,
  172 + "2-dimensional binary table"));
  173 + m_header->update(GFitsHeaderCard("NAXIS1", 0,
  174 + "width of table in bytes"));
  175 + m_header->update(GFitsHeaderCard("NAXIS2", table.rows(),
  176 + "number of rows in table"));
  177 + m_header->update(GFitsHeaderCard("PCOUNT", 0,
  178 + "size of special data area"));
  179 + m_header->update(GFitsHeaderCard("GCOUNT", 1,
  180 + "one data group (required keyword)"));
  181 + m_header->update(GFitsHeaderCard("TFIELDS", 1,
  182 + "number of fields in each row"));
  183 +*/
  184 + // Return
  185 + return;
  186 +}
  187 +
  188 +
  189 +/***********************************************************************//**
102 190 * @brief Copy constructor
103 191 *
104   - * @param hdu HDU from which the instance should be constructed
  192 + * @param[in] hdu HDU from which the instance should be constructed
105 193 ***************************************************************************/
106 194 GFitsHDU::GFitsHDU(const GFitsHDU& hdu)
107 195 {
... ... @@ -138,7 +226,7 @@ GFitsHDU::~GFitsHDU()
138 226 /***********************************************************************//**
139 227 * @brief Assignment operator
140 228 *
141   - * @param hdu HDU which should be assigned
  229 + * @param[in] hdu HDU which should be assigned
142 230 ***************************************************************************/
143 231 GFitsHDU& GFitsHDU::operator= (const GFitsHDU& hdu)
144 232 {
... ... @@ -170,8 +258,8 @@ GFitsHDU&amp; GFitsHDU::operator= (const GFitsHDU&amp; hdu)
170 258 /***********************************************************************//**
171 259 * @brief Open HDU
172 260 *
173   - * @param fptr FITS file pointer
174   - * @param hdunum Number of HDU (starting from 1)
  261 + * @param[in] fptr FITS file pointer
  262 + * @param[in] hdunum Number of HDU (starting from 1)
175 263 *
176 264 * Opens an (existing) HDU in the FITS file. This method does NOT create any
177 265 * HDU if it does not exist. Opening consists of fetching all header cards
... ... @@ -204,13 +292,13 @@ void GFitsHDU::open(__fitsfile* fptr, int hdunum)
204 292 // Open HDU data area
205 293 if (m_data != NULL) delete m_data;
206 294 switch (m_type) {
207   - case 0: // Image HDU
  295 + case HT_IMAGE: // Image HDU
208 296 m_data = new_image();
209 297 break;
210   - case 1: // ASCII Table HDU
  298 + case HT_ASCII_TABLE: // ASCII Table HDU
211 299 m_data = new GFitsAsciiTable();
212 300 break;
213   - case 2: // Binary Table HDU
  301 + case HT_BIN_TABLE: // Binary Table HDU
214 302 m_data = new GFitsBinTable();
215 303 break;
216 304 default:
... ... @@ -251,30 +339,31 @@ void GFitsHDU::save(void)
251 339 {
252 340 //cout << "GFitsHDU::save " << m_fitsfile.Fptr << " " << m_hdunum << endl;
253 341 // Move to HDU
254   - int status = 0;
255   - status = __ffmahd(&m_fitsfile, m_hdunum, NULL, &status);
  342 +// int status = 0;
  343 +// status = __ffmahd(&m_fitsfile, m_hdunum, NULL, &status);
256 344  
257 345 // If HDU does not yet exist in file then create it now. This works even
258 346 // in the case that the actual HDU has no associated header and/or data
259 347 // (these will be created automatically). However, to make this work we have
260 348 // to set the fitsfile HDU position to the position we want to go. In that
261 349 // was the save members will know that they have to create the HDU ...
  350 +/*
262 351 if (status == 107) {
263 352 m_fitsfile.HDUposition = m_hdunum-1;
264   - status = 0;
  353 + status = 0;
265 354 if (m_data != NULL) {
266 355 switch (m_type) {
267   - case 0: // Image HDU
  356 + case HT_IMAGE: // Image HDU
268 357 m_data->connect(&m_fitsfile);
269   - m_data->save();
  358 + //m_data->save();
270 359 break;
271   - case 1: // ASCII Table HDU
  360 + case HT_ASCII_TABLE: // ASCII Table HDU
272 361 m_data->connect(&m_fitsfile);
273   - m_data->save();
  362 + //m_data->save();
274 363 break;
275   - case 2: // Binary Table HDU
  364 + case HT_BIN_TABLE: // Binary Table HDU
276 365 m_data->connect(&m_fitsfile);
277   - m_data->save();
  366 + //m_data->save();
278 367 break;
279 368 default:
280 369 throw GException::fits_unknown_HDU_type(G_SAVE, m_type);
... ... @@ -282,9 +371,11 @@ void GFitsHDU::save(void)
282 371 }
283 372 }
284 373 }
  374 +*/
285 375  
286   - // If they exist then save data and header
  376 + // Save data and header if they exist
287 377 if (m_data != NULL) {
  378 + m_data->connect(&m_fitsfile);
288 379 m_data->save();
289 380 if (m_header != NULL)
290 381 m_header->save(&m_fitsfile);
... ... @@ -297,7 +388,8 @@ void GFitsHDU::save(void)
297 388 // Special case: The first HDU does not exist. A FITS file needs at least
298 389 // one primary HDU. Thus an empty image is created.
299 390 if (m_fitsfile.HDUposition == 0) {
300   - status = __ffcrim(&m_fitsfile, 8, 0, NULL, &status);
  391 + int status = 0;
  392 + status = __ffcrim(&m_fitsfile, 8, 0, NULL, &status);
301 393 if (status != 0)
302 394 throw GException::fits_error(G_SAVE, status);
303 395 if (m_header != NULL)
... ... @@ -314,7 +406,7 @@ void GFitsHDU::save(void)
314 406 /***********************************************************************//**
315 407 * @brief Set HDU extension name (EXTNAME keyword)
316 408 *
317   - * @param extname Name of HDU
  409 + * @param[in] extname Name of HDU
318 410 *
319 411 * This methos sets the extension name of the HDU. The extension name will
320 412 * be saved in the 'EXTNAME' header keyword. The header attached to the
... ... @@ -340,7 +432,7 @@ void GFitsHDU::extname(const std::string&amp; extname)
340 432 /***********************************************************************//**
341 433 * @brief Return pointer to column of table
342 434 *
343   - * @param colname Name of FITS table column to be returned
  435 + * @param[in] colname Name of FITS table column to be returned
344 436 *
345 437 * If this method is called for an image a 'fits_HDU_not_a_table' exception
346 438 * will be thrown.
... ... @@ -352,13 +444,13 @@ GFitsTableCol* GFitsHDU::column(const std::string&amp; colname) const
352 444  
353 445 // Get pointer to table column
354 446 switch (m_type) {
355   - case 0: // Image HDU
  447 + case HT_IMAGE: // Image HDU
356 448 throw GException::fits_HDU_not_a_table(G_COLUMN, m_type);
357 449 break;
358   - case 1: // ASCII Table HDU
  450 + case HT_ASCII_TABLE: // ASCII Table HDU
359 451 ptr = ((GFitsAsciiTable*)this->data())->column(colname);
360 452 break;
361   - case 2: // Binary Table HDU
  453 + case HT_BIN_TABLE: // Binary Table HDU
362 454 ptr = ((GFitsBinTable*)this->data())->column(colname);
363 455 break;
364 456 default:
... ... @@ -427,7 +519,7 @@ void GFitsHDU::init_members(void)
427 519 /***********************************************************************//**
428 520 * @brief Copy class members
429 521 *
430   - * @param hdu HDU to be copied
  522 + * @param[in] hdu HDU to be copied
431 523 *
432 524 * Assumes that all memory has been freed correctly before calling.
433 525 ***************************************************************************/
... ... @@ -467,7 +559,7 @@ void GFitsHDU::free_members(void)
467 559 /***********************************************************************//**
468 560 * @brief Connect HDU to FITS file
469 561 *
470   - * @param fptr FITS file pointer to which the HDU should be connected
  562 + * @param[in] fptr FITS file pointer to which the HDU should be connected
471 563 *
472 564 * Connects the HDU and the associated data area to the specified FITS file.
473 565 * Note that the header area does not require a FITS pointer, hence no
... ... @@ -553,8 +645,8 @@ GFitsImage* GFitsHDU::new_image(void)
553 645 /***********************************************************************//**
554 646 * @brief Output operator
555 647 *
556   - * @param os Output stream into which the HDU will be dumped
557   - * @param hdu HDU to be dumped
  648 + * @param[in] os Output stream into which the HDU will be dumped
  649 + * @param[in] hdu HDU to be dumped
558 650 ***************************************************************************/
559 651 ostream& operator<< (ostream& os, const GFitsHDU& hdu)
560 652 {
... ... @@ -585,13 +677,13 @@ ostream&amp; operator&lt;&lt; (ostream&amp; os, const GFitsHDU&amp; hdu)
585 677 // Put FITS data in stream
586 678 if (hdu.m_data != NULL) {
587 679 switch (hdu.m_type) {
588   - case 0: // Image HDU
  680 + case HT_IMAGE: // Image HDU
589 681 os << *(GFitsImage*)hdu.m_data;
590 682 break;
591   - case 1: // ASCII Table HDU
  683 + case HT_ASCII_TABLE: // ASCII Table HDU
592 684 os << *(GFitsAsciiTable*)hdu.m_data;
593 685 break;
594   - case 2: // Binary Table HDU
  686 + case HT_BIN_TABLE: // Binary Table HDU
595 687 os << *(GFitsBinTable*)hdu.m_data;
596 688 break;
597 689 default:
... ...
src/fits/GFitsHeaderCard.cpp
... ... @@ -243,7 +243,7 @@ void GFitsHeaderCard::value(const std::string&amp; value)
243 243 if (m_value[m_value.length()-1] != '\x27')
244 244 m_value += "'";
245 245 }
246   -
  246 +
247 247 // Return
248 248 return;
249 249 }
... ... @@ -598,10 +598,12 @@ void GFitsHeaderCard::write(__fitsfile* fptr)
598 598 (char*)m_comment.c_str(), &status);
599 599 break;
600 600 case CT_COMMENT:
601   - status = __ffpcom(fptr, (char*)m_comment.c_str(), &status);
  601 + if (m_comment_write)
  602 + status = __ffpcom(fptr, (char*)m_comment.c_str(), &status);
602 603 break;
603 604 case CT_HISTORY:
604   - status = __ffphis(fptr, (char*)m_comment.c_str(), &status);
  605 + if (m_comment_write)
  606 + status = __ffphis(fptr, (char*)m_comment.c_str(), &status);
605 607 break;
606 608 default:
607 609 break;
... ... @@ -632,6 +634,7 @@ void GFitsHeaderCard::init_members(void)
632 634 m_value_decimals = 10;
633 635 m_unit.clear();
634 636 m_comment.clear();
  637 + m_comment_write = 0;
635 638  
636 639 // Return
637 640 return;
... ... @@ -652,6 +655,7 @@ void GFitsHeaderCard::copy_members(const GFitsHeaderCard&amp; card)
652 655 m_value_decimals = card.m_value_decimals;
653 656 m_unit = card.m_unit;
654 657 m_comment = card.m_comment;
  658 + m_comment_write = card.m_comment_write;
655 659  
656 660 // Return
657 661 return;
... ...
src/fits/GFitsImage.cpp
... ... @@ -273,21 +273,6 @@ void GFitsImage::free_members(void)
273 273  
274 274  
275 275 /***********************************************************************//**
276   - * @brief Connect image to FITS file
277   - *
278   - * @param[in] fptr FITS file pointer to which the image should be connected
279   - ***************************************************************************/
280   -void GFitsImage::connect(__fitsfile* fptr)
281   -{
282   - // Connect Image
283   - m_fitsfile = *fptr;
284   -
285   - // Return
286   - return;
287   -}
288   -
289   -
290   -/***********************************************************************//**
291 276 * @brief Open Image
292 277 *
293 278 * @param[in] fptr FITS file pointer
... ...
src/fits/GFitsTable.cpp 0 โ†’ 100644
  1 +/***************************************************************************
  2 + * GFitsTable.cpp - FITS table 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 <iostream>
  17 +#include "GException.hpp"
  18 +#include "GTools.hpp"
  19 +#include "GFitsTable.hpp"
  20 +#include "GFitsTableStrCol.hpp"
  21 +#include "GFitsTableShtCol.hpp"
  22 +#include "GFitsTableLngCol.hpp"
  23 +#include "GFitsTableFltCol.hpp"
  24 +#include "GFitsTableDblCol.hpp"
  25 +
  26 +/* __ Namespaces _________________________________________________________ */
  27 +
  28 +/* __ Method name definitions ____________________________________________ */
  29 +#define G_OPEN "GFitsTable::open(fitsfile*)"
  30 +#define G_SAVE "GFitsTable::save()"
  31 +#define G_COLUMN1 "GFitsTable::column(const std::string&)"
  32 +#define G_COLUMN2 "GFitsTable::column(const int&)"
  33 +
  34 +/* __ Macros _____________________________________________________________ */
  35 +
  36 +/* __ Coding definitions _________________________________________________ */
  37 +
  38 +/* __ Debug definitions __________________________________________________ */
  39 +
  40 +
  41 +/*==========================================================================
  42 + = =
  43 + = GFitsTable constructors/destructors =
  44 + = =
  45 + ==========================================================================*/
  46 +
  47 +/***********************************************************************//**
  48 + * @brief Constructor
  49 + ***************************************************************************/
  50 +GFitsTable::GFitsTable() : GFitsData()
  51 +{
  52 + // Initialise class members for clean destruction
  53 + init_members();
  54 +
  55 + // Return
  56 + return;
  57 +}
  58 +
  59 +
  60 +/***********************************************************************//**
  61 + * @brief Constructor
  62 + *
  63 + * @param[in] nrows Number of rows in table
  64 + * @param[in] ncols Number of columns in table
  65 + ***************************************************************************/
  66 +GFitsTable::GFitsTable(int nrows, int ncols) : GFitsData()
  67 +{
  68 + // Initialise class members for clean destruction
  69 + init_members();
  70 +
  71 + // Store table dimension
  72 + m_rows = nrows;
  73 + m_cols = ncols;
  74 +
  75 + // If there are columns then allocate memory for column pointers
  76 + if (m_cols > 0) {
  77 +
  78 + // Allocate pointer memory
  79 + m_columns = new GFitsTableCol*[m_cols];
  80 +
  81 + // Initialise pointers
  82 + for (int i = 0; i < m_cols; ++i)
  83 + m_columns[i] = NULL;
  84 +
  85 + } // endfor: looped over all columns
  86 +
  87 + // Return
  88 + return;
  89 +}
  90 +
  91 +
  92 +/***********************************************************************//**
  93 + * @brief Copy constructor
  94 + *
  95 + * @param[in] table Table which will be used to construct GFitsTable instance
  96 + ***************************************************************************/
  97 +GFitsTable::GFitsTable(const GFitsTable& table) : GFitsData(table)
  98 +{
  99 + // Initialise class members for clean destruction
  100 + init_members();
  101 +
  102 + // Copy members
  103 + copy_members(table);
  104 +
  105 + // Return
  106 + return;
  107 +}
  108 +
  109 +
  110 +/***********************************************************************//**
  111 + * @brief Destructor
  112 + ***************************************************************************/
  113 +GFitsTable::~GFitsTable()
  114 +{
  115 + // Free members
  116 + free_members();
  117 +
  118 + // Return
  119 + return;
  120 +}
  121 +
  122 +
  123 +/*==========================================================================
  124 + = =
  125 + = GFitsTable operators =
  126 + = =
  127 + ==========================================================================*/
  128 +
  129 +/***********************************************************************//**
  130 + * @brief Assignment operator
  131 + *
  132 + * @param[in] table Table which will be assigned
  133 + ***************************************************************************/
  134 +GFitsTable& GFitsTable::operator= (const GFitsTable& table)
  135 +{
  136 + // Execute only if object is not identical
  137 + if (this != &table) {
  138 +
  139 + // Copy base class members
  140 + this->GFitsData::operator=(table);
  141 +
  142 + // Free members
  143 + free_members();
  144 +
  145 + // Initialise private members for clean destruction
  146 + init_members();
  147 +
  148 + // Copy members
  149 + copy_members(table);
  150 +
  151 + } // endif: object was not identical
  152 +
  153 + // Return this object
  154 + return *this;
  155 +}
  156 +
  157 +
  158 +/*==========================================================================
  159 + = =
  160 + = GFitsTable public methods =
  161 + = =
  162 + ==========================================================================*/
  163 +
  164 +/***********************************************************************//**
  165 + * @brief Open Table
  166 + *
  167 + * @param[in] fptr FITS file pointer
  168 + *
  169 + * Builds a description of the binary table in memory. Columns are not loaded
  170 + * but column descriptors are allocated. The column data will only be loaded
  171 + * once it needs to be accessed.
  172 + ***************************************************************************/
  173 +void GFitsTable::open(__fitsfile* fptr)
  174 +{
  175 + // Move to HDU
  176 + int status = 0;
  177 + status = __ffmahd(fptr, (fptr->HDUposition)+1, NULL, &status);
  178 + if (status != 0)
  179 + throw GException::fits_error(G_OPEN, status);
  180 +
  181 + // Save FITS file pointer
  182 + m_fitsfile = *fptr;
  183 +
  184 + // Determine number of rows in table
  185 + long nrows = 0;
  186 + status = __ffgnrw(&m_fitsfile, &nrows, &status);
  187 + if (status != 0)
  188 + throw GException::fits_error(G_OPEN, status);
  189 + else
  190 + m_rows = (int)nrows;
  191 +
  192 + // Determine number of columns in table
  193 + status = __ffgncl(&m_fitsfile, &m_cols, &status);
  194 + if (status != 0)
  195 + throw GException::fits_error(G_OPEN, status);
  196 +
  197 + // Allocate memory for column pointers
  198 + if (m_columns != NULL) delete [] m_columns;
  199 + m_columns = new GFitsTableCol*[m_cols];
  200 +
  201 + // Get table column information
  202 + int typecode = 0;
  203 + long repeat = 0;
  204 + long width = 0;
  205 + for (int i = 0; i < m_cols; ++i) {
  206 +
  207 + // Get column name
  208 + char keyname[10];
  209 + char value[80];
  210 + sprintf(keyname, "TTYPE%d", i+1);
  211 + status = __ffgkey(&m_fitsfile, keyname, value, NULL, &status);
  212 + if (status != 0)
  213 + throw GException::fits_error(G_OPEN, status);
  214 + value[strlen(value)-1] = '\0';
  215 +
  216 + // Get column definition
  217 + status = __ffgtcl(&m_fitsfile, i+1, &typecode, &repeat, &width, &status);
  218 + if (status != 0)
  219 + throw GException::fits_error(G_OPEN, status);
  220 +
  221 + // Allocate column
  222 + switch (typecode) {
  223 + case __TSTRING:
  224 + m_columns[i] = new GFitsTableStrCol();
  225 + break;
  226 + case __TSHORT:
  227 + m_columns[i] = new GFitsTableShtCol();
  228 + break;
  229 + case __TLONG:
  230 + m_columns[i] = new GFitsTableLngCol();
  231 + break;
  232 + case __TFLOAT:
  233 + m_columns[i] = new GFitsTableFltCol();
  234 + break;
  235 + case __TDOUBLE:
  236 + m_columns[i] = new GFitsTableDblCol();
  237 + break;
  238 + default:
  239 + throw GException::fits_unknown_coltype(G_OPEN, typecode);
  240 + break;
  241 + }
  242 +
  243 + // Store column definition
  244 + m_columns[i]->set_name(strip_whitespace(&(value[1])));
  245 + m_columns[i]->set_colnum(i+1);
  246 + m_columns[i]->set_type(typecode);
  247 + m_columns[i]->set_repeat(repeat);
  248 + m_columns[i]->set_width(width);
  249 + m_columns[i]->set_length(m_rows);
  250 + m_columns[i]->set_fitsfile(fptr);
  251 +
  252 + } // endfor: looped over all columns
  253 +
  254 + // Return
  255 + return;
  256 +}
  257 +
  258 +
  259 +/***********************************************************************//**
  260 + * @brief Save FITS table
  261 + ***************************************************************************/
  262 +void GFitsTable::save(void)
  263 +{
  264 +//cout << "GFitsTable::save entry" << endl;
  265 + // Move to HDU
  266 + int status = 0;
  267 + status = __ffmahd(&m_fitsfile, (m_fitsfile.HDUposition)+1, NULL, &status);
  268 +
  269 + // If HDU does not yet exist in file then create it now
  270 + if (status == 107) {
  271 +
  272 + // Reset status
  273 + status = 0;
  274 +
  275 + // Initialise number of fields
  276 + int tfields = 0;
  277 +
  278 + // Setup cfitsio column definition arrays
  279 + char** ttype = NULL;
  280 + char** tform = NULL;
  281 + char** tunit = NULL;
  282 + if (m_cols > 0) {
  283 + ttype = new char*[m_cols];
  284 + tform = new char*[m_cols];
  285 + tunit = new char*[m_cols];
  286 + for (int i = 0; i < m_cols; ++i) {
  287 + ttype[i] = NULL;
  288 + tform[i] = NULL;
  289 + tunit[i] = NULL;
  290 + }
  291 + for (int i = 0; i < m_cols; ++i) {
  292 + ttype[tfields] = get_ttype(i);
  293 + tform[tfields] = get_tform(i);
  294 + tunit[tfields] = get_tunit(i);
  295 + if (ttype[tfields] != NULL && tform[tfields] != NULL &&
  296 + tunit[tfields] != NULL)
  297 + tfields++;
  298 + }
  299 + }
  300 +
  301 + // Create FITS table
  302 + status = __ffcrtb(&m_fitsfile, m_type, m_rows, tfields, ttype, tform,
  303 + tunit, NULL, &status);
  304 + if (status != 0)
  305 + throw GException::fits_error(G_SAVE, status);
  306 +
  307 + // De-allocate column definition arrays
  308 + if (m_cols > 0) {
  309 + for (int i = 0; i < m_cols; ++i) {
  310 + if (ttype[i] != NULL) delete [] ttype[i];
  311 + if (tform[i] != NULL) delete [] tform[i];
  312 + if (tunit[i] != NULL) delete [] tunit[i];
  313 + }
  314 + if (ttype != NULL) delete [] ttype;
  315 + if (ttype != NULL) delete [] tform;
  316 + if (ttype != NULL) delete [] tunit;
  317 + }
  318 +
  319 + }
  320 + else if (status != 0)
  321 + throw GException::fits_error(G_SAVE, status);
  322 +
  323 + // Return
  324 + return;
  325 +}
  326 +
  327 +
  328 +/***********************************************************************//**
  329 + * @brief Close table
  330 + ***************************************************************************/
  331 +void GFitsTable::close(void)
  332 +{
  333 + // Free members
  334 + free_members();
  335 +
  336 + // Initialise members
  337 + init_members();
  338 +
  339 + // Return
  340 + return;
  341 +}
  342 +
  343 +
  344 +/***********************************************************************//**
  345 + * @brief Return pointer to column with specified name
  346 + *
  347 + * @param[in] colname Name of column which should be accessed
  348 + *
  349 + * @exception GException::fits_no_data
  350 + * There are no column data in the table or there is not data
  351 + * for this column
  352 + * @exception GException::fits_column_not_found
  353 + * Requested column has not been found in table.
  354 + ***************************************************************************/
  355 +GFitsTableCol* GFitsTable::column(const std::string& colname)
  356 +{
  357 + // If there is no data then throw an exception
  358 + if (m_columns == NULL)
  359 + throw GException::fits_no_data(G_COLUMN1, "No column data in table");
  360 +
  361 + // Initialise pointer
  362 + GFitsTableCol* ptr = NULL;
  363 +
  364 + // If there are columns then search for the specified name
  365 + if (m_columns != NULL) {
  366 + for (int i = 0; i < m_cols; ++i) {
  367 + if (m_columns[i]->name() == colname) {
  368 + ptr = m_columns[i];
  369 + if (ptr == NULL)
  370 + throw GException::fits_no_data(G_COLUMN1,
  371 + "No data for this column");
  372 + break;
  373 + }
  374 + }
  375 + }
  376 +
  377 + // If column has not been found throw an exception
  378 + if (ptr == NULL)
  379 + throw GException::fits_column_not_found(G_COLUMN1, colname);
  380 +
  381 + // Return column pointer
  382 + return ptr;
  383 +}
  384 +
  385 +
  386 +/***********************************************************************//**
  387 + * @brief Return pointer to column with number
  388 + *
  389 + * @param[in] colnum Number of requested column (starting from 0)
  390 + *
  391 + * @exception GException::fits_no_data
  392 + * There are no column data in the table or there is not data
  393 + * for this column
  394 + * @exception GException::out_of_range
  395 + * Requested column has not been found in table.
  396 + ***************************************************************************/
  397 +GFitsTableCol* GFitsTable::column(const int& colnum)
  398 +{
  399 + // If there is no data then throw an exception
  400 + if (m_columns == NULL)
  401 + throw GException::fits_no_data(G_COLUMN2, "No column data in table");
  402 +
  403 + // If column number is out of range then throw an exception
  404 + if (colnum < 0 || colnum >= m_cols)
  405 + throw GException::out_of_range(G_COLUMN2, colnum, 0, m_cols-1);
  406 +
  407 + // Get column pointer
  408 + GFitsTableCol* ptr = ptr = m_columns[colnum];
  409 + if (ptr == NULL)
  410 + throw GException::fits_no_data(G_COLUMN2, "No data for this column");
  411 +
  412 + // Return column pointer
  413 + return ptr;
  414 +}
  415 +
  416 +
  417 +/***********************************************************************//**
  418 + * @brief Return number of rows in table
  419 + ***************************************************************************/
  420 +int GFitsTable::rows(void) const
  421 +{
  422 + // Return number of rows
  423 + return m_rows;
  424 +}
  425 +
  426 +
  427 +/***********************************************************************//**
  428 + * @brief Return number of columns in table
  429 + ***************************************************************************/
  430 +int GFitsTable::cols(void) const
  431 +{
  432 + // Return number of columns
  433 + return m_cols;
  434 +}
  435 +
  436 +
  437 +/*==========================================================================
  438 + = =
  439 + = GFitsTable private methods =
  440 + = =
  441 + ==========================================================================*/
  442 +
  443 +/***********************************************************************//**
  444 + * @brief Initialise class members
  445 + ***************************************************************************/
  446 +void GFitsTable::init_members(void)
  447 +{
  448 + // Initialise members
  449 + m_type = -1;
  450 + m_rows = 0;
  451 + m_cols = 0;
  452 + m_columns = NULL;
  453 +
  454 + // Return
  455 + return;
  456 +}
  457 +
  458 +
  459 +/***********************************************************************//**
  460 + * @brief Copy class members
  461 + *
  462 + * @param[in] table Table to copy
  463 + ***************************************************************************/
  464 +void GFitsTable::copy_members(const GFitsTable& table)
  465 +{
  466 + // Copy attributes
  467 + m_type = table.m_type;
  468 + m_rows = table.m_rows;
  469 + m_cols = table.m_cols;
  470 +
  471 + // Copy column definition
  472 + if (table.m_columns != NULL && m_cols > 0) {
  473 + m_columns = new GFitsTableCol*[m_cols];
  474 + for (int i = 0; i < m_cols; ++i) {
  475 + if (table.m_columns[i] != NULL)
  476 + m_columns[i] = table.m_columns[i]->clone();
  477 + else
  478 + m_columns[i] = NULL;
  479 + }
  480 + }
  481 +
  482 + // Return
  483 + return;
  484 +}
  485 +
  486 +
  487 +/***********************************************************************//**
  488 + * @brief Delete class members
  489 + ***************************************************************************/
  490 +void GFitsTable::free_members(void)
  491 +{
  492 + // Free memory
  493 + for (int i = 0; i < m_cols; ++i) {
  494 + if (m_columns[i] != NULL) delete m_columns[i];
  495 + }
  496 + if (m_columns != NULL) delete [] m_columns;
  497 +
  498 + // Mark memory as freed
  499 + m_columns = NULL;
  500 +
  501 + // Return
  502 + return;
  503 +}
  504 +
  505 +
  506 +/***********************************************************************//**
  507 + * @brief Connect table to FITS file
  508 + *
  509 + * @param[in] fptr FITS file pointer to which the table should be connected
  510 + *
  511 + * The connection of the table is done by connecting all columns.
  512 + ***************************************************************************/
  513 +void GFitsTable::connect(__fitsfile* fptr)
  514 +{
  515 + // First connect binary table
  516 + m_fitsfile = *fptr;
  517 +
  518 + // Then connect all columns
  519 + if (m_columns != NULL) {
  520 + for (int i = 0; i < m_cols; ++i) {
  521 + if (m_columns[i] != NULL) m_columns[i]->connect(fptr);
  522 + }
  523 + }
  524 +
  525 + // Return
  526 + return;
  527 +}
  528 +
  529 +
  530 +/***********************************************************************//**
  531 + * @brief Returns pointer to column type
  532 + *
  533 + * @param[in] colnum Column number for which type is to be returned
  534 + *
  535 + * This methods allocates memory for the character string that holds the
  536 + * column type. The client has to de-allocate this memory after usage.
  537 + * In case that the column does not exist a NULL pointer is returned.
  538 + ***************************************************************************/
  539 +char* GFitsTable::get_ttype(const int& colnum) const
  540 +{
  541 + // Initialise result with NULL pointer
  542 + char* ptr = NULL;
  543 +
  544 + // Get type only if column exists
  545 + if (m_columns != NULL && colnum >=0 && colnum < m_cols &&
  546 + m_columns[colnum] != NULL) {
  547 + int size = m_columns[colnum]->m_name.length() + 1;
  548 + ptr = new char[size];
  549 + strncpy(ptr, m_columns[colnum]->m_name.c_str(), size-1);
  550 + }
  551 +
  552 + // Return result
  553 + return ptr;
  554 +}
  555 +
  556 +
  557 +/***********************************************************************//**
  558 + * @brief Returns pointer to column format
  559 + *
  560 + * @param[in] colnum Column number for which format is to be returned
  561 + *
  562 + * This methods allocates memory for the character string that holds the
  563 + * column format. The client has to de-allocate this memory after usage.
  564 + * In case that the column does not exist a NULL pointer is returned.
  565 + ***************************************************************************/
  566 +char* GFitsTable::get_tform(const int& colnum) const
  567 +{
  568 + // Initialise result with NULL pointer
  569 + char* ptr = NULL;
  570 +
  571 + // Get type only if column exists
  572 + if (m_columns != NULL && colnum >=0 && colnum < m_cols &&
  573 + m_columns[colnum] != NULL) {
  574 + int size = m_columns[colnum]->m_format.length() + 1;
  575 + ptr = new char[size];
  576 + strncpy(ptr, m_columns[colnum]->m_format.c_str(), size-1);
  577 + }
  578 +
  579 + // Return result
  580 + return ptr;
  581 +}
  582 +
  583 +
  584 +/***********************************************************************//**
  585 + * @brief Returns pointer to column unit
  586 + *
  587 + * @param[in] colnum Column number for which unit is to be returned
  588 + *
  589 + * This methods allocates memory for the character string that holds the
  590 + * column unit. The client has to de-allocate this memory after usage.
  591 + * In case that the column does not exist a NULL pointer is returned.
  592 + ***************************************************************************/
  593 +char* GFitsTable::get_tunit(const int& colnum) const
  594 +{
  595 + // Initialise result with NULL pointer
  596 + char* ptr = NULL;
  597 +
  598 + // Get type only if column exists
  599 + if (m_columns != NULL && colnum >=0 && colnum < m_cols &&
  600 + m_columns[colnum] != NULL) {
  601 + int size = m_columns[colnum]->m_unit.length() + 1;
  602 + ptr = new char[size];
  603 + strncpy(ptr, m_columns[colnum]->m_unit.c_str(), size-1);
  604 + }
  605 +
  606 + // Return result
  607 + return ptr;
  608 +}
  609 +
  610 +
  611 +/*==========================================================================
  612 + = =
  613 + = GFitsTable friends =
  614 + = =
  615 + ==========================================================================*/
  616 +
  617 +/***********************************************************************//**
  618 + * @brief Output operator
  619 + *
  620 + * @param[in] os Output stream
  621 + * @param[in] table Table to put in output stream
  622 + ***************************************************************************/
  623 +ostream& operator<< (ostream& os, const GFitsTable& table)
  624 +{
  625 + // Put header in stream
  626 + os << "=== GFitsTable ===" << endl;
  627 + os << " Table type ................: ";
  628 + switch (table.m_type) {
  629 + case 1:
  630 + os << "ASCII table" << endl;
  631 + break;
  632 + case 2:
  633 + os << "Binary table" << endl;
  634 + break;
  635 + default:
  636 + os << "Unknown" << endl;
  637 + break;
  638 + }
  639 + os << " Number of rows ............: " << table.m_rows << endl;
  640 + os << " Number of columns .........: " << table.m_cols << endl;
  641 + if (table.m_columns != NULL) {
  642 + for (int i = 0; i < table.m_cols; ++i) {
  643 + if (table.m_columns[i] != NULL)
  644 + os << " " << *(table.m_columns[i]);
  645 + else
  646 + os << " column " << i << " undefined" << endl;
  647 + }
  648 + }
  649 + else
  650 + os << " table columns undefined" << endl;
  651 +
  652 + // Return output stream
  653 + return os;
  654 +}
  655 +
  656 +
  657 +/*==========================================================================
  658 + = =
  659 + = Other functions used by GFitsTable =
  660 + = =
  661 + ==========================================================================*/
... ...
src/fits/GFitsTableCol.cpp
... ... @@ -131,6 +131,8 @@ void GFitsTableCol::init_members(void)
131 131 {
132 132 // Initialise members
133 133 m_name.clear();
  134 + m_format.clear();
  135 + m_unit.clear();
134 136 m_colnum = 0;
135 137 m_type = 0;
136 138 m_repeat = 0;
... ... @@ -152,6 +154,8 @@ void GFitsTableCol::copy_members(const GFitsTableCol&amp; column)
152 154 {
153 155 // Copy attributes
154 156 m_name = column.m_name;
  157 + m_format = column.m_format;
  158 + m_unit = column.m_unit;
155 159 m_colnum = column.m_colnum;
156 160 m_type = column.m_type;
157 161 m_repeat = column.m_repeat;
... ...
test/test_GFits.cpp
... ... @@ -335,7 +335,7 @@ void test_create(void)
335 335 }
336 336 GFitsHDU hdu(image);
337 337 fits.append(&hdu);
338   - cout << fits;
  338 + //cout << fits;
339 339 fits.save();
340 340 }
341 341 catch (exception &e) {
... ... @@ -370,6 +370,44 @@ void test_create(void)
370 370 throw;
371 371 }
372 372 cout << ".";
  373 +
  374 + // Attach binary table
  375 + try {
  376 + GFits fits;
  377 + fits.open("test.fits");
  378 + int nrows = 10;
  379 + int ncols = 5;
  380 + GFitsBinTable table(nrows,ncols);
  381 + GFitsHDU hdu(table);
  382 + fits.append(&hdu);
  383 + cout << fits;
  384 + fits.save();
  385 + }
  386 + catch (exception &e) {
  387 + cout << endl << "TEST ERROR: Unable to attach binary table." << endl;
  388 + cout << e.what() << endl;
  389 + throw;
  390 + }
  391 + cout << ".";
  392 +
  393 + // Attach ASCII table
  394 + try {
  395 + GFits fits;
  396 + fits.open("test.fits");
  397 + int nrows = 10;
  398 + int ncols = 5;
  399 + GFitsAsciiTable table(nrows,ncols);
  400 + GFitsHDU hdu(table);
  401 + fits.append(&hdu);
  402 + cout << fits;
  403 + fits.save();
  404 + }
  405 + catch (exception &e) {
  406 + cout << endl << "TEST ERROR: Unable to attach ASCII table." << endl;
  407 + cout << e.what() << endl;
  408 + throw;
  409 + }
  410 + cout << ".";
373 411  
374 412  
375 413 cout << ". ok." << endl;
... ...