Commit e821ba0f99688d28d559ce98df3fa4818aafdfe2

Authored by Jürgen Knödlseder
1 parent 3e38d75b

The FITS read() and write() methods now take reference instead of pointers.

@@ -180,6 +180,13 @@ GPars @@ -180,6 +180,13 @@ GPars
180 GPhoton 180 GPhoton
181 Add mcid argument to Photon constructor (defaults to -1). 181 Add mcid argument to Photon constructor (defaults to -1).
182 182
  183 +GSkymap
  184 + Rename xy2dir() to pix2dir(), dir2xy() to dir2pix(), xy2pix() to
  185 + pix2inx() and pix2xy() to inx2pix(). The nmaps argument in the
  186 + sky map constructor is now passed by reference. The isinmap()
  187 + method has been renamed to contains(). The read() and write()
  188 + methods now take a reference instead of a pointer.
  189 +
183 GSkyPixel 190 GSkyPixel
184 The class now supports 1D and 2D pixels. Type conversion methods 191 The class now supports 1D and 2D pixels. Type conversion methods
185 have been added that allow assigning integer and double precision 192 have been added that allow assigning integer and double precision
@@ -222,16 +229,19 @@ GWcs => GSkyProjection @@ -222,16 +229,19 @@ GWcs => GSkyProjection
222 general than the World Coordinate Systems. A size() method has 229 general than the World Coordinate Systems. A size() method has
223 been added that returns the dimension of the projection (1D or 230 been added that returns the dimension of the projection (1D or
224 2D). The integer index methods have been removed as GSkyPixel 231 2D). The integer index methods have been removed as GSkyPixel
225 - now supports 1D and 2D pixels. 232 + now supports 1D and 2D pixels. The read() and write() methods
  233 + now take a reference instead of a pointer.
226 234
227 GWcslib => GWcs 235 GWcslib => GWcs
228 The GWcslib class has been renamed to GWcs. The class now conforms 236 The GWcslib class has been renamed to GWcs. The class now conforms
229 - to the GSkyProjection base class interface. 237 + to the GSkyProjection base class interface. The read() and write()
  238 + methods now take a reference instead of a pointer.
230 239
231 GWcsHPX => GHealpix 240 GWcsHPX => GHealpix
232 The GWcsHPX class has been renamed to GHealpix as the Healpix 241 The GWcsHPX class has been renamed to GHealpix as the Healpix
233 projection is not a World Coordinate System. GHealpix is no 242 projection is not a World Coordinate System. GHealpix is no
234 - longer registered in GWcsRegistry. 243 + longer registered in GWcsRegistry. The read() and write()
  244 + methods now take a reference instead of a pointer.
235 245
236 GWcsRegistry 246 GWcsRegistry
237 Now holds objects of renamed type GWcs (see GHealpix). 247 Now holds objects of renamed type GWcs (see GHealpix).
include/GArf.hpp
@@ -63,8 +63,9 @@ public: @@ -63,8 +63,9 @@ public:
63 const double& at(const int& index) const; 63 const double& at(const int& index) const;
64 const GEbounds& ebounds(void) const; 64 const GEbounds& ebounds(void) const;
65 void load(const std::string& filename); 65 void load(const std::string& filename);
66 - void save(const std::string& filename, const bool& clobber = false) const;  
67 - void read(const GFitsTable* hdu); 66 + void save(const std::string& filename,
  67 + const bool& clobber = false) const;
  68 + void read(const GFitsTable& table);
68 void write(GFits& fits) const; 69 void write(GFits& fits) const;
69 const std::string& filename(void) const; 70 const std::string& filename(void) const;
70 std::string print(const GChatter& chatter = NORMAL) const; 71 std::string print(const GChatter& chatter = NORMAL) const;
include/GEnergies.hpp
@@ -75,8 +75,8 @@ public: @@ -75,8 +75,8 @@ public:
75 const std::string& extname = "ENERGIES"); 75 const std::string& extname = "ENERGIES");
76 void save(const std::string& filename, bool clobber, 76 void save(const std::string& filename, bool clobber,
77 const std::string& extname = "ENERGIES") const; 77 const std::string& extname = "ENERGIES") const;
78 - void read(const GFitsTable* hdu);  
79 - void write(GFits* file, 78 + void read(const GFitsTable& table);
  79 + void write(GFits& file,
80 const std::string& extname = "ENERGIES") const; 80 const std::string& extname = "ENERGIES") const;
81 std::string print(const GChatter& chatter = NORMAL) const; 81 std::string print(const GChatter& chatter = NORMAL) const;
82 82
include/GHealpix.hpp
@@ -51,7 +51,7 @@ public: @@ -51,7 +51,7 @@ public:
51 explicit GHealpix(const int& nside, 51 explicit GHealpix(const int& nside,
52 const std::string& ordering = "NESTED", 52 const std::string& ordering = "NESTED",
53 const std::string& coordsys = "GAL"); 53 const std::string& coordsys = "GAL");
54 - explicit GHealpix(const GFitsHDU* hdu); 54 + explicit GHealpix(const GFitsHDU& hdu);
55 GHealpix(const GHealpix& wcs); 55 GHealpix(const GHealpix& wcs);
56 virtual ~GHealpix(void); 56 virtual ~GHealpix(void);
57 57
@@ -64,8 +64,8 @@ public: @@ -64,8 +64,8 @@ public:
64 virtual int size(void) const; 64 virtual int size(void) const;
65 virtual std::string code(void) const; 65 virtual std::string code(void) const;
66 virtual std::string name(void) const; 66 virtual std::string name(void) const;
67 - virtual void read(const GFitsHDU* hdu);  
68 - virtual void write(GFitsHDU* hdu) const; 67 + virtual void read(const GFitsHDU& hdu);
  68 + virtual void write(GFitsHDU& hdu) const;
69 virtual double omega(const GSkyPixel& pixel) const; 69 virtual double omega(const GSkyPixel& pixel) const;
70 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const; 70 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const;
71 virtual GSkyPixel dir2pix(const GSkyDir& dir) const; 71 virtual GSkyPixel dir2pix(const GSkyDir& dir) const;
include/GPha.hpp
@@ -80,8 +80,9 @@ public: @@ -80,8 +80,9 @@ public:
80 const double& outflow(void) const; 80 const double& outflow(void) const;
81 void fill(const GEnergy& energy, const double& value = 1.0); 81 void fill(const GEnergy& energy, const double& value = 1.0);
82 void load(const std::string& filename); 82 void load(const std::string& filename);
83 - void save(const std::string& filename, const bool& clobber = false) const;  
84 - void read(const GFitsTable* hdu); 83 + void save(const std::string& filename,
  84 + const bool& clobber = false) const;
  85 + void read(const GFitsTable& table);
85 void write(GFits& fits) const; 86 void write(GFits& fits) const;
86 const std::string& filename(void) const; 87 const std::string& filename(void) const;
87 std::string print(const GChatter& chatter = NORMAL) const; 88 std::string print(const GChatter& chatter = NORMAL) const;
include/GPhotons.hpp
@@ -58,8 +58,8 @@ public: @@ -58,8 +58,8 @@ public:
58 // Methods 58 // Methods
59 void clear(void); 59 void clear(void);
60 GPhotons* clone(void) const; 60 GPhotons* clone(void) const;
61 - int size(void) const { return m_photons.size(); }  
62 - bool isempty(void) const { return m_photons.empty(); } 61 + int size(void) const;
  62 + bool isempty(void) const;
63 void append(const GPhoton& photon); 63 void append(const GPhoton& photon);
64 void insert(const int& index, const GPhoton& photon); 64 void insert(const int& index, const GPhoton& photon);
65 void remove(const int& index); 65 void remove(const int& index);
@@ -77,4 +77,28 @@ protected: @@ -77,4 +77,28 @@ protected:
77 std::vector<GPhoton> m_photons; //!< List of photons 77 std::vector<GPhoton> m_photons; //!< List of photons
78 }; 78 };
79 79
  80 +
  81 +/***********************************************************************//**
  82 + * @brief Return number of photons
  83 + *
  84 + * @return Number of photons.
  85 + ***************************************************************************/
  86 +inline
  87 +int GPhotons::size(void) const
  88 +{
  89 + return m_photons.size();
  90 +}
  91 +
  92 +
  93 +/***********************************************************************//**
  94 + * @brief Signal if there are no photons
  95 + *
  96 + * @return True if there are no photons.
  97 + ***************************************************************************/
  98 +inline
  99 +bool GPhotons::isempty(void) const
  100 +{
  101 + return m_photons.empty();
  102 +}
  103 +
80 #endif /* GPHOTONS_HPP */ 104 #endif /* GPHOTONS_HPP */
include/GRmf.hpp
@@ -69,8 +69,9 @@ public: @@ -69,8 +69,9 @@ public:
69 const GEbounds& etrue(void) const; 69 const GEbounds& etrue(void) const;
70 const GEbounds& emeasured(void) const; 70 const GEbounds& emeasured(void) const;
71 void load(const std::string& filename); 71 void load(const std::string& filename);
72 - void save(const std::string& filename, const bool& clobber = false) const;  
73 - void read(const GFitsTable* hdu); 72 + void save(const std::string& filename,
  73 + const bool& clobber = false) const;
  74 + void read(const GFitsTable& table);
74 void write(GFits& fits) const; 75 void write(GFits& fits) const;
75 const std::string& filename(void) const; 76 const std::string& filename(void) const;
76 std::string print(const GChatter& chatter = NORMAL) const; 77 std::string print(const GChatter& chatter = NORMAL) const;
include/GSkyProjection.hpp
@@ -65,8 +65,8 @@ public: @@ -65,8 +65,8 @@ public:
65 virtual int size(void) const = 0; 65 virtual int size(void) const = 0;
66 virtual std::string code(void) const = 0; 66 virtual std::string code(void) const = 0;
67 virtual std::string name(void) const = 0; 67 virtual std::string name(void) const = 0;
68 - virtual void read(const GFitsHDU* hdu) = 0;  
69 - virtual void write(GFitsHDU* hdu) const = 0; 68 + virtual void read(const GFitsHDU& hdu) = 0;
  69 + virtual void write(GFitsHDU& hdu) const = 0;
70 virtual double omega(const GSkyPixel& pixel) const = 0; 70 virtual double omega(const GSkyPixel& pixel) const = 0;
71 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const = 0; 71 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const = 0;
72 virtual GSkyPixel dir2pix(const GSkyDir& dir) const = 0; 72 virtual GSkyPixel dir2pix(const GSkyDir& dir) const = 0;
include/GSkymap.hpp
@@ -128,8 +128,8 @@ public: @@ -128,8 +128,8 @@ public:
128 const double* pixels(void) const; 128 const double* pixels(void) const;
129 void load(const std::string& filename); 129 void load(const std::string& filename);
130 void save(const std::string& filename, bool clobber = false) const; 130 void save(const std::string& filename, bool clobber = false) const;
131 - void read(const GFitsHDU* hdu);  
132 - void write(GFits* file) const; 131 + void read(const GFitsHDU& hdu);
  132 + void write(GFits& file) const;
133 std::string print(const GChatter& chatter = NORMAL) const; 133 std::string print(const GChatter& chatter = NORMAL) const;
134 134
135 private: 135 private:
@@ -143,9 +143,9 @@ private: @@ -143,9 +143,9 @@ private:
143 const double& crpix1, const double& crpix2, 143 const double& crpix1, const double& crpix2,
144 const double& cdelt1, const double& cdelt2, 144 const double& cdelt1, const double& cdelt2,
145 const GMatrix& cd, const GVector& pv2); 145 const GMatrix& cd, const GVector& pv2);
146 - void read_healpix(const GFitsTable* hdu);  
147 - void read_wcs(const GFitsImage* hdu);  
148 - void alloc_wcs(const GFitsImage* hdu); 146 + void read_healpix(const GFitsTable& table);
  147 + void read_wcs(const GFitsImage& image);
  148 + void alloc_wcs(const GFitsImage& image);
149 GFitsBinTable* create_healpix_hdu(void) const; 149 GFitsBinTable* create_healpix_hdu(void) const;
150 GFitsImageDouble* create_wcs_hdu(void) const; 150 GFitsImageDouble* create_wcs_hdu(void) const;
151 151
include/GTimes.hpp
@@ -58,8 +58,8 @@ public: @@ -58,8 +58,8 @@ public:
58 // Methods 58 // Methods
59 void clear(void); 59 void clear(void);
60 GTimes* clone(void) const; 60 GTimes* clone(void) const;
61 - int size(void) const { return m_times.size(); }  
62 - bool isempty(void) const { return m_times.empty(); } 61 + int size(void) const;
  62 + bool isempty(void) const;
63 void append(const GTime& time); 63 void append(const GTime& time);
64 void insert(const int& index, const GTime& time); 64 void insert(const int& index, const GTime& time);
65 void remove(const int& index); 65 void remove(const int& index);
@@ -77,4 +77,28 @@ protected: @@ -77,4 +77,28 @@ protected:
77 std::vector<GTime> m_times; //!< List of times 77 std::vector<GTime> m_times; //!< List of times
78 }; 78 };
79 79
  80 +
  81 +/***********************************************************************//**
  82 + * @brief Return number of times
  83 + *
  84 + * @return Number of times.
  85 + ***************************************************************************/
  86 +inline
  87 +int GTimes::size(void) const
  88 +{
  89 + return m_times.size();
  90 +}
  91 +
  92 +
  93 +/***********************************************************************//**
  94 + * @brief Signal if there are no times
  95 + *
  96 + * @return True if there are no times.
  97 + ***************************************************************************/
  98 +inline
  99 +bool GTimes::isempty(void) const
  100 +{
  101 + return m_times.empty();
  102 +}
  103 +
80 #endif /* GTIMES_HPP */ 104 #endif /* GTIMES_HPP */
include/GWcs.hpp
@@ -52,7 +52,7 @@ public: @@ -52,7 +52,7 @@ public:
52 const double& crval1, const double& crval2, 52 const double& crval1, const double& crval2,
53 const double& crpix1, const double& crpix2, 53 const double& crpix1, const double& crpix2,
54 const double& cdelt1, const double& cdelt2); 54 const double& cdelt1, const double& cdelt2);
55 - explicit GWcs(const GFitsHDU* hdu); 55 + explicit GWcs(const GFitsHDU& hdu);
56 GWcs(const GWcs& wcs); 56 GWcs(const GWcs& wcs);
57 virtual ~GWcs(void); 57 virtual ~GWcs(void);
58 58
@@ -68,8 +68,8 @@ public: @@ -68,8 +68,8 @@ public:
68 68
69 // Implemented virtual base class methods 69 // Implemented virtual base class methods
70 virtual int size(void) const; 70 virtual int size(void) const;
71 - virtual void read(const GFitsHDU* hdu);  
72 - virtual void write(GFitsHDU* hdu) const; 71 + virtual void read(const GFitsHDU& hdu);
  72 + virtual void write(GFitsHDU& hdu) const;
73 virtual double omega(const GSkyPixel& pixel) const; 73 virtual double omega(const GSkyPixel& pixel) const;
74 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const; 74 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const;
75 virtual GSkyPixel dir2pix(const GSkyDir& dir) const; 75 virtual GSkyPixel dir2pix(const GSkyDir& dir) const;
inst/com/src/GCOMEventCube.cpp
@@ -417,11 +417,11 @@ void GCOMEventCube::read(const GFits&amp; fits) @@ -417,11 +417,11 @@ void GCOMEventCube::read(const GFits&amp; fits)
417 // Clear object 417 // Clear object
418 clear(); 418 clear();
419 419
420 - // Get HDU  
421 - const GFitsImage* hdu = fits.image("Primary"); 420 + // Get image
  421 + const GFitsImage& image = *fits.image("Primary");
422 422
423 // Load counts map as sky map 423 // Load counts map as sky map
424 - m_map.read(hdu); 424 + m_map.read(image);
425 425
426 // Correct WCS projection (HEASARC data format kluge) 426 // Correct WCS projection (HEASARC data format kluge)
427 com_wcs_mer2car(m_map); 427 com_wcs_mer2car(m_map);
@@ -430,9 +430,9 @@ void GCOMEventCube::read(const GFits&amp; fits) @@ -430,9 +430,9 @@ void GCOMEventCube::read(const GFits&amp; fits)
430 set_scatter_directions(); 430 set_scatter_directions();
431 431
432 // Extract Phibar minimum and step size 432 // Extract Phibar minimum and step size
433 - double crval3 = hdu->real("CRVAL3");  
434 - double crpix3 = hdu->real("CRPIX3");  
435 - double dphi = hdu->real("CDELT3"); 433 + double crval3 = image.real("CRVAL3");
  434 + double crpix3 = image.real("CRPIX3");
  435 + double dphi = image.real("CDELT3");
436 double phimin = crval3 + (crpix3-1.0) * dphi; 436 double phimin = crval3 + (crpix3-1.0) * dphi;
437 437
438 // Set scatter angles 438 // Set scatter angles
@@ -441,8 +441,8 @@ void GCOMEventCube::read(const GFits&amp; fits) @@ -441,8 +441,8 @@ void GCOMEventCube::read(const GFits&amp; fits)
441 // Extract energy range 441 // Extract energy range
442 GEnergy emin; 442 GEnergy emin;
443 GEnergy emax; 443 GEnergy emax;
444 - emin.MeV(hdu->real("E_MIN"));  
445 - emax.MeV(hdu->real("E_MAX")); 444 + emin.MeV(image.real("E_MIN"));
  445 + emax.MeV(image.real("E_MAX"));
446 446
447 // Set energy boundaries 447 // Set energy boundaries
448 m_ebounds.clear(); 448 m_ebounds.clear();
@@ -454,8 +454,8 @@ void GCOMEventCube::read(const GFits&amp; fits) @@ -454,8 +454,8 @@ void GCOMEventCube::read(const GFits&amp; fits)
454 // Extract time range 454 // Extract time range
455 GTime tstart; 455 GTime tstart;
456 GTime tstop; 456 GTime tstop;
457 - tstart.jd(hdu->real("TSTART"));  
458 - tstop.jd(hdu->real("TSTOP")); 457 + tstart.jd(image.real("TSTART"));
  458 + tstop.jd(image.real("TSTOP"));
459 459
460 // Set GTIs 460 // Set GTIs
461 m_gti.clear(); 461 m_gti.clear();
@@ -479,7 +479,7 @@ void GCOMEventCube::read(const GFits&amp; fits) @@ -479,7 +479,7 @@ void GCOMEventCube::read(const GFits&amp; fits)
479 void GCOMEventCube::write(GFits& file) const 479 void GCOMEventCube::write(GFits& file) const
480 { 480 {
481 // Write cube 481 // Write cube
482 - m_map.write(&file); 482 + m_map.write(file);
483 483
484 // Write energy boundaries 484 // Write energy boundaries
485 485
inst/com/src/GCOMObservation.cpp
@@ -734,11 +734,11 @@ void GCOMObservation::load_drb(const std::string&amp; drbname) @@ -734,11 +734,11 @@ void GCOMObservation::load_drb(const std::string&amp; drbname)
734 // Open FITS file 734 // Open FITS file
735 GFits file(drbname); 735 GFits file(drbname);
736 736
737 - // Get HDU  
738 - GFitsImage* hdu = file.image("Primary"); 737 + // Get image
  738 + const GFitsImage& image = *file.image("Primary");
739 739
740 // Load background model as sky map 740 // Load background model as sky map
741 - m_drb.read(hdu); 741 + m_drb.read(image);
742 742
743 // Correct WCS projection (HEASARC data format kluge) 743 // Correct WCS projection (HEASARC data format kluge)
744 com_wcs_mer2car(m_drb); 744 com_wcs_mer2car(m_drb);
@@ -776,11 +776,11 @@ void GCOMObservation::load_drg(const std::string&amp; drgname) @@ -776,11 +776,11 @@ void GCOMObservation::load_drg(const std::string&amp; drgname)
776 // Open FITS file 776 // Open FITS file
777 GFits file(drgname); 777 GFits file(drgname);
778 778
779 - // Get HDU  
780 - GFitsImage* hdu = file.image("Primary"); 779 + // Get image
  780 + const GFitsImage& image = *file.image("Primary");
781 781
782 // Load geometry factors as sky map 782 // Load geometry factors as sky map
783 - m_drg.read(hdu); 783 + m_drg.read(image);
784 784
785 // Correct WCS projection (HEASARC data format kluge) 785 // Correct WCS projection (HEASARC data format kluge)
786 com_wcs_mer2car(m_drg); 786 com_wcs_mer2car(m_drg);
@@ -815,10 +815,10 @@ void GCOMObservation::load_drx(const std::string&amp; drxname) @@ -815,10 +815,10 @@ void GCOMObservation::load_drx(const std::string&amp; drxname)
815 GFits file(drxname); 815 GFits file(drxname);
816 816
817 // Get HDU 817 // Get HDU
818 - GFitsImage* hdu = file.image("Primary"); 818 + const GFitsImage& image = *file.image("Primary");
819 819
820 // Load exposure map as sky map 820 // Load exposure map as sky map
821 - m_drx.read(hdu); 821 + m_drx.read(image);
822 822
823 // Correct WCS projection (HEASARC data format kluge) 823 // Correct WCS projection (HEASARC data format kluge)
824 com_wcs_mer2car(m_drx); 824 com_wcs_mer2car(m_drx);
inst/cta/pyext/GCTAInstDir.i
@@ -48,9 +48,8 @@ public: @@ -48,9 +48,8 @@ public:
48 GCTAInstDir* clone(void) const; 48 GCTAInstDir* clone(void) const;
49 49
50 // Other methods 50 // Other methods
51 - void dir(const GSkyDir& dir);  
52 - GSkyDir& dir(void);  
53 - const GSkyDir& dir(void) const; 51 + void dir(const GSkyDir& dir);
  52 + GSkyDir& dir(void);
54 }; 53 };
55 54
56 55
inst/cta/src/GCTAEventCube.cpp
@@ -396,7 +396,7 @@ void GCTAEventCube::read(const GFits&amp; fits) @@ -396,7 +396,7 @@ void GCTAEventCube::read(const GFits&amp; fits)
396 void GCTAEventCube::write(GFits& fits) const 396 void GCTAEventCube::write(GFits& fits) const
397 { 397 {
398 // Write cube 398 // Write cube
399 - m_map.write(&fits); 399 + m_map.write(fits);
400 400
401 // Write energy boundaries 401 // Write energy boundaries
402 ebounds().write(fits); 402 ebounds().write(fits);
@@ -574,7 +574,7 @@ void GCTAEventCube::read_cntmap(const GFitsImage* hdu) @@ -574,7 +574,7 @@ void GCTAEventCube::read_cntmap(const GFitsImage* hdu)
574 if (hdu != NULL) { 574 if (hdu != NULL) {
575 575
576 // Load counts map as sky map 576 // Load counts map as sky map
577 - m_map.read(hdu); 577 + m_map.read(*hdu);
578 578
579 // Set sky directions 579 // Set sky directions
580 set_directions(); 580 set_directions();
inst/lat/src/GLATEventCube.cpp
@@ -695,7 +695,7 @@ void GLATEventCube::read_cntmap(const GFitsImage* hdu) @@ -695,7 +695,7 @@ void GLATEventCube::read_cntmap(const GFitsImage* hdu)
695 if (hdu != NULL) { 695 if (hdu != NULL) {
696 696
697 // Load counts map as sky map 697 // Load counts map as sky map
698 - m_map.read(hdu); 698 + m_map.read(*hdu);
699 699
700 // Set sky directions 700 // Set sky directions
701 set_directions(); 701 set_directions();
@@ -727,7 +727,7 @@ void GLATEventCube::read_srcmap(const GFitsImage* hdu) @@ -727,7 +727,7 @@ void GLATEventCube::read_srcmap(const GFitsImage* hdu)
727 GSkymap* map = new GSkymap; 727 GSkymap* map = new GSkymap;
728 728
729 // Read skymap 729 // Read skymap
730 - map->read(hdu); 730 + map->read(*hdu);
731 731
732 // Check that source map sky projection is consistent with counts 732 // Check that source map sky projection is consistent with counts
733 // map sky projection 733 // map sky projection
inst/lat/src/GLATLtCubeMap.cpp
@@ -372,7 +372,7 @@ void GLATLtCubeMap::read(const GFitsTable* hdu) @@ -372,7 +372,7 @@ void GLATLtCubeMap::read(const GFitsTable* hdu)
372 clear(); 372 clear();
373 373
374 // Load skymap 374 // Load skymap
375 - m_map.read(hdu); 375 + m_map.read(*hdu);
376 376
377 // Set costheta binning scheme 377 // Set costheta binning scheme
378 std::string scheme = gammalib::strip_whitespace(gammalib::toupper(hdu->string("THETABIN"))); 378 std::string scheme = gammalib::strip_whitespace(gammalib::toupper(hdu->string("THETABIN")));
pyext/GArf.i
@@ -51,8 +51,9 @@ public: @@ -51,8 +51,9 @@ public:
51 double& at(const int& index); 51 double& at(const int& index);
52 const GEbounds& ebounds(void) const; 52 const GEbounds& ebounds(void) const;
53 void load(const std::string& filename); 53 void load(const std::string& filename);
54 - void save(const std::string& filename, const bool& clobber = false) const;  
55 - void read(const GFitsTable* hdu); 54 + void save(const std::string& filename,
  55 + const bool& clobber = false) const;
  56 + void read(const GFitsTable& table);
56 void write(GFits& fits) const; 57 void write(GFits& fits) const;
57 }; 58 };
58 59
pyext/GEnergies.i
@@ -61,8 +61,8 @@ public: @@ -61,8 +61,8 @@ public:
61 const std::string& extname = "ENERGIES"); 61 const std::string& extname = "ENERGIES");
62 void save(const std::string& filename, bool clobber, 62 void save(const std::string& filename, bool clobber,
63 const std::string& extname = "ENERGIES") const; 63 const std::string& extname = "ENERGIES") const;
64 - void read(const GFitsTable* hdu);  
65 - void write(GFits* file, const std::string& extname = "ENERGIES") const; 64 + void read(const GFitsTable& table);
  65 + void write(GFits& file, const std::string& extname = "ENERGIES") const;
66 }; 66 };
67 67
68 68
pyext/GHealpix.i
@@ -40,7 +40,7 @@ public: @@ -40,7 +40,7 @@ public:
40 GHealpix(void); 40 GHealpix(void);
41 explicit GHealpix(const int& nside, const std::string& ordering = "NESTED", 41 explicit GHealpix(const int& nside, const std::string& ordering = "NESTED",
42 const std::string& coordsys = "GAL"); 42 const std::string& coordsys = "GAL");
43 - explicit GHealpix(const GFitsHDU* hdu); 43 + explicit GHealpix(const GFitsHDU& hdu);
44 GHealpix(const GHealpix& wcs); 44 GHealpix(const GHealpix& wcs);
45 virtual ~GHealpix(void); 45 virtual ~GHealpix(void);
46 46
@@ -50,8 +50,8 @@ public: @@ -50,8 +50,8 @@ public:
50 virtual int size(void) const; 50 virtual int size(void) const;
51 virtual std::string code(void) const; 51 virtual std::string code(void) const;
52 virtual std::string name(void) const; 52 virtual std::string name(void) const;
53 - virtual void read(const GFitsHDU* hdu);  
54 - virtual void write(GFitsHDU* hdu) const; 53 + virtual void read(const GFitsHDU& hdu);
  54 + virtual void write(GFitsHDU& hdu) const;
55 virtual double omega(const GSkyPixel& pixel) const; 55 virtual double omega(const GSkyPixel& pixel) const;
56 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const; 56 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const;
57 virtual GSkyPixel dir2pix(const GSkyDir& dir) const; 57 virtual GSkyPixel dir2pix(const GSkyDir& dir) const;
pyext/GPha.i
@@ -57,8 +57,9 @@ public: @@ -57,8 +57,9 @@ public:
57 const double& outflow(void) const; 57 const double& outflow(void) const;
58 void fill(const GEnergy& energy, const double& value = 1.0); 58 void fill(const GEnergy& energy, const double& value = 1.0);
59 void load(const std::string& filename); 59 void load(const std::string& filename);
60 - void save(const std::string& filename, const bool& clobber = false) const;  
61 - void read(const GFitsTable* hdu); 60 + void save(const std::string& filename,
  61 + const bool& clobber = false) const;
  62 + void read(const GFitsTable& table);
62 void write(GFits& fits) const; 63 void write(GFits& fits) const;
63 const std::string& filename(void) const; 64 const std::string& filename(void) const;
64 }; 65 };
pyext/GRmf.i
@@ -57,8 +57,9 @@ public: @@ -57,8 +57,9 @@ public:
57 const GEbounds& etrue(void) const; 57 const GEbounds& etrue(void) const;
58 const GEbounds& emeasured(void) const; 58 const GEbounds& emeasured(void) const;
59 void load(const std::string& filename); 59 void load(const std::string& filename);
60 - void save(const std::string& filename, const bool& clobber = false) const;  
61 - void read(const GFitsTable* hdu); 60 + void save(const std::string& filename,
  61 + const bool& clobber = false) const;
  62 + void read(const GFitsTable& table);
62 void write(GFits& fits) const; 63 void write(GFits& fits) const;
63 }; 64 };
64 65
pyext/GSkyProjection.i
@@ -51,8 +51,8 @@ public: @@ -51,8 +51,8 @@ public:
51 virtual int size(void) const = 0; 51 virtual int size(void) const = 0;
52 virtual std::string code(void) const = 0; 52 virtual std::string code(void) const = 0;
53 virtual std::string name(void) const = 0; 53 virtual std::string name(void) const = 0;
54 - virtual void read(const GFitsHDU* hdu) = 0;  
55 - virtual void write(GFitsHDU* hdu) const = 0; 54 + virtual void read(const GFitsHDU& hdu) = 0;
  55 + virtual void write(GFitsHDU& hdu) const = 0;
56 virtual double omega(const GSkyPixel& pixel) const = 0; 56 virtual double omega(const GSkyPixel& pixel) const = 0;
57 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const = 0; 57 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const = 0;
58 virtual GSkyPixel dir2pix(const GSkyDir& dir) const = 0; 58 virtual GSkyPixel dir2pix(const GSkyDir& dir) const = 0;
pyext/GSkymap.i
@@ -149,8 +149,8 @@ public: @@ -149,8 +149,8 @@ public:
149 const double* pixels(void) const; 149 const double* pixels(void) const;
150 void load(const std::string& filename); 150 void load(const std::string& filename);
151 void save(const std::string& filename, bool clobber = false) const; 151 void save(const std::string& filename, bool clobber = false) const;
152 - void read(const GFitsHDU* hdu);  
153 - void write(GFits* file) const; 152 + void read(const GFitsHDU& hdu);
  153 + void write(GFits& file) const;
154 }; 154 };
155 155
156 156
pyext/GWcs.i
@@ -42,7 +42,7 @@ public: @@ -42,7 +42,7 @@ public:
42 const double& crval1, const double& crval2, 42 const double& crval1, const double& crval2,
43 const double& crpix1, const double& crpix2, 43 const double& crpix1, const double& crpix2,
44 const double& cdelt1, const double& cdelt2); 44 const double& cdelt1, const double& cdelt2);
45 - explicit GWcs(const GFitsHDU* hdu); 45 + explicit GWcs(const GFitsHDU& hdu);
46 GWcs(const GWcs& wcs); 46 GWcs(const GWcs& wcs);
47 virtual ~GWcs(void); 47 virtual ~GWcs(void);
48 48
@@ -54,8 +54,8 @@ public: @@ -54,8 +54,8 @@ public:
54 54
55 // Implemented virtual methods 55 // Implemented virtual methods
56 virtual int size(void) const; 56 virtual int size(void) const;
57 - virtual void read(const GFitsHDU* hdu);  
58 - virtual void write(GFitsHDU* hdu) const; 57 + virtual void read(const GFitsHDU& hdu);
  58 + virtual void write(GFitsHDU& hdu) const;
59 virtual double omega(const GSkyPixel& pixel) const; 59 virtual double omega(const GSkyPixel& pixel) const;
60 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const; 60 virtual GSkyDir pix2dir(const GSkyPixel& pixel) const;
61 virtual GSkyPixel dir2pix(const GSkyDir& dir) const; 61 virtual GSkyPixel dir2pix(const GSkyDir& dir) const;
src/obs/GEnergies.cpp
@@ -363,11 +363,11 @@ void GEnergies::load(const std::string&amp; filename, const std::string&amp; extname) @@ -363,11 +363,11 @@ void GEnergies::load(const std::string&amp; filename, const std::string&amp; extname)
363 // Open FITS file 363 // Open FITS file
364 file.open(filename); 364 file.open(filename);
365 365
366 - // Get energies HDU  
367 - GFitsTable* hdu = file.table(extname); 366 + // Get energies table
  367 + const GFitsTable& table = *file.table(extname);
368 368
369 - // Read energies from HDU  
370 - read(hdu); 369 + // Read energies from table
  370 + read(table);
371 371
372 // Close FITS file 372 // Close FITS file
373 file.close(); 373 file.close();
@@ -396,7 +396,7 @@ void GEnergies::save(const std::string&amp; filename, bool clobber, @@ -396,7 +396,7 @@ void GEnergies::save(const std::string&amp; filename, bool clobber,
396 GFits file; 396 GFits file;
397 397
398 // Write energies to FITS file 398 // Write energies to FITS file
399 - write(&file, extname); 399 + write(file, extname);
400 400
401 // Save to file 401 // Save to file
402 file.saveto(filename, clobber); 402 file.saveto(filename, clobber);
@@ -409,11 +409,11 @@ void GEnergies::save(const std::string&amp; filename, bool clobber, @@ -409,11 +409,11 @@ void GEnergies::save(const std::string&amp; filename, bool clobber,
409 /***********************************************************************//** 409 /***********************************************************************//**
410 * @brief Read energies from FITS table 410 * @brief Read energies from FITS table
411 * 411 *
412 - * @param[in] hdu Pointer to FITS table. 412 + * @param[in] table FITS table.
413 * 413 *
414 * Reads the energies from a FITS table. 414 * Reads the energies from a FITS table.
415 ***************************************************************************/ 415 ***************************************************************************/
416 -void GEnergies::read(const GFitsTable* hdu) 416 +void GEnergies::read(const GFitsTable& table)
417 { 417 {
418 // Free members 418 // Free members
419 free_members(); 419 free_members();
@@ -421,33 +421,28 @@ void GEnergies::read(const GFitsTable* hdu) @@ -421,33 +421,28 @@ void GEnergies::read(const GFitsTable* hdu)
421 // Initialise attributes 421 // Initialise attributes
422 init_members(); 422 init_members();
423 423
424 - // Continue only if HDU is valid  
425 - if (hdu != NULL) { 424 + // Extract number of energy bins in FITS file
  425 + int num = table.integer("NAXIS2");
426 426
427 - // Extract number of energy bins in FITS file  
428 - int num = hdu->integer("NAXIS2"); 427 + // Continue only if there are energy bins
  428 + if (num > 0) {
429 429
430 - // Continue only if there are energy bins  
431 - if (num > 0) {  
432 -  
433 - // Get the unit of the energies. If no TUNIT1 header keyword is  
434 - // found then use MeV  
435 - std::string unit = "MeV";  
436 - if (hdu->hascard("TUNIT1")) {  
437 - unit = hdu->string("TUNIT1");  
438 - } 430 + // Get the unit of the energies. If no TUNIT1 header keyword is
  431 + // found then use MeV
  432 + std::string unit = "MeV";
  433 + if (table.hascard("TUNIT1")) {
  434 + unit = table.string("TUNIT1");
  435 + }
439 436
440 - // Get the column with the name "Energy"  
441 - const GFitsTableCol* col_energy = (*hdu)["Energy"]; 437 + // Get the column with the name "Energy"
  438 + const GFitsTableCol* col_energy = table["Energy"];
442 439
443 - // Set energies  
444 - for (int i = 0; i < num; ++i) {  
445 - append(GEnergy(col_energy->real(i), unit));  
446 - }  
447 -  
448 - } // endif: there were energy bins 440 + // Set energies
  441 + for (int i = 0; i < num; ++i) {
  442 + append(GEnergy(col_energy->real(i), unit));
  443 + }
449 444
450 - } // endif: the HDU was valid 445 + } // endif: there were energy bins
451 446
452 // Return 447 // Return
453 return; 448 return;
@@ -457,12 +452,12 @@ void GEnergies::read(const GFitsTable* hdu) @@ -457,12 +452,12 @@ void GEnergies::read(const GFitsTable* hdu)
457 /***********************************************************************//** 452 /***********************************************************************//**
458 * @brief Write energies into FITS object 453 * @brief Write energies into FITS object
459 * 454 *
460 - * @param[in] file Pointer to FITS file. 455 + * @param[in] file FITS file.
461 * @param[in] extname Energy extension name (defaults to "ENERGIES") 456 * @param[in] extname Energy extension name (defaults to "ENERGIES")
462 * 457 *
463 * Writes energies into FITS object. 458 * Writes energies into FITS object.
464 ***************************************************************************/ 459 ***************************************************************************/
465 -void GEnergies::write(GFits* file, const std::string& extname) const 460 +void GEnergies::write(GFits& file, const std::string& extname) const
466 { 461 {
467 // Set number of energies 462 // Set number of energies
468 int num = m_energies.size(); 463 int num = m_energies.size();
@@ -482,7 +477,7 @@ void GEnergies::write(GFits* file, const std::string&amp; extname) const @@ -482,7 +477,7 @@ void GEnergies::write(GFits* file, const std::string&amp; extname) const
482 table->extname(extname); 477 table->extname(extname);
483 478
484 // Write to FITS file 479 // Write to FITS file
485 - file->append(*table); 480 + file.append(*table);
486 481
487 // Free table 482 // Free table
488 delete table; 483 delete table;
src/sky/GHealpix.cpp
@@ -36,7 +36,7 @@ @@ -36,7 +36,7 @@
36 36
37 /* __ Method name definitions ____________________________________________ */ 37 /* __ Method name definitions ____________________________________________ */
38 #define G_CONSTRUCT "GHealpix::GHealpix(int& ,std::string& ,std::string&)" 38 #define G_CONSTRUCT "GHealpix::GHealpix(int& ,std::string& ,std::string&)"
39 -#define G_READ "GHealpix::read(GFitsHDU*)" 39 +#define G_READ "GHealpix::read(GFitsHDU&)"
40 #define G_XY2DIR "GHealpix::xy2dir(GSkyPixel&)" 40 #define G_XY2DIR "GHealpix::xy2dir(GSkyPixel&)"
41 #define G_DIR2XY2 "GHealpix::dir2xy(GSkyDir&)" 41 #define G_DIR2XY2 "GHealpix::dir2xy(GSkyDir&)"
42 #define G_PIX2ANG_RING "GHealpix::pix2ang_ring(int, double*, double*)" 42 #define G_PIX2ANG_RING "GHealpix::pix2ang_ring(int, double*, double*)"
@@ -133,14 +133,14 @@ GHealpix::GHealpix(const int&amp; nside, @@ -133,14 +133,14 @@ GHealpix::GHealpix(const int&amp; nside,
133 /***********************************************************************//** 133 /***********************************************************************//**
134 * @brief Constructor from FITS HDU table 134 * @brief Constructor from FITS HDU table
135 * 135 *
136 - * @param[in] hdu Pointer to FITS HDU. 136 + * @param[in] hdu FITS HDU.
137 ***************************************************************************/ 137 ***************************************************************************/
138 -GHealpix::GHealpix(const GFitsHDU* hdu) : GSkyProjection() 138 +GHealpix::GHealpix(const GFitsHDU& hdu) : GSkyProjection()
139 { 139 {
140 // Initialise class members 140 // Initialise class members
141 init_members(); 141 init_members();
142 142
143 - // Read Healpix defintion from FITS HDU 143 + // Read Healpix defintion from FITS table
144 read(hdu); 144 read(hdu);
145 145
146 // Return 146 // Return
@@ -253,7 +253,7 @@ GHealpix* GHealpix::clone(void) const @@ -253,7 +253,7 @@ GHealpix* GHealpix::clone(void) const
253 /***********************************************************************//** 253 /***********************************************************************//**
254 * @brief Read Healpix definiton from FITS header 254 * @brief Read Healpix definiton from FITS header
255 * 255 *
256 - * @param[in] hdu FITS HDU containing the Healpix definition. 256 + * @param[in] hdu FITS HDU.
257 * 257 *
258 * @exception GException::wcs 258 * @exception GException::wcs
259 * Unable to load Healpix definition from HDU. 259 * Unable to load Healpix definition from HDU.
@@ -262,29 +262,29 @@ GHealpix* GHealpix::clone(void) const @@ -262,29 +262,29 @@ GHealpix* GHealpix::clone(void) const
262 * @exception GException::wcs_hpx_bad_ordering 262 * @exception GException::wcs_hpx_bad_ordering
263 * Invalid ordering parameter. 263 * Invalid ordering parameter.
264 ***************************************************************************/ 264 ***************************************************************************/
265 -void GHealpix::read(const GFitsHDU* hdu) 265 +void GHealpix::read(const GFitsHDU& hdu)
266 { 266 {
267 // Clear object 267 // Clear object
268 clear(); 268 clear();
269 269
270 // Check if we have a healpix representation 270 // Check if we have a healpix representation
271 - if (hdu->string("PIXTYPE") != "HEALPIX") { 271 + if (hdu.string("PIXTYPE") != "HEALPIX") {
272 throw GException::wcs(G_READ, "HDU does not contain Healpix data"); 272 throw GException::wcs(G_READ, "HDU does not contain Healpix data");
273 } 273 }
274 274
275 // Get pixel ordering 275 // Get pixel ordering
276 - std::string order = hdu->string("ORDERING"); 276 + std::string order = hdu.string("ORDERING");
277 277
278 // Get coordinate system. 278 // Get coordinate system.
279 // First search for HIER_CRD keyword (this has been used in older 279 // First search for HIER_CRD keyword (this has been used in older
280 // versions of LAT exposure cubes). If not found then search for standard 280 // versions of LAT exposure cubes). If not found then search for standard
281 // COORDSYS keyword. 281 // COORDSYS keyword.
282 std::string coords; 282 std::string coords;
283 - if (hdu->hascard("HIER_CRD")) {  
284 - coords = hdu->string("HIER_CRD"); 283 + if (hdu.hascard("HIER_CRD")) {
  284 + coords = hdu.string("HIER_CRD");
285 } 285 }
286 - else if (hdu->hascard("COORDSYS")) {  
287 - coords = hdu->string("COORDSYS"); 286 + else if (hdu.hascard("COORDSYS")) {
  287 + coords = hdu.string("COORDSYS");
288 } 288 }
289 289
290 // Set coordinate system 290 // Set coordinate system
@@ -294,7 +294,7 @@ void GHealpix::read(const GFitsHDU* hdu) @@ -294,7 +294,7 @@ void GHealpix::read(const GFitsHDU* hdu)
294 ordering(order); 294 ordering(order);
295 295
296 // Get Healpix resolution and determine number of pixels and solid angle 296 // Get Healpix resolution and determine number of pixels and solid angle
297 - m_nside = hdu->integer("NSIDE"); 297 + m_nside = hdu.integer("NSIDE");
298 m_npface = m_nside * m_nside; 298 m_npface = m_nside * m_nside;
299 m_ncap = 2 * (m_npface - m_nside); 299 m_ncap = 2 * (m_npface - m_nside);
300 m_num_pixels = 12 * m_npface; 300 m_num_pixels = 12 * m_npface;
@@ -322,25 +322,20 @@ void GHealpix::read(const GFitsHDU* hdu) @@ -322,25 +322,20 @@ void GHealpix::read(const GFitsHDU* hdu)
322 * ORDERING = ordering() 322 * ORDERING = ordering()
323 * COORDSYS = coordsys() 323 * COORDSYS = coordsys()
324 ***************************************************************************/ 324 ***************************************************************************/
325 -void GHealpix::write(GFitsHDU* hdu) const 325 +void GHealpix::write(GFitsHDU& hdu) const
326 { 326 {
327 - // Continue only if file pointer is valid  
328 - if (hdu != NULL) {  
329 -  
330 - // Set extension name  
331 - hdu->extname("HEALPIX");  
332 -  
333 - // Set keywords  
334 - hdu->card("PIXTYPE", "HEALPIX", "HEALPix pixelisation");  
335 - hdu->card("NSIDE", nside(), "HEALPix resolution parameter");  
336 - hdu->card("FIRSTPIX", 0, "Index of first pixel");  
337 - hdu->card("LASTPIX", npix()-1, "Index of last pixel");  
338 - hdu->card("ORDERING", ordering(),  
339 - "Pixel ordering scheme, either RING or NESTED");  
340 - hdu->card("COORDSYS", coordsys(),  
341 - "Coordinate system, either EQU or GAL");  
342 -  
343 - } // endif: HDU was valid 327 + // Set extension name
  328 + hdu.extname("HEALPIX");
  329 +
  330 + // Set keywords
  331 + hdu.card("PIXTYPE", "HEALPIX", "HEALPix pixelisation");
  332 + hdu.card("NSIDE", nside(), "HEALPix resolution parameter");
  333 + hdu.card("FIRSTPIX", 0, "Index of first pixel");
  334 + hdu.card("LASTPIX", npix()-1, "Index of last pixel");
  335 + hdu.card("ORDERING", ordering(),
  336 + "Pixel ordering scheme, either RING or NESTED");
  337 + hdu.card("COORDSYS", coordsys(),
  338 + "Coordinate system, either EQU or GAL");
344 339
345 // Return 340 // Return
346 return; 341 return;
src/sky/GSkymap.cpp
@@ -52,7 +52,7 @@ @@ -52,7 +52,7 @@
52 #define G_DIR2PIX "GSkymap::dir2pix(GSkyDir&)" 52 #define G_DIR2PIX "GSkymap::dir2pix(GSkyDir&)"
53 #define G_OMEGA1 "GSkymap::omega(int&)" 53 #define G_OMEGA1 "GSkymap::omega(int&)"
54 #define G_OMEGA2 "GSkymap::omega(GSkyPixel&)" 54 #define G_OMEGA2 "GSkymap::omega(GSkyPixel&)"
55 -#define G_READ "GSkymap::read(const GFitsHDU*)" 55 +#define G_READ "GSkymap::read(const GFitsHDU&)"
56 #define G_SET_WCS "GSkymap::set_wcs(std::string&, std::string&, double&,"\ 56 #define G_SET_WCS "GSkymap::set_wcs(std::string&, std::string&, double&,"\
57 " double&, double&, double&, double&, double&,"\ 57 " double&, double&, double&, double&, double&,"\
58 " GMatrix&, GVector&)" 58 " GMatrix&, GVector&)"
@@ -937,21 +937,20 @@ void GSkymap::load(const std::string&amp; filename) @@ -937,21 +937,20 @@ void GSkymap::load(const std::string&amp; filename)
937 // Get number of HDUs 937 // Get number of HDUs
938 int num = fits.size(); 938 int num = fits.size();
939 939
940 - // Initialize pointer to HDU and load flag  
941 - GFitsHDU* hdu = NULL;  
942 - bool loaded = false; 940 + // Initialize load flag
  941 + bool loaded = false;
943 942
944 // First search for HEALPix extension. We can skip the first extension 943 // First search for HEALPix extension. We can skip the first extension
945 // since this is always an image and a HEALPix map is stored in a 944 // since this is always an image and a HEALPix map is stored in a
946 // binary table 945 // binary table
947 for (int extno = 1; extno < num; ++extno) { 946 for (int extno = 1; extno < num; ++extno) {
948 947
949 - // Get pointer to HDU  
950 - hdu = fits.at(extno); 948 + // Get reference to HDU
  949 + const GFitsHDU& hdu = *fits.at(extno);
951 950
952 // If PIXTYPE keyword equals "HEALPIX" then load map 951 // If PIXTYPE keyword equals "HEALPIX" then load map
953 - if (hdu->hascard("PIXTYPE") && hdu->string("PIXTYPE") == "HEALPIX") {  
954 - read_healpix(static_cast<const GFitsTable*>(hdu)); 952 + if (hdu.hascard("PIXTYPE") && hdu.string("PIXTYPE") == "HEALPIX") {
  953 + read_healpix(static_cast<const GFitsTable&>(hdu));
955 loaded = true; 954 loaded = true;
956 break; 955 break;
957 } 956 }
@@ -963,17 +962,17 @@ void GSkymap::load(const std::string&amp; filename) @@ -963,17 +962,17 @@ void GSkymap::load(const std::string&amp; filename)
963 if (!loaded) { 962 if (!loaded) {
964 for (int extno = 0; extno < num; ++extno) { 963 for (int extno = 0; extno < num; ++extno) {
965 964
966 - // Get pointer to HDU  
967 - hdu = fits.at(extno); 965 + // Get referene to HDU
  966 + const GFitsHDU& hdu = *fits.at(extno);
968 967
969 // Skip if extension is not an image 968 // Skip if extension is not an image
970 if (extno > 0) { 969 if (extno > 0) {
971 - if (hdu->string("XTENSION") != "IMAGE") 970 + if (hdu.string("XTENSION") != "IMAGE")
972 continue; 971 continue;
973 } 972 }
974 973
975 // Load WCS map 974 // Load WCS map
976 - read_wcs(static_cast<const GFitsImage*>(hdu)); 975 + read_wcs(static_cast<const GFitsImage&>(hdu));
977 loaded = true; 976 loaded = true;
978 break; 977 break;
979 978
@@ -1035,39 +1034,32 @@ void GSkymap::save(const std::string&amp; filename, bool clobber) const @@ -1035,39 +1034,32 @@ void GSkymap::save(const std::string&amp; filename, bool clobber) const
1035 * @brief Read skymap from FITS HDU 1034 * @brief Read skymap from FITS HDU
1036 * 1035 *
1037 * @param[in] hdu FITS HDU. 1036 * @param[in] hdu FITS HDU.
1038 - *  
1039 - * The method returns an empty skymap of the HDU pointer was not valid.  
1040 ***************************************************************************/ 1037 ***************************************************************************/
1041 -void GSkymap::read(const GFitsHDU* hdu) 1038 +void GSkymap::read(const GFitsHDU& hdu)
1042 { 1039 {
1043 // Free memory and initialise members 1040 // Free memory and initialise members
1044 free_members(); 1041 free_members();
1045 init_members(); 1042 init_members();
1046 1043
1047 - // Continue only if HDU pointer is valid  
1048 - if (hdu != NULL) { 1044 + // Initialize load flag
  1045 + bool loaded = false;
1049 1046
1050 - // Initialize load flag  
1051 - bool loaded = false; 1047 + // If PIXTYPE keyword equals "HEALPIX" then load map
  1048 + if (hdu.hascard("PIXTYPE") && hdu.string("PIXTYPE") == "HEALPIX") {
  1049 + read_healpix(static_cast<const GFitsTable&>(hdu));
  1050 + loaded = true;
  1051 + }
1052 1052
1053 - // If PIXTYPE keyword equals "HEALPIX" then load map  
1054 - if (hdu->hascard("PIXTYPE") && hdu->string("PIXTYPE") == "HEALPIX") {  
1055 - read_healpix(static_cast<const GFitsTable*>(hdu)); 1053 + // ... otherwise try loading as non HEALPix map
  1054 + if (!loaded) {
  1055 +
  1056 + // Load only if HDU contains an image
  1057 + if (hdu.exttype() == 0) {
  1058 + read_wcs(static_cast<const GFitsImage&>(hdu));
1056 loaded = true; 1059 loaded = true;
1057 } 1060 }
1058 1061
1059 - // ... otherwise try loading as non HEALPix map  
1060 - if (!loaded) {  
1061 -  
1062 - // Load only if HDU contains an image  
1063 - if (hdu->exttype() == 0) {  
1064 - read_wcs(static_cast<const GFitsImage*>(hdu));  
1065 - loaded = true;  
1066 - }  
1067 -  
1068 - } // endif  
1069 -  
1070 - } // endif: HDU pointer was valid 1062 + } // endif
1071 1063
1072 // Return 1064 // Return
1073 return; 1065 return;
@@ -1079,7 +1071,7 @@ void GSkymap::read(const GFitsHDU* hdu) @@ -1079,7 +1071,7 @@ void GSkymap::read(const GFitsHDU* hdu)
1079 * 1071 *
1080 * @param[in] file FITS file pointer. 1072 * @param[in] file FITS file pointer.
1081 ***************************************************************************/ 1073 ***************************************************************************/
1082 -void GSkymap::write(GFits* file) const 1074 +void GSkymap::write(GFits& file) const
1083 { 1075 {
1084 // Continue only if we have data to save 1076 // Continue only if we have data to save
1085 if (m_proj != NULL) { 1077 if (m_proj != NULL) {
@@ -1099,7 +1091,7 @@ void GSkymap::write(GFits* file) const @@ -1099,7 +1091,7 @@ void GSkymap::write(GFits* file) const
1099 1091
1100 // Append HDU to FITS file. 1092 // Append HDU to FITS file.
1101 if (hdu != NULL) { 1093 if (hdu != NULL) {
1102 - file->append(*hdu); 1094 + file.append(*hdu);
1103 } 1095 }
1104 1096
1105 // Delete HDU 1097 // Delete HDU
@@ -1330,7 +1322,7 @@ void GSkymap::set_wcs(const std::string&amp; wcs, const std::string&amp; coords, @@ -1330,7 +1322,7 @@ void GSkymap::set_wcs(const std::string&amp; wcs, const std::string&amp; coords,
1330 /***********************************************************************//** 1322 /***********************************************************************//**
1331 * @brief Read Healpix data from FITS table. 1323 * @brief Read Healpix data from FITS table.
1332 * 1324 *
1333 - * @param[in] hdu FITS HDU containing the Healpix data. 1325 + * @param[in] table FITS table.
1334 * 1326 *
1335 * HEALPix data may be stored in various formats depending on the 1327 * HEALPix data may be stored in various formats depending on the
1336 * application that has writted the data. HEALPix IDL, for example, may 1328 * application that has writted the data. HEALPix IDL, for example, may
@@ -1339,114 +1331,109 @@ void GSkymap::set_wcs(const std::string&amp; wcs, const std::string&amp; coords, @@ -1339,114 +1331,109 @@ void GSkymap::set_wcs(const std::string&amp; wcs, const std::string&amp; coords,
1339 * several HEALPix maps into a single column. Alternatively, multiple maps 1331 * several HEALPix maps into a single column. Alternatively, multiple maps
1340 * may be stored in multiple columns. 1332 * may be stored in multiple columns.
1341 ***************************************************************************/ 1333 ***************************************************************************/
1342 -void GSkymap::read_healpix(const GFitsTable* hdu) 1334 +void GSkymap::read_healpix(const GFitsTable& table)
1343 { 1335 {
1344 - // Continue only if HDU is valid  
1345 - if (hdu != NULL) {  
1346 -  
1347 - // Determine number of rows and columns in table  
1348 - int nrows = hdu->nrows();  
1349 - int ncols = hdu->ncols();  
1350 - #if defined(G_READ_HEALPIX_DEBUG)  
1351 - std::cout << "nrows=" << nrows << " ncols=" << ncols << std::endl;  
1352 - #endif  
1353 -  
1354 - // Allocate Healpix projection  
1355 - m_proj = new GHealpix;  
1356 -  
1357 - // Read WCS information from FITS header  
1358 - m_proj->read(hdu);  
1359 -  
1360 - // Set number of pixels based on NSIDE parameter  
1361 - m_num_pixels = static_cast<GHealpix*>(m_proj)->npix();  
1362 - #if defined(G_READ_HEALPIX_DEBUG)  
1363 - std::cout << "m_num_pixels=" << m_num_pixels << std::endl;  
1364 - #endif  
1365 -  
1366 - // Number of map pixels has to be a multiple of the number of  
1367 - // rows in column  
1368 - if (m_num_pixels % nrows != 0) {  
1369 - throw GException::skymap_bad_size(G_READ_HEALPIX, nrows,  
1370 - m_num_pixels);  
1371 - } 1336 + // Determine number of rows and columns in table
  1337 + int nrows = table.nrows();
  1338 + int ncols = table.ncols();
  1339 + #if defined(G_READ_HEALPIX_DEBUG)
  1340 + std::cout << "nrows=" << nrows << " ncols=" << ncols << std::endl;
  1341 + #endif
1372 1342
1373 - // Determine vector length for HEALPix data storage  
1374 - int nentry = m_num_pixels / nrows;  
1375 - #if defined(G_READ_HEALPIX_DEBUG)  
1376 - std::cout << "nentry=" << nentry << std::endl;  
1377 - #endif  
1378 -  
1379 - // Determine number of maps from the number of maps that fit into  
1380 - // all columns. Only count columns that can fully hold the map.  
1381 - m_num_maps = 0;  
1382 - for (int icol = 0; icol < ncols; ++icol) {  
1383 - const GFitsTableCol* col = (*hdu)[icol];  
1384 - if (col->number() % nentry == 0) {  
1385 - m_num_maps += col->number() / nentry;  
1386 - }  
1387 - }  
1388 - #if defined(G_READ_HEALPIX_DEBUG)  
1389 - std::cout << "m_num_maps=" << m_num_maps << std::endl;  
1390 - #endif 1343 + // Allocate Healpix projection
  1344 + m_proj = new GHealpix;
1391 1345
1392 - // Allocate pixels to hold the map  
1393 - alloc_pixels(); 1346 + // Read WCS information from FITS header
  1347 + m_proj->read(table);
  1348 +
  1349 + // Set number of pixels based on NSIDE parameter
  1350 + m_num_pixels = static_cast<GHealpix*>(m_proj)->npix();
  1351 + #if defined(G_READ_HEALPIX_DEBUG)
  1352 + std::cout << "m_num_pixels=" << m_num_pixels << std::endl;
  1353 + #endif
1394 1354
1395 - // Initialise map counter  
1396 - int imap = 0; 1355 + // Number of map pixels has to be a multiple of the number of
  1356 + // rows in column
  1357 + if (m_num_pixels % nrows != 0) {
  1358 + throw GException::skymap_bad_size(G_READ_HEALPIX, nrows,
  1359 + m_num_pixels);
  1360 + }
1397 1361
1398 - // Loop over all columns  
1399 - for (int icol = 0; icol < ncols; ++icol) { 1362 + // Determine vector length for HEALPix data storage
  1363 + int nentry = m_num_pixels / nrows;
  1364 + #if defined(G_READ_HEALPIX_DEBUG)
  1365 + std::cout << "nentry=" << nentry << std::endl;
  1366 + #endif
  1367 +
  1368 + // Determine number of maps from the number of maps that fit into
  1369 + // all columns. Only count columns that can fully hold the map.
  1370 + m_num_maps = 0;
  1371 + for (int icol = 0; icol < ncols; ++icol) {
  1372 + const GFitsTableCol* col = table[icol];
  1373 + if (col->number() % nentry == 0) {
  1374 + m_num_maps += col->number() / nentry;
  1375 + }
  1376 + }
  1377 + #if defined(G_READ_HEALPIX_DEBUG)
  1378 + std::cout << "m_num_maps=" << m_num_maps << std::endl;
  1379 + #endif
1400 1380
1401 - // Get next column  
1402 - const GFitsTableCol* col = (*hdu)[icol]; 1381 + // Allocate pixels to hold the map
  1382 + alloc_pixels();
1403 1383
1404 - // Only consider columns that can fully hold maps  
1405 - if (col->number() % nentry == 0) { 1384 + // Initialise map counter
  1385 + int imap = 0;
1406 1386
1407 - // Determine number of maps in column  
1408 - int num = col->number() / nentry; 1387 + // Loop over all columns
  1388 + for (int icol = 0; icol < ncols; ++icol) {
1409 1389
1410 - // Loop over all maps in column  
1411 - int inx_start = 0;  
1412 - int inx_end = nentry;  
1413 - for (int i = 0; i < num; ++i) { 1390 + // Get next column
  1391 + const GFitsTableCol* col = table[icol];
1414 1392
1415 - // Load map  
1416 - double *ptr = m_pixels + m_num_pixels*imap;  
1417 - for (int row = 0; row < col->length(); ++row) {  
1418 - for (int inx = inx_start; inx < inx_end; ++inx) {  
1419 - *ptr++ = col->real(row,inx);  
1420 - }  
1421 - }  
1422 - #if defined(G_READ_HEALPIX_DEBUG)  
1423 - std::cout << "Load map=" << imap << " index="  
1424 - << inx_start << "-" << inx_end << std::endl;  
1425 - #endif 1393 + // Only consider columns that can fully hold maps
  1394 + if (col->number() % nentry == 0) {
1426 1395
1427 - // Increment index range  
1428 - inx_start = inx_end;  
1429 - inx_end += nentry; 1396 + // Determine number of maps in column
  1397 + int num = col->number() / nentry;
1430 1398
1431 - // Increment map counter  
1432 - imap++; 1399 + // Loop over all maps in column
  1400 + int inx_start = 0;
  1401 + int inx_end = nentry;
  1402 + for (int i = 0; i < num; ++i) {
1433 1403
1434 - // Break if we have loaded all maps  
1435 - if (imap >= m_num_maps) {  
1436 - break; 1404 + // Load map
  1405 + double *ptr = m_pixels + m_num_pixels*imap;
  1406 + for (int row = 0; row < col->length(); ++row) {
  1407 + for (int inx = inx_start; inx < inx_end; ++inx) {
  1408 + *ptr++ = col->real(row,inx);
1437 } 1409 }
  1410 + }
  1411 + #if defined(G_READ_HEALPIX_DEBUG)
  1412 + std::cout << "Load map=" << imap << " index="
  1413 + << inx_start << "-" << inx_end << std::endl;
  1414 + #endif
1438 1415
1439 - } // endfor: looped over all maps in column  
1440 - } // endif: column could fully hold maps 1416 + // Increment index range
  1417 + inx_start = inx_end;
  1418 + inx_end += nentry;
1441 1419
1442 - // Break if we have loaded all maps  
1443 - if (imap >= m_num_maps) {  
1444 - break;  
1445 - } 1420 + // Increment map counter
  1421 + imap++;
1446 1422
1447 - } // endfor: looped over all columns 1423 + // Break if we have loaded all maps
  1424 + if (imap >= m_num_maps) {
  1425 + break;
  1426 + }
  1427 +
  1428 + } // endfor: looped over all maps in column
  1429 + } // endif: column could fully hold maps
  1430 +
  1431 + // Break if we have loaded all maps
  1432 + if (imap >= m_num_maps) {
  1433 + break;
  1434 + }
1448 1435
1449 - } // endif: HDU was valid 1436 + } // endfor: looped over all columns
1450 1437
1451 // Return 1438 // Return
1452 return; 1439 return;
@@ -1456,72 +1443,67 @@ void GSkymap::read_healpix(const GFitsTable* hdu) @@ -1456,72 +1443,67 @@ void GSkymap::read_healpix(const GFitsTable* hdu)
1456 /***********************************************************************//** 1443 /***********************************************************************//**
1457 * @brief Read WCS image from FITS HDU 1444 * @brief Read WCS image from FITS HDU
1458 * 1445 *
1459 - * @param[in] hdu FITS HDU containing the WCS image. 1446 + * @param[in] image FITS image.
1460 * 1447 *
1461 * @exception GException::skymap_bad_image_dim 1448 * @exception GException::skymap_bad_image_dim
1462 * WCS image has invalid dimension (naxis=2 or 3). 1449 * WCS image has invalid dimension (naxis=2 or 3).
1463 ***************************************************************************/ 1450 ***************************************************************************/
1464 -void GSkymap::read_wcs(const GFitsImage* hdu) 1451 +void GSkymap::read_wcs(const GFitsImage& image)
1465 { 1452 {
1466 - // Continue only if HDU is valid  
1467 - if (hdu != NULL) { 1453 + // Allocate WCS
  1454 + alloc_wcs(image);
1468 1455
1469 - // Allocate WCS  
1470 - alloc_wcs(hdu); 1456 + // Read projection information from FITS header
  1457 + m_proj->read(image);
1471 1458
1472 - // Read projection information from FITS header  
1473 - m_proj->read(hdu); 1459 + // Extract map dimension and number of maps from image
  1460 + if (image.naxis() == 2) {
  1461 + m_num_x = image.naxes(0);
  1462 + m_num_y = image.naxes(1);
  1463 + m_num_maps = 1;
  1464 + }
  1465 + else if (image.naxis() >= 3) {
  1466 + m_num_x = image.naxes(0);
  1467 + m_num_y = image.naxes(1);
  1468 + m_num_maps = image.naxes(2);
  1469 + }
  1470 + else {
  1471 + throw GException::skymap_bad_image_dim(G_READ_WCS, image.naxis());
  1472 + }
  1473 + #if defined(G_READ_WCS_DEBUG)
  1474 + std::cout << "m_num_x=" << m_num_x << std::endl;
  1475 + std::cout << "m_num_y=" << m_num_y << std::endl;
  1476 + std::cout << "m_num_maps=" << m_num_maps << std::endl;
  1477 + #endif
1474 1478
1475 - // Extract map dimension and number of maps from image  
1476 - if (hdu->naxis() == 2) {  
1477 - m_num_x = hdu->naxes(0);  
1478 - m_num_y = hdu->naxes(1);  
1479 - m_num_maps = 1;  
1480 - }  
1481 - else if (hdu->naxis() >= 3) {  
1482 - m_num_x = hdu->naxes(0);  
1483 - m_num_y = hdu->naxes(1);  
1484 - m_num_maps = hdu->naxes(2);  
1485 - }  
1486 - else {  
1487 - throw GException::skymap_bad_image_dim(G_READ_WCS, hdu->naxis());  
1488 - }  
1489 - #if defined(G_READ_WCS_DEBUG)  
1490 - std::cout << "m_num_x=" << m_num_x << std::endl;  
1491 - std::cout << "m_num_y=" << m_num_y << std::endl;  
1492 - std::cout << "m_num_maps=" << m_num_maps << std::endl;  
1493 - #endif  
1494 -  
1495 - // Compute number of pixels  
1496 - m_num_pixels = m_num_x * m_num_y;  
1497 - #if defined(G_READ_WCS_DEBUG)  
1498 - std::cout << "m_num_pixels=" << m_num_pixels << std::endl;  
1499 - #endif  
1500 -  
1501 - // Allocate pixels to hold the map  
1502 - alloc_pixels(); 1479 + // Compute number of pixels
  1480 + m_num_pixels = m_num_x * m_num_y;
  1481 + #if defined(G_READ_WCS_DEBUG)
  1482 + std::cout << "m_num_pixels=" << m_num_pixels << std::endl;
  1483 + #endif
1503 1484
1504 - // Read image  
1505 - if (hdu->naxis() == 2) {  
1506 - double* ptr = m_pixels;  
1507 - for (int iy = 0; iy < m_num_y; ++iy) {  
1508 - for (int ix = 0; ix < m_num_x; ++ix) {  
1509 - *ptr++ = hdu->pixel(ix,iy);  
1510 - } 1485 + // Allocate pixels to hold the map
  1486 + alloc_pixels();
  1487 +
  1488 + // Read image
  1489 + if (image.naxis() == 2) {
  1490 + double* ptr = m_pixels;
  1491 + for (int iy = 0; iy < m_num_y; ++iy) {
  1492 + for (int ix = 0; ix < m_num_x; ++ix) {
  1493 + *ptr++ = image.pixel(ix,iy);
1511 } 1494 }
1512 } 1495 }
1513 - else {  
1514 - double* ptr = m_pixels;  
1515 - for (int imap = 0; imap < m_num_maps; ++imap) {  
1516 - for (int iy = 0; iy < m_num_y; ++iy) {  
1517 - for (int ix = 0; ix < m_num_x; ++ix) {  
1518 - *ptr++ = hdu->pixel(ix,iy,imap);  
1519 - } 1496 + }
  1497 + else {
  1498 + double* ptr = m_pixels;
  1499 + for (int imap = 0; imap < m_num_maps; ++imap) {
  1500 + for (int iy = 0; iy < m_num_y; ++iy) {
  1501 + for (int ix = 0; ix < m_num_x; ++ix) {
  1502 + *ptr++ = image.pixel(ix,iy,imap);
1520 } 1503 }
1521 } 1504 }
1522 } 1505 }
1523 -  
1524 - } // endif: HDU was valid 1506 + }
1525 1507
1526 // Return 1508 // Return
1527 return; 1509 return;
@@ -1531,7 +1513,7 @@ void GSkymap::read_wcs(const GFitsImage* hdu) @@ -1531,7 +1513,7 @@ void GSkymap::read_wcs(const GFitsImage* hdu)
1531 /***********************************************************************//** 1513 /***********************************************************************//**
1532 * @brief Allocate WCS class 1514 * @brief Allocate WCS class
1533 * 1515 *
1534 - * @param[in] hdu FITS HDU containing the WCS image. 1516 + * @param[in] image FITS image.
1535 * 1517 *
1536 * @exception GException::fits_key_not_found 1518 * @exception GException::fits_key_not_found
1537 * Unable to find required FITS header keyword. 1519 * Unable to find required FITS header keyword.
@@ -1540,39 +1522,34 @@ void GSkymap::read_wcs(const GFitsImage* hdu) @@ -1540,39 +1522,34 @@ void GSkymap::read_wcs(const GFitsImage* hdu)
1540 * @exception GException::wcs_invalid 1522 * @exception GException::wcs_invalid
1541 * WCS projection of FITS file not supported by GammaLib. 1523 * WCS projection of FITS file not supported by GammaLib.
1542 ***************************************************************************/ 1524 ***************************************************************************/
1543 -void GSkymap::alloc_wcs(const GFitsImage* hdu) 1525 +void GSkymap::alloc_wcs(const GFitsImage& image)
1544 { 1526 {
1545 - // Continue only if HDU is valid  
1546 - if (hdu != NULL) {  
1547 -  
1548 - // Get standard keywords  
1549 - std::string ctype1 = hdu->string("CTYPE1");  
1550 - std::string ctype2 = hdu->string("CTYPE2");  
1551 -  
1552 - // Extract projection type  
1553 - std::string xproj = ctype1.substr(5,3);  
1554 - std::string yproj = ctype2.substr(5,3);  
1555 -  
1556 - // Check that projection type is identical on both axes  
1557 - if (xproj != yproj) {  
1558 - throw GException::skymap_bad_ctype(G_ALLOC_WCS,  
1559 - ctype1, ctype2);  
1560 - }  
1561 -  
1562 - // Allocate WCS registry  
1563 - GWcsRegistry registry;  
1564 -  
1565 - // Allocate projection from registry  
1566 - m_proj = registry.alloc(xproj);  
1567 -  
1568 - // Signal if projection type is not known  
1569 - if (m_proj == NULL) {  
1570 - std::string message = "Projection code not known. "  
1571 - "Should be one of "+registry.list()+".";  
1572 - throw GException::wcs_invalid(G_ALLOC_WCS, xproj, message);  
1573 - } 1527 + // Get standard keywords
  1528 + std::string ctype1 = image.string("CTYPE1");
  1529 + std::string ctype2 = image.string("CTYPE2");
  1530 +
  1531 + // Extract projection type
  1532 + std::string xproj = ctype1.substr(5,3);
  1533 + std::string yproj = ctype2.substr(5,3);
  1534 +
  1535 + // Check that projection type is identical on both axes
  1536 + if (xproj != yproj) {
  1537 + throw GException::skymap_bad_ctype(G_ALLOC_WCS,
  1538 + ctype1, ctype2);
  1539 + }
1574 1540
1575 - } // endif: HDU was valid 1541 + // Allocate WCS registry
  1542 + GWcsRegistry registry;
  1543 +
  1544 + // Allocate projection from registry
  1545 + m_proj = registry.alloc(xproj);
  1546 +
  1547 + // Signal if projection type is not known
  1548 + if (m_proj == NULL) {
  1549 + std::string message = "Projection code not known. "
  1550 + "Should be one of "+registry.list()+".";
  1551 + throw GException::wcs_invalid(G_ALLOC_WCS, xproj, message);
  1552 + }
1576 1553
1577 // Return 1554 // Return
1578 return; 1555 return;
@@ -1626,7 +1603,7 @@ GFitsBinTable* GSkymap::create_healpix_hdu(void) const @@ -1626,7 +1603,7 @@ GFitsBinTable* GSkymap::create_healpix_hdu(void) const
1626 hdu->extname("HEALPIX"); 1603 hdu->extname("HEALPIX");
1627 1604
1628 // If we have WCS information then write into FITS header 1605 // If we have WCS information then write into FITS header
1629 - if (m_proj != NULL) m_proj->write(hdu); 1606 + if (m_proj != NULL) m_proj->write(*hdu);
1630 1607
1631 // Set additional keywords 1608 // Set additional keywords
1632 hdu->card("NBRBINS", m_num_maps, "Number of HEALPix maps"); 1609 hdu->card("NBRBINS", m_num_maps, "Number of HEALPix maps");
@@ -1693,7 +1670,7 @@ GFitsImageDouble* GSkymap::create_wcs_hdu(void) const @@ -1693,7 +1670,7 @@ GFitsImageDouble* GSkymap::create_wcs_hdu(void) const
1693 hdu->extname("IMAGE"); 1670 hdu->extname("IMAGE");
1694 1671
1695 // If we have sky projection information then write into FITS header 1672 // If we have sky projection information then write into FITS header
1696 - if (m_proj != NULL) m_proj->write(hdu); 1673 + if (m_proj != NULL) m_proj->write(*hdu);
1697 1674
1698 // Set additional keywords 1675 // Set additional keywords
1699 //TODO 1676 //TODO
src/sky/GWcs.cpp
@@ -36,7 +36,7 @@ @@ -36,7 +36,7 @@
36 #include "GWcs.hpp" 36 #include "GWcs.hpp"
37 37
38 /* __ Method name definitions ____________________________________________ */ 38 /* __ Method name definitions ____________________________________________ */
39 -#define G_READ "GWcs::read(GFitsHDU*)" 39 +#define G_READ "GWcs::read(GFitsHDU&)"
40 #define G_OMEGA "GWcs::omega(int&)" 40 #define G_OMEGA "GWcs::omega(int&)"
41 #define G_PIX2DIR "GWcs::pix2dir(int&)" 41 #define G_PIX2DIR "GWcs::pix2dir(int&)"
42 #define G_DIR2PIX "GWcs::dir2pix(GSkyDir&)" 42 #define G_DIR2PIX "GWcs::dir2pix(GSkyDir&)"
@@ -121,7 +121,7 @@ GWcs::GWcs(const std::string&amp; coords, @@ -121,7 +121,7 @@ GWcs::GWcs(const std::string&amp; coords,
121 * 121 *
122 * @param[in] hdu FITS HDU. 122 * @param[in] hdu FITS HDU.
123 ***************************************************************************/ 123 ***************************************************************************/
124 -GWcs::GWcs(const GFitsHDU* hdu) : GSkyProjection() 124 +GWcs::GWcs(const GFitsHDU& hdu) : GSkyProjection()
125 { 125 {
126 // Initialise class members 126 // Initialise class members
127 init_members(); 127 init_members();
@@ -210,93 +210,88 @@ GWcs&amp; GWcs::operator=(const GWcs&amp; wcs) @@ -210,93 +210,88 @@ GWcs&amp; GWcs::operator=(const GWcs&amp; wcs)
210 /***********************************************************************//** 210 /***********************************************************************//**
211 * @brief Read WCS definiton from FITS header. 211 * @brief Read WCS definiton from FITS header.
212 * 212 *
213 - * @param[in] hdu FITS HDU containing the WCS definition. 213 + * @param[in] hdu FITS HDU.
214 * 214 *
215 * @exception GException::wcs_bad_coords 215 * @exception GException::wcs_bad_coords
216 * Coordinate system is not of valid type. 216 * Coordinate system is not of valid type.
217 * 217 *
218 * This method reads the WCS definition from the FITS header. 218 * This method reads the WCS definition from the FITS header.
219 ***************************************************************************/ 219 ***************************************************************************/
220 -void GWcs::read(const GFitsHDU* hdu) 220 +void GWcs::read(const GFitsHDU& hdu)
221 { 221 {
222 // Clear object 222 // Clear object
223 clear(); 223 clear();
224 224
225 - // Continue only if HDU is valid  
226 - if (hdu != NULL) {  
227 -  
228 - // Get standard keywords  
229 - std::string ctype1 = hdu->string("CTYPE1");  
230 - std::string ctype2 = hdu->string("CTYPE2");  
231 - double crval1 = hdu->real("CRVAL1");  
232 - double crval2 = hdu->real("CRVAL2");  
233 - double crpix1 = hdu->real("CRPIX1");  
234 - double crpix2 = hdu->real("CRPIX2");  
235 - double cdelt1 = hdu->real("CDELT1");  
236 - double cdelt2 = hdu->real("CDELT2");  
237 -  
238 - // Determine coordinate system  
239 - std::string coords;  
240 - std::string xcoord = ctype1.substr(0,4);  
241 - std::string ycoord = ctype2.substr(0,4);  
242 - if (xcoord == "RA--" && ycoord == "DEC-") {  
243 - m_lng = 0;  
244 - m_lat = 1;  
245 - coords = "EQU";  
246 - }  
247 - else if (xcoord == "DEC-" && ycoord == "RA--") {  
248 - m_lng = 1;  
249 - m_lat = 0;  
250 - coords = "EQU";  
251 - }  
252 - else if (xcoord == "GLON" && ycoord == "GLAT") {  
253 - m_lng = 0;  
254 - m_lat = 1;  
255 - coords = "GAL";  
256 - }  
257 - else if (xcoord == "GLAT" && ycoord == "GLON") {  
258 - m_lng = 1;  
259 - m_lat = 0;  
260 - coords = "GAL";  
261 - }  
262 - else if (xcoord == "ELON" && ycoord == "ELAT") {  
263 - m_lng = 0;  
264 - m_lat = 1;  
265 - coords = "ECL";  
266 - }  
267 - else if (xcoord == "ELAT" && ycoord == "ELON") {  
268 - m_lng = 1;  
269 - m_lat = 0;  
270 - coords = "ECL";  
271 - }  
272 - else if (xcoord == "HLON" && ycoord == "HLAT") {  
273 - m_lng = 0;  
274 - m_lat = 1;  
275 - coords = "HEL";  
276 - }  
277 - else if (xcoord == "HLAT" && ycoord == "HLON") {  
278 - m_lng = 1;  
279 - m_lat = 0;  
280 - coords = "HEL";  
281 - }  
282 - else if (xcoord == "SLON" && ycoord == "SLAT") {  
283 - m_lng = 0;  
284 - m_lat = 1;  
285 - coords = "SGL";  
286 - }  
287 - else if (xcoord == "SLAT" && ycoord == "SLON") {  
288 - m_lng = 1;  
289 - m_lat = 0;  
290 - coords = "SGL";  
291 - }  
292 - else {  
293 - throw GException::wcs_bad_coords(G_READ, coordsys());  
294 - }  
295 -  
296 - // Set standard parameters  
297 - set_members(coords, crval1, crval2, crpix1, crpix2, cdelt1, cdelt2); 225 + // Get standard keywords
  226 + std::string ctype1 = hdu.string("CTYPE1");
  227 + std::string ctype2 = hdu.string("CTYPE2");
  228 + double crval1 = hdu.real("CRVAL1");
  229 + double crval2 = hdu.real("CRVAL2");
  230 + double crpix1 = hdu.real("CRPIX1");
  231 + double crpix2 = hdu.real("CRPIX2");
  232 + double cdelt1 = hdu.real("CDELT1");
  233 + double cdelt2 = hdu.real("CDELT2");
  234 +
  235 + // Determine coordinate system
  236 + std::string coords;
  237 + std::string xcoord = ctype1.substr(0,4);
  238 + std::string ycoord = ctype2.substr(0,4);
  239 + if (xcoord == "RA--" && ycoord == "DEC-") {
  240 + m_lng = 0;
  241 + m_lat = 1;
  242 + coords = "EQU";
  243 + }
  244 + else if (xcoord == "DEC-" && ycoord == "RA--") {
  245 + m_lng = 1;
  246 + m_lat = 0;
  247 + coords = "EQU";
  248 + }
  249 + else if (xcoord == "GLON" && ycoord == "GLAT") {
  250 + m_lng = 0;
  251 + m_lat = 1;
  252 + coords = "GAL";
  253 + }
  254 + else if (xcoord == "GLAT" && ycoord == "GLON") {
  255 + m_lng = 1;
  256 + m_lat = 0;
  257 + coords = "GAL";
  258 + }
  259 + else if (xcoord == "ELON" && ycoord == "ELAT") {
  260 + m_lng = 0;
  261 + m_lat = 1;
  262 + coords = "ECL";
  263 + }
  264 + else if (xcoord == "ELAT" && ycoord == "ELON") {
  265 + m_lng = 1;
  266 + m_lat = 0;
  267 + coords = "ECL";
  268 + }
  269 + else if (xcoord == "HLON" && ycoord == "HLAT") {
  270 + m_lng = 0;
  271 + m_lat = 1;
  272 + coords = "HEL";
  273 + }
  274 + else if (xcoord == "HLAT" && ycoord == "HLON") {
  275 + m_lng = 1;
  276 + m_lat = 0;
  277 + coords = "HEL";
  278 + }
  279 + else if (xcoord == "SLON" && ycoord == "SLAT") {
  280 + m_lng = 0;
  281 + m_lat = 1;
  282 + coords = "SGL";
  283 + }
  284 + else if (xcoord == "SLAT" && ycoord == "SLON") {
  285 + m_lng = 1;
  286 + m_lat = 0;
  287 + coords = "SGL";
  288 + }
  289 + else {
  290 + throw GException::wcs_bad_coords(G_READ, coordsys());
  291 + }
298 292
299 - } // endif: HDU was valid 293 + // Set standard parameters
  294 + set_members(coords, crval1, crval2, crpix1, crpix2, cdelt1, cdelt2);
300 295
301 // Return 296 // Return
302 return; 297 return;
@@ -311,122 +306,115 @@ void GWcs::read(const GFitsHDU* hdu) @@ -311,122 +306,115 @@ void GWcs::read(const GFitsHDU* hdu)
311 * This method writes the World Coordinate System definition into the FITS 306 * This method writes the World Coordinate System definition into the FITS
312 * HDU header. 307 * HDU header.
313 * 308 *
314 - * The method does nothing if the HDU is not valid.  
315 - *  
316 * This method has been adapted from wcshdr.c::wcshdo(). 309 * This method has been adapted from wcshdr.c::wcshdo().
317 ***************************************************************************/ 310 ***************************************************************************/
318 -void GWcs::write(GFitsHDU* hdu) const 311 +void GWcs::write(GFitsHDU& hdu) const
319 { 312 {
320 - // Continue only if HDU is valid  
321 - if (hdu != NULL) {  
322 -  
323 - // Write reference pixel coordinates  
324 - for (int i = 0; i < m_naxis; ++i) {  
325 - std::string keyname = "CRPIX"+gammalib::str(i+1);  
326 - std::string comment = "Pixel coordinate of reference point (starting from 1)";  
327 - hdu->card(keyname, m_crpix.at(i), comment);  
328 - }  
329 -  
330 - //TODO: Write linear transformation matrix  
331 -  
332 - // Write coordinate increment at reference point  
333 - for (int i = 0; i < m_naxis; ++i) {  
334 - std::string keyname = "CDELT"+gammalib::str(i+1);  
335 - std::string comment;  
336 - if (m_cunit.at(i).length() > 0) {  
337 - comment += "["+gammalib::strip_whitespace(m_cunit.at(i))+"] ";  
338 - }  
339 - comment += "Coordinate increment at reference point";  
340 - hdu->card(keyname, m_cdelt.at(i), comment);  
341 - }  
342 -  
343 - // Write units of coordinate increment and reference value  
344 - for (int i = 0; i < m_naxis; ++i) {  
345 - if (m_cunit.at(i).length() > 0) {  
346 - std::string keyname = "CUNIT"+gammalib::str(i+1);  
347 - std::string comment = "Units of coordinate increment and value";  
348 - hdu->card(keyname, m_cunit.at(0), comment);  
349 - }  
350 - }  
351 -  
352 - // Write coordinate type  
353 - wcs_set_ctype();  
354 - for (int i = 0; i < m_naxis; ++i) {  
355 - if (i == m_lng) {  
356 - std::string keyname = "CTYPE"+gammalib::str(i+1);  
357 - hdu->card(keyname, m_ctype.at(i), m_ctype_c.at(i));  
358 - }  
359 - if (i == m_lat) {  
360 - std::string keyname = "CTYPE"+gammalib::str(i+1);  
361 - hdu->card(keyname, m_ctype.at(i), m_ctype_c.at(i));  
362 - }  
363 - if (i == m_spec) {  
364 - std::string keyname = "CTYPE"+gammalib::str(i+1);  
365 - hdu->card(keyname, m_ctype.at(i), m_ctype_c.at(i));  
366 - }  
367 - }  
368 -  
369 - // Write coordinate value at reference point  
370 - for (int i = 0; i < m_naxis; ++i) {  
371 - std::string keyname = "CRVAL"+gammalib::str(i+1);  
372 - std::string comment;  
373 - if (m_cunit.at(i).length() > 0) {  
374 - comment += "["+gammalib::strip_whitespace(m_cunit.at(i))+"] ";  
375 - }  
376 - comment += "Coordinate value at reference point";  
377 - hdu->card(keyname, m_crval.at(i), comment);  
378 - }  
379 -  
380 - //TODO: Parameter values  
381 - hdu->card("CROTA2", 0.0, "[deg] Rotation Angle"); // Old style, use PV instead  
382 - //hdu->card("PV2_1", 0.0, "Projection parameter 1");  
383 - //hdu->card("PV2_2", 0.0, "Projection parameter 2");  
384 -  
385 - // Celestial and spectral transformation parameters  
386 - if (!undefined(m_lonpole)) {  
387 - hdu->card("LONPOLE", m_lonpole, "[deg] Native longitude of celestial pole");  
388 - }  
389 - if (!undefined(m_latpole)) {  
390 - hdu->card("LATPOLE", m_latpole, "[deg] Native latitude of celestial pole"); 313 + // Write reference pixel coordinates
  314 + for (int i = 0; i < m_naxis; ++i) {
  315 + std::string keyname = "CRPIX"+gammalib::str(i+1);
  316 + std::string comment = "Pixel coordinate of reference point (starting from 1)";
  317 + hdu.card(keyname, m_crpix.at(i), comment);
  318 + }
  319 +
  320 + //TODO: Write linear transformation matrix
  321 +
  322 + // Write coordinate increment at reference point
  323 + for (int i = 0; i < m_naxis; ++i) {
  324 + std::string keyname = "CDELT"+gammalib::str(i+1);
  325 + std::string comment;
  326 + if (m_cunit.at(i).length() > 0) {
  327 + comment += "["+gammalib::strip_whitespace(m_cunit.at(i))+"] ";
391 } 328 }
392 - if (!undefined(m_restfrq)) {  
393 - hdu->card("RESTFRQ", m_restfrq, "[Hz] Line rest frequency"); 329 + comment += "Coordinate increment at reference point";
  330 + hdu.card(keyname, m_cdelt.at(i), comment);
  331 + }
  332 +
  333 + // Write units of coordinate increment and reference value
  334 + for (int i = 0; i < m_naxis; ++i) {
  335 + if (m_cunit.at(i).length() > 0) {
  336 + std::string keyname = "CUNIT"+gammalib::str(i+1);
  337 + std::string comment = "Units of coordinate increment and value";
  338 + hdu.card(keyname, m_cunit.at(0), comment);
394 } 339 }
395 - if (!undefined(m_restwav)) {  
396 - hdu->card("RESTWAV", m_restwav, "[Hz] Line rest wavelength"); 340 + }
  341 +
  342 + // Write coordinate type
  343 + wcs_set_ctype();
  344 + for (int i = 0; i < m_naxis; ++i) {
  345 + if (i == m_lng) {
  346 + std::string keyname = "CTYPE"+gammalib::str(i+1);
  347 + hdu.card(keyname, m_ctype.at(i), m_ctype_c.at(i));
397 } 348 }
398 -  
399 - // Equatorial coordinate system type  
400 - if (m_radesys.length() > 0) {  
401 - hdu->card("RADESYS", m_radesys, "Equatorial coordinate system"); 349 + if (i == m_lat) {
  350 + std::string keyname = "CTYPE"+gammalib::str(i+1);
  351 + hdu.card(keyname, m_ctype.at(i), m_ctype_c.at(i));
402 } 352 }
403 -  
404 - // Equinox of equatorial coordinate system  
405 - if (!undefined(m_equinox)) {  
406 - hdu->card("EQUINOX", m_equinox, "[yr] Equinox of equatorial coordinates"); 353 + if (i == m_spec) {
  354 + std::string keyname = "CTYPE"+gammalib::str(i+1);
  355 + hdu.card(keyname, m_ctype.at(i), m_ctype_c.at(i));
407 } 356 }
408 -  
409 - //TODO: Reference frame of spectral coordinates  
410 -  
411 - //TODO: Reference frame of spectral observation  
412 -  
413 - //TODO: Observer's velocity towards source  
414 -  
415 - //TODO: Reference frame of source redshift  
416 -  
417 - //TODO: Redshift of the source  
418 -  
419 - //TODO: Observatory coordinates  
420 -  
421 - //TODO: MJD of observation  
422 -  
423 - //TODO: MJD mid-observation time  
424 -  
425 - //TODO: ISO-8601 date corresponding to MJD-OBS  
426 -  
427 - //TODO: ISO-8601 date corresponding to MJD-AVG 357 + }
428 358
429 - } // endif: HDU was valid 359 + // Write coordinate value at reference point
  360 + for (int i = 0; i < m_naxis; ++i) {
  361 + std::string keyname = "CRVAL"+gammalib::str(i+1);
  362 + std::string comment;
  363 + if (m_cunit.at(i).length() > 0) {
  364 + comment += "["+gammalib::strip_whitespace(m_cunit.at(i))+"] ";
  365 + }
  366 + comment += "Coordinate value at reference point";
  367 + hdu.card(keyname, m_crval.at(i), comment);
  368 + }
  369 +
  370 + //TODO: Parameter values
  371 + hdu.card("CROTA2", 0.0, "[deg] Rotation Angle"); // Old style, use PV instead
  372 + //hdu.card("PV2_1", 0.0, "Projection parameter 1");
  373 + //hdu.card("PV2_2", 0.0, "Projection parameter 2");
  374 +
  375 + // Celestial and spectral transformation parameters
  376 + if (!undefined(m_lonpole)) {
  377 + hdu.card("LONPOLE", m_lonpole, "[deg] Native longitude of celestial pole");
  378 + }
  379 + if (!undefined(m_latpole)) {
  380 + hdu.card("LATPOLE", m_latpole, "[deg] Native latitude of celestial pole");
  381 + }
  382 + if (!undefined(m_restfrq)) {
  383 + hdu.card("RESTFRQ", m_restfrq, "[Hz] Line rest frequency");
  384 + }
  385 + if (!undefined(m_restwav)) {
  386 + hdu.card("RESTWAV", m_restwav, "[Hz] Line rest wavelength");
  387 + }
  388 +
  389 + // Equatorial coordinate system type
  390 + if (m_radesys.length() > 0) {
  391 + hdu.card("RADESYS", m_radesys, "Equatorial coordinate system");
  392 + }
  393 +
  394 + // Equinox of equatorial coordinate system
  395 + if (!undefined(m_equinox)) {
  396 + hdu.card("EQUINOX", m_equinox, "[yr] Equinox of equatorial coordinates");
  397 + }
  398 +
  399 + //TODO: Reference frame of spectral coordinates
  400 +
  401 + //TODO: Reference frame of spectral observation
  402 +
  403 + //TODO: Observer's velocity towards source
  404 +
  405 + //TODO: Reference frame of source redshift
  406 +
  407 + //TODO: Redshift of the source
  408 +
  409 + //TODO: Observatory coordinates
  410 +
  411 + //TODO: MJD of observation
  412 +
  413 + //TODO: MJD mid-observation time
  414 +
  415 + //TODO: ISO-8601 date corresponding to MJD-OBS
  416 +
  417 + //TODO: ISO-8601 date corresponding to MJD-AVG
430 418
431 // Return 419 // Return
432 return; 420 return;
src/xspec/GArf.cpp
@@ -259,7 +259,7 @@ void GArf::load(const std::string&amp; filename) @@ -259,7 +259,7 @@ void GArf::load(const std::string&amp; filename)
259 GFits file(filename); 259 GFits file(filename);
260 260
261 // Get ARF table 261 // Get ARF table
262 - GFitsTable* table = file.table("SPECRESP"); 262 + const GFitsTable& table = *file.table("SPECRESP");
263 263
264 // Read ARF data 264 // Read ARF data
265 read(table); 265 read(table);
@@ -303,44 +303,39 @@ void GArf::save(const std::string&amp; filename, const bool&amp; clobber) const @@ -303,44 +303,39 @@ void GArf::save(const std::string&amp; filename, const bool&amp; clobber) const
303 /***********************************************************************//** 303 /***********************************************************************//**
304 * @brief Read Auxiliary Response File 304 * @brief Read Auxiliary Response File
305 * 305 *
306 - * @param[in] hdu ARF FITS table. 306 + * @param[in] table ARF FITS table.
307 ***************************************************************************/ 307 ***************************************************************************/
308 -void GArf::read(const GFitsTable* hdu) 308 +void GArf::read(const GFitsTable& table)
309 { 309 {
310 - // Continue only if HDU is valid  
311 - if (hdu != NULL) {  
312 -  
313 - // Get pointer to data columns  
314 - const GFitsTableCol* energy_lo = (*hdu)["ENERG_LO"];  
315 - const GFitsTableCol* energy_hi = (*hdu)["ENERG_HI"];  
316 - const GFitsTableCol* specresp = (*hdu)["SPECRESP"];  
317 -  
318 - // Determine effective area conversion factor. Internal  
319 - // units are cm^2  
320 - std::string u_specresp = gammalib::tolower(gammalib::strip_whitespace(specresp->unit()));  
321 - double c_specresp = 1.0;  
322 - if (u_specresp == "m^2" || u_specresp == "m2") {  
323 - c_specresp = 10000.0;  
324 - } 310 + // Get pointer to data columns
  311 + const GFitsTableCol* energy_lo = table["ENERG_LO"];
  312 + const GFitsTableCol* energy_hi = table["ENERG_HI"];
  313 + const GFitsTableCol* specresp = table["SPECRESP"];
  314 +
  315 + // Determine effective area conversion factor. Internal
  316 + // units are cm^2
  317 + std::string u_specresp = gammalib::tolower(gammalib::strip_whitespace(specresp->unit()));
  318 + double c_specresp = 1.0;
  319 + if (u_specresp == "m^2" || u_specresp == "m2") {
  320 + c_specresp = 10000.0;
  321 + }
325 322
326 - // Extract number of energy bins  
327 - int num = energy_lo->length(); 323 + // Extract number of energy bins
  324 + int num = energy_lo->length();
328 325
329 - // Set energy bins  
330 - for (int i = 0; i < num; ++i) { 326 + // Set energy bins
  327 + for (int i = 0; i < num; ++i) {
331 328
332 - // Append energy bin  
333 - GEnergy emin(energy_lo->real(i), energy_lo->unit());  
334 - GEnergy emax(energy_hi->real(i), energy_hi->unit());  
335 - m_ebounds.append(emin, emax);  
336 -  
337 - // Append effective area value  
338 - double aeff = specresp->real(i) * c_specresp;  
339 - m_specresp.push_back(aeff); 329 + // Append energy bin
  330 + GEnergy emin(energy_lo->real(i), energy_lo->unit());
  331 + GEnergy emax(energy_hi->real(i), energy_hi->unit());
  332 + m_ebounds.append(emin, emax);
340 333
341 - } // endfor: looped over energy bins 334 + // Append effective area value
  335 + double aeff = specresp->real(i) * c_specresp;
  336 + m_specresp.push_back(aeff);
342 337
343 - } // endif: HDU was valid 338 + } // endfor: looped over energy bins
344 339
345 // Return 340 // Return
346 return; 341 return;
src/xspec/GPha.cpp
@@ -339,7 +339,7 @@ void GPha::load(const std::string&amp; filename) @@ -339,7 +339,7 @@ void GPha::load(const std::string&amp; filename)
339 GFits fits(filename); 339 GFits fits(filename);
340 340
341 // Get PHA table 341 // Get PHA table
342 - GFitsTable* pha = fits.table("SPECTRUM"); 342 + const GFitsTable& pha = *fits.table("SPECTRUM");
343 343
344 // Read PHA data 344 // Read PHA data
345 read(pha); 345 read(pha);
@@ -394,44 +394,39 @@ void GPha::save(const std::string&amp; filename, const bool&amp; clobber) const @@ -394,44 +394,39 @@ void GPha::save(const std::string&amp; filename, const bool&amp; clobber) const
394 /***********************************************************************//** 394 /***********************************************************************//**
395 * @brief Read Pulse Height Analyzer spectrum 395 * @brief Read Pulse Height Analyzer spectrum
396 * 396 *
397 - * @param[in] hdu PHA FITS table. 397 + * @param[in] table PHA FITS table.
398 * 398 *
399 * @exception GException::invalid_value 399 * @exception GException::invalid_value
400 * Mismatch between PHA file and energy boundaries. 400 * Mismatch between PHA file and energy boundaries.
401 ***************************************************************************/ 401 ***************************************************************************/
402 -void GPha::read(const GFitsTable* hdu) 402 +void GPha::read(const GFitsTable& table)
403 { 403 {
404 - // Continue only if HDU is valid  
405 - if (hdu != NULL) {  
406 -  
407 - // Get data column  
408 - const GFitsTableCol* col_data = (*hdu)["COUNTS"];  
409 -  
410 - // Extract number of channels in FITS file  
411 - int length = hdu->integer("NAXIS2");  
412 -  
413 - // Check whether column length is okay  
414 - if (m_ebounds.size() > 0) {  
415 - if (m_ebounds.size() != length) {  
416 - std::string msg = "Number of channels in PHA file ("  
417 - ""+gammalib::str(length)+") mismatches the"  
418 - " number of energy boundaries ("  
419 - ""+gammalib::str(m_ebounds.size())+") that"  
420 - " are defined in the GPha instance.\n"  
421 - "Please define the correct energy boundaries.";  
422 - throw GException::invalid_value(G_READ, msg);  
423 - } 404 + // Get data column
  405 + const GFitsTableCol* col_data = table["COUNTS"];
  406 +
  407 + // Extract number of channels in FITS file
  408 + int length = table.integer("NAXIS2");
  409 +
  410 + // Check whether column length is okay
  411 + if (m_ebounds.size() > 0) {
  412 + if (m_ebounds.size() != length) {
  413 + std::string msg = "Number of channels in PHA file ("
  414 + ""+gammalib::str(length)+") mismatches the"
  415 + " number of energy boundaries ("
  416 + ""+gammalib::str(m_ebounds.size())+") that"
  417 + " are defined in the GPha instance.\n"
  418 + "Please define the correct energy boundaries.";
  419 + throw GException::invalid_value(G_READ, msg);
424 } 420 }
  421 + }
425 422
426 - // Initialize spectrum  
427 - m_counts.assign(length, 0.0);  
428 -  
429 - // Copy data  
430 - for (int i = 0; i < length; ++i) {  
431 - m_counts[i] = col_data->real(i);  
432 - } 423 + // Initialize spectrum
  424 + m_counts.assign(length, 0.0);
433 425
434 - } // endif: HDU was valid 426 + // Copy data
  427 + for (int i = 0; i < length; ++i) {
  428 + m_counts[i] = col_data->real(i);
  429 + }
435 430
436 // Return 431 // Return
437 return; 432 return;
src/xspec/GRmf.cpp
@@ -276,7 +276,7 @@ void GRmf::load(const std::string&amp; filename) @@ -276,7 +276,7 @@ void GRmf::load(const std::string&amp; filename)
276 m_ebds_measured.load(filename); 276 m_ebds_measured.load(filename);
277 277
278 // Get RMF table 278 // Get RMF table
279 - GFitsTable* table = file.table("MATRIX"); 279 + const GFitsTable& table = *file.table("MATRIX");
280 280
281 // Read RMF data 281 // Read RMF data
282 read(table); 282 read(table);
@@ -320,58 +320,53 @@ void GRmf::save(const std::string&amp; filename, const bool&amp; clobber) const @@ -320,58 +320,53 @@ void GRmf::save(const std::string&amp; filename, const bool&amp; clobber) const
320 /***********************************************************************//** 320 /***********************************************************************//**
321 * @brief Read Redistribution Matrix File 321 * @brief Read Redistribution Matrix File
322 * 322 *
323 - * @param[in] hdu RMF FITS table. 323 + * @param[in] table RMF FITS table.
324 ***************************************************************************/ 324 ***************************************************************************/
325 -void GRmf::read(const GFitsTable* hdu) 325 +void GRmf::read(const GFitsTable& table)
326 { 326 {
327 - // Continue only if HDU is valid  
328 - if (hdu != NULL) {  
329 -  
330 - // Initialise members  
331 - m_ebds_true.clear(); 327 + // Initialise members
  328 + m_ebds_true.clear();
332 329
333 - // Get pointer to data columns  
334 - const GFitsTableCol* energy_lo = (*hdu)["ENERG_LO"];  
335 - const GFitsTableCol* energy_hi = (*hdu)["ENERG_HI"];  
336 - const GFitsTableCol* n_grp = (*hdu)["N_GRP"];  
337 - const GFitsTableCol* f_chan = (*hdu)["F_CHAN"];  
338 - const GFitsTableCol* n_chan = (*hdu)["N_CHAN"];  
339 - const GFitsTableCol* matrix = (*hdu)["MATRIX"]; 330 + // Get pointer to data columns
  331 + const GFitsTableCol* energy_lo = table["ENERG_LO"];
  332 + const GFitsTableCol* energy_hi = table["ENERG_HI"];
  333 + const GFitsTableCol* n_grp = table["N_GRP"];
  334 + const GFitsTableCol* f_chan = table["F_CHAN"];
  335 + const GFitsTableCol* n_chan = table["N_CHAN"];
  336 + const GFitsTableCol* matrix = table["MATRIX"];
340 337
341 - // Set matrix rows and columns  
342 - int rows = energy_lo->length();  
343 - int columns = m_ebds_measured.size(); 338 + // Set matrix rows and columns
  339 + int rows = energy_lo->length();
  340 + int columns = m_ebds_measured.size();
344 341
345 - // Initialize matrix  
346 - m_matrix = GMatrixSparse(rows, columns); 342 + // Initialize matrix
  343 + m_matrix = GMatrixSparse(rows, columns);
347 344
348 - // Set true energy bins  
349 - for (int itrue = 0; itrue < rows; ++itrue) { 345 + // Set true energy bins
  346 + for (int itrue = 0; itrue < rows; ++itrue) {
350 347
351 - // Append energy bin  
352 - GEnergy emin(energy_lo->real(itrue), energy_lo->unit());  
353 - GEnergy emax(energy_hi->real(itrue), energy_hi->unit());  
354 - m_ebds_true.append(emin, emax);  
355 -  
356 - // Loop over groups  
357 - int icolumn = 0;  
358 - int ngroups = n_grp->integer(itrue);  
359 - for (int igroup = 0; igroup < ngroups; ++igroup) {  
360 -  
361 - // Get start column index and number of columns  
362 - int imeasured = f_chan->integer(itrue, igroup);  
363 - int nvalues = n_chan->integer(itrue, igroup);  
364 -  
365 - // Get values  
366 - for (int i = 0; i < nvalues; ++i, ++imeasured, ++icolumn) {  
367 - m_matrix(itrue, imeasured) = matrix->real(itrue, icolumn);  
368 - }  
369 -  
370 - } // endfor: looped over groups 348 + // Append energy bin
  349 + GEnergy emin(energy_lo->real(itrue), energy_lo->unit());
  350 + GEnergy emax(energy_hi->real(itrue), energy_hi->unit());
  351 + m_ebds_true.append(emin, emax);
  352 +
  353 + // Loop over groups
  354 + int icolumn = 0;
  355 + int ngroups = n_grp->integer(itrue);
  356 + for (int igroup = 0; igroup < ngroups; ++igroup) {
  357 +
  358 + // Get start column index and number of columns
  359 + int imeasured = f_chan->integer(itrue, igroup);
  360 + int nvalues = n_chan->integer(itrue, igroup);
  361 +
  362 + // Get values
  363 + for (int i = 0; i < nvalues; ++i, ++imeasured, ++icolumn) {
  364 + m_matrix(itrue, imeasured) = matrix->real(itrue, icolumn);
  365 + }
371 366
372 - } // endfor: looped over true energy bins 367 + } // endfor: looped over groups
373 368
374 - } // endif: HDU was valid 369 + } // endfor: looped over true energy bins
375 370
376 // Return 371 // Return
377 return; 372 return;