GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFitsAsciiTable.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GFitsAsciiTable.cpp - FITS ASCII 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 GFitsAsciiTable.cpp
23  * @brief FITS ASCII table class implementation
24  * @author Juergen Knodlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #include "GFitsAsciiTable.hpp"
29 
30 /* __ Method name definitions ____________________________________________ */
31 
32 /* __ Macros _____________________________________________________________ */
33 
34 /* __ Coding definitions _________________________________________________ */
35 
36 /* __ Debug definitions __________________________________________________ */
37 
38 
39 
40 /*==========================================================================
41  = =
42  = Constructors/destructors =
43  = =
44  ==========================================================================*/
45 
46 /***********************************************************************//**
47  * @brief Void constructor
48  ***************************************************************************/
50 {
51  // Initialise class members for clean destruction
52  init_members();
53 
54  // Return
55  return;
56 }
57 
58 
59 /***********************************************************************//**
60  * @brief Table constructor
61  *
62  * @param[in] nrows Number of rows in table.
63  ***************************************************************************/
64 GFitsAsciiTable::GFitsAsciiTable(const int& nrows) : GFitsTable(nrows)
65 {
66  // Initialise class members for clean destruction
67  init_members();
68 
69  // Initialise header
71 
72  // Return
73  return;
74 }
75 
76 
77 /***********************************************************************//**
78  * @brief Copy constructor
79  *
80  * @param[in] table ASCII table.
81  ***************************************************************************/
83 {
84  // Initialise class members for clean destruction
85  init_members();
86 
87  // Copy members
88  copy_members(table);
89 
90  // Return
91  return;
92 }
93 
94 
95 /***********************************************************************//**
96  * @brief Destructor
97  ***************************************************************************/
99 {
100  // Free members
101  free_members();
102 
103  // Return
104  return;
105 }
106 
107 
108 /*==========================================================================
109  = =
110  = Operators =
111  = =
112  ==========================================================================*/
113 
114 /***********************************************************************//**
115  * @brief Assignment operator
116  *
117  * @param[in] table ASCII table.
118  * @return ASCII table.
119  ***************************************************************************/
121 {
122  // Execute only if object is not identical
123  if (this != &table) {
124 
125  // Copy base class members
126  this->GFitsTable::operator=(table);
127 
128  // Free members
129  free_members();
130 
131  // Initialise private members for clean destruction
132  init_members();
133 
134  // Copy members
135  copy_members(table);
136 
137  } // endif: object was not identical
138 
139  // Return this object
140  return *this;
141 }
142 
143 
144 /*==========================================================================
145  = =
146  = Public methods =
147  = =
148  ==========================================================================*/
149 
150 /***********************************************************************//**
151  * @brief Clear ASCII table
152  *
153  * This method properly resets the object to an initial state.
154  ***************************************************************************/
156 {
157  // Free class members (base and derived classes, derived class first)
158  free_members();
159  this->GFitsTable::free_members();
160  this->GFitsHDU::free_members();
161 
162  // Initialise members
163  this->GFitsHDU::init_members();
164  this->GFitsTable::init_members();
165  init_members();
166 
167  // Return
168  return;
169 }
170 
171 
172 /***********************************************************************//**
173  * @brief Clone ASCII table
174  *
175  * @return Pointer to deep copy of ASCII table.
176  ***************************************************************************/
178 {
179  return new GFitsAsciiTable(*this);
180 }
181 
182 
183 /*==========================================================================
184  = =
185  = Private methods =
186  = =
187  ==========================================================================*/
188 
189 /***********************************************************************//**
190  * @brief Initialise class members
191  ***************************************************************************/
193 {
194  // Initialise members
195  m_type = 1;
196 
197  // Return
198  return;
199 }
200 
201 
202 /***********************************************************************//**
203  * @brief Copy class members
204  *
205  * @param table Table.
206  ***************************************************************************/
208 {
209  // Return
210  return;
211 }
212 
213 
214 /***********************************************************************//**
215  * @brief Delete class members
216  ***************************************************************************/
218 {
219  // Return
220  return;
221 }
222 
223 
224 
225 
226 /***********************************************************************//**
227  * @brief Initialise ASCII table header
228  *
229  * Initialises the table header by setting the default header cards.
230  ***************************************************************************/
232 {
233  // Compute total width in Bytes
234  int width = 0;
235  for (int i = 0; i < ncols(); ++i) {
236  width += m_columns[i]->width();
237  }
238 
239  // Set image header keywords
240  m_header.append(GFitsHeaderCard("XTENSION", "TABLE",
241  "ASCII table extension"));
242  m_header.append(GFitsHeaderCard("BITPIX", 8,
243  "8-bit ASCII characters"));
244  m_header.append(GFitsHeaderCard("NAXIS", 2,
245  "2-dimensional ASCII table"));
246  m_header.append(GFitsHeaderCard("NAXIS1", width,
247  "width of table in characters"));
248  m_header.append(GFitsHeaderCard("NAXIS2", nrows(),
249  "number of rows in table"));
250  m_header.append(GFitsHeaderCard("PCOUNT", 0,
251  "no group parameters (required keyword)"));
252  m_header.append(GFitsHeaderCard("GCOUNT", 1,
253  "one data group (required keyword)"));
254 
255  // Return
256  return;
257 }
const int & ncols(void) const
Return number of columns in table.
Definition: GFitsTable.hpp:134
int m_type
Table type (1=ASCII, 2=Binary)
Definition: GFitsTable.hpp:98
GFitsTableCol ** m_columns
Array of table columns.
Definition: GFitsTable.hpp:101
Implements FITS header card interface.
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
virtual void clear(void)
Clear ASCII table.
void init_table_header(void)
Initialise ASCII table header.
GFitsHeader m_header
HDU header.
Definition: GFitsHDU.hpp:136
FITS ASCII table class.
virtual GFitsAsciiTable * clone(void) const
Clone ASCII table.
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
GFitsAsciiTable(void)
Void constructor.
virtual ~GFitsAsciiTable(void)
Destructor.
void free_members(void)
Free class members.
Definition: GFitsTable.cpp:855
GFitsAsciiTable & operator=(const GFitsAsciiTable &table)
Assignment operator.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
Definition: GFitsHDU.cpp:503
FITS ASCII table class definition.
GFitsTable & operator=(const GFitsTable &table)
Assignment operator.
Definition: GFitsTable.cpp:162
void copy_members(const GFitsAsciiTable &table)
Copy class members.
void free_members(void)
Delete class members.