GammaLib  2.0.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFits.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GFits.hpp - FITS file class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2008-2016 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 GFits.hpp
23  * @brief FITS file class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GFITS_HPP
28 #define GFITS_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GContainer.hpp"
34 #include "GFitsHDU.hpp"
35 #include "GFitsImage.hpp"
36 #include "GFitsTable.hpp"
37 #include "GFilename.hpp"
38 
39 /* __ Prototypes _________________________________________________________ */
40 namespace gammalib {
41  int fits_move_to_hdu(const std::string& caller, void* vptr,
42  const int& hdunum = 0);
43 }
44 
45 
46 /***********************************************************************//**
47  * @class GFits
48  *
49  * @brief FITS file class
50  *
51  * This class provides a physical representation of a FITS file in memory.
52  * It handles creation, manipulation, writing and reading of FITS files.
53  * As a FITS file is a collection of Header Data Units (HDUs), also known
54  * as FITS file extensions, the class is designed as a container class of
55  * HDUs.
56  *
57  * HDUs are represented by the abstract GFitsHDU base class. A HDU may be
58  * either an image, represented by the abstract GFitsImage base class, or
59  * a table, represented by the abstract GFitsTable class. The image() and
60  * table() method allow accessing the HDUs. HDUs may be accessed by index
61  * (also called extension number) or by extension name.
62  ***************************************************************************/
63 class GFits : public GContainer {
64 
65 public:
66  // Constructors and destructors
67  GFits(void);
68  GFits(const GFilename& filename, const bool& create = false);
69  GFits(const GFits& fits);
70  virtual ~GFits(void);
71 
72  // Operators
73  GFits& operator=(const GFits& fits);
74  GFitsHDU* operator[](const int& extno);
75  const GFitsHDU* operator[](const int& extno) const;
76  GFitsHDU* operator[](const std::string& extname);
77  const GFitsHDU* operator[](const std::string& extname) const;
78 
79  // Methods
80  void clear(void);
81  GFits* clone(void) const;
82  std::string classname(void) const;
83  GFitsHDU* at(const int& extno);
84  const GFitsHDU* at(const int& extno) const;
85  GFitsHDU* at(const std::string& extname);
86  const GFitsHDU* at(const std::string& extname) const;
87  GFitsImage* image(const int& extno);
88  const GFitsImage* image(const int& extno) const;
89  GFitsImage* image(const std::string& extname);
90  const GFitsImage* image(const std::string& extname) const;
91  GFitsTable* table(const int& extno);
92  const GFitsTable* table(const int& extno) const;
93  GFitsTable* table(const std::string& extname);
94  const GFitsTable* table(const std::string& extname) const;
95  int size(void) const;
96  bool is_empty(void) const;
97  GFitsHDU* set(const int& extno, const GFitsHDU& hdu);
98  GFitsHDU* set(const std::string& extname, const GFitsHDU& hdu);
99  GFitsHDU* append(const GFitsHDU& hdu);
100  GFitsHDU* insert(const int& extno, const GFitsHDU& hdu);
101  GFitsHDU* insert(const std::string& extname, const GFitsHDU& hdu);
102  void remove(const int& extno);
103  void remove(const std::string& extname);
104  void reserve(const int& num);
105  void extend(const GFits& fits);
106  bool contains(const int& extno) const;
107  bool contains(const std::string& extname) const;
108  const GFilename& filename(void) const;
109  int extno(const std::string& extname) const;
110  void open(const GFilename& filename,
111  const bool& create = false);
112  void save(const bool& clobber = false);
113  void saveto(const GFilename& filename,
114  const bool& clobber = false);
115  void close(void);
116  void publish(const int& extno,
117  const std::string& name = "") const;
118  void publish(const std::string& extname,
119  const std::string& name = "") const;
120  std::string print(const GChatter& chatter = NORMAL) const;
121 
122  // Complex single precision type
123  typedef struct {
124  float re;
125  float im;
126  } cfloat;
127 
128  // Complex double precision type
129  typedef struct {
130  float re;
131  float im;
132  } cdouble;
133 
134 private:
135  // Private methods
136  void init_members(void);
137  void copy_members(const GFits& fits);
138  void free_members(void);
139  GFitsImage* new_image(void);
140  GFitsImage* new_primary(void);
141 
142  // Private data area
143  std::vector<GFitsHDU*> m_hdu; //!< Pointers to HDUs
144  GFilename m_filename; //!< FITS file name
145  void* m_fitsfile; //!< FITS file pointer
146  bool m_readwrite; //!< FITS file is readwrite (true/false)
147  bool m_created; //!< FITS file has been created (true/false)
148 };
149 
150 
151 /***********************************************************************//**
152  * @brief Return class name
153  *
154  * @return String containing the class name ("GFits").
155  ***************************************************************************/
156 inline
157 std::string GFits::classname(void) const
158 {
159  return ("GFits");
160 }
161 
162 
163 /***********************************************************************//**
164  * @brief Get pointer to HDU
165  *
166  * @param[in] extno Extension number [0,...,size()-1].
167  * @return Pointer to HDU.
168  *
169  * Returns a pointer to the HDU with the specified extension number @p extno.
170  * No range checking is performed. If the HDU is not valid, NULL is returned.
171  ***************************************************************************/
172 inline
173 GFitsHDU* GFits::operator[](const int& extno)
174 {
175  return (m_hdu[extno]);
176 }
177 
178 
179 /***********************************************************************//**
180  * @brief Get pointer to HDU (const version)
181  *
182  * @param[in] extno Extension number [0,...,size()-1].
183  * @return Pointer to HDU.
184  *
185  * Returns a pointer to the HDU with the specified extension number @p extno.
186  * No range checking is performed. If the HDU is not valid, NULL is returned.
187  ***************************************************************************/
188 inline
189 const GFitsHDU* GFits::operator[](const int& extno) const
190 {
191  return (m_hdu[extno]);
192 }
193 
194 
195 /***********************************************************************//**
196  * @brief Get pointer to HDU
197  *
198  * @param[in] extname Name of HDU extension.
199  * @return Pointer to HDU.
200  *
201  * Returns a pointer to the HDU with the specified @p extname. No checking
202  * for the existence of @p extname is performed. If the HDU is not valid,
203  * NULL is returned.
204  ***************************************************************************/
205 inline
206 GFitsHDU* GFits::operator[](const std::string& extname)
207 {
208  return at(extname);
209 }
210 
211 
212 /***********************************************************************//**
213  * @brief Get pointer to HDU (const version)
214  *
215  * @param[in] extname Name of HDU extension.
216  * @return Pointer to HDU.
217  *
218  * Returns a pointer to the HDU with the specified @p extname. No checking
219  * for the existence of @p extname is performed. If the HDU is not valid,
220  * NULL is returned.
221  ***************************************************************************/
222 inline
223 const GFitsHDU* GFits::operator[](const std::string& extname) const
224 {
225  return at(extname);
226 }
227 
228 
229 /***********************************************************************//**
230  * @brief Return number of HDUs in FITS file
231  *
232  * @return Number of HDUs in FITS file.
233  *
234  * Returns the number of Header Data Units (HDUs) in the FITS file.
235  ***************************************************************************/
236 inline
237 int GFits::size(void) const
238 {
239  return (int)m_hdu.size();
240 }
241 
242 
243 /***********************************************************************//**
244  * @brief Signals if there are no HDUs in FITS file
245  *
246  * @return True if FITS file is empty, false otherwise.
247  *
248  * Signals if the FITS file does not contain any HDUs.
249  ***************************************************************************/
250 inline
251 bool GFits::is_empty(void) const
252 {
253  return (m_hdu.empty());
254 }
255 
256 
257 /***********************************************************************//**
258  * @brief Reserves space for HDUs in FITS file
259  *
260  * @param[in] num Number of HDUs
261  *
262  * Reserves space for @p num HDUs in the FITS file.
263  ***************************************************************************/
264 inline
265 void GFits::reserve(const int& num)
266 {
267  m_hdu.reserve(num);
268  return;
269 }
270 
271 
272 /***********************************************************************//**
273  * @brief Check if HDU exists in FITS file
274  *
275  * @param[in] extno Extension number [0,...,size()-1].
276  * @return True if HDU with specified @p extno exists, false otherwise.
277  *
278  * Returns true if a HDU with the specified extension number is present,
279  * false otherwise.
280  ***************************************************************************/
281 inline
282 bool GFits::contains(const int& extno) const
283 {
284  return (extno >= 0 && extno < size());
285 }
286 
287 
288 /***********************************************************************//**
289  * @brief Check if HDU exists in FITS file
290  *
291  * @param[in] extname Name of HDU extension.
292  * @return True if HDU with specified @p extname exists, false otherwise.
293  *
294  * Returns true if a HDU with the specified extension name is present,
295  * false otherwise.
296  ***************************************************************************/
297 inline
298 bool GFits::contains(const std::string& extname) const
299 {
300  return (extno(extname) != -1);
301 }
302 
303 
304 /***********************************************************************//**
305  * @brief Return FITS filename
306  *
307  * @return FITS file name.
308  *
309  * Returns the FITS file name. If the object is not yet associated to a file
310  * the file name will be empty.
311  ***************************************************************************/
312 inline
313 const GFilename& GFits::filename(void) const
314 {
315  return (m_filename);
316 }
317 
318 #endif /* GFITS_HPP */
std::vector< GFitsHDU * > m_hdu
Pointers to HDUs.
Definition: GFits.hpp:143
GFitsImage * new_image(void)
Allocate new FITS image and return memory pointer.
Definition: GFits.cpp:1615
float re
Definition: GFits.hpp:124
GFitsHDU * at(const int &extno)
Get pointer to HDU.
Definition: GFits.cpp:233
Abstract FITS image base class.
Definition: GFitsImage.hpp:43
GFitsTable * table(const int &extno)
Get pointer to table HDU.
Definition: GFits.cpp:472
GFits(void)
Void constructor.
Definition: GFits.cpp:90
bool contains(const int &extno) const
Check if HDU exists in FITS file.
Definition: GFits.hpp:282
void clear(void)
Clear FITS file.
Definition: GFits.cpp:195
Abstract FITS extension base class.
Definition: GFitsHDU.hpp:51
const GFilename & filename(void) const
Return FITS filename.
Definition: GFits.hpp:313
GFilename m_filename
FITS file name.
Definition: GFits.hpp:144
FITS file class.
Definition: GFits.hpp:63
GFits & operator=(const GFits &fits)
Assignment operator.
Definition: GFits.cpp:165
Abstract FITS image base class definition.
Abstract FITS extension base class definition.
void saveto(const GFilename &filename, const bool &clobber=false)
Saves to specified FITS file.
Definition: GFits.cpp:1267
GFitsImage * new_primary(void)
Return minimal primary HDU.
Definition: GFits.cpp:1695
void save(const bool &clobber=false)
Saves FITS file.
Definition: GFits.cpp:1156
GFits * clone(void) const
Clone FITS file.
Definition: GFits.cpp:213
GFitsHDU * operator[](const int &extno)
Get pointer to HDU.
Definition: GFits.hpp:173
Filename class.
Definition: GFilename.hpp:62
void open(const GFilename &filename, const bool &create=false)
Open or (optionally) create FITS file.
Definition: GFits.cpp:1023
void publish(const int &extno, const std::string &name="") const
Publish FITS HDU on VO Hub.
Definition: GFits.cpp:1335
void free_members(void)
Delete class members.
Definition: GFits.cpp:1537
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
GChatter
Definition: GTypemaps.hpp:33
GFitsImage * image(const int &extno)
Get pointer to image HDU.
Definition: GFits.cpp:360
void reserve(const int &num)
Reserves space for HDUs in FITS file.
Definition: GFits.hpp:265
void init_members(void)
Initialise class members.
Definition: GFits.cpp:1482
bool is_empty(void) const
Signals if there are no HDUs in FITS file.
Definition: GFits.hpp:251
int size(void) const
Return number of HDUs in FITS file.
Definition: GFits.hpp:237
GFitsHDU * insert(const int &extno, const GFitsHDU &hdu)
Set HDU for the specified extension number.
Definition: GFits.cpp:765
virtual ~GFits(void)
Destructor.
Definition: GFits.cpp:143
bool m_created
FITS file has been created (true/false)
Definition: GFits.hpp:147
bool m_readwrite
FITS file is readwrite (true/false)
Definition: GFits.hpp:146
GFitsHDU * append(const GFitsHDU &hdu)
Append HDU to FITS file.
Definition: GFits.cpp:665
float im
Definition: GFits.hpp:125
std::string classname(void) const
Return class name.
Definition: GFits.hpp:157
void copy_members(const GFits &fits)
Copy class members.
Definition: GFits.cpp:1507
Definition of interface for container classes.
int fits_move_to_hdu(const std::string &caller, void *vptr, const int &hdunum=0)
Move to FITS extension.
Definition: GFits.cpp:1745
GFitsHDU * set(const int &extno, const GFitsHDU &hdu)
Set HDU for the specified extension number.
Definition: GFits.cpp:585
std::string print(const GChatter &chatter=NORMAL) const
Print FITS information.
Definition: GFits.cpp:1427
void close(void)
Close FITS file.
Definition: GFits.cpp:1314
int extno(const std::string &extname) const
Return extension number for specified extension name.
Definition: GFits.cpp:973
Interface class for container classes.
Definition: GContainer.hpp:52
Filename class interface definition.
void * m_fitsfile
FITS file pointer.
Definition: GFits.hpp:145
void extend(const GFits &fits)
Append FITS file.
Definition: GFits.cpp:919
FITS table abstract base class interface definition.