GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFitsBinTable.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GFitsBinTable.cpp - FITS binary table class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2008-2018 by Juergen Knoedlseder *
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 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GFitsBinTable.cpp
23  * @brief FITS binary table class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GFitsBinTable.hpp"
32 
33 /* __ Method name definitions ____________________________________________ */
34 
35 /* __ Macros _____________________________________________________________ */
36 
37 /* __ Coding definitions _________________________________________________ */
38 
39 /* __ Debug definitions __________________________________________________ */
40 
41 /* __ Prototypes of local functions ______________________________________ */
42 
43 
44 /*==========================================================================
45  = =
46  = Constructors/destructors =
47  = =
48  ==========================================================================*/
49 
50 /***********************************************************************//**
51  * @brief Void constructor
52  ***************************************************************************/
54 {
55  // Initialise class members for clean destruction
56  init_members();
57 
58  // Return
59  return;
60 }
61 
62 
63 /***********************************************************************//**
64  * @brief Table constructor
65  *
66  * @param[in] nrows Number of rows in table
67  ***************************************************************************/
68 GFitsBinTable::GFitsBinTable(const int& nrows) : GFitsTable(nrows)
69 {
70  // Initialise class members for clean destruction
71  init_members();
72 
73  // Initialise header
75 
76  // Return
77  return;
78 }
79 
80 
81 /***********************************************************************//**
82  * @brief Copy constructor
83  *
84  * @param[in] table Binary table.
85  ***************************************************************************/
87 {
88  // Initialise class members for clean destruction
89  init_members();
90 
91  // Copy members
92  copy_members(table);
93 
94  // Return
95  return;
96 }
97 
98 
99 /***********************************************************************//**
100  * @brief Destructor
101  ***************************************************************************/
103 {
104  // Free members
105  free_members();
106 
107  // Return
108  return;
109 }
110 
111 
112 /*==========================================================================
113  = =
114  = Operators =
115  = =
116  ==========================================================================*/
117 
118 /***********************************************************************//**
119  * @brief Assignment operator
120  *
121  * @param[in] table Binary table.
122  * @return Binary table.
123  ***************************************************************************/
125 {
126  // Execute only if object is not identical
127  if (this != &table) {
128 
129  // Copy base class members
130  this->GFitsTable::operator=(table);
131 
132  // Free members
133  free_members();
134 
135  // Initialise private members for clean destruction
136  init_members();
137 
138  // Copy members
139  copy_members(table);
140 
141  } // endif: object was not identical
142 
143  // Return this object
144  return *this;
145 }
146 
147 
148 /*==========================================================================
149  = =
150  = Public methods =
151  = =
152  ==========================================================================*/
153 
154 /***********************************************************************//**
155  * @brief Clear binary table
156  *
157  * This method properly resets the object to an initial state.
158  ***************************************************************************/
160 {
161  // Free class members (base and derived classes, derived class first)
162  free_members();
163  this->GFitsTable::free_members();
164  this->GFitsHDU::free_members();
165 
166  // Initialise members
167  this->GFitsHDU::init_members();
168  this->GFitsTable::init_members();
169  init_members();
170 
171  // Return
172  return;
173 }
174 
175 
176 /***********************************************************************//**
177  * @brief Clone binary table
178  *
179  * @return Pointer to deep copy of binary table.
180  ***************************************************************************/
182 {
183  return new GFitsBinTable(*this);
184 }
185 
186 
187 /*==========================================================================
188  = =
189  = Private methods =
190  = =
191  ==========================================================================*/
192 
193 /***********************************************************************//**
194  * @brief Initialise class members
195  ***************************************************************************/
197 {
198  // Initialise members
199  m_type = 2;
200 
201  // Return
202  return;
203 }
204 
205 
206 /***********************************************************************//**
207  * @brief Copy class members
208  *
209  * @param[in] table Table to copy
210  ***************************************************************************/
212 {
213  // Return
214  return;
215 }
216 
217 
218 /***********************************************************************//**
219  * @brief Delete class members
220  ***************************************************************************/
222 {
223  // Return
224  return;
225 }
226 
227 
228 /***********************************************************************//**
229  * @brief Initialise binary table header
230  *
231  * Initialises the table header by setting the default header cards.
232  ***************************************************************************/
234 {
235  // Compute total width in Bytes
236  int width = 0;
237  for (int i = 0; i < ncols(); ++i) {
238  width += m_columns[i]->width();
239  }
240 
241  // Set image header keywords
242  m_header.append(GFitsHeaderCard("XTENSION", "BINTABLE",
243  "binary table extension"));
244  m_header.append(GFitsHeaderCard("BITPIX", 8,
245  "8-bit bytes"));
246  m_header.append(GFitsHeaderCard("NAXIS", 2,
247  "2-dimensional binary table"));
248  m_header.append(GFitsHeaderCard("NAXIS1", width,
249  "width of table in bytes"));
250  m_header.append(GFitsHeaderCard("NAXIS2", nrows(),
251  "number of rows in table"));
252  m_header.append(GFitsHeaderCard("PCOUNT", 0,
253  "size of special data area"));
254  m_header.append(GFitsHeaderCard("GCOUNT", 1,
255  "one data group (required keyword)"));
256 
257  // Return
258  return;
259 }
const int & ncols(void) const
Return number of columns in table.
Definition: GFitsTable.hpp:134
GFitsBinTable(void)
Void constructor.
void copy_members(const GFitsBinTable &table)
Copy class members.
int m_type
Table type (1=ASCII, 2=Binary)
Definition: GFitsTable.hpp:98
void init_members(void)
Initialise class members.
GFitsTableCol ** m_columns
Array of table columns.
Definition: GFitsTable.hpp:101
virtual void clear(void)
Clear binary table.
Implements FITS header card interface.
virtual ~GFitsBinTable(void)
Destructor.
GFitsHeaderCard & append(const GFitsHeaderCard &card)
Append or update header card.
void width(const int &width)
Set width in Bytes of one column element.
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
GFitsHeader m_header
HDU header.
Definition: GFitsHDU.hpp:136
void init_members(void)
Initialise class members.
Definition: GFitsTable.cpp:805
void init_members(void)
Initialise class members.
Definition: GFitsHDU.cpp:460
const int & nrows(void) const
Return number of rows in table.
Definition: GFitsTable.hpp:119
void free_members(void)
Free class members.
Definition: GFitsTable.cpp:855
void init_table_header(void)
Initialise binary table header.
FITS binary table class.
virtual GFitsBinTable * clone(void) const
Clone binary table.
FITS binary table class definition.
GFitsBinTable & operator=(const GFitsBinTable &table)
Assignment operator.
void free_members(void)
Delete class members.
Definition: GFitsHDU.cpp:503
void free_members(void)
Delete class members.
GFitsTable & operator=(const GFitsTable &table)
Assignment operator.
Definition: GFitsTable.cpp:162