Commit 4cda6d05b4c02f53a2c49a4f9dafa76001b8f8ee

Authored by Jürgen Knödlseder
1 parent f1613f0a

Review GFits interface definition.

The GFits class now derives from GContainer and implements all generic container class methods (at(), size(), isempty(), set(), append(), insert(), remove(), reserve(), extend()). The hashdu() method has been renamed to contains() for compliance with other container classes. The hdu() methods have been renamed to at(), also for compliance. Boolean arguments are now passed as const references, and members are returned as const references. HDU access operators[] have been implemented to access FITS extensions without range checking.
... ... @@ -33,6 +33,16 @@ GEbounds
33 33 The emin(), emax(), emean() and elogmean() methods now take a const
34 34 integer reference as argument instead of an integer value.
35 35  
  36 +GFits
  37 + The GFits class now derives from GContainer and implements all generic
  38 + container class methods (at(), size(), isempty(), set(), append(),
  39 + insert(), remove(), reserve(), extend()). The hashdu() method has
  40 + been renamed to contains() for compliance with other container classes.
  41 + The hdu() methods have been renamed to at(), also for compliance.
  42 + Boolean arguments are now passed as const references, and members are
  43 + returned as const references. HDU access operators[] have been
  44 + implemented to access FITS extensions without range checking.
  45 +
36 46 GFitsTable
37 47 The column table operator[] now returns a pointer instead of a
38 48 reference. Set set() method has been added for column setting.
... ...
include/GFits.hpp
1 1 /***************************************************************************
2   - * GFits.hpp - FITS file access class *
  2 + * GFits.hpp - FITS file class *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2008-2013 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file GFits.hpp
23   - * @brief FITS file access class interface definition
  23 + * @brief FITS file class interface definition
24 24 * @author Juergen Knoedlseder
25 25 */
26 26  
... ... @@ -30,7 +30,7 @@
30 30 /* __ Includes ___________________________________________________________ */
31 31 #include <string>
32 32 #include <vector>
33   -#include "GBase.hpp"
  33 +#include "GContainer.hpp"
34 34 #include "GFitsHDU.hpp"
35 35 #include "GFitsImage.hpp"
36 36 #include "GFitsTable.hpp"
... ... @@ -39,44 +39,73 @@
39 39 /***********************************************************************//**
40 40 * @class GFits
41 41 *
42   - * @brief FITS file access class
  42 + * @brief FITS file class
43 43 *
44   - * GFits is the basic FITS file interface. All FITS file handlings operate
45   - * via members of GFits. A FITS file is composed of Header Data Units (HDU)
46   - * which are implemented by the GFitsHDU class. Each HDU is composed of a
47   - * header (GFitsHeader) and some data (GFitsData).
  44 + * This class provides a physical representation of a FITS file in memory.
  45 + * It handles creation, manipulation, writing and reading of FITS files.
  46 + * As a FITS file is a collection of Header Data Units (HDUs), also known
  47 + * as FITS file extensions, the class is designed as a container class of
  48 + * HDUs.
  49 + *
  50 + * HDUs are represented by the abstract GFitsHDU base class. A HDU may be
  51 + * either an image, represented by the abstract GFitsImage base class, or
  52 + * a table, represented by the abstract GFitsTable class. The image() and
  53 + * table() method allow accessing the HDUs. HDUs may be accessed by index
  54 + * (also called extension number) or by extension name.
48 55 ***************************************************************************/
49   -class GFits : public GBase {
  56 +class GFits : public GContainer {
50 57  
51 58 public:
52 59 // Constructors and destructors
53 60 GFits(void);
54   - explicit GFits(const std::string& filename, bool create = false);
  61 + explicit GFits(const std::string& filename, const bool& create = false);
55 62 GFits(const GFits& fits);
56 63 virtual ~GFits(void);
57 64  
58 65 // Operators
59 66 GFits& operator=(const GFits& fits);
  67 + GFitsHDU* operator[](const int& extno);
  68 + const GFitsHDU* operator[](const int& extno) const;
  69 + GFitsHDU* operator[](const std::string& extname);
  70 + const GFitsHDU* operator[](const std::string& extname) const;
60 71  
61 72 // Methods
62   - void clear(void);
63   - GFits* clone(void) const;
64   - int size(void) const;
65   - void open(const std::string& filename, bool create = false);
66   - void save(bool clobber = false);
67   - void saveto(const std::string& filename, bool clobber = false);
68   - void close(void);
69   - void append(const GFitsHDU& hdu);
70   - bool hashdu(const std::string& extname) const;
71   - bool hashdu(int extno) const;
72   - GFitsHDU* hdu(const std::string& extname) const;
73   - GFitsHDU* hdu(int extno) const;
74   - GFitsImage* image(const std::string& extname) const;
75   - GFitsImage* image(int extno) const;
76   - GFitsTable* table(const std::string& extname) const;
77   - GFitsTable* table(int extno) const;
78   - std::string name(void) const { return m_filename; }
79   - std::string print(const GChatter& chatter = NORMAL) const;
  73 + void clear(void);
  74 + GFits* clone(void) const;
  75 + GFitsHDU* at(const int& extno);
  76 + const GFitsHDU* at(const int& extno) const;
  77 + GFitsHDU* at(const std::string& extname);
  78 + const GFitsHDU* at(const std::string& extname) const;
  79 + GFitsImage* image(const int& extno);
  80 + const GFitsImage* image(const int& extno) const;
  81 + GFitsImage* image(const std::string& extname);
  82 + const GFitsImage* image(const std::string& extname) const;
  83 + GFitsTable* table(const int& extno);
  84 + const GFitsTable* table(const int& extno) const;
  85 + GFitsTable* table(const std::string& extname);
  86 + const GFitsTable* table(const std::string& extname) const;
  87 + int size(void) const;
  88 + bool isempty(void) const;
  89 + GFitsHDU* set(const int& extno, const GFitsHDU& hdu);
  90 + GFitsHDU* set(const std::string& extname, const GFitsHDU& hdu);
  91 + GFitsHDU* append(const GFitsHDU& hdu);
  92 + GFitsHDU* insert(const int& extno, const GFitsHDU& hdu);
  93 + GFitsHDU* insert(const std::string& extname, const GFitsHDU& hdu);
  94 + void remove(const int& extno);
  95 + void remove(const std::string& extname);
  96 + void reserve(const int& num);
  97 + void extend(const GFits& fits);
  98 + bool contains(const int& extno) const;
  99 + bool contains(const std::string& extname) const;
  100 + const std::string& filename(void) const;
  101 + int extno(const std::string& extname) const;
  102 + void open(const std::string& filename,
  103 + const bool& create = false);
  104 + void save(const bool& clobber = false);
  105 + void saveto(const std::string& filename,
  106 + const bool& clobber = false);
  107 + void close(void);
  108 + std::string print(const GChatter& chatter = NORMAL) const;
80 109  
81 110 // Complex single precision type
82 111 typedef struct {
... ... @@ -106,4 +135,160 @@ private:
106 135 bool m_created; //!< FITS file has been created (true/false)
107 136 };
108 137  
  138 +
  139 +/***********************************************************************//**
  140 + * @brief Get pointer to HDU
  141 + *
  142 + * @param[in] extno Extension number [0,...,size()-1].
  143 + * @return Pointer to HDU.
  144 + *
  145 + * Returns a pointer to the HDU with the specified extension number @p extno.
  146 + * No range checking is performed. If the HDU is not valid, NULL is returned.
  147 + ***************************************************************************/
  148 +inline
  149 +GFitsHDU* GFits::operator[](const int& extno)
  150 +{
  151 + return (m_hdu[extno]);
  152 +}
  153 +
  154 +
  155 +/***********************************************************************//**
  156 + * @brief Get pointer to HDU (const version)
  157 + *
  158 + * @param[in] extno Extension number [0,...,size()-1].
  159 + * @return Pointer to HDU.
  160 + *
  161 + * Returns a pointer to the HDU with the specified extension number @p extno.
  162 + * No range checking is performed. If the HDU is not valid, NULL is returned.
  163 + ***************************************************************************/
  164 +inline
  165 +const GFitsHDU* GFits::operator[](const int& extno) const
  166 +{
  167 + return (m_hdu[extno]);
  168 +}
  169 +
  170 +
  171 +/***********************************************************************//**
  172 + * @brief Get pointer to HDU
  173 + *
  174 + * @param[in] extname Name of HDU extension.
  175 + * @return Pointer to HDU.
  176 + *
  177 + * Returns a pointer to the HDU with the specified @p extname. No checking
  178 + * for the existence of @p extname is performed. If the HDU is not valid,
  179 + * NULL is returned.
  180 + ***************************************************************************/
  181 +inline
  182 +GFitsHDU* GFits::operator[](const std::string& extname)
  183 +{
  184 + return at(extname);
  185 +}
  186 +
  187 +
  188 +/***********************************************************************//**
  189 + * @brief Get pointer to HDU (const version)
  190 + *
  191 + * @param[in] extname Name of HDU extension.
  192 + * @return Pointer to HDU.
  193 + *
  194 + * Returns a pointer to the HDU with the specified @p extname. No checking
  195 + * for the existence of @p extname is performed. If the HDU is not valid,
  196 + * NULL is returned.
  197 + ***************************************************************************/
  198 +inline
  199 +const GFitsHDU* GFits::operator[](const std::string& extname) const
  200 +{
  201 + return at(extname);
  202 +}
  203 +
  204 +
  205 +/***********************************************************************//**
  206 + * @brief Return number of HDUs in FITS file
  207 + *
  208 + * @return Number of HDUs in FITS file.
  209 + *
  210 + * Returns the number of Header Data Units (HDUs) in the FITS file.
  211 + ***************************************************************************/
  212 +inline
  213 +int GFits::size(void) const
  214 +{
  215 + return (m_hdu.size());
  216 +}
  217 +
  218 +
  219 +/***********************************************************************//**
  220 + * @brief Signals if there are no HDUs in FITS file
  221 + *
  222 + * @return True if FITS file is empty, false otherwise.
  223 + *
  224 + * Signals if the FITS file does not contain any HDUs.
  225 + ***************************************************************************/
  226 +inline
  227 +bool GFits::isempty(void) const
  228 +{
  229 + return (m_hdu.empty());
  230 +}
  231 +
  232 +
  233 +/***********************************************************************//**
  234 + * @brief Reserves space for HDUs in FITS file
  235 + *
  236 + * @param[in] num Number of HDUs
  237 + *
  238 + * Reserves space for @p num HDUs in the FITS file.
  239 + ***************************************************************************/
  240 +inline
  241 +void GFits::reserve(const int& num)
  242 +{
  243 + m_hdu.reserve(num);
  244 + return;
  245 +}
  246 +
  247 +
  248 +/***********************************************************************//**
  249 + * @brief Check if HDU exists in FITS file
  250 + *
  251 + * @param[in] extno Extension number [0,...,size()-1].
  252 + * @return True if HDU with specified @p extno exists, false otherwise.
  253 + *
  254 + * Returns true if a HDU with the specified extension number is present,
  255 + * false otherwise.
  256 + ***************************************************************************/
  257 +inline
  258 +bool GFits::contains(const int& extno) const
  259 +{
  260 + return (extno >= 0 && extno < size());
  261 +}
  262 +
  263 +
  264 +/***********************************************************************//**
  265 + * @brief Check if HDU exists in FITS file
  266 + *
  267 + * @param[in] extname Name of HDU extension.
  268 + * @return True if HDU with specified @p extname exists, false otherwise.
  269 + *
  270 + * Returns true if a HDU with the specified extension name is present,
  271 + * false otherwise.
  272 + ***************************************************************************/
  273 +inline
  274 +bool GFits::contains(const std::string& extname) const
  275 +{
  276 + return (extno(extname) != -1);
  277 +}
  278 +
  279 +
  280 +/***********************************************************************//**
  281 + * @brief Return FITS filename
  282 + *
  283 + * @return FITS filename.
  284 + *
  285 + * Returns the FITS filename. If the object is not yet associated to a file
  286 + * an empty string will be returned.
  287 + ***************************************************************************/
  288 +inline
  289 +const std::string& GFits::filename(void) const
  290 +{
  291 + return (m_filename);
  292 +}
  293 +
109 294 #endif /* GFITS_HPP */
... ...
inst/com/src/GCOMEventCube.cpp
... ... @@ -406,19 +406,19 @@ void GCOMEventCube::save(const std::string&amp; filename, bool clobber) const
406 406 /***********************************************************************//**
407 407 * @brief Read COMPTEL event cube from FITS file
408 408 *
409   - * @param[in] file FITS file.
  409 + * @param[in] fits FITS file.
410 410 *
411 411 * Reads an COMPTEL event cube from a DRE FITS file. The event cube is loaded
412 412 * into a skymap and the header keywords are analyzed to determine the
413 413 * scatter angle axis, the energy range and the time range.
414 414 ***************************************************************************/
415   -void GCOMEventCube::read(const GFits& file)
  415 +void GCOMEventCube::read(const GFits& fits)
416 416 {
417 417 // Clear object
418 418 clear();
419 419  
420 420 // Get HDU
421   - GFitsImage* hdu = file.image("Primary");
  421 + const GFitsImage* hdu = fits.image("Primary");
422 422  
423 423 // Load counts map as sky map
424 424 m_map.read(hdu);
... ...
inst/com/src/GCOMObservation.cpp
... ... @@ -704,7 +704,7 @@ void GCOMObservation::load_dre(const std::string&amp; drename)
704 704 m_events->read(file);
705 705  
706 706 // Read observation attributes from primary extension
707   - GFitsHDU* hdu = file.hdu(0);
  707 + GFitsHDU* hdu = file[0];
708 708 read_attributes(hdu);
709 709  
710 710 // Close FITS file
... ...
inst/cta/src/GCTAAeff2D.cpp
... ... @@ -283,7 +283,7 @@ void GCTAAeff2D::read(const GFits* fits)
283 283 m_aeff.clear();
284 284  
285 285 // Get pointer to effective area HDU
286   - GFitsTable* hdu = fits->table("EFFECTIVE AREA");
  286 + const GFitsTable* hdu = fits->table("EFFECTIVE AREA");
287 287  
288 288 // Read effective area table
289 289 m_aeff.read(hdu);
... ...
inst/cta/src/GCTAEventCube.cpp
... ... @@ -316,13 +316,13 @@ void GCTAEventCube::load(const std::string&amp; filename)
316 316 clear();
317 317  
318 318 // Open counts map FITS file
319   - GFits file(filename);
  319 + GFits fits(filename);
320 320  
321 321 // Load counts map
322   - read(file);
  322 + read(fits);
323 323  
324 324 // Close FITS file
325   - file.close();
  325 + fits.close();
326 326  
327 327 // Return
328 328 return;
... ... @@ -356,7 +356,7 @@ void GCTAEventCube::save(const std::string&amp; filename, bool clobber) const
356 356 /***********************************************************************//**
357 357 * @brief Read CTA event cube from FITS file
358 358 *
359   - * @param[in] file FITS file.
  359 + * @param[in] fits FITS file.
360 360 *
361 361 * It is assumed that the counts map resides in the primary extension of the
362 362 * FITS file, the energy boundaries reside in the EBOUNDS extension and the
... ... @@ -364,15 +364,15 @@ void GCTAEventCube::save(const std::string&amp; filename, bool clobber) const
364 364 * object before loading, thus any events residing in the object before
365 365 * loading will be lost.
366 366 ***************************************************************************/
367   -void GCTAEventCube::read(const GFits& file)
  367 +void GCTAEventCube::read(const GFits& fits)
368 368 {
369 369 // Clear object
370 370 clear();
371 371  
372 372 // Get HDUs
373   - GFitsImage* hdu_cntmap = file.image("Primary");
374   - GFitsTable* hdu_ebounds = file.table("EBOUNDS");
375   - GFitsTable* hdu_gti = file.table("GTI");
  373 + const GFitsImage* hdu_cntmap = fits.image("Primary");
  374 + const GFitsTable* hdu_ebounds = fits.table("EBOUNDS");
  375 + const GFitsTable* hdu_gti = fits.table("GTI");
376 376  
377 377 // Load counts map
378 378 read_cntmap(hdu_cntmap);
... ... @@ -391,18 +391,18 @@ void GCTAEventCube::read(const GFits&amp; file)
391 391 /***********************************************************************//**
392 392 * @brief Write CTA event cube into FITS file.
393 393 *
394   - * @param[in] file FITS file.
  394 + * @param[in] fits FITS file.
395 395 ***************************************************************************/
396   -void GCTAEventCube::write(GFits& file) const
  396 +void GCTAEventCube::write(GFits& fits) const
397 397 {
398 398 // Write cube
399   - m_map.write(&file);
  399 + m_map.write(&fits);
400 400  
401 401 // Write energy boundaries
402   - ebounds().write(&file);
  402 + ebounds().write(&fits);
403 403  
404 404 // Write Good Time intervals
405   - gti().write(&file);
  405 + gti().write(&fits);
406 406  
407 407 // Return
408 408 return;
... ...
inst/cta/src/GCTAEventList.cpp
... ... @@ -303,18 +303,18 @@ void GCTAEventList::save(const std::string&amp; filename, bool clobber) const
303 303 * @todo Ultimately, any events file should have a GTI extension, hence the
304 304 * extraction of GTIs from TSTART and TSTOP should not be necessary.
305 305 ***************************************************************************/
306   -void GCTAEventList::read(const GFits& file)
  306 +void GCTAEventList::read(const GFits& fits)
307 307 {
308 308 // Clear object
309 309 clear();
310 310  
311 311 // Get event list HDU
312   - GFitsTable* events = file.table("EVENTS");
  312 + const GFitsTable* events = fits.table("EVENTS");
313 313  
314 314 // If we have a GTI extension, then read Good Time Intervals from that
315 315 // extension
316   - if (file.hashdu("GTI")) {
317   - GFitsTable* gti = file.table("GTI");
  316 + if (fits.contains("GTI")) {
  317 + const GFitsTable* gti = fits.table("GTI");
318 318 m_gti.read(gti);
319 319 }
320 320  
... ...
inst/cta/src/GCTAObservation.cpp
... ... @@ -760,17 +760,17 @@ void GCTAObservation::load_unbinned(const std::string&amp; filename)
760 760 m_events = events;
761 761  
762 762 // Open FITS file
763   - GFits file(filename);
  763 + GFits fits(filename);
764 764  
765 765 // Read event list
766   - events->read(file);
  766 + events->read(fits);
767 767  
768 768 // Read observation attributes from EVENTS extension
769   - GFitsHDU* hdu = file.hdu("EVENTS");
  769 + const GFitsHDU* hdu = fits.at("EVENTS");
770 770 read_attributes(hdu);
771 771  
772 772 // Close FITS file
773   - file.close();
  773 + fits.close();
774 774  
775 775 // Store event filename
776 776 m_eventfile = filename;
... ... @@ -799,17 +799,17 @@ void GCTAObservation::load_binned(const std::string&amp; filename)
799 799 m_events = events;
800 800  
801 801 // Open FITS file
802   - GFits file(filename);
  802 + GFits fits(filename);
803 803  
804 804 // Read event cube
805   - events->read(file);
  805 + events->read(fits);
806 806  
807 807 // Read observation attributes from primary extension
808   - GFitsHDU* hdu = file.hdu(0);
  808 + const GFitsHDU* hdu = fits.at(0);
809 809 read_attributes(hdu);
810 810  
811 811 // Close FITS file
812   - file.close();
  812 + fits.close();
813 813  
814 814 // Store event filename
815 815 m_eventfile = filename;
... ... @@ -842,7 +842,7 @@ void GCTAObservation::save(const std::string&amp; filename, bool clobber) const
842 842 list->write(fits);
843 843  
844 844 // Write observation attributes into EVENTS header
845   - GFitsHDU* hdu = fits.hdu("EVENTS");
  845 + GFitsHDU* hdu = fits.at("EVENTS");
846 846 write_attributes(hdu);
847 847  
848 848 } // endif: observation contained an event list
... ... @@ -856,7 +856,7 @@ void GCTAObservation::save(const std::string&amp; filename, bool clobber) const
856 856 cube->write(fits);
857 857  
858 858 // Write observation attributes into primary header
859   - GFitsHDU* hdu = fits.hdu(0);
  859 + GFitsHDU* hdu = fits.at(0);
860 860 write_attributes(hdu);
861 861  
862 862 } // endelse: observation contained an event cube
... ...
inst/cta/src/GCTAResponse.cpp
... ... @@ -659,14 +659,14 @@ void GCTAResponse::load_aeff(const std::string&amp; filename)
659 659  
660 660 // If file contains an "EFFECTIVE AREA" extension then load it
661 661 // as CTA response table
662   - if (file.hashdu("EFFECTIVE AREA")) {
  662 + if (file.contains("EFFECTIVE AREA")) {
663 663 file.close();
664 664 m_aeff = new GCTAAeff2D(filename);
665 665 }
666 666  
667 667 // ... else if file contains a "SPECRESP" extension then load it
668 668 // as ARF
669   - else if (file.hashdu("SPECRESP")) {
  669 + else if (file.contains("SPECRESP")) {
670 670 file.close();
671 671 m_aeff = new GCTAAeffArf(filename);
672 672 }
... ... @@ -723,7 +723,7 @@ void GCTAResponse::load_psf(const std::string&amp; filename)
723 723  
724 724 // If file contains a "POINT SPREAD FUNCTION" extension then load it
725 725 // as CTA response table
726   - if (file.hashdu("POINT SPREAD FUNCTION")) {
  726 + if (file.contains("POINT SPREAD FUNCTION")) {
727 727 file.close();
728 728 m_psf = new GCTAPsf2D(filename);
729 729 }
... ...
inst/lat/src/GLATAeff.cpp
... ... @@ -331,7 +331,7 @@ void GLATAeff::read(const GFits* fits)
331 331 clear();
332 332  
333 333 // Get pointer to effective area HDU
334   - GFitsTable* hdu_aeff = fits->table("EFFECTIVE AREA");
  334 + const GFitsTable* hdu_aeff = fits->table("EFFECTIVE AREA");
335 335  
336 336 // Read effective area
337 337 read_aeff(hdu_aeff);
... ... @@ -341,7 +341,7 @@ void GLATAeff::read(const GFits* fits)
341 341 try {
342 342  
343 343 // Get pointer to efficiency factor HDU
344   - GFitsTable* hdu_eff = fits->table("EFFICIENCY_PARAMS");
  344 + const GFitsTable* hdu_eff = fits->table("EFFICIENCY_PARAMS");
345 345  
346 346 // Read efficiency factors
347 347 read_efficiency(hdu_eff);
... ...
inst/lat/src/GLATEdisp.cpp
... ... @@ -239,8 +239,8 @@ void GLATEdisp::read(const GFits&amp; fits)
239 239 clear();
240 240  
241 241 // Get pointer to effective area HDU
242   - GFitsTable* hdu_edisp = fits.table("ENERGY DISPERSION");
243   - GFitsTable* hdu_scale = fits.table("EDISP_SCALING_PARAMS");
  242 + const GFitsTable* hdu_edisp = fits.table("ENERGY DISPERSION");
  243 + const GFitsTable* hdu_scale = fits.table("EDISP_SCALING_PARAMS");
244 244 if (hdu_edisp == NULL)
245 245 throw GException::fits_hdu_not_found(G_READ, "ENERGY DISPERSION");
246 246 if (hdu_scale == NULL)
... ...
inst/lat/src/GLATEventCube.cpp
... ... @@ -323,7 +323,7 @@ void GLATEventCube::save(const std::string&amp; filename, bool clobber) const
323 323 /***********************************************************************//**
324 324 * @brief Read LAT event cube from FITS file.
325 325 *
326   - * @param[in] file FITS file.
  326 + * @param[in] fits FITS file.
327 327 *
328 328 * It is assumed that the counts map resides in the primary extension of the
329 329 * FITS file, the energy boundaries reside in the EBOUNDS extension and the
... ... @@ -331,15 +331,15 @@ void GLATEventCube::save(const std::string&amp; filename, bool clobber) const
331 331 * object before loading, thus any events residing in the object before
332 332 * loading will be lost.
333 333 ***************************************************************************/
334   -void GLATEventCube::read(const GFits& file)
  334 +void GLATEventCube::read(const GFits& fits)
335 335 {
336 336 // Clear object
337 337 clear();
338 338  
339 339 // Get HDUs
340   - GFitsImage* hdu_cntmap = file.image("Primary");
341   - GFitsTable* hdu_ebounds = file.table("EBOUNDS");
342   - GFitsTable* hdu_gti = file.table("GTI");
  340 + const GFitsImage* hdu_cntmap = fits.image("Primary");
  341 + const GFitsTable* hdu_ebounds = fits.table("EBOUNDS");
  342 + const GFitsTable* hdu_gti = fits.table("GTI");
343 343  
344 344 // Load counts map
345 345 read_cntmap(hdu_cntmap);
... ... @@ -351,9 +351,9 @@ void GLATEventCube::read(const GFits&amp; file)
351 351 read_gti(hdu_gti);
352 352  
353 353 // Load additional source maps
354   - for (int i = 1; i < file.size(); ++i) {
355   - if (file.hdu(i)->exttype() == GFitsHDU::HT_IMAGE) {
356   - GFitsImage* hdu_srcmap = file.image(i);
  354 + for (int i = 1; i < fits.size(); ++i) {
  355 + if (fits.at(i)->exttype() == GFitsHDU::HT_IMAGE) {
  356 + const GFitsImage* hdu_srcmap = fits.image(i);
357 357 read_srcmap(hdu_srcmap);
358 358 }
359 359 }
... ... @@ -366,11 +366,11 @@ void GLATEventCube::read(const GFits&amp; file)
366 366 /***********************************************************************//**
367 367 * @brief Write LAT event cube into FITS file
368 368 *
369   - * @param[in] file FITS file.
  369 + * @param[in] fits FITS file.
370 370 *
371 371 * @todo To be implemented.
372 372 ***************************************************************************/
373   -void GLATEventCube::write(GFits& file) const
  373 +void GLATEventCube::write(GFits& fits) const
374 374 {
375 375 // Return
376 376 return;
... ...
inst/lat/src/GLATEventList.cpp
... ... @@ -277,7 +277,7 @@ void GLATEventList::read(const GFits&amp; file)
277 277 clear();
278 278  
279 279 // Get HDU
280   - GFitsTable* hdu = file.table("EVENTS");
  280 + const GFitsTable* hdu = file.table("EVENTS");
281 281  
282 282 // Continue only if event HDU is valid
283 283 if (hdu != NULL) {
... ... @@ -292,8 +292,8 @@ void GLATEventList::read(const GFits&amp; file)
292 292  
293 293 // If we have a GTI extension, then read Good Time Intervals from that
294 294 // extension
295   - if (file.hashdu("GTI")) {
296   - GFitsTable* gti = file.table("GTI");
  295 + if (file.contains("GTI")) {
  296 + const GFitsTable* gti = file.table("GTI");
297 297 m_gti.read(gti);
298 298 }
299 299  
... ...
inst/lat/src/GLATPsf.cpp
... ... @@ -302,13 +302,13 @@ void GLATPsf::read(const GFits&amp; fits)
302 302 clear();
303 303  
304 304 // Get pointer to PSF parameters table
305   - GFitsTable* hdu_rpsf = fits.table("RPSF");
  305 + const GFitsTable* hdu_rpsf = fits.table("RPSF");
306 306 if (hdu_rpsf == NULL) {
307 307 throw GException::fits_hdu_not_found(G_READ, "RPSF");
308 308 }
309 309  
310 310 // Get pointer to PSF scaling parameters table
311   - GFitsTable* hdu_scale = fits.table("PSF_SCALING_PARAMS");
  311 + const GFitsTable* hdu_scale = fits.table("PSF_SCALING_PARAMS");
312 312 if (hdu_scale == NULL) {
313 313 throw GException::fits_hdu_not_found(G_READ, "PSF_SCALING_PARAMS");
314 314 }
... ...
inst/mwl/src/GMWLSpectrum.cpp
1 1 /***************************************************************************
2   - * GMWLSpectrum.cpp - Multi-wavelength spectrum class *
  2 + * GMWLSpectrum.cpp - Multi-wavelength spectrum class *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2010-2013 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -369,16 +369,16 @@ void GMWLSpectrum::read(const GFits&amp; file)
369 369 /***********************************************************************//**
370 370 * @brief Read spectrum from FITS file
371 371 *
372   - * @param[in] file FITS file.
  372 + * @param[in] fits FITS file.
373 373 * @param[in] extname FITS extension name.
374 374 ***************************************************************************/
375   -void GMWLSpectrum::read(const GFits& file, const std::string& extname)
  375 +void GMWLSpectrum::read(const GFits& fits, const std::string& extname)
376 376 {
377 377 // Clear object
378 378 clear();
379 379  
380 380 // Get table pointer
381   - GFitsTable* table = file.table(extname);
  381 + const GFitsTable* table = fits.table(extname);
382 382  
383 383 // Read spectrum from table
384 384 read_fits(table);
... ... @@ -391,7 +391,7 @@ void GMWLSpectrum::read(const GFits&amp; file, const std::string&amp; extname)
391 391 /***********************************************************************//**
392 392 * @brief Read spectrum from FITS file
393 393 *
394   - * @param[in] file FITS file.
  394 + * @param[in] fits FITS file.
395 395 * @param[in] extno Extension number of spectrum.
396 396 *
397 397 * @exception GMWLException::file_open_error
... ... @@ -401,16 +401,16 @@ void GMWLSpectrum::read(const GFits&amp; file, const std::string&amp; extname)
401 401 * In no extension number if specified (or if extno=0) then the spectrum
402 402 * is loaded from the first table extension that is found in the file.
403 403 ***************************************************************************/
404   -void GMWLSpectrum::read(const GFits& file, int extno)
  404 +void GMWLSpectrum::read(const GFits& fits, int extno)
405 405 {
406 406 // Clear object
407 407 clear();
408 408  
409 409 // If the extension number is 0 then load first FITS table in file.
410 410 if (extno == 0) {
411   - for (int i = 0; i < file.size(); ++i) {
412   - if (file.hdu(i)->exttype() == GFitsHDU::HT_ASCII_TABLE ||
413   - file.hdu(i)->exttype() == GFitsHDU::HT_BIN_TABLE) {
  411 + for (int i = 0; i < fits.size(); ++i) {
  412 + if (fits.at(i)->exttype() == GFitsHDU::HT_ASCII_TABLE ||
  413 + fits.at(i)->exttype() == GFitsHDU::HT_BIN_TABLE) {
414 414 extno = i;
415 415 break;
416 416 }
... ... @@ -418,12 +418,13 @@ void GMWLSpectrum::read(const GFits&amp; file, int extno)
418 418 }
419 419  
420 420 // If we found no table then throw an exception
421   - if (extno == 0)
422   - throw GMWLException::file_open_error(G_READ, file.name(),
  421 + if (extno == 0) {
  422 + throw GMWLException::file_open_error(G_READ, fits.filename(),
423 423 "No table found in file.");
  424 + }
424 425  
425 426 // Get table pointer
426   - GFitsTable* table = file.table(extno);
  427 + const GFitsTable* table = fits.table(extno);
427 428  
428 429 // Read spectrum from table
429 430 read_fits(table);
... ...
pyext/GFits.i
1 1 /***************************************************************************
2   - * GFits.i - FITS file access class *
  2 + * GFits.hpp - FITS file class *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2008-2013 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file GFits.i
23   - * @brief Fits file access class Python interface definition
  23 + * @brief FITS file class interface definition
24 24 * @author Juergen Knoedlseder
25 25 */
26 26 %{
... ... @@ -140,39 +140,52 @@
140 140 /***********************************************************************//**
141 141 * @class GFits
142 142 *
143   - * @brief FITS file access class
144   - *
145   - * GFits is the basic FITS file interface. All FITS file handlings operate
146   - * via members of GFits. A FITS file is composed of Header Data Units (HDU)
147   - * which are implemented by the GFitsHDU class.
  143 + * @brief FITS file class
148 144 ***************************************************************************/
149   -class GFits : public GBase {
150   -
  145 +class GFits : public GContainer {
151 146 public:
152 147 // Constructors and destructors
153 148 GFits(void);
154   - explicit GFits(const std::string& filename, bool create = false);
  149 + explicit GFits(const std::string& filename, const bool& create = false);
155 150 GFits(const GFits& fits);
156 151 virtual ~GFits(void);
157 152  
158 153 // Methods
159   - void clear(void);
160   - GFits* clone(void) const;
161   - int size(void) const;
162   - void open(const std::string& filename, bool create = false);
163   - void save(bool clobber = false);
164   - void saveto(const std::string& filename, bool clobber = false);
165   - void close(void);
166   - void append(const GFitsHDU& hdu);
167   - bool hashdu(const std::string& extname) const;
168   - bool hashdu(int extno) const;
169   - GFitsHDU* hdu(const std::string& extname) const;
170   - GFitsHDU* hdu(int extno) const;
171   - GFitsImage* image(const std::string& extname) const;
172   - GFitsImage* image(int extno) const;
173   - GFitsTable* table(const std::string& extname) const;
174   - GFitsTable* table(int extno) const;
175   - std::string name(void) const;
  154 + void clear(void);
  155 + GFits* clone(void) const;
  156 + GFitsHDU* at(const int& extno);
  157 + const GFitsHDU* at(const int& extno) const;
  158 + GFitsHDU* at(const std::string& extname);
  159 + const GFitsHDU* at(const std::string& extname) const;
  160 + GFitsImage* image(const int& extno);
  161 + const GFitsImage* image(const int& extno) const;
  162 + GFitsImage* image(const std::string& extname);
  163 + const GFitsImage* image(const std::string& extname) const;
  164 + GFitsTable* table(const int& extno);
  165 + const GFitsTable* table(const int& extno) const;
  166 + GFitsTable* table(const std::string& extname);
  167 + const GFitsTable* table(const std::string& extname) const;
  168 + int size(void) const;
  169 + bool isempty(void) const;
  170 + GFitsHDU* set(const int& extno, const GFitsHDU& hdu);
  171 + GFitsHDU* set(const std::string& extname, const GFitsHDU& hdu);
  172 + GFitsHDU* append(const GFitsHDU& hdu);
  173 + GFitsHDU* insert(const int& extno, const GFitsHDU& hdu);
  174 + GFitsHDU* insert(const std::string& extname, const GFitsHDU& hdu);
  175 + void remove(const int& extno);
  176 + void remove(const std::string& extname);
  177 + void reserve(const int& num);
  178 + void extend(const GFits& fits);
  179 + bool contains(const int& extno) const;
  180 + bool contains(const std::string& extname) const;
  181 + const std::string& filename(void) const;
  182 + int extno(const std::string& extname) const;
  183 + void open(const std::string& filename,
  184 + const bool& create = false);
  185 + void save(const bool& clobber = false);
  186 + void saveto(const std::string& filename,
  187 + const bool& clobber = false);
  188 + void close(void);
176 189 };
177 190  
178 191  
... ... @@ -180,6 +193,34 @@ public:
180 193 * @brief GFits class SWIG extension
181 194 ***************************************************************************/
182 195 %extend GFits {
  196 + GFitsHDU* __getitem__(const int& extno) {
  197 + if (extno >= 0 && extno < self->size()) {
  198 + return (*self)[extno];
  199 + }
  200 + else {
  201 + throw GException::out_of_range("__getitem__(int)",
  202 + "Extension number",
  203 + extno, self->size());
  204 + }
  205 + }
  206 + GFitsHDU* __getitem__(const std::string& extname) {
  207 + return (*self)[extname];
  208 + }
  209 + void __setitem__(const int& extno, const GFitsHDU& hdu) {
  210 + if (extno >= 0 && extno < self->size()) {
  211 + self->set(extno, hdu);
  212 + return;
  213 + }
  214 + else {
  215 + throw GException::out_of_range("__setitem__(int)",
  216 + "Extension number",
  217 + extno, self->size());
  218 + }
  219 + }
  220 + void __setitem__(const std::string& extname, const GFitsHDU& hdu) {
  221 + self->set(extname, hdu);
  222 + return;
  223 + }
183 224 GFits copy() {
184 225 return (*self);
185 226 }
... ...
src/app/GPars.cpp
... ... @@ -282,10 +282,12 @@ GPars* GPars::clone(void) const
282 282 ***************************************************************************/
283 283 GPar& GPars::at(const int& index)
284 284 {
285   - // Raise exception if index is out of range
  285 + // Compile option: raise an exception if index is out of range
  286 + #if defined(G_RANGE_CHECK)
286 287 if (index < 0 || index >= size()) {
287 288 throw GException::out_of_range(G_AT, "Parameter index", index, size());
288 289 }
  290 + #endif
289 291  
290 292 // Return reference
291 293 return (m_pars[index]);
... ... @@ -302,10 +304,12 @@ GPar&amp; GPars::at(const int&amp; index)
302 304 ***************************************************************************/
303 305 const GPar& GPars::at(const int& index) const
304 306 {
305   - // Raise exception if index is out of range
  307 + // Compile option: raise an exception if index is out of range
  308 + #if defined(G_RANGE_CHECK)
306 309 if (index < 0 || index >= size()) {
307 310 throw GException::out_of_range(G_AT, "Parameter index", index, size());
308 311 }
  312 + #endif
309 313  
310 314 // Return reference
311 315 return (m_pars[index]);
... ...
src/fits/GFits.cpp
... ... @@ -46,15 +46,21 @@
46 46 #include "GTools.hpp"
47 47  
48 48 /* __ Method name definitions ____________________________________________ */
  49 +#define G_AT1 "GFits::at(int&)"
  50 +#define G_AT2 "GFits::at(std::string&)"
  51 +#define G_IMAGE1 "GFits::image(int&)"
  52 +#define G_IMAGE2 "GFits::image(std::string&)"
  53 +#define G_TABLE1 "GFits::table(int&)"
  54 +#define G_TABLE2 "GFits::table(std::string&)"
  55 +#define G_SET1 "GFits::set(int&, GFitsHDU&)"
  56 +#define G_SET2 "GFits::set(std::string&, GFitsHDU&)"
  57 +#define G_INSERT1 "GFits::insert(const int& extno, GFitsHDU& hdu)"
  58 +#define G_INSERT2 "GFits::insert(std::string&, GFitsHDU& hdu)"
  59 +#define G_REMOVE1 "GFits::remove(int&)"
  60 +#define G_REMOVE2 "GFits::remove(std::string&)"
49 61 #define G_OPEN "GFits::open(std::string&)"
50   -#define G_SAVE "GFits::save()"
51   -#define G_SAVETO "GFits::saveto(std::string&,bool)"
52   -#define G_HDU1 "GFits::hdu(std::string&)"
53   -#define G_HDU2 "GFits::hdu(int)"
54   -#define G_IMAGE1 "GFits::image(std::string&)"
55   -#define G_IMAGE2 "GFits::image(int)"
56   -#define G_TABLE1 "GFits::table(std::string&)"
57   -#define G_TABLE2 "GFits::table(int)"
  62 +#define G_SAVE "GFits::save(bool&)"
  63 +#define G_SAVETO "GFits::saveto(std::string&, bool&)"
58 64 #define G_FREE_MEM "GFits::free_members()"
59 65 #define G_NEW_IMAGE "GFits::new_image()"
60 66  
... ... @@ -87,15 +93,15 @@ GFits::GFits(void)
87 93  
88 94  
89 95 /***********************************************************************//**
90   - * @brief Constructor from FITS file
  96 + * @brief FITS file constructor
91 97 *
92 98 * @param[in] filename FITS file name.
93   - * @param[in] create Create FITS file if it does not exist (default=false)
  99 + * @param[in] create Create file if it does not exist (default=false)?
94 100 *
95 101 * Construct an object by opening a FITS file. If the file does not exist it
96   - * will (optionally) be created.
  102 + * will be created if @p create is set to true.
97 103 ***************************************************************************/
98   -GFits::GFits(const std::string& filename, bool create)
  104 +GFits::GFits(const std::string& filename, const bool& create)
99 105 {
100 106 // Initialise class members
101 107 init_members();
... ... @@ -149,8 +155,9 @@ GFits::~GFits(void)
149 155 * @brief Assignment operator
150 156 *
151 157 * @param[in] fits FITS file.
  158 + * @return FITS file.
152 159 ***************************************************************************/
153   -GFits& GFits::operator= (const GFits& fits)
  160 +GFits& GFits::operator=(const GFits& fits)
154 161 {
155 162 // Execute only if object is not identical
156 163 if (this != &fits) {
... ... @@ -178,15 +185,702 @@ GFits&amp; GFits::operator= (const GFits&amp; fits)
178 185 ==========================================================================*/
179 186  
180 187 /***********************************************************************//**
181   - * @brief Reset object to an initial state
  188 + * @brief Clear FITS file
182 189 ***************************************************************************/
183 190 void GFits::clear(void)
184 191 {
185   - // Close file and free all members
186   - free_members();
  192 + // Close file and free all members
  193 + free_members();
  194 +
  195 + // Initialise members
  196 + init_members();
  197 +
  198 + // Return
  199 + return;
  200 +}
  201 +
  202 +
  203 +/***********************************************************************//**
  204 + * @brief Clone FITS file
  205 + *
  206 + * @return Pointer to deep copy of FITS file.
  207 + ***************************************************************************/
  208 +GFits* GFits::clone(void) const
  209 +{
  210 + return new GFits(*this);
  211 +}
  212 +
  213 +
  214 +/***********************************************************************//**
  215 + * @brief Get pointer to HDU
  216 + *
  217 + * @param[in] extno Extension number [0,...,size()-1].
  218 + * @return Pointer to HDU.
  219 + *
  220 + * @exception GException::out_of_range
  221 + * Extension number is out of range.
  222 + * @exception GException::fits_hdu_not_found
  223 + * No HDU found for specified extension number.
  224 + *
  225 + * Returns a pointer to the HDU with the specified extension number @p extno.
  226 + * An exception is thrown if the HDU is not valid (i.e. NULL).
  227 + ***************************************************************************/
  228 +GFitsHDU* GFits::at(const int& extno)
  229 +{
  230 + // Compile option: raise an exception if index is out of range
  231 + #if defined(G_RANGE_CHECK)
  232 + if (extno < 0 || extno >= size()) {
  233 + throw GException::out_of_range(G_AT1, "Extension number", extno, size());
  234 + }
  235 + #endif
  236 +
  237 + // Get HDU pointer
  238 + GFitsHDU* ptr = m_hdu[extno];
  239 +
  240 + // Throw an error if HDU has not been found
  241 + if (ptr == NULL) {
  242 + std::string extname = "extno="+gammalib::str(extno);
  243 + throw GException::fits_hdu_not_found(G_AT1, extname);
  244 + }
  245 +
  246 + // Return pointer
  247 + return ptr;
  248 +}
  249 +
  250 +
  251 +/***********************************************************************//**
  252 + * @brief Get pointer to HDU (const version)
  253 + *
  254 + * @param[in] extno Extension number [0,...,size()-1].
  255 + * @return Pointer to HDU.
  256 + *
  257 + * @exception GException::out_of_range
  258 + * Extension number is out of range.
  259 + * @exception GException::fits_hdu_not_found
  260 + * No HDU found for specified extension number.
  261 + *
  262 + * Returns a pointer to the HDU with the specified extension number @p extno.
  263 + * An exception is thrown if the HDU is not valid (i.e. NULL).
  264 + ***************************************************************************/
  265 +const GFitsHDU* GFits::at(const int& extno) const
  266 +{
  267 + // Compile option: raise an exception if index is out of range
  268 + #if defined(G_RANGE_CHECK)
  269 + if (extno < 0 || extno >= size()) {
  270 + throw GException::out_of_range(G_AT1, "Extension number", extno, size());
  271 + }
  272 + #endif
  273 +
  274 + // Get HDU pointer
  275 + GFitsHDU* ptr = m_hdu[extno];
  276 +
  277 + // Throw an error if HDU has not been found
  278 + if (ptr == NULL) {
  279 + std::string extname = "extno="+gammalib::str(extno);
  280 + throw GException::fits_hdu_not_found(G_AT1, extname);
  281 + }
  282 +
  283 + // Return pointer
  284 + return ptr;
  285 +}
  286 +
  287 +
  288 +/***********************************************************************//**
  289 + * @brief Get pointer to HDU
  290 + *
  291 + * @param[in] extname Name of HDU extension.
  292 + * @return Pointer to HDU.
  293 + *
  294 + * @exception GException::fits_hdu_not_found
  295 + * No HDU with specified name has been found.
  296 + *
  297 + * Returns a pointer to the HDU with the specified @p extname. An exception
  298 + * is thrown if the HDU is not valid (i.e. NULL).
  299 + ***************************************************************************/
  300 +GFitsHDU* GFits::at(const std::string& extname)
  301 +{
  302 + // Get extenion number
  303 + int extno = this->extno(extname);
  304 + if (extno == -1) {
  305 + throw GException::fits_hdu_not_found(G_AT2, extname);
  306 + }
  307 +
  308 + // Get HDU pointer
  309 + GFitsHDU* ptr = m_hdu[extno];
  310 +
  311 + // Return pointer
  312 + return ptr;
  313 +}
  314 +
  315 +
  316 +/***********************************************************************//**
  317 + * @brief Get pointer to HDU (const version)
  318 + *
  319 + * @param[in] extname Name of HDU extension.
  320 + * @return Pointer to HDU.
  321 + *
  322 + * @exception GException::fits_hdu_not_found
  323 + * No HDU with specified name has been found.
  324 + *
  325 + * Returns a pointer to the HDU with the specified @p extname. An exception
  326 + * is thrown if the HDU is not valid (i.e. NULL).
  327 + ***************************************************************************/
  328 +const GFitsHDU* GFits::at(const std::string& extname) const
  329 +{
  330 + // Get extenion number
  331 + int extno = this->extno(extname);
  332 + if (extno == -1) {
  333 + throw GException::fits_hdu_not_found(G_AT2, extname);
  334 + }
  335 +
  336 + // Get HDU pointer
  337 + GFitsHDU* ptr = m_hdu[extno];
  338 +
  339 + // Return pointer
  340 + return ptr;
  341 +}
  342 +
  343 +
  344 +/***********************************************************************//**
  345 + * @brief Get pointer to image HDU
  346 + *
  347 + * @param[in] extno Extension number [0,...,size()-1].
  348 + * @return Pointer to FITS image.
  349 + *
  350 + * @exception GException::fits_hdu_not_image
  351 + * Requested HDU is not an image.
  352 + *
  353 + * Returns a pointer to the image HDU with extension number extno.
  354 + ***************************************************************************/
  355 +GFitsImage* GFits::image(const int& extno)
  356 +{
  357 + // Get HDU pointer
  358 + GFitsImage* ptr = dynamic_cast<GFitsImage*>(at(extno));
  359 +
  360 + // Throw an error if HDU is not an image
  361 + if (ptr == NULL) {
  362 + throw GException::fits_hdu_not_image(G_IMAGE1,
  363 + "(extno="+gammalib::str(extno)+")",
  364 + at(extno)->exttype());
  365 + }
  366 +
  367 + // Return pointer
  368 + return ptr;
  369 +}
  370 +
  371 +
  372 +/***********************************************************************//**
  373 + * @brief Get pointer to image HDU (const version)
  374 + *
  375 + * @param[in] extno Extension number [0,...,size()-1].
  376 + * @return Pointer to FITS image.
  377 + *
  378 + * @exception GException::fits_hdu_not_image
  379 + * Requested HDU is not an image.
  380 + *
  381 + * Returns a pointer to the image HDU with extension number extno.
  382 + ***************************************************************************/
  383 +const GFitsImage* GFits::image(const int& extno) const
  384 +{
  385 + // Get HDU pointer
  386 + const GFitsImage* ptr = dynamic_cast<const GFitsImage*>(at(extno));
  387 +
  388 + // Throw an error if HDU is not an image
  389 + if (ptr == NULL) {
  390 + throw GException::fits_hdu_not_image(G_IMAGE1,
  391 + "(extno="+gammalib::str(extno)+")",
  392 + at(extno)->exttype());
  393 + }
  394 +
  395 + // Return pointer
  396 + return ptr;
  397 +}
  398 +
  399 +
  400 +/***********************************************************************//**
  401 + * @brief Get pointer to image HDU
  402 + *
  403 + * @param[in] extname Name of HDU extension.
  404 + * @return Pointer to FITS image.
  405 + *
  406 + * @exception GException::fits_hdu_not_image
  407 + * Requested HDU is not an image.
  408 + *
  409 + * Returns a pointer to the image HDU with extension name extname.
  410 + ***************************************************************************/
  411 +GFitsImage* GFits::image(const std::string& extname)
  412 +{
  413 + // Get HDU pointer
  414 + GFitsImage* ptr = dynamic_cast<GFitsImage*>(at(extname));
  415 +
  416 + // Throw an error if HDU is not an image
  417 + if (ptr == NULL) {
  418 + throw GException::fits_hdu_not_image(G_IMAGE2,
  419 + extname,
  420 + at(extname)->exttype());
  421 + }
  422 +
  423 + // Return pointer
  424 + return ptr;
  425 +}
  426 +
  427 +
  428 +/***********************************************************************//**
  429 + * @brief Get pointer to image HDU (const version)
  430 + *
  431 + * @param[in] extname Name of HDU extension.
  432 + * @return Pointer to FITS image.
  433 + *
  434 + * @exception GException::fits_hdu_not_image
  435 + * Requested HDU is not an image.
  436 + *
  437 + * Returns a pointer to the image HDU with extension name extname.
  438 + ***************************************************************************/
  439 +const GFitsImage* GFits::image(const std::string& extname) const
  440 +{
  441 + // Get HDU pointer
  442 + const GFitsImage* ptr = dynamic_cast<const GFitsImage*>(at(extname));
  443 +
  444 + // Throw an error if HDU is not an image
  445 + if (ptr == NULL) {
  446 + throw GException::fits_hdu_not_image(G_IMAGE2,
  447 + extname,
  448 + at(extname)->exttype());
  449 + }
  450 +
  451 + // Return pointer
  452 + return ptr;
  453 +}
  454 +
  455 +
  456 +/***********************************************************************//**
  457 + * @brief Get pointer to table HDU
  458 + *
  459 + * @param[in] extno Extension number [0,...,size()-1].
  460 + * @return Pointer to FITS table.
  461 + *
  462 + * @exception GException::fits_hdu_not_table
  463 + * Requested HDU is not a table.
  464 + *
  465 + * Returns a pointer to the table HDU with extension number extno.
  466 + ***************************************************************************/
  467 +GFitsTable* GFits::table(const int& extno)
  468 +{
  469 + // Get HDU pointer
  470 + GFitsTable* ptr = dynamic_cast<GFitsTable*>(at(extno));
  471 +
  472 + // Throw an error if HDU is not an image
  473 + if (ptr == NULL) {
  474 + throw GException::fits_hdu_not_table(G_TABLE1,
  475 + "(extno="+gammalib::str(extno)+")",
  476 + at(extno)->exttype());
  477 + }
  478 +
  479 + // Return pointer
  480 + return ptr;
  481 +}
  482 +
  483 +
  484 +/***********************************************************************//**
  485 + * @brief Get pointer to table HDU (const version)
  486 + *
  487 + * @param[in] extno Extension number [0,...,size()-1].
  488 + * @return Pointer to FITS table.
  489 + *
  490 + * @exception GException::fits_hdu_not_table
  491 + * Requested HDU is not a table.
  492 + *
  493 + * Returns a pointer to the table HDU with extension number extno.
  494 + ***************************************************************************/
  495 +const GFitsTable* GFits::table(const int& extno) const
  496 +{
  497 + // Get HDU pointer
  498 + const GFitsTable* ptr = dynamic_cast<const GFitsTable*>(at(extno));
  499 +
  500 + // Throw an error if HDU is not an image
  501 + if (ptr == NULL) {
  502 + throw GException::fits_hdu_not_table(G_TABLE1,
  503 + "(extno="+gammalib::str(extno)+")",
  504 + at(extno)->exttype());
  505 + }
  506 +
  507 + // Return pointer
  508 + return ptr;
  509 +}
  510 +
  511 +
  512 +/***********************************************************************//**
  513 + * @brief Get pointer to table HDU
  514 + *
  515 + * @param[in] extname Name of HDU extension.
  516 + * @return Pointer to FITS table.
  517 + *
  518 + * @exception GException::fits_hdu_not_table
  519 + * Requested HDU is not a table.
  520 + *
  521 + * Returns a pointer to the table HDU with extension name extname.
  522 + ***************************************************************************/
  523 +GFitsTable* GFits::table(const std::string& extname)
  524 +{
  525 + // Get HDU pointer
  526 + GFitsTable* ptr = dynamic_cast<GFitsTable*>(at(extname));
  527 +
  528 + // Throw an error if HDU is not an image
  529 + if (ptr == NULL) {
  530 + throw GException::fits_hdu_not_table(G_TABLE2,
  531 + extname,
  532 + at(extname)->exttype());
  533 + }
  534 +
  535 + // Return pointer
  536 + return ptr;
  537 +}
  538 +
  539 +
  540 +/***********************************************************************//**
  541 + * @brief Get pointer to table HDU
  542 + *
  543 + * @param[in] extname Name of HDU extension.
  544 + * @return Pointer to FITS table.
  545 + *
  546 + * @exception GException::fits_hdu_not_table
  547 + * Requested HDU is not a table.
  548 + *
  549 + * Returns a pointer to the table HDU with extension name extname.
  550 + ***************************************************************************/
  551 +const GFitsTable* GFits::table(const std::string& extname) const
  552 +{
  553 + // Get HDU pointer
  554 + const GFitsTable* ptr = dynamic_cast<const GFitsTable*>(at(extname));
  555 +
  556 + // Throw an error if HDU is not an image
  557 + if (ptr == NULL) {
  558 + throw GException::fits_hdu_not_table(G_TABLE2,
  559 + extname,
  560 + at(extname)->exttype());
  561 + }
  562 +
  563 + // Return pointer
  564 + return ptr;
  565 +}
  566 +
  567 +
  568 +/***********************************************************************//**
  569 + * @brief Set HDU for the specified extension number
  570 + *
  571 + * @param[in] extno Extension number [0,...,size()-1].
  572 + * @param[in] hdu HDU.
  573 + * @return Pointer to cloned HDU.
  574 + *
  575 + * @exception GException::out_of_range
  576 + * Extension number out of range.
  577 + * @exception GException::invalid_argument
  578 + * Attempt to insert non-image HDU in first slot.
  579 + ***************************************************************************/
  580 +GFitsHDU* GFits::set(const int& extno, const GFitsHDU& hdu)
  581 +{
  582 + // Compile option: raise exception if index is out of range
  583 + #if defined(G_RANGE_CHECK)
  584 + if (extno < 0 || extno >= size()) {
  585 + throw GException::out_of_range(G_SET1, "Extension number", extno, size());
  586 + }
  587 + #endif
  588 +
  589 + // Throw an exception if a non-image extension should be set in the
  590 + // first slot
  591 + if (extno == 0 && hdu.exttype() != GFitsHDU::HT_IMAGE) {
  592 + std::string msg = "Attempt to set a table extension as the first"
  593 + " extension of a FITS file.\n"
  594 + "The first extension of a FITS file must be an"
  595 + " image, hence use the next slot to set a"
  596 + " table.";
  597 + throw GException::invalid_argument(G_SET1, msg);
  598 + }
  599 +
  600 + // Delete any existing HDU
  601 + if (m_hdu[extno] != NULL) delete m_hdu[extno];
  602 +
  603 + // Assign new HDU by cloning
  604 + m_hdu[extno] = hdu.clone();
  605 +
  606 + // If FITS file exists then connect cloned HDU to FITS file
  607 + if (m_fitsfile != NULL) {
  608 + __fitsfile fptr = *(FPTR(m_fitsfile));
  609 + fptr.HDUposition = extno;
  610 + m_hdu[extno]->connect(&fptr);
  611 + }
  612 + else {
  613 + m_hdu[extno]->extno(extno);
  614 + }
  615 +
  616 + // Return pointer to HDU
  617 + return (m_hdu[extno]);
  618 +}
  619 +
  620 +
  621 +/***********************************************************************//**
  622 + * @brief Set HDU for the specified extension name
  623 + *
  624 + * @param[in] extname Name of HDU extension.
  625 + * @param[in] hdu HDU.
  626 + * @return Pointer to cloned HDU.
  627 + *
  628 + * @exception GException::invalid_argument
  629 + * Extension name not found.
  630 + ***************************************************************************/
  631 +GFitsHDU* GFits::set(const std::string& extname, const GFitsHDU& hdu)
  632 +{
  633 + // Get extenion number
  634 + int extno = this->extno(extname);
  635 + if (extno == -1) {
  636 + std::string msg = "No extension with name \""+extname+"\" found in"
  637 + " FITS file.\n"
  638 + "Please specify a valid extension name.";
  639 + throw GException::invalid_argument(G_SET2, msg);
  640 + }
  641 +
  642 + // Set HDU and return pointer
  643 + return (set(extno, hdu));
  644 +}
  645 +
  646 +
  647 +/***********************************************************************//**
  648 + * @brief Append HDU to FITS file
  649 + *
  650 + * @param[in] hdu HDU.
  651 + * @return Pointer to appended HDU.
  652 + *
  653 + * Append HDU to the next free position in a FITS file. In case that no HDU
  654 + * exists so far in the FITS file and if the HDU to append is NOT an image,
  655 + * an empty primary image will be inserted as first HDU in the FITS file.
  656 + * This guarantees the compatibility with the FITS standard.
  657 + ***************************************************************************/
  658 +GFitsHDU* GFits::append(const GFitsHDU& hdu)
  659 +{
  660 + // Debug header
  661 + #if DEBUG
  662 + std::cout << "GFits::append(";
  663 + switch (hdu.exttype()) {
  664 + case GFitsHDU::HT_IMAGE:
  665 + std::cout << "GFitsImage";
  666 + break;
  667 + case GFitsHDU::HT_ASCII_TABLE:
  668 + std::cout << "GFitsAsciiTable";
  669 + break;
  670 + case GFitsHDU::HT_BIN_TABLE:
  671 + std::cout << "GFitsBinTable";
  672 + break;
  673 + default:
  674 + std::cout << "<unknown header type>";
  675 + break;
  676 + }
  677 + std::cout << ") (size=" << size() << ") -->" << std::endl;
  678 + #endif
  679 +
  680 + // Determine next free HDU number
  681 + int n_hdu = size();
  682 +
  683 + // Add primary image if required
  684 + if (n_hdu == 0 && hdu.exttype() != GFitsHDU::HT_IMAGE) {
  685 +
  686 + // Allocate primary image
  687 + GFitsHDU* primary = new_primary();
  688 +
  689 + // If FITS file exists then connect primary image to FITS file
  690 + if (m_fitsfile != NULL) {
  691 + __fitsfile fptr = *(FPTR(m_fitsfile));
  692 + fptr.HDUposition = n_hdu;
  693 + primary->connect(&fptr);
  694 + }
  695 +
  696 + // Debug information
  697 + #if DEBUG
  698 + std::cout << "Append primary image to HDU." << std::endl;
  699 + #endif
  700 +
  701 + // Push back primary image
  702 + m_hdu.push_back(primary);
  703 +
  704 + // Increment HDU number
  705 + n_hdu++;
  706 + }
  707 +
  708 + // Clone FITS HDU
  709 + GFitsHDU* ptr = hdu.clone();
  710 +
  711 + // Append HDU if it's valid
  712 + if (ptr != NULL) {
  713 +
  714 + // If FITS file exists then connect cloned HDU to FITS file
  715 + if (m_fitsfile != NULL) {
  716 + __fitsfile fptr = *(FPTR(m_fitsfile));
  717 + fptr.HDUposition = n_hdu;
  718 + ptr->connect(&fptr);
  719 + }
  720 + else {
  721 + ptr->extno(n_hdu);
  722 + }
  723 +
  724 + // Debug information
  725 + #if DEBUG
  726 + std::cout << "Append HDU (extno=" << n_hdu << ")." << std::endl;
  727 + #endif
  728 +
  729 + // Push back HDU
  730 + m_hdu.push_back(ptr);
  731 +
  732 + // Debug trailer
  733 + #if DEBUG
  734 + std::cout << "<-- GFits::append" << std::endl;
  735 + #endif
  736 +
  737 + } // endif: HDU was valid
  738 +
  739 + // Return
  740 + return ptr;
  741 +}
  742 +
  743 +
  744 +/***********************************************************************//**
  745 + * @brief Set HDU for the specified extension number
  746 + *
  747 + * @param[in] extno Extension number [0,...,size()-1].
  748 + * @param[in] hdu HDU.
  749 + * @return Pointer to cloned HDU.
  750 + *
  751 + * @exception GException::out_of_range
  752 + * Extension number out of range.
  753 + * @exception GException::invalid_argument
  754 + * Attempt to insert non-image HDU in first slot.
  755 + ***************************************************************************/
  756 +GFitsHDU* GFits::insert(const int& extno, const GFitsHDU& hdu)
  757 +{
  758 + // Compile option: raise exception if extension number is out of range
  759 + #if defined(G_RANGE_CHECK)
  760 + if (extno < 0 || extno >= size()) {
  761 + throw GException::out_of_range(G_INSERT1, "Extension number", extno, size());
  762 + }
  763 + #endif
  764 +
  765 + // Throw an exception if a non-image extension should be inserted in the
  766 + // first slot
  767 + if (extno == 0 && hdu.exttype() != GFitsHDU::HT_IMAGE) {
  768 + std::string msg = "Attempt to insert a table extension as the first"
  769 + " extension of a FITS file.\n"
  770 + "The first extension of a FITS file must be an"
  771 + " image, hence use the next slot to insert a"
  772 + " table.";
  773 + throw GException::invalid_argument(G_INSERT1, msg);
  774 + }
  775 +
  776 + // Create deep copy of HDU
  777 + GFitsHDU* ptr = hdu.clone();
  778 +
  779 + // Inserts deep copy of HDU
  780 + m_hdu.insert(m_hdu.begin() + extno, ptr);
  781 +
  782 + // If FITS file exists then connect cloned HDU to FITS file
  783 + if (m_fitsfile != NULL) {
  784 + __fitsfile fptr = *(FPTR(m_fitsfile));
  785 + fptr.HDUposition = extno;
  786 + ptr->connect(&fptr);
  787 + }
  788 + else {
  789 + ptr->extno(extno);
  790 + }
  791 +
  792 + // Update extno for all subsequent HDUs
  793 + for (int i = extno + 1; i < size(); ++i) {
  794 + m_hdu[i]->extno(i);
  795 + }
  796 +
  797 + // Return pointer to HDU
  798 + return ptr;
  799 +}
  800 +
  801 +
  802 +/***********************************************************************//**
  803 + * @brief Insert HDU into FITS file
  804 + *
  805 + * @param[in] extname Extension name.
  806 + * @param[in] hdu Extension.
  807 + * @return Pointer to deep copy of extension @p hdu.
  808 + *
  809 + * @exception GException::invalid_argument
  810 + * Extension name not found.
  811 + *
  812 + * Inserts an extension @p hdu into the FITS file before the extension with
  813 + * the specified @p extname.
  814 + ***************************************************************************/
  815 +GFitsHDU* GFits::insert(const std::string& extname, const GFitsHDU& hdu)
  816 +{
  817 + // Get extenion number
  818 + int extno = this->extno(extname);
  819 + if (extno == -1) {
  820 + std::string msg = "No extension with name \""+extname+"\" found in"
  821 + " FITS file.\n"
  822 + "Please specify a valid extension name.";
  823 + throw GException::invalid_argument(G_INSERT2, msg);
  824 + }
  825 +
  826 + // Insert HDU and return pointer
  827 + return (insert(extno, hdu));
  828 +}
  829 +
  830 +
  831 +/***********************************************************************//**
  832 + * @brief Remove HDU from FITS file
  833 + *
  834 + * @param[in] extno Extension number [0,...,size()-1].
  835 + *
  836 + * @exception GException::out_of_range
  837 + * Specified @p extno is out of range.
  838 + *
  839 + * @todo Handle HDU update in FITS file.
  840 + ***************************************************************************/
  841 +void GFits::remove(const int& extno)
  842 +{
  843 + // Compile option: raise an exception if index is out of range
  844 + #if defined(G_RANGE_CHECK)
  845 + if (extno < 0 || extno >= size()) {
  846 + throw GException::out_of_range(G_REMOVE1, "Extension number", extno, size());
  847 + }
  848 + #endif
  849 +
  850 + // Erase HDU from FITS file
  851 + m_hdu.erase(m_hdu.begin() + extno);
  852 +
  853 + // Update extno for all subsequent HDUs
  854 + for (int i = extno; i < size(); ++i) {
  855 + m_hdu[i]->extno(i);
  856 + }
  857 +
  858 + // Return
  859 + return;
  860 +}
  861 +
  862 +
  863 +/***********************************************************************//**
  864 + * @brief Remove HDU from FITS file
  865 + *
  866 + * @param[in] extname Name of HDU extension.
  867 + *
  868 + * @exception GException::invalid_argument
  869 + * Specified @p extname not found in FITS file.
  870 + ***************************************************************************/
  871 +void GFits::remove(const std::string& extname)
  872 +{
  873 + // Get extenion number
  874 + int extno = this->extno(extname);
  875 + if (extno == -1) {
  876 + std::string msg = "No extension with name \""+extname+"\" found in"
  877 + " FITS file.\n"
  878 + "Please specify a valid extension name.";
  879 + throw GException::invalid_argument(G_REMOVE2, msg);
  880 + }
187 881  
188   - // Initialise members
189   - init_members();
  882 + // Remove extension
  883 + remove(extno);
190 884  
191 885 // Return
192 886 return;
... ... @@ -194,21 +888,92 @@ void GFits::clear(void)
194 888  
195 889  
196 890 /***********************************************************************//**
197   - * @brief Clone object
  891 + * @brief Append FITS file
  892 + *
  893 + * @param[in] fits FITS file.
  894 + *
  895 + * Append all extension of @p fits file to FITS file.
  896 + *
  897 + * @todo Handle HDU update in FITS file.
198 898 ***************************************************************************/
199   -GFits* GFits::clone(void) const
  899 +void GFits::extend(const GFits& fits)
200 900 {
201   - return new GFits(*this);
  901 + // Do nothing if FITS file is empty
  902 + if (!fits.isempty()) {
  903 +
  904 + // Get size. Note that we extract the size first to avoid an
  905 + // endless loop that arises when a container is appended to
  906 + // itself.
  907 + int num = fits.size();
  908 +
  909 + // Reserve enough space
  910 + reserve(size() + num);
  911 +
  912 + // Loop over all HDUs and append pointers to deep copies
  913 + for (int i = 0; i < num; ++i) {
  914 +
  915 + // Clone HDU
  916 + GFitsHDU* ptr = m_hdu[i]->clone();
  917 +
  918 + // Push back HDU on stack
  919 + m_hdu.push_back(ptr);
  920 +
  921 + // Retrieve extno
  922 + int extno = m_hdu.size()-1;
  923 +
  924 + // If FITS file exists then connect cloned HDU to FITS file
  925 + if (m_fitsfile != NULL) {
  926 + __fitsfile fptr = *(FPTR(m_fitsfile));
  927 + fptr.HDUposition = extno;
  928 + ptr->connect(&fptr);
  929 + }
  930 + else {
  931 + ptr->extno(extno);
  932 + }
  933 +
  934 + } // endfor: looped over all HDUs
  935 +
  936 + } // endif: FITS file was not empty
  937 +
  938 + // Return
  939 + return;
202 940 }
203 941  
204 942  
205 943 /***********************************************************************//**
206   - * @brief Return number of HDUs in FITS file
  944 + * @brief Return extension number for specified extension name
  945 + *
  946 + * @param[in] extname Name of HDU extension.
  947 + * @return Extension number (-1 of not found).
  948 + *
  949 + * Returns the extension number for a specified extension name @p extname. If
  950 + * the extension name if "PRIMARY" an extension number of 0 is returned.
  951 + * If the extension is not found, -1 is returned.
207 952 ***************************************************************************/
208   -int GFits::size(void) const
  953 +int GFits::extno(const std::string& extname) const
209 954 {
210   - // Return number of HDUs
211   - return m_hdu.size();
  955 + // Initialise extension number
  956 + int extno = -1;
  957 +
  958 + // Return primary HDU if requested ...
  959 + if (gammalib::toupper(extname) == "PRIMARY") {
  960 + if (size() > 0) {
  961 + extno = 0;
  962 + }
  963 + }
  964 +
  965 + // ... otherwise search for specified extension
  966 + else {
  967 + for (int i = 0; i < size(); ++i) {
  968 + if (m_hdu[i]->extname() == extname) {
  969 + extno = i;
  970 + break;
  971 + }
  972 + }
  973 + }
  974 +
  975 + // Return extno
  976 + return extno;
212 977 }
213 978  
214 979  
... ... @@ -235,7 +1000,7 @@ int GFits::size(void) const
235 1000 * hdu(int extno) method.
236 1001 * Any environment variable present in the filename will be expanded.
237 1002 ***************************************************************************/
238   -void GFits::open(const std::string& filename, bool create)
  1003 +void GFits::open(const std::string& filename, const bool& create)
239 1004 {
240 1005 // Remove any HDUs
241 1006 m_hdu.clear();
... ... @@ -359,7 +1124,7 @@ void GFits::open(const std::string&amp; filename, bool create)
359 1124 * In the special case that no first HDU exists an empty primary image is
360 1125 * created.
361 1126 ***************************************************************************/
362   -void GFits::save(bool clobber)
  1127 +void GFits::save(const bool& clobber)
363 1128 {
364 1129 // Debug header
365 1130 #if DEBUG
... ... @@ -419,7 +1184,7 @@ void GFits::save(bool clobber)
419 1184 * Saves object into a specific FITS file.
420 1185 * Any environment variable present in the filename will be expanded.
421 1186 ***************************************************************************/
422   -void GFits::saveto(const std::string& filename, bool clobber)
  1187 +void GFits::saveto(const std::string& filename, const bool& clobber)
423 1188 {
424 1189 // Expand environment variables
425 1190 std::string fname = gammalib::expand_env(filename);
... ... @@ -432,7 +1197,7 @@ void GFits::saveto(const std::string&amp; filename, bool clobber)
432 1197  
433 1198 // If overwriting has been specified then remove any existing file ...
434 1199 if (clobber) {
435   - remove(fname.c_str());
  1200 + std::remove(fname.c_str());
436 1201 }
437 1202  
438 1203 // ... otherwise, if file exists then throw an exception
... ... @@ -485,155 +1250,6 @@ void GFits::close(void)
485 1250  
486 1251  
487 1252 /***********************************************************************//**
488   - * @brief Append HDU to FITS file
489   - *
490   - * @param[in] hdu HDU.
491   - *
492   - * Append HDU to the next free position in a FITS file. In case that no HDU
493   - * exists so far in the FITS file and if the HDU to append is NOT an image,
494   - * an empty primary image will be inserted as first HDU in the FITS file.
495   - * This guarantees the compatibility with the FITS standard.
496   - ***************************************************************************/
497   -void GFits::append(const GFitsHDU& hdu)
498   -{
499   - // Debug header
500   - #if DEBUG
501   - std::cout << "GFits::append(";
502   - switch (hdu.exttype()) {
503   - case GFitsHDU::HT_IMAGE:
504   - std::cout << "GFitsImage";
505   - break;
506   - case GFitsHDU::HT_ASCII_TABLE:
507   - std::cout << "GFitsAsciiTable";
508   - break;
509   - case GFitsHDU::HT_BIN_TABLE:
510   - std::cout << "GFitsBinTable";
511   - break;
512   - default:
513   - std::cout << "<unknown header type>";
514   - break;
515   - }
516   - std::cout << ") (size=" << size() << ") -->" << std::endl;
517   - #endif
518   -
519   - // Determine next free HDU number
520   - int n_hdu = size();
521   -
522   - // Add primary image if required
523   - if (n_hdu == 0 && hdu.exttype() != GFitsHDU::HT_IMAGE) {
524   -
525   - // Allocate primary image
526   - GFitsHDU* primary = new_primary();
527   -
528   - // If FITS file exists then connect primary image to FITS file
529   - if (m_fitsfile != NULL) {
530   - __fitsfile fptr = *(FPTR(m_fitsfile));
531   - fptr.HDUposition = n_hdu;
532   - primary->connect(&fptr);
533   - }
534   -
535   - // Debug information
536   - #if DEBUG
537   - std::cout << "Append primary image to HDU." << std::endl;
538   - #endif
539   -
540   - // Push back primary image
541   - m_hdu.push_back(primary);
542   -
543   - // Increment HDU number
544   - n_hdu++;
545   - }
546   -
547   - // Clone FITS HDU
548   - GFitsHDU* ptr = hdu.clone();
549   -
550   - // Append HDU if it's valid
551   - if (ptr != NULL) {
552   -
553   - // If FITS file exists then connect cloned HDU to FITS file
554   - if (m_fitsfile != NULL) {
555   - __fitsfile fptr = *(FPTR(m_fitsfile));
556   - fptr.HDUposition = n_hdu;
557   - ptr->connect(&fptr);
558   - }
559   - else {
560   - ptr->extno(n_hdu);
561   - }
562   -
563   - // Debug information
564   - #if DEBUG
565   - std::cout << "Append HDU (extno=" << n_hdu << ")." << std::endl;
566   - #endif
567   -
568   - // Push back HDU
569   - m_hdu.push_back(ptr);
570   -
571   - // Debug trailer
572   - #if DEBUG
573   - std::cout << "<-- GFits::append" << std::endl;
574   - #endif
575   -
576   - } // endif: HDU was valid
577   -
578   - // Return
579   - return;
580   -}
581   -
582   -
583   -/***********************************************************************//**
584   - * @brief Verify if HDU exists
585   - *
586   - * @param[in] extname Name of HDU extension.
587   - *
588   - * Returns true if a HDU with the specified extension name is present,
589   - * otherwise false.
590   - ***************************************************************************/
591   -bool GFits::hashdu(const std::string& extname) const
592   -{
593   - // Initialise result
594   - bool present = false;
595   -
596   - // Check primary HDU if requested ...
597   - if (gammalib::toupper(extname) == "PRIMARY") {
598   - if (size() > 0) {
599   - present = true;
600   - }
601   - }
602   -
603   - // ... otherwise search for specified extension
604   - else {
605   - for (int i = 0; i < size(); ++i) {
606   - if (m_hdu[i]->extname() == extname) {
607   - present = true;
608   - break;
609   - }
610   - }
611   - }
612   -
613   - // Return presence flag
614   - return present;
615   -}
616   -
617   -
618   -/***********************************************************************//**
619   - * @brief Verify if HDU exists
620   - *
621   - * @param[in] extno Extension number (starting from 0).
622   - *
623   - * Returns true if a HDU with the specified extension number is present,
624   - * otherwise false.
625   - ***************************************************************************/
626   -bool GFits::hashdu(int extno) const
627   -{
628   - // Set result
629   - bool present = (extno >= 0 && extno < size());
630   -
631   - // Return presence flag
632   - return present;
633   -}
634   -
635   -
636   -/***********************************************************************//**
637 1253 * @brief Get pointer to HDU
638 1254 *
639 1255 * @param[in] extname Name of HDU extension.
... ... @@ -643,6 +1259,7 @@ bool GFits::hashdu(int extno) const
643 1259 *
644 1260 * Returns a pointer to the HDU with the specified extname.
645 1261 ***************************************************************************/
  1262 +/*
646 1263 GFitsHDU* GFits::hdu(const std::string& extname) const
647 1264 {
648 1265 // Initialise result to NULL pointer
... ... @@ -673,7 +1290,7 @@ GFitsHDU* GFits::hdu(const std::string&amp; extname) const
673 1290 // Return pointer
674 1291 return ptr;
675 1292 }
676   -
  1293 +*/
677 1294  
678 1295 /***********************************************************************//**
679 1296 * @brief Get pointer to HDU
... ... @@ -686,7 +1303,8 @@ GFitsHDU* GFits::hdu(const std::string&amp; extname) const
686 1303 * Returns a pointer to the HDU with the specified extension number extno.
687 1304 * Performs extno range checking if G_RANGE_CHECK is defined.
688 1305 ***************************************************************************/
689   -GFitsHDU* GFits::hdu(int extno) const
  1306 +/*
  1307 +GFitsHDU* GFits::hdu(const int& extno) const
690 1308 {
691 1309 // Verify that extension number is in valid range
692 1310 #if defined(G_RANGE_CHECK)
... ... @@ -709,113 +1327,7 @@ GFitsHDU* GFits::hdu(int extno) const
709 1327 // Return pointer
710 1328 return ptr;
711 1329 }
712   -
713   -
714   -/***********************************************************************//**
715   - * @brief Get pointer to image HDU
716   - *
717   - * @param[in] extname Name of HDU extension.
718   - *
719   - * @exception GException::fits_hdu_not_image
720   - * Requested HDU is not an image.
721   - *
722   - * Returns a pointer to the image HDU with extension name extname.
723   - ***************************************************************************/
724   -GFitsImage* GFits::image(const std::string& extname) const
725   -{
726   - // Get HDU pointer
727   - GFitsHDU* ptr = hdu(extname);
728   -
729   - // Throw an error if HDU is not an image
730   - if (ptr->exttype() != GFitsHDU::HT_IMAGE) {
731   - throw GException::fits_hdu_not_image(G_IMAGE1, extname, ptr->exttype());
732   - }
733   -
734   - // Return pointer
735   - return (static_cast<GFitsImage*>(ptr));
736   -}
737   -
738   -
739   -/***********************************************************************//**
740   - * @brief Get pointer to image HDU
741   - *
742   - * @param[in] extno Extension number (starting from 0).
743   - *
744   - * @exception GException::fits_hdu_not_image
745   - * Requested HDU is not an image.
746   - *
747   - * Returns a pointer to the image HDU with extension number extno.
748   - ***************************************************************************/
749   -GFitsImage* GFits::image(int extno) const
750   -{
751   - // Get HDU pointer
752   - GFitsHDU* ptr = hdu(extno);
753   -
754   - // Throw an error if HDU is not an image
755   - if (ptr->exttype() != GFitsHDU::HT_IMAGE) {
756   - throw GException::fits_hdu_not_image(G_IMAGE2,
757   - "(extno="+gammalib::str(extno)+")",
758   - ptr->exttype());
759   - }
760   -
761   - // Return pointer
762   - return (static_cast<GFitsImage*>(ptr));
763   -}
764   -
765   -
766   -/***********************************************************************//**
767   - * @brief Get pointer to table HDU
768   - *
769   - * @param[in] extname Name of HDU extension.
770   - *
771   - * @exception GException::fits_hdu_not_table
772   - * Requested HDU is not a table.
773   - *
774   - * Returns a pointer to the table HDU with extension name extname.
775   - ***************************************************************************/
776   -GFitsTable* GFits::table(const std::string& extname) const
777   -{
778   - // Get HDU pointer
779   - GFitsHDU* ptr = hdu(extname);
780   -
781   - // Throw an error if HDU is not a table
782   - if (ptr->exttype() != GFitsHDU::HT_ASCII_TABLE &&
783   - ptr->exttype() != GFitsHDU::HT_BIN_TABLE) {
784   - throw GException::fits_hdu_not_table(G_TABLE1, extname, ptr->exttype());
785   - }
786   -
787   - // Return pointer
788   - return (static_cast<GFitsTable*>(ptr));
789   -}
790   -
791   -
792   -/***********************************************************************//**
793   - * @brief Get pointer to table HDU
794   - *
795   - * @param[in] extno Extension number (starting from 0).
796   - *
797   - * @exception GException::fits_hdu_not_table
798   - * Requested HDU is not a table.
799   - *
800   - * Returns a pointer to the table HDU with extension number extno.
801   - ***************************************************************************/
802   -GFitsTable* GFits::table(int extno) const
803   -{
804   - // Get HDU pointer
805   - GFitsHDU* ptr = hdu(extno);
806   -
807   - // Throw an error if HDU is not a table
808   - if (ptr->exttype() != GFitsHDU::HT_ASCII_TABLE &&
809   - ptr->exttype() != GFitsHDU::HT_BIN_TABLE) {
810   - throw GException::fits_hdu_not_table(G_TABLE2,
811   - "(extno="+gammalib::str(extno)+")",
812   - ptr->exttype());
813   - }
814   -
815   - // Return pointer
816   - return (static_cast<GFitsTable*>(ptr));
817   -}
818   -
  1330 +*/
819 1331  
820 1332 /***********************************************************************//**
821 1333 * @brief Print FITS information
... ...
src/model/GModels.cpp
... ... @@ -265,10 +265,12 @@ GModels* GModels::clone(void) const
265 265 ***************************************************************************/
266 266 GModel* GModels::at(const int& index)
267 267 {
268   - // Raise exception if index is out of range
  268 + // Compile option: raise an exception if index is out of range
  269 + #if defined(G_RANGE_CHECK)
269 270 if (index < 0 || index >= size()) {
270   - throw GException::out_of_range(G_AT, index, 0, size()-1);
  271 + throw GException::out_of_range(G_AT, "Model index", index, size());
271 272 }
  273 + #endif
272 274  
273 275 // Return pointer
274 276 return m_models[index];
... ... @@ -287,10 +289,12 @@ GModel* GModels::at(const int&amp; index)
287 289 ***************************************************************************/
288 290 const GModel* GModels::at(const int& index) const
289 291 {
290   - // Raise exception if index is out of range
  292 + // Compile option: raise an exception if index is out of range
  293 + #if defined(G_RANGE_CHECK)
291 294 if (index < 0 || index >= size()) {
292   - throw GException::out_of_range(G_AT, index, 0, size()-1);
  295 + throw GException::out_of_range(G_AT, "Model index", index, size());
293 296 }
  297 + #endif
294 298  
295 299 // Return pointer
296 300 return m_models[index];
... ...
src/sky/GSkymap.cpp
... ... @@ -947,7 +947,7 @@ void GSkymap::load(const std::string&amp; filename)
947 947 for (int extno = 1; extno < num; ++extno) {
948 948  
949 949 // Get pointer to HDU
950   - hdu = fits.hdu(extno);
  950 + hdu = fits.at(extno);
951 951  
952 952 // If PIXTYPE keyword equals "HEALPIX" then load map
953 953 if (hdu->hascard("PIXTYPE") && hdu->string("PIXTYPE") == "HEALPIX") {
... ... @@ -964,7 +964,7 @@ void GSkymap::load(const std::string&amp; filename)
964 964 for (int extno = 0; extno < num; ++extno) {
965 965  
966 966 // Get pointer to HDU
967   - hdu = fits.hdu(extno);
  967 + hdu = fits.at(extno);
968 968  
969 969 // Skip if extension is not an image
970 970 if (extno > 0) {
... ...
src/xspec/GPha.cpp
... ... @@ -336,13 +336,13 @@ void GPha::load(const std::string&amp; filename)
336 336 clear();
337 337  
338 338 // Open FITS file
339   - GFits file(filename);
  339 + GFits fits(filename);
340 340  
341 341 // Get PHA table
342   - GFitsTable* pha = file.table("SPECTRUM");
  342 + GFitsTable* pha = fits.table("SPECTRUM");
343 343  
344 344 // Get EBOUNDS table (NULL if the table does not exist)
345   - GFitsTable* ebounds = (file.hashdu("EBOUNDS")) ? file.table("EBOUNDS") : NULL;
  345 + GFitsTable* ebounds = (fits.contains("EBOUNDS")) ? fits.table("EBOUNDS") : NULL;
346 346  
347 347 // Read PHA data
348 348 read(pha);
... ... @@ -351,7 +351,7 @@ void GPha::load(const std::string&amp; filename)
351 351 m_ebounds.read(ebounds);
352 352  
353 353 // Close FITS file
354   - file.close();
  354 + fits.close();
355 355  
356 356 // Store filename
357 357 m_filename = filename;
... ...
test/test_GFits.cpp
... ... @@ -478,8 +478,8 @@ void TestGFits::test_create(void)
478 478 try {
479 479 GFits fits;
480 480 fits.open("test.fits");
481   - GFitsHDU* hdu = fits.hdu(0);
482   - GFitsImageDouble* image = static_cast<GFitsImageDouble*>(fits.hdu(1));
  481 + GFitsHDU* hdu = fits.at(0);
  482 + GFitsImageDouble* image = static_cast<GFitsImageDouble*>(fits.at(1));
483 483 int nx = image->naxes(0);
484 484 int ny = image->naxes(1);
485 485 for (int ix = 0; ix < nx; ++ix) {
... ...