GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSkyProjection.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GSkyProjection.cpp - Abstract sky projection base class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2012 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 GSkyProjection.cpp
23  * @brief Abstract sky projection base class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GException.hpp"
32 #include "GTools.hpp"
33 #include "GSkyProjection.hpp"
34 
35 /* __ Method name definitions ____________________________________________ */
36 #define G_COORDSYS_SET "GSkyProjection::coordsys(std::string)"
37 
38 /* __ Macros _____________________________________________________________ */
39 
40 /* __ Coding definitions _________________________________________________ */
41 
42 /* __ Debug definitions __________________________________________________ */
43 
44 /* __ Local prototypes ___________________________________________________ */
45 
46 /* __ Constants __________________________________________________________ */
47 
48 
49 /*==========================================================================
50  = =
51  = Constructors/destructors =
52  = =
53  ==========================================================================*/
54 
55 /***********************************************************************//**
56  * @brief Void constructor
57  ***************************************************************************/
59 {
60  // Initialise class members
61  init_members();
62 
63  // Return
64  return;
65 }
66 
67 
68 /***********************************************************************//**
69  * @brief Copy constructor
70  *
71  * @param[in] proj Sky projection.
72  ***************************************************************************/
74 {
75  // Initialise class members
76  init_members();
77 
78  // Copy members
79  copy_members(proj);
80 
81  // Return
82  return;
83 }
84 
85 
86 /***********************************************************************//**
87  * @brief Destructor
88  ***************************************************************************/
90 {
91  // Free members
92  free_members();
93 
94  // Return
95  return;
96 }
97 
98 
99 /*==========================================================================
100  = =
101  = Operators =
102  = =
103  ==========================================================================*/
104 
105 /***********************************************************************//**
106  * @brief Assignment operator
107  *
108  * @param[in] proj Sky projection.
109  * @return Sky projection.
110  ***************************************************************************/
112 {
113  // Execute only if object is not identical
114  if (this != &proj) {
115 
116  // Free members
117  free_members();
118 
119  // Initialise private members for clean destruction
120  init_members();
121 
122  // Copy members
123  copy_members(proj);
124 
125  } // endif: object was not identical
126 
127  // Return this object
128  return *this;
129 }
130 
131 
132 /*==========================================================================
133  = =
134  = Public methods =
135  = =
136  ==========================================================================*/
137 
138 /***********************************************************************//**
139  * @brief Returns coordinate system.
140  *
141  * @return Coordinate system string.
142  *
143  * Returns one of
144  * 'EQU' (equatorial),
145  * 'GAL' (galactic),
146  ***************************************************************************/
147 std::string GSkyProjection::coordsys(void) const
148 {
149  // Set coordinate system
150  std::string s_coordsys;
151  switch (m_coordsys) {
152  case 0:
153  s_coordsys = "EQU";
154  break;
155  case 1:
156  s_coordsys = "GAL";
157  break;
158  default:
159  s_coordsys = "UNKNOWN";
160  break;
161  }
162 
163  // Return coordinate system
164  return s_coordsys;
165 }
166 
167 
168 /***********************************************************************//**
169  * @brief Set coordinate system
170  *
171  * @param[in] coordsys Coordinate system
172  *
173  * @exception GException::wcs_bad_coords
174  * Invalid coordsys parameter.
175  *
176  * Set coordinate system from std::string. The method recognizes the
177  * following codes:
178  * 'EQU', 'CEL', 'C': celestial,
179  * 'GAL', 'G': galactic,
180  ***************************************************************************/
181 void GSkyProjection::coordsys(const std::string& coordsys)
182 {
183  // Convert argument to upper case
184  std::string ucoordsys = gammalib::toupper(coordsys);
185 
186  // Set coordinate system
187  if (ucoordsys == "EQU" || ucoordsys == "CEL" || ucoordsys == "C") {
188  m_coordsys = 0;
189  }
190  else if (ucoordsys == "GAL" || ucoordsys == "G") {
191  m_coordsys = 1;
192  }
193  else {
195  }
196 
197  // Return
198  return;
199 }
200 
201 
202 /*==========================================================================
203  = =
204  = Protected methods =
205  = =
206  ==========================================================================*/
207 
208 /***********************************************************************//**
209  * @brief Initialise class members
210  ***************************************************************************/
212 {
213  // Initialise members
214  m_coordsys = 0; // 0 means EQU
215 
216  // Return
217  return;
218 }
219 
220 
221 /***********************************************************************//**
222  * @brief Copy class members
223  *
224  * @param[in] proj Sky projection.
225  ***************************************************************************/
227 {
228  // Copy attributes
229  m_coordsys = proj.m_coordsys;
230 
231  // Return
232  return;
233 }
234 
235 
236 /***********************************************************************//**
237  * @brief Delete class members
238  ***************************************************************************/
240 {
241  // Return
242  return;
243 }
244 
245 
246 /*==========================================================================
247  = =
248  = Friends =
249  = =
250  ==========================================================================*/
251 
252 /***********************************************************************//**
253  * @brief Equality operator
254  *
255  * @param[in] a First sky projection.
256  * @param[in] b Second sky projection.
257  * @return True if @p a and @p b are identical.
258  ***************************************************************************/
259 bool operator==(const GSkyProjection &a, const GSkyProjection &b)
260 {
261  // Return result
262  return a.compare(b);
263 }
264 
265 
266 /***********************************************************************//**
267  * @brief Non-equality operator
268  *
269  * @param[in] a First sky projection.
270  * @param[in] b Second sky projection.
271  * @return True if @p a and @p b are not identical.
272  ***************************************************************************/
273 bool operator!=(const GSkyProjection &a, const GSkyProjection &b)
274 {
275  // Return result
276  return !(a == b);
277 }
virtual GSkyProjection & operator=(const GSkyProjection &proj)
Assignment operator.
Abstract sky projection base class definition.
Gammalib tools definition.
#define G_COORDSYS_SET
void copy_members(const GSkyProjection &proj)
Copy class members.
virtual bool compare(const GSkyProjection &proj) const =0
GSkyProjection(void)
Void constructor.
int m_coordsys
0=EQU, 1=GAL
virtual std::string coordsys(void) const
Returns coordinate system.
void free_members(void)
Delete class members.
Exception handler interface definition.
void init_members(void)
Initialise class members.
std::string toupper(const std::string &s)
Convert string to upper case.
Definition: GTools.cpp:820
bool operator==(const GEnergy &a, const GEnergy &b)
Energy equality operator friend.
Definition: GEnergy.hpp:297
Abstract sky projection base class.
bool operator!=(const GEbounds &a, const GEbounds &b)
Energy boundaries inequality operator friend.
Definition: GEbounds.hpp:207
virtual ~GSkyProjection(void)
Destructor.