diff --git a/include/GEbounds.hpp b/include/GEbounds.hpp index 00d1e1d..cf0df39 100644 --- a/include/GEbounds.hpp +++ b/include/GEbounds.hpp @@ -55,12 +55,12 @@ class GEbounds : public GContainer { public: // Constructors and destructors GEbounds(void); - GEbounds(const GEbounds& ebds); + explicit GEbounds(const std::string& filename); explicit GEbounds(const GXmlElement& xml); + GEbounds(const GEbounds& ebds); GEbounds(const GEnergy& emin, const GEnergy& emax); GEbounds(const int& num, const GEnergy& emin, const GEnergy& emax, const bool& log = true); - GEbounds(const std::string& filename); virtual ~GEbounds(void); // Operators diff --git a/include/GEnergies.hpp b/include/GEnergies.hpp index 3b97cad..b245938 100644 --- a/include/GEnergies.hpp +++ b/include/GEnergies.hpp @@ -49,8 +49,7 @@ class GEnergies : public GContainer { public: // Constructors and destructors GEnergies(void); - GEnergies(const std::string& filename, - const std::string& extname = "ENERGIES"); + explicit GEnergies(const std::string& filename); GEnergies(const GEnergies& energies); GEnergies(const int& num, const GEnergy& emin, const GEnergy& emax, const bool& log = true); @@ -78,11 +77,9 @@ public: const GEnergy& emax); void set_log(const int& num, const GEnergy& emin, const GEnergy& emax); - void load(const std::string& filename, - const std::string& extname = "ENERGIES"); + void load(const std::string& filename); void save(const std::string& filename, - const bool& clobber = false, - const std::string& extname = "ENERGIES") const; + const bool& clobber = false) const; void read(const GFitsTable& table); void write(GFits& file, const std::string& extname = "ENERGIES") const; diff --git a/include/GGti.hpp b/include/GGti.hpp index 1477d45..60e5eef 100644 --- a/include/GGti.hpp +++ b/include/GGti.hpp @@ -58,6 +58,7 @@ class GGti : public GContainer { public: // Constructors and destructors GGti(void); + explicit GGti(const std::string& filename); GGti(const GGti& gti); GGti(const GTime& tstart, const GTime& tstop); explicit GGti(const GXmlElement& xml); @@ -81,11 +82,9 @@ public: void remove(const int& index); void reserve(const int& num); void extend(const GGti& gti); - void load(const std::string& filename, - const std::string& extname = "GTI"); + void load(const std::string& filename); void save(const std::string& filename, - const bool& clobber = false, - const std::string& extname = "GTI") const; + const bool& clobber = false) const; void read(const GFitsTable& table); void write(GFits& file, const std::string& extname = "GTI") const; diff --git a/include/GNodeArray.hpp b/include/GNodeArray.hpp index 74d0d87..d764e0b 100644 --- a/include/GNodeArray.hpp +++ b/include/GNodeArray.hpp @@ -59,9 +59,10 @@ class GNodeArray : public GContainer { public: // Constructors and destructors GNodeArray(void); - GNodeArray(const int& num, const double* array); + explicit GNodeArray(const std::string& filename); explicit GNodeArray(const GVector& vector); explicit GNodeArray(const std::vector& vector); + GNodeArray(const int& num, const double* array); GNodeArray(const GNodeArray& array); virtual ~GNodeArray(void); @@ -93,10 +94,9 @@ public: const int& inx_right(void) const; const double& wgt_left(void) const; const double& wgt_right(void) const; - void load(const std::string& filename, - const std::string& extname = "NODES"); - void save(const std::string& filename, const bool& clobber = false, - const std::string& extname = "NODES") const; + void load(const std::string& filename); + void save(const std::string& filename, + const bool& clobber = false) const; void read(const GFitsTable& table); void write(GFits& file, const std::string& extname = "NODES") const; diff --git a/inst/cta/include/GCTAPointing.hpp b/inst/cta/include/GCTAPointing.hpp index cc15738..e2e2904 100644 --- a/inst/cta/include/GCTAPointing.hpp +++ b/inst/cta/include/GCTAPointing.hpp @@ -61,8 +61,7 @@ public: GCTAPointing(void); explicit GCTAPointing(const GSkyDir& dir); explicit GCTAPointing(const GXmlElement& xml); - GCTAPointing(const std::string& filename, - const std::string& extname = "POINTING"); + explicit GCTAPointing(const std::string& filename); GCTAPointing(const GCTAPointing& pnt); virtual ~GCTAPointing(void); @@ -83,8 +82,7 @@ public: void zenith(const double& zenith); void azimuth(const double& azimuth); GHorizDir dir_horiz(const GTime& time) const; - void load(const std::string& filename, - const std::string& extname = "POINTING"); + void load(const std::string& filename); void read(const GFitsTable& table); void read(const GXmlElement& xml); void write(GXmlElement& xml) const; diff --git a/inst/cta/pyext/GCTAPointing.i b/inst/cta/pyext/GCTAPointing.i index 9041191..a152e70 100644 --- a/inst/cta/pyext/GCTAPointing.i +++ b/inst/cta/pyext/GCTAPointing.i @@ -40,8 +40,7 @@ public: GCTAPointing(void); explicit GCTAPointing(const GSkyDir& dir); explicit GCTAPointing(const GXmlElement& xml); - GCTAPointing(const std::string& filename, - const std::string& extname = "POINTING"); + explicit GCTAPointing(const std::string& filename); GCTAPointing(const GCTAPointing& pnt); virtual ~GCTAPointing(void); @@ -59,8 +58,7 @@ public: void zenith(const double& zenith); void azimuth(const double& azimuth); GHorizDir dir_horiz(const GTime& time) const; - void load(const std::string& filename, - const std::string& extname = "POINTING"); + void load(const std::string& filename); void read(const GFitsTable& table); void read(const GXmlElement& xml); void write(GXmlElement& xml) const; diff --git a/inst/cta/src/GCTAPointing.cpp b/inst/cta/src/GCTAPointing.cpp index dc6e411..ebad18e 100644 --- a/inst/cta/src/GCTAPointing.cpp +++ b/inst/cta/src/GCTAPointing.cpp @@ -28,8 +28,9 @@ #ifdef HAVE_CONFIG_H #include #endif -#include "GCTAPointing.hpp" #include "GTools.hpp" +#include "GFilename.hpp" +#include "GCTAPointing.hpp" #include "GFits.hpp" #include "GHorizDir.hpp" @@ -107,21 +108,19 @@ GCTAPointing::GCTAPointing(const GXmlElement& xml) /***********************************************************************//** - * @brief Pointing table constructor + * @brief FITS file constructor * - * @param[in] filename Pointing table file. - * @param[in] extname Pointing extension name (defaults to "POINTING") + * @param[in] filename FITS file. * - * Construct CTA pointing from a pointing table file. + * Construct CTA pointing from a pointing table FITS file. ***************************************************************************/ -GCTAPointing::GCTAPointing(const std::string& filename, - const std::string& extname) +GCTAPointing::GCTAPointing(const std::string& filename) { // Initialise members init_members(); // Load pointing table - load(filename, extname); + load(filename); // Return return; @@ -400,24 +399,28 @@ GHorizDir GCTAPointing::dir_horiz(const GTime& time) const /************************************************************************ - * @brief Load pointing table from a pointing file + * @brief Load pointings from a FITS file * - * @param[in] filename Pointing table filename. - * @param[in] extname Pointing extension name (defaults to "POINTING") + * @param[in] filename FITS file name. + * + * Loads pointings from a pointing table FITS file. * - * Loads a pointing table from a FITS file. See the read() method for - * more information about the structure of the FITS file. + * If no extension name is provided, the pointing is are loaded from the + * "POINTING" extension. ************************************************************************/ -void GCTAPointing::load(const std::string& filename, const std::string& extname) +void GCTAPointing::load(const std::string& filename) { + // Create file name + GFilename fname(filename); + // Allocate FITS file GFits file; // Open FITS file - file.open(filename); + file.open(fname.filename()); // Get pointing table - const GFitsTable& table = *file.table(extname); + const GFitsTable& table = *file.table(fname.extname("POINTING")); // Read pointing from table read(table); @@ -431,7 +434,7 @@ void GCTAPointing::load(const std::string& filename, const std::string& extname) /************************************************************************ - * @brief Load pointing table from a pointing file + * @brief Read pointings from a FITS table * * @param[in] filename Pointing table filename. * @param[in] extname Pointing extension name (defaults to "POINTING") diff --git a/inst/mwl/include/GMWLObservation.hpp b/inst/mwl/include/GMWLObservation.hpp index e08822c..dace35f 100644 --- a/inst/mwl/include/GMWLObservation.hpp +++ b/inst/mwl/include/GMWLObservation.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GMWLObservation.hpp - Multi-wavelength observation class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2014 by Juergen Knoedlseder * + * copyright (C) 2010-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -49,8 +49,6 @@ public: // Constructors and destructors GMWLObservation(void); explicit GMWLObservation(const std::string& filename); - explicit GMWLObservation(const std::string& filename, const int& extno); - explicit GMWLObservation(const std::string& filename, const std::string& extname); GMWLObservation(const GMWLObservation& obs); virtual ~GMWLObservation(void); @@ -73,8 +71,6 @@ public: // Other methods void load(const std::string& filename); - void load(const std::string& filename, const int& extno); - void load(const std::string& filename, const std::string& extname); const std::string& filename(void) const; const std::string& extno(void) const; const std::string& extname(void) const; diff --git a/inst/mwl/include/GMWLSpectrum.hpp b/inst/mwl/include/GMWLSpectrum.hpp index f54d3a4..1eb84f6 100644 --- a/inst/mwl/include/GMWLSpectrum.hpp +++ b/inst/mwl/include/GMWLSpectrum.hpp @@ -74,8 +74,6 @@ public: virtual std::string print(const GChatter& chatter = NORMAL) const; // Other methods - void load(const std::string& filename, const std::string& extname); - void load(const std::string& filename, const int& extno); void read(const GFits& file, const std::string& extname); void read(const GFits& file, const int& extno); const std::string& telescope(void) const; diff --git a/inst/mwl/pyext/GMWLObservation.i b/inst/mwl/pyext/GMWLObservation.i index da6c7da..61d7b7c 100644 --- a/inst/mwl/pyext/GMWLObservation.i +++ b/inst/mwl/pyext/GMWLObservation.i @@ -1,7 +1,7 @@ /*************************************************************************** * GMWLObservation.i - Multi-wavelength observation class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2014 by Juergen Knoedlseder * + * copyright (C) 2010-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -39,12 +39,11 @@ * instrument. The spectral points are given in physical units. ***************************************************************************/ class GMWLObservation : public GObservation { + public: // Constructors and destructors GMWLObservation(void); explicit GMWLObservation(const std::string& filename); - explicit GMWLObservation(const std::string& filename, const int& extno); - explicit GMWLObservation(const std::string& filename, const std::string& extname); GMWLObservation(const GMWLObservation& obs); virtual ~GMWLObservation(void); @@ -63,8 +62,6 @@ public: // Other methods void load(const std::string& filename); - void load(const std::string& filename, const int& extno); - void load(const std::string& filename, const std::string& extname); const std::string& filename(void) const; const std::string& extno(void) const; const std::string& extname(void) const; diff --git a/inst/mwl/pyext/GMWLSpectrum.i b/inst/mwl/pyext/GMWLSpectrum.i index f89ea48..d93e09e 100644 --- a/inst/mwl/pyext/GMWLSpectrum.i +++ b/inst/mwl/pyext/GMWLSpectrum.i @@ -57,8 +57,6 @@ public: virtual int number(void) const; // Other methods - void load(const std::string& filename, const std::string& extname); - void load(const std::string& filename, const int& extno); void read(const GFits& file, const std::string& extname); void read(const GFits& file, const int& extno); const std::string& telescope(void) const; diff --git a/inst/mwl/src/GMWLObservation.cpp b/inst/mwl/src/GMWLObservation.cpp index 92e1a11..1f01cad 100644 --- a/inst/mwl/src/GMWLObservation.cpp +++ b/inst/mwl/src/GMWLObservation.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GMWLObservation.cpp - Multi-wavelength observation class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2013 by Juergen Knoedlseder * + * copyright (C) 2010-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -28,8 +28,9 @@ #ifdef HAVE_CONFIG_H #include #endif -#include "GObservationRegistry.hpp" #include "GTools.hpp" +#include "GFilename.hpp" +#include "GObservationRegistry.hpp" #include "GException.hpp" #include "GMWLObservation.hpp" #include "GMWLSpectrum.hpp" @@ -93,50 +94,6 @@ GMWLObservation::GMWLObservation(const std::string& filename) : GObservation() /***********************************************************************//** - * @brief File constructor - * - * @param[in] filename File name. - * @param[in] extno FITS file extension number. - * - * Creates instance from file. - ***************************************************************************/ -GMWLObservation::GMWLObservation(const std::string& filename, - const int& extno) : GObservation() -{ - // Initialise members - init_members(); - - // Load observation - load(filename, extno); - - // Return - return; -} - - -/***********************************************************************//** - * @brief File constructor - * - * @param[in] filename File name. - * @param[in] extname FITS file extension name. - * - * Creates instance from file. - ***************************************************************************/ -GMWLObservation::GMWLObservation(const std::string& filename, - const std::string& extname) : GObservation() -{ - // Initialise members - init_members(); - - // Load observation - load(filename, extname); - - // Return - return; -} - - -/***********************************************************************//** * @brief Copy constructor * * @param[in] obs Observation. @@ -336,11 +293,11 @@ void GMWLObservation::read(const GXmlElement& xml) // Load file (this also stores the filename, extno and // extname) - if (gammalib::strip_whitespace(extno).length() > 0) { - load(filename, gammalib::toint(extno)); + if (!gammalib::strip_whitespace(extno).empty()) { + load(filename+"["+extno+"]"); } - else if (gammalib::strip_whitespace(extname).length() > 0) { - load(filename, extname); + else if (!gammalib::strip_whitespace(extname).empty()) { + load(filename+"["+extname+"]"); } else { load(filename); @@ -442,79 +399,32 @@ void GMWLObservation::load(const std::string& filename) // Clear observation clear(); - // Allocate spectrum - GMWLSpectrum* spec = new GMWLSpectrum; - m_events = spec; - - // Load spectrum - spec->load(filename); - - // Set attributes - name("Multi-wavelength observation"); - id(filename); - m_filename = filename; - m_instrument = spec->instrument(); - - // Return - return; -} - - -/***********************************************************************//** - * @brief Load observation - * - * @param[in] filename File name. - * @param[in] extno FITS extension number. - ***************************************************************************/ -void GMWLObservation::load(const std::string& filename, - const int& extno) -{ - // Clear observation - clear(); - - // Allocate spectrum - GMWLSpectrum* spec = new GMWLSpectrum; - m_events = spec; - - // Load spectrum - spec->load(filename, extno); - - // Set attributes - name("Multi-wavelength observation"); - id(filename+"["+gammalib::str(extno)+"]"); - m_filename = filename; - m_extno = gammalib::str(extno); - m_instrument = spec->instrument(); - - // Return - return; -} - - -/***********************************************************************//** - * @brief Load observation - * - * @param[in] filename File name. - * @param[in] extname FITS extension name. - ***************************************************************************/ -void GMWLObservation::load(const std::string& filename, - const std::string& extname) -{ - // Clear observation - clear(); + // Create file name + GFilename fname(filename); // Allocate spectrum GMWLSpectrum* spec = new GMWLSpectrum; m_events = spec; // Load spectrum - spec->load(filename, extname); + if (fname.has_extno()) { + spec->load(filename); + m_extno = gammalib::str(fname.extno()); + id(filename+"["+m_extno+"]"); + } + else if (fname.has_extname()) { + spec->load(filename); + m_extname = fname.extname(); + id(filename+"["+m_extname+"]"); + } + else { + spec->load(filename); + id(filename); + } // Set attributes name("Multi-wavelength observation"); - id(filename+"["+extname+"]"); - m_filename = filename; - m_extname = extname; + m_filename = fname.filename(); m_instrument = spec->instrument(); // Return diff --git a/inst/mwl/src/GMWLSpectrum.cpp b/inst/mwl/src/GMWLSpectrum.cpp index c5f92c6..31f3abf 100644 --- a/inst/mwl/src/GMWLSpectrum.cpp +++ b/inst/mwl/src/GMWLSpectrum.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GMWLSpectrum.cpp - Multi-wavelength spectrum class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2013 by Juergen Knoedlseder * + * copyright (C) 2010-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -29,6 +29,7 @@ #include #endif #include "GTools.hpp" +#include "GFilename.hpp" #include "GFits.hpp" #include "GFitsTable.hpp" #include "GEnergy.hpp" @@ -259,70 +260,25 @@ GMWLSpectrum* GMWLSpectrum::clone(void) const ***************************************************************************/ void GMWLSpectrum::load(const std::string& filename) { - // Clear object - clear(); - - // Open FITS file - GFits file(filename); - - // Read spectrum - read(file); - - // Close FITS file - file.close(); - - // Return - return; -} - - -/***********************************************************************//** - * @brief Load spectrum from FITS file - * - * @param[in] filename FITS file name. - * @param[in] extname FITS extension name. - * - * This method loads a spectrum from the specified extension from a FITS - * file. - ***************************************************************************/ -void GMWLSpectrum::load(const std::string& filename, const std::string& extname) -{ - // Clear object - clear(); - - // Open FITS file - GFits file(filename); - - // Read spectrum from FITS file - read(file, extname); - - // Close FITS file - file.close(); - - // Return - return; -} + // Create file name + GFilename fname(filename); - -/***********************************************************************//** - * @brief Load spectrum from FITS file - * - * @param[in] filename FITS file name. - * @param[in] extno FITS extension number. - * - * This method loads a spectrum from the specified extension number from a - * FITS file. - ***************************************************************************/ -void GMWLSpectrum::load(const std::string& filename, const int& extno) -{ // Clear object clear(); // Open FITS file - GFits file(filename); + GFits file(fname.filename()); - // Read spectrum from FITS file - read(file, extno); + // Read spectrum + if (fname.has_extno()) { + read(file, fname.extno()); + } + else if (fname.has_extname()) { + read(file, fname.extname()); + } + else { + read(file); + } // Close FITS file file.close(); @@ -336,7 +292,7 @@ void GMWLSpectrum::load(const std::string& filename, const int& extno) * @brief Save spectrum * * @param[in] filename File name. - * @param[in] clobber Overwrite existing file (default=false). + * @param[in] clobber Overwrite existing file (default: false). * * @todo To be implemented. ***************************************************************************/ diff --git a/inst/mwl/test/test_MWL.cpp b/inst/mwl/test/test_MWL.cpp index 8235e2f..437f1b2 100644 --- a/inst/mwl/test/test_MWL.cpp +++ b/inst/mwl/test/test_MWL.cpp @@ -191,9 +191,9 @@ void TestGMWL::test_optimizer(void) test_try("Load multi-wavelength observations"); try { obs.clear(); - GMWLObservation comptel(crab_fits, "COMPTEL"); - GMWLObservation lat(crab_fits, "LAT"); - GMWLObservation hess(crab_fits, "HESS"); + GMWLObservation comptel(crab_fits+"[COMPTEL]"); + GMWLObservation lat(crab_fits+"[LAT]"); + GMWLObservation hess(crab_fits+"[HESS]"); obs.append(comptel); obs.append(lat); obs.append(hess); diff --git a/pyext/GEbounds.i b/pyext/GEbounds.i index aeef309..0625a84 100644 --- a/pyext/GEbounds.i +++ b/pyext/GEbounds.i @@ -39,12 +39,12 @@ class GEbounds : public GContainer { public: // Constructors and destructors GEbounds(void); - GEbounds(const GEbounds& ebds); + explicit GEbounds(const std::string& filename); explicit GEbounds(const GXmlElement& xml); + GEbounds(const GEbounds& ebds); GEbounds(const GEnergy& emin, const GEnergy& emax); GEbounds(const int& num, const GEnergy& emin, const GEnergy& emax, const bool& log = true); - GEbounds(const std::string& filename); virtual ~GEbounds(void); // Methods diff --git a/pyext/GEnergies.i b/pyext/GEnergies.i index c51a1d2..44378a3 100644 --- a/pyext/GEnergies.i +++ b/pyext/GEnergies.i @@ -41,8 +41,7 @@ class GEnergies : public GContainer { public: // Constructors and destructors GEnergies(void); - GEnergies(const std::string& filename, - const std::string& extname = "ENERGIES"); + explicit GEnergies(const std::string& filename); GEnergies(const GEnergies& energies); GEnergies(const int& num, const GEnergy& emin, const GEnergy& emax, const bool& log = true); @@ -64,13 +63,12 @@ public: const GEnergy& emax); void set_log(const int& num, const GEnergy& emin, const GEnergy& emax); - void load(const std::string& filename, - const std::string& extname = "ENERGIES"); + void load(const std::string& filename); void save(const std::string& filename, - const bool& clobber = false, - const std::string& extname = "ENERGIES") const; + const bool& clobber = false) const; void read(const GFitsTable& table); - void write(GFits& file, const std::string& extname = "ENERGIES") const; + void write(GFits& file, + const std::string& extname = "ENERGIES") const; }; diff --git a/pyext/GGti.i b/pyext/GGti.i index 4421b3d..82fec3f 100644 --- a/pyext/GGti.i +++ b/pyext/GGti.i @@ -36,9 +36,11 @@ * @brief Good Time Interval class ***************************************************************************/ class GGti : public GBase { + public: // Constructors and destructors GGti(void); + explicit GGti(const std::string& filename); GGti(const GGti& gti); GGti(const GTime& tstart, const GTime& tstop); explicit GGti(const GXmlElement& xml); @@ -59,11 +61,9 @@ public: void remove(const int& index); void reserve(const int& num); void extend(const GGti& gti); - void load(const std::string& filename, - const std::string& extname = "GTI"); + void load(const std::string& filename); void save(const std::string& filename, - const bool& clobber = false, - const std::string& extname = "GTI") const; + const bool& clobber = false) const; void read(const GFitsTable& table); void write(GFits& file, const std::string& extname = "GTI") const; diff --git a/pyext/GNodeArray.i b/pyext/GNodeArray.i index 9820a67..76285cb 100644 --- a/pyext/GNodeArray.i +++ b/pyext/GNodeArray.i @@ -39,12 +39,14 @@ namespace std { * @brief Node array class ***************************************************************************/ class GNodeArray : public GContainer { + public: // Constructors and destructors GNodeArray(void); - GNodeArray(const int& num, const double* array); + explicit GNodeArray(const std::string& filename); explicit GNodeArray(const GVector& vector); explicit GNodeArray(const std::vector& vector); + GNodeArray(const int& num, const double* array); GNodeArray(const GNodeArray& array); virtual ~GNodeArray(void); @@ -70,10 +72,9 @@ public: const int& inx_right(void) const; const double& wgt_left(void) const; const double& wgt_right(void) const; - void load(const std::string& filename, - const std::string& extname = "NODES"); - void save(const std::string& filename, const bool& clobber = false, - const std::string& extname = "NODES") const; + void load(const std::string& filename); + void save(const std::string& filename, + const bool& clobber = false) const; void read(const GFitsTable& table); void write(GFits& file, const std::string& extname = "NODES") const; diff --git a/src/obs/GEbounds.cpp b/src/obs/GEbounds.cpp index 71a6fda..4b6fa93 100644 --- a/src/obs/GEbounds.cpp +++ b/src/obs/GEbounds.cpp @@ -77,17 +77,19 @@ GEbounds::GEbounds(void) /***********************************************************************//** - * @brief Copy constructor + * @brief FITS file constructor * - * @param[in] ebds Energy boundaries. + * @param[in] filename FITS file name. + * + * Constructs energy boundaries from a FITS file. ***************************************************************************/ -GEbounds::GEbounds(const GEbounds& ebds) +GEbounds::GEbounds(const std::string& filename) { - // Initialise class members for clean destruction + // Initialise members init_members(); - // Copy members - copy_members(ebds); + // Load FITS file + load(filename); // Return return; @@ -99,7 +101,7 @@ GEbounds::GEbounds(const GEbounds& ebds) * * @param[in] xml XML element. * - * Constructs energy bounds from an XML element. + * Constructs energy boundaries from an XML element. ***************************************************************************/ GEbounds::GEbounds(const GXmlElement& xml) { @@ -115,12 +117,30 @@ GEbounds::GEbounds(const GXmlElement& xml) /***********************************************************************//** + * @brief Copy constructor + * + * @param[in] ebds Energy boundaries. + ***************************************************************************/ +GEbounds::GEbounds(const GEbounds& ebds) +{ + // Initialise class members for clean destruction + init_members(); + + // Copy members + copy_members(ebds); + + // Return + return; +} + + +/***********************************************************************//** * @brief Single energy band constructor * * @param[in] emin Minimum energy of the interval. * @param[in] emax Maximum energy of the interval. * - * Constructs energy bounds for one (emin, emax) energy band. + * Constructs energy boundaries for one (emin, emax) energy band. ***************************************************************************/ GEbounds::GEbounds(const GEnergy& emin, const GEnergy& emax) { @@ -167,24 +187,6 @@ GEbounds::GEbounds(const int& num, const GEnergy& emin, const GEnergy& emax, /***********************************************************************//** - * @brief Load constructor - * - * @param[in] filename FITS filename. - ***************************************************************************/ -GEbounds::GEbounds(const std::string& filename) -{ - // Initialise members - init_members(); - - // Load FITS file - load(filename); - - // Return - return; -} - - -/***********************************************************************//** * @brief Destructor ***************************************************************************/ GEbounds::~GEbounds(void) @@ -570,6 +572,9 @@ void GEbounds::set_log(const int& num, const GEnergy& emin, const GEnergy& emax) * @param[in] filename FITS file name. * * Loads the energy boundaries from a FITS file. + * + * If no extension name is provided, the energy boundaries are loaded from + * the "EBOUNDS" extension. ***************************************************************************/ void GEbounds::load(const std::string& filename) { @@ -603,7 +608,10 @@ void GEbounds::load(const std::string& filename) * @param[in] clobber Overwrite any existing file (default: false)? * @param[in] unit Energy units (default: "keV") * - * Saves the energy boundaries into a FITS file. + * Saves energy boundaries into a FITS file. + * + * If no extension name is provided, the energy boundaries are saved into + * an "EBOUNDS" extension. ***************************************************************************/ void GEbounds::save(const std::string& filename, const bool& clobber, diff --git a/src/obs/GEnergies.cpp b/src/obs/GEnergies.cpp index 1ce4ee9..bb29869 100644 --- a/src/obs/GEnergies.cpp +++ b/src/obs/GEnergies.cpp @@ -30,6 +30,7 @@ #endif #include "GTools.hpp" #include "GException.hpp" +#include "GFilename.hpp" #include "GEnergies.hpp" #include "GFits.hpp" #include "GFitsTable.hpp" @@ -71,20 +72,19 @@ GEnergies::GEnergies(void) /***********************************************************************//** - * @brief Load constructor + * @brief FITS file constructor * - * @param[in] filename FITS filename. - * @param[in] extname Energies extension name (defaults to "ENERGIES") + * @param[in] filename FITS file name. * - * Constructs energy container by loading energies from FITS file. + * Constructs energy container from a FITS file. ***************************************************************************/ -GEnergies::GEnergies(const std::string& filename, const std::string& extname) +GEnergies::GEnergies(const std::string& filename) { // Initialise members init_members(); // Load energies - load(filename, extname); + load(filename); // Return return; @@ -534,21 +534,26 @@ void GEnergies::set_log(const int& num, /***********************************************************************//** * @brief Load energies from FITS file * - * @param[in] filename FITS filename. - * @param[in] extname Energies extension name (defaults to "ENERGIES") + * @param[in] filename FITS file name. * * Loads the energies from FITS file. + * + * If no extension name is provided, the energies are loaded from the + * "ENERGIES" extension. ***************************************************************************/ -void GEnergies::load(const std::string& filename, const std::string& extname) +void GEnergies::load(const std::string& filename) { + // Create file name + GFilename fname(filename); + // Allocate FITS file GFits file; // Open FITS file - file.open(filename); + file.open(fname.filename()); // Get energies table - const GFitsTable& table = *file.table(extname); + const GFitsTable& table = *file.table(fname.extname("ENERGIES")); // Read energies from table read(table); @@ -566,24 +571,25 @@ void GEnergies::load(const std::string& filename, const std::string& extname) * * @param[in] filename FITS filename. * @param[in] clobber Overwrite any existing energies extension? - * @param[in] extname Energies extension name (defaults to "ENERGIES") * - * Saves energies into extension @p extname of a FITS file. If the file does - * not exist it is created. If the file exists the energies are appended as - * extension. If another energies extension exists already it is overwritten - * if @p clobber=true. + * Saves energies into a FITS file. + * + * If no extension name is provided, the energies are saved into an + * "ENERGIES" extension. ***************************************************************************/ -void GEnergies::save(const std::string& filename, const bool& clobber, - const std::string& extname) const +void GEnergies::save(const std::string& filename, const bool& clobber) const { + // Create file name + GFilename fname(filename); + // Allocate FITS file GFits file; // Write energies to FITS file - write(file, extname); + write(file, fname.extname("ENERGIES")); // Save to file - file.saveto(filename, clobber); + file.saveto(fname.filename(), clobber); // Return return; @@ -637,7 +643,7 @@ void GEnergies::read(const GFitsTable& table) * @brief Write energies into FITS object * * @param[in] file FITS file. - * @param[in] extname Energy extension name (defaults to "ENERGIES") + * @param[in] extname Energy extension name (default: "ENERGIES") * * Writes energies into FITS object. ***************************************************************************/ diff --git a/src/obs/GGti.cpp b/src/obs/GGti.cpp index 007c810..5b2b736 100644 --- a/src/obs/GGti.cpp +++ b/src/obs/GGti.cpp @@ -30,6 +30,7 @@ #endif #include "GException.hpp" #include "GTools.hpp" +#include "GFilename.hpp" #include "GGti.hpp" #include "GFits.hpp" #include "GFitsTable.hpp" @@ -73,6 +74,26 @@ GGti::GGti(void) /***********************************************************************//** + * @brief FITS file constructor + * + * @param[in] filename FITS file name. + * + * Constructs Good Time Intervals from a FITS file. + ***************************************************************************/ +GGti::GGti(const std::string& filename) +{ + // Initialise members + init_members(); + + // Load FITS file + load(filename); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] gti Good Time Intervals. @@ -551,20 +572,25 @@ void GGti::extend(const GGti& gti) * @brief Load Good Time Intervals from FITS file * * @param[in] filename FITS filename. - * @param[in] extname GTI extension name (defaults to "GTI") * * Loads the Good Time Intervals from FITS file. + * + * If no extension name is provided, the energy boundaries are loaded from + * the "GTI" extension. ***************************************************************************/ -void GGti::load(const std::string& filename, const std::string& extname) +void GGti::load(const std::string& filename) { + // Create file name + GFilename fname(filename); + // Allocate FITS file GFits file; // Open FITS file - file.open(filename); + file.open(fname.filename()); // Get GTI table - const GFitsTable& table = *file.table(extname); + const GFitsTable& table = *file.table(fname.extname("GTI")); // Read GTI from table read(table); @@ -582,24 +608,25 @@ void GGti::load(const std::string& filename, const std::string& extname) * * @param[in] filename FITS filename. * @param[in] clobber Overwrite any existing GTI extension? - * @param[in] extname GTI extension name (defaults to "GTI") * - * Saves Good Time Intervals into extension @p extname of a FITS file. If the - * file does not exist it is created. If the file exists the GTI is appended - * as extension. If another GTI exists already it is overwritten if - * @p clobber=true. + * Saves Good Time Intervals into a FITS file. + * + * If no extension name is provided, the Good Time Intervals are saved into + * an "GTI" extension. ***************************************************************************/ -void GGti::save(const std::string& filename, const bool& clobber, - const std::string& extname) const +void GGti::save(const std::string& filename, const bool& clobber) const { + // Create file name + GFilename fname(filename); + // Allocate FITS file GFits file; // Write GTI to FITS file - write(file, extname); + write(file, fname.extname("GTI")); // Save to file - file.saveto(filename, clobber); + file.saveto(fname.filename(), clobber); // Return return; diff --git a/src/support/GNodeArray.cpp b/src/support/GNodeArray.cpp index 0502520..9d98efd 100644 --- a/src/support/GNodeArray.cpp +++ b/src/support/GNodeArray.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GNodeArray.cpp - Array of nodes class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2014 by Juergen Knoedlseder * + * copyright (C) 2008-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -29,9 +29,10 @@ #include #endif #include +#include "GTools.hpp" #include "GException.hpp" +#include "GFilename.hpp" #include "GNodeArray.hpp" -#include "GTools.hpp" #include "GFits.hpp" #include "GFitsTable.hpp" #include "GFitsBinTable.hpp" @@ -75,6 +76,26 @@ GNodeArray::GNodeArray(void) /***********************************************************************//** + * @brief FITS file constructor + * + * @param[in] filename FITS file name. + * + * Constructs node array from a FITS file. + ***************************************************************************/ +GNodeArray::GNodeArray(const std::string& filename) +{ + // Initialise members + init_members(); + + // Load FITS file + load(filename); + + // Return + return; +} + + +/***********************************************************************//** * @brief Element constructor * * @param[in] num Number of elements. @@ -673,20 +694,25 @@ void GNodeArray::set_value(const double& value) const * @brief Load nodes from FITS file * * @param[in] filename FITS filename. - * @param[in] extname Energies extension name (defaults to "NODES") * - * Loads the nodes from FITS file. + * Loads the node array from a FITS file. + * + * If no extension name is provided, the node array is loaded from the + * "NODES" extension. ***************************************************************************/ -void GNodeArray::load(const std::string& filename, const std::string& extname) +void GNodeArray::load(const std::string& filename) { + // Create file name + GFilename fname(filename); + // Allocate FITS file GFits file; // Open FITS file - file.open(filename); + file.open(fname.filename()); // Get nodes table - const GFitsTable& table = *file.table(extname); + const GFitsTable& table = *file.table(fname.extname("NODES")); // Read nodes from table read(table); @@ -704,24 +730,25 @@ void GNodeArray::load(const std::string& filename, const std::string& extname) * * @param[in] filename FITS filename. * @param[in] clobber Overwrite any existing nodes extension? - * @param[in] extname Nodes extension name (defaults to "NODES") * - * Saves nodes into extension @p extname of a FITS file. If the file does - * not exist it is created. If the file exists the nodes are appended as - * extension. If another nodes extension exists already it is overwritten - * if @p clobber=true. + * Saves node array into a FITS file. + * + * If no extension name is provided, the node array is saved into a + * "NODES" extension. ***************************************************************************/ -void GNodeArray::save(const std::string& filename, const bool& clobber, - const std::string& extname) const +void GNodeArray::save(const std::string& filename, const bool& clobber) const { + // Create file name + GFilename fname(filename); + // Allocate FITS file GFits file; // Write nodes to FITS file - write(file, extname); + write(file, fname.extname("NODES")); // Save to file - file.saveto(filename, clobber); + file.saveto(fname.filename(), clobber); // Return return; @@ -733,7 +760,7 @@ void GNodeArray::save(const std::string& filename, const bool& clobber, * * @param[in] table FITS table. * - * Reads the nodes from a FITS table. + * Reads the nodes from a FITS @p table. ***************************************************************************/ void GNodeArray::read(const GFitsTable& table) {