Commit ab3d8d5480424a3c868b53b9c8a15fcf23054a74

Authored by knodlseder
1 parent 47811a46

initial version

inst/mwl/Makefile.am 0 → 100644
  1 +## Process this file with automake to produce Makefile.in
  2 +
  3 +# Set include directories
  4 +INCLUDES = -I$(top_srcdir)/include \
  5 + -I$(top_builddir)/src \
  6 + -I$(top_srcdir)/src/support \
  7 + -I$(top_srcdir)/inst/mwl/include
  8 +
  9 +# Define sources for this directory
  10 +sources = src/GMWLException.cpp \
  11 + src/GMWLObservation.cpp \
  12 + src/GMWLSpectrum.cpp \
  13 + src/GMWLDatum.cpp \
  14 + src/GMWLInstDir.cpp
  15 +
  16 +# Define headers to be installed
  17 +pkginclude_HEADERS = include/GMWLException.hpp \
  18 + include/GMWLObservation.hpp \
  19 + include/GMWLSpectrum.hpp \
  20 + include/GMWLDatum.hpp \
  21 + include/GMWLInstDir.hpp
  22 +
  23 +# Build libtool library
  24 +noinst_LTLIBRARIES = libmwl.la
  25 +libmwl_la_SOURCES = $(sources)
  26 +libmwl_la_LDFLAGS = -version-info $(GAMMALIB_LT_VERSION)
... ...
inst/mwl/include/GMWLDatum.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLDatum.hpp - Multi-wavelength spectral point class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLDatum.hpp
  15 + * @brief GMWLDatum class interface definition.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef GMWLDATUM_HPP
  20 +#define GMWLDATUM_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include <iostream>
  24 +#include "GLog.hpp"
  25 +#include "GEventBin.hpp"
  26 +#include "GEnergy.hpp"
  27 +#include "GTime.hpp"
  28 +#include "GMWLInstDir.hpp"
  29 +
  30 +
  31 +/***********************************************************************//**
  32 + * @class GMWLDatum
  33 + *
  34 + * @brief GMWLDatum class interface defintion
  35 + *
  36 + * This class defines a spectral data point for the multi-wavelength
  37 + * interface. It derives from the abstract GEventBin base class.
  38 + ***************************************************************************/
  39 +class GMWLDatum : public GEventBin {
  40 +
  41 + // Friend classes
  42 + friend class GMWLSpectrum; //!< Needs access to load data
  43 +
  44 + // I/O friends
  45 + friend std::ostream& operator<< (std::ostream& os, const GMWLDatum& datum);
  46 + friend GLog& operator<< (GLog& log, const GMWLDatum& datum);
  47 +
  48 +public:
  49 + // Constructors and destructors
  50 + GMWLDatum(void);
  51 + GMWLDatum(const GMWLDatum& datum);
  52 + virtual ~GMWLDatum(void);
  53 +
  54 + // Operators
  55 + GMWLDatum& operator= (const GMWLDatum& datum);
  56 +
  57 + // Event access methods
  58 + const GEnergy& energy(void) const { return m_eng; }
  59 + const GInstDir& dir(void) const { return m_dir; }
  60 + const GTime& time(void) const { return m_time; }
  61 + double counts(void) const { return m_flux; }
  62 + double error(void) const { return m_flux_err; }
  63 +
  64 + // Other methods
  65 + void clear(void);
  66 + GMWLDatum* clone(void) const;
  67 + double size(void) const { return 1.0; }
  68 + GEnergy energy_err(void) const { return m_eng_err; }
  69 + double flux(void) const { return m_flux; }
  70 + double flux_err(void) const { return m_flux_err; }
  71 + std::string print(void) const;
  72 +
  73 +protected:
  74 + // Protected methods
  75 + void init_members(void);
  76 + void copy_members(const GMWLDatum& datum);
  77 + void free_members(void);
  78 +
  79 + // Protected members
  80 + GMWLInstDir m_dir; //!< Instrument direction of spectral point (not used)
  81 + GTime m_time; //!< Time of spectral point (not used)
  82 + GEnergy m_eng; //!< Energy of spectral point
  83 + GEnergy m_eng_err; //!< Uncertainty in energy
  84 + double m_flux; //!< Flux of spectral point
  85 + double m_flux_err; //!< Uncertainty in flux
  86 +
  87 +};
  88 +
  89 +#endif /* GMWLDATUM_HPP */
... ...
inst/mwl/include/GMWLException.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLException.hpp - Multi-wavelength exception handler *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLException.hpp
  15 + * @brief MWL exception handler interface definition.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef GMWLEXCEPTION_HPP
  20 +#define GMWLEXCEPTION_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include <string> // string
  24 +#include <sstream> // ostringstream
  25 +#include <stdexcept> // exception
  26 +
  27 +
  28 +/***********************************************************************//**
  29 + * @class GMWLExceptionHandler
  30 + *
  31 + * @brief Interface for multi-wavelength exception handler
  32 + ***************************************************************************/
  33 +class GMWLExceptionHandler : public std::exception {
  34 +public:
  35 + GMWLExceptionHandler(void) { }
  36 + virtual ~GMWLExceptionHandler(void) throw() { }
  37 + virtual const char* what() const throw();
  38 +protected:
  39 + std::string m_origin;
  40 + std::string m_message;
  41 +};
  42 +
  43 +
  44 +/***********************************************************************//**
  45 + * @class GMWLException
  46 + *
  47 + * @brief Interface for multi-wavelength exceptions
  48 + *
  49 + * This object is thrown in case of a multi-wavelength exception.
  50 + ***************************************************************************/
  51 +class GMWLException : public GMWLExceptionHandler {
  52 +public:
  53 + // Exceptions
  54 + class file_open_error : public GMWLExceptionHandler {
  55 + public:
  56 + file_open_error(std::string origin, std::string filename,
  57 + std::string message = "");
  58 + };
  59 + class bad_file_format : public GMWLExceptionHandler {
  60 + public:
  61 + bad_file_format(std::string origin, std::string message = "");
  62 + };
  63 +};
  64 +
  65 +#endif /* GMWLEXCEPTION_HPP */
... ...
inst/mwl/include/GMWLInstDir.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLInstDir.hpp - Multi-wavelength instrument direction class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLInstDir.hpp
  15 + * @brief GMWLInstDir class definition.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef GMWLINSTDIR_HPP
  20 +#define GMWLINSTDIR_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include "GInstDir.hpp"
  24 +
  25 +
  26 +/***********************************************************************//**
  27 + * @class GMWLInstDir
  28 + *
  29 + * @brief Interface for the Multi-wavelength instrument direction class.
  30 + *
  31 + * The Multi-wavelength instrument direction class is a dummy class that is
  32 + * needed but not used for the implementation of the Multi-wavelength
  33 + * interface as an instrument class.
  34 + ***************************************************************************/
  35 +class GMWLInstDir : public GInstDir {
  36 +
  37 +public:
  38 + // Constructors and destructors
  39 + GMWLInstDir(void);
  40 + GMWLInstDir(const GMWLInstDir& dir);
  41 + virtual ~GMWLInstDir(void);
  42 +
  43 + // Operators
  44 + GMWLInstDir& operator= (const GMWLInstDir& dir);
  45 +
  46 + // Methods
  47 + void clear(void);
  48 + GMWLInstDir* clone(void) const;
  49 +
  50 +protected:
  51 + // Protected methods
  52 + void init_members(void);
  53 + void copy_members(const GMWLInstDir& dir);
  54 + void free_members(void);
  55 +};
  56 +
  57 +#endif /* GMWLINSTDIR_HPP */
... ...
inst/mwl/include/GMWLLib.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLLib.hpp - Multi-wavelength Support Header files *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +
  14 +#ifndef GMWLLIB_HPP
  15 +#define GMWLLIB_HPP
  16 +
  17 +/* __ Includes ___________________________________________________________ */
  18 +#include "GammaLib.hpp"
  19 +
  20 +/* __ MWL specific headers _______________________________________________ */
  21 +#include "GMWLException.hpp"
  22 +#include "GMWLObservation.hpp"
  23 +#include "GMWLSpectrum.hpp"
  24 +#include "GMWLDatum.hpp"
  25 +
  26 +#endif /* GMWLLIB_HPP */
... ...
inst/mwl/include/GMWLObservation.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLObservation.hpp - Multi-wavelength observation class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLObservation.hpp
  15 + * @brief GMWLObservation class interface definition.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef GMWLOBSERVATION_HPP
  20 +#define GMWLOBSERVATION_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include <iostream>
  24 +#include "GLog.hpp"
  25 +#include "GObservation.hpp"
  26 +#include "GTime.hpp"
  27 +#include "GModel.hpp"
  28 +#include "GResponse.hpp"
  29 +#include "GPointing.hpp"
  30 +
  31 +
  32 +/***********************************************************************//**
  33 + * @class GMWLObservation
  34 + *
  35 + * @brief Interface class for multi-wavelength observations
  36 + *
  37 + * This class implements a multi-wavelength observation. A multi-wavelength
  38 + * observation contains spectral points obtained with an unspecified
  39 + * instrument. The spectral points are given in physical units.
  40 + ***************************************************************************/
  41 +class GMWLObservation : public GObservation {
  42 +
  43 + // I/O friends
  44 + friend std::ostream& operator<< (std::ostream& os, const GMWLObservation& obs);
  45 + friend GLog& operator<< (GLog& log, const GMWLObservation& obs);
  46 +
  47 +public:
  48 + // Constructors and destructors
  49 + GMWLObservation(void);
  50 + GMWLObservation(const std::string& filename);
  51 + GMWLObservation(const GMWLObservation& obs);
  52 + virtual ~GMWLObservation(void);
  53 +
  54 + // Operators
  55 + GMWLObservation& operator= (const GMWLObservation& obs);
  56 +
  57 + // Implement pure virtual methods
  58 + void clear(void);
  59 + GMWLObservation* clone(void) const;
  60 + void response(const std::string& rspname, std::string caldb = "");
  61 + GResponse* response(const GTime& time) const;
  62 + GPointing* pointing(const GTime& time) const;
  63 + std::string instrument(void) const { return m_instrument; }
  64 +
  65 + // Other methods
  66 + void load(const std::string& filename);
  67 + std::string print(void) const;
  68 +
  69 +protected:
  70 + // Protected methods
  71 + void init_members(void);
  72 + void copy_members(const GMWLObservation& obs);
  73 + void free_members(void);
  74 +
  75 + // Protected members
  76 + std::string m_instrument; //!< Instrument name
  77 +
  78 +};
  79 +
  80 +#endif /* GMWLOBSERVATION_HPP */
... ...
inst/mwl/include/GMWLSpectrum.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLSpectrum.hpp - Multi-wavelength spectrum class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLSpectrum.hpp
  15 + * @brief GMWLSpectrum class interface definition.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +#ifndef GMWLSPECTRUM_HPP
  20 +#define GMWLSPECTRUM_HPP
  21 +
  22 +/* __ Includes ___________________________________________________________ */
  23 +#include <iostream>
  24 +#include "GLog.hpp"
  25 +#include "GEventCube.hpp"
  26 +#include "GMWLDatum.hpp"
  27 +
  28 +
  29 +/***********************************************************************//**
  30 + * @class GMWLSpectrum
  31 + *
  32 + * @brief GMWLSpectrum class interface defintion
  33 + *
  34 + * This class defines a multi-wavelength spectrum and is a container for
  35 + * spectral points of type GMWLDatum. It derives from the abstract
  36 + * GEventCube base class.
  37 + ***************************************************************************/
  38 +class GMWLSpectrum : public GEventCube {
  39 +
  40 + // Friend classes
  41 + friend class GMWLObservation;
  42 +
  43 + // I/O friends
  44 + friend std::ostream& operator<< (std::ostream& os, const GMWLSpectrum& spec);
  45 + friend GLog& operator<< (GLog& log, const GMWLSpectrum& spec);
  46 +
  47 +public:
  48 + // Constructors and destructors
  49 + GMWLSpectrum(void);
  50 + GMWLSpectrum(const std::string& filename);
  51 + GMWLSpectrum(const GMWLSpectrum& spec);
  52 + virtual ~GMWLSpectrum(void);
  53 +
  54 + // Operators
  55 + GMWLSpectrum& operator= (const GMWLSpectrum& spec);
  56 +
  57 + // Implemented pure virtul methods
  58 + void clear(void);
  59 + GMWLSpectrum* clone(void) const;
  60 + void load(const std::string& filename);
  61 + GMWLDatum* pointer(int index);
  62 + int number(void) const;
  63 +
  64 + // Other methods
  65 + int size(void) const;
  66 + std::string print(void) const;
  67 + void load_fits(const std::string& filename, int extno = 0);
  68 + void load_fits(const std::string& filename, const std::string& extname);
  69 +
  70 +protected:
  71 + // Protected methods
  72 + void init_members(void);
  73 + void copy_members(const GMWLSpectrum& spec);
  74 + void free_members(void);
  75 + void read_fits(const GFitsTable* table);
  76 +
  77 + // Protected members
  78 + std::vector<GMWLDatum> m_data; //!< Spectral data
  79 +};
  80 +
  81 +#endif /* GMWLSPECTRUM_HPP */
... ...
inst/mwl/pyext/GMWLObservation.i 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLObservation.i - Multi-wavelength observation class python I/F *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLObservation.i
  15 + * @brief GMWLObservation class python interface
  16 + * @author J. Knodlseder
  17 + */
  18 +%{
  19 +/* Put headers and other declarations here that are needed for compilation */
  20 +#include "GMWLObservation.hpp"
  21 +%}
  22 +
  23 +
  24 +/***********************************************************************//**
  25 + * @class GMWLObservation
  26 + *
  27 + * @brief Interface class for multi-wavelength observations
  28 + *
  29 + * This class implements a multi-wavelength observation. A multi-wavelength
  30 + * observation contains spectral points obtained with an unspecified
  31 + * instrument. The spectral points are given in physical units.
  32 + ***************************************************************************/
  33 +class GMWLObservation : public GObservation {
  34 +public:
  35 + // Constructors and destructors
  36 + GMWLObservation(void);
  37 + GMWLObservation(const std::string& filename);
  38 + GMWLObservation(const GMWLObservation& obs);
  39 + virtual ~GMWLObservation(void);
  40 +
  41 + // Implement pure virtual methods
  42 + GMWLObservation* clone(void) const;
  43 + void response(const std::string& irfname, std::string caldb = "");
  44 + GResponse* response(const GTime& time) const { return NULL; }
  45 + GPointing* pointing(const GTime& time) const { return NULL; }
  46 + std::string instrument(void) const { return m_instrument; }
  47 +
  48 + // Other methods
  49 + void load(const std::string& filename);
  50 +};
  51 +
  52 +
  53 +/***********************************************************************//**
  54 + * @brief GMWLObservation class extension
  55 + ***************************************************************************/
  56 +%extend GMWLObservation {
  57 + char *__str__() {
  58 + static std::string result = self->print();
  59 + return ((char*)result.c_str());
  60 + }
  61 + GMWLObservation copy() {
  62 + return (*self);
  63 + }
  64 +};
... ...
inst/mwl/pyext/mwllib.i 0 → 100644
  1 +/***************************************************************************
  2 + * mwllib - Multi-wavelength support python bindings *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +%module mwllib
  14 +
  15 +/* __ MWL ________________________________________________________________ */
  16 +#include "GMWLObservation.i"
  17 +
  18 +
  19 +
... ...
inst/mwl/src/GMWLDatum.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLDatum.cpp - Multi-wavelength spectral point class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLDatum.cpp
  15 + * @brief GMWLDatum class implementation
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <iostream>
  24 +#include "GLog.hpp"
  25 +#include "GTools.hpp"
  26 +#include "GMWLDatum.hpp"
  27 +
  28 +/* __ Method name definitions ____________________________________________ */
  29 +
  30 +/* __ Macros _____________________________________________________________ */
  31 +
  32 +/* __ Coding definitions _________________________________________________ */
  33 +
  34 +/* __ Debug definitions __________________________________________________ */
  35 +
  36 +
  37 +/*==========================================================================
  38 + = =
  39 + = Constructors/destructors =
  40 + = =
  41 + ==========================================================================*/
  42 +
  43 +/***********************************************************************//**
  44 + * @brief Void constructor
  45 + *
  46 + * Creates instance of an undefined spectral point.
  47 + ***************************************************************************/
  48 +GMWLDatum::GMWLDatum(void) : GEventBin()
  49 +{
  50 + // Initialise class members for clean destruction
  51 + init_members();
  52 +
  53 + // Return
  54 + return;
  55 +}
  56 +
  57 +
  58 +/***********************************************************************//**
  59 + * @brief Copy constructor
  60 + *
  61 + * @param[in] datum Spectral point.
  62 + *
  63 + * Creates instance by copying an existing spectral point.
  64 + ***************************************************************************/
  65 +GMWLDatum::GMWLDatum(const GMWLDatum& datum) : GEventBin(datum)
  66 +{
  67 + // Initialise class members for clean destruction
  68 + init_members();
  69 +
  70 + // Copy members
  71 + copy_members(datum);
  72 +
  73 + // Return
  74 + return;
  75 +}
  76 +
  77 +
  78 +/***********************************************************************//**
  79 + * @brief Destructor
  80 + *
  81 + * Destroy instance.
  82 + ***************************************************************************/
  83 +GMWLDatum::~GMWLDatum(void)
  84 +{
  85 + // Free members
  86 + free_members();
  87 +
  88 + // Return
  89 + return;
  90 +}
  91 +
  92 +
  93 +/*==========================================================================
  94 + = =
  95 + = Operators =
  96 + = =
  97 + ==========================================================================*/
  98 +
  99 +/***********************************************************************//**
  100 + * @brief Assignment operator
  101 + *
  102 + * @param[in] datum Spectral point.
  103 + *
  104 + * Copies spectral point into the instance.
  105 + ***************************************************************************/
  106 +GMWLDatum& GMWLDatum::operator= (const GMWLDatum& datum)
  107 +{
  108 + // Execute only if object is not identical
  109 + if (this != &datum) {
  110 +
  111 + // Copy base class members
  112 + this->GEventBin::operator=(datum);
  113 +
  114 + // Free members
  115 + free_members();
  116 +
  117 + // Initialise private members for clean destruction
  118 + init_members();
  119 +
  120 + // Copy members
  121 + copy_members(datum);
  122 +
  123 + } // endif: object was not identical
  124 +
  125 + // Return this object
  126 + return *this;
  127 +}
  128 +
  129 +
  130 +/*==========================================================================
  131 + = =
  132 + = Public methods =
  133 + = =
  134 + ==========================================================================*/
  135 +
  136 +/***********************************************************************//**
  137 + * @brief Clear instance
  138 + *
  139 + * This method properly resets the instance to an initial state.
  140 + ***************************************************************************/
  141 +void GMWLDatum::clear(void)
  142 +{
  143 + // Free class members (base and derived classes, derived class first)
  144 + free_members();
  145 + this->GEventBin::free_members();
  146 + this->GEvent::free_members();
  147 +
  148 + // Initialise members
  149 + this->GEvent::init_members();
  150 + this->GEventBin::init_members();
  151 + init_members();
  152 +
  153 + // Return
  154 + return;
  155 +}
  156 +
  157 +
  158 +/***********************************************************************//**
  159 + * @brief Clone instance
  160 +***************************************************************************/
  161 +GMWLDatum* GMWLDatum::clone(void) const
  162 +{
  163 + return new GMWLDatum(*this);
  164 +}
  165 +
  166 +
  167 +/***********************************************************************//**
  168 + * @brief Print spectral point information
  169 + ***************************************************************************/
  170 +std::string GMWLDatum::print(void) const
  171 +{
  172 + // Initialise result string
  173 + std::string result;
  174 +
  175 + // Append spectral point
  176 + result.append(m_eng.print());
  177 + if (m_eng_err.MeV() > 0.0)
  178 + result.append(" +/- "+m_eng_err.print());
  179 + result.append(": "+str(m_flux));
  180 + if (m_flux_err > 0.0)
  181 + result.append(" +/- "+str(m_flux_err));
  182 +
  183 + // Return result
  184 + return result;
  185 +}
  186 +
  187 +
  188 +/*==========================================================================
  189 + = =
  190 + = Private methods =
  191 + = =
  192 + ==========================================================================*/
  193 +
  194 +/***********************************************************************//**
  195 + * @brief Initialise class members
  196 + ***************************************************************************/
  197 +void GMWLDatum::init_members(void)
  198 +{
  199 + // Initialise members
  200 + m_dir.clear();
  201 + m_time.clear();
  202 + m_eng.clear();
  203 + m_eng_err.clear();
  204 + m_flux = 0.0;
  205 + m_flux_err = 0.0;
  206 +
  207 + // Return
  208 + return;
  209 +}
  210 +
  211 +
  212 +/***********************************************************************//**
  213 + * @brief Copy class members
  214 + *
  215 + * @param[in] datum Instance to be copied.
  216 + ***************************************************************************/
  217 +void GMWLDatum::copy_members(const GMWLDatum& datum)
  218 +{
  219 + // Copy members
  220 + m_dir = datum.m_dir;
  221 + m_time = datum.m_time;
  222 + m_eng = datum.m_eng;
  223 + m_eng_err = datum.m_eng_err;
  224 + m_flux = datum.m_flux;
  225 + m_flux_err = datum.m_flux_err;
  226 +
  227 + // Return
  228 + return;
  229 +}
  230 +
  231 +
  232 +/***********************************************************************//**
  233 + * @brief Delete class members
  234 + *
  235 + * This class does not allocate any memory but simply holds pointers. Hence
  236 + * nothing has to be deallocated.
  237 + ***************************************************************************/
  238 +void GMWLDatum::free_members(void)
  239 +{
  240 + // Return
  241 + return;
  242 +}
  243 +
  244 +
  245 +/*==========================================================================
  246 + = =
  247 + = Friends =
  248 + = =
  249 + ==========================================================================*/
  250 +
  251 +/***********************************************************************//**
  252 + * @brief Output operator
  253 + *
  254 + * @param[in] os Output stream.
  255 + * @param[in] datum Spectral point.
  256 + ***************************************************************************/
  257 +std::ostream& operator<< (std::ostream& os, const GMWLDatum& datum)
  258 +{
  259 + // Write spectral point in output stream
  260 + os << datum.print();
  261 +
  262 + // Return output stream
  263 + return os;
  264 +}
  265 +
  266 +
  267 +/***********************************************************************//**
  268 + * @brief Log operator
  269 + *
  270 + * @param[in] log Logger.
  271 + * @param[in] datum Spectral point.
  272 + ***************************************************************************/
  273 +GLog& operator<< (GLog& log, const GMWLDatum& datum)
  274 +{
  275 + // Write spectral point into logger
  276 + log << datum.print();
  277 +
  278 + // Return logger
  279 + return log;
  280 +}
... ...
inst/mwl/src/GMWLException.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLException.cpp - Multi-wavelength exception handler *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLException.cpp
  15 + * @brief MWL exception handler interface implementation.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#include "GMWLException.hpp"
  21 +#include "GTools.hpp"
  22 +
  23 +
  24 +/***********************************************************************//**
  25 + * @brief Exception message
  26 + ***************************************************************************/
  27 +const char* GMWLExceptionHandler::what() const throw()
  28 +{
  29 + std::string message = "*** ERROR in " + m_origin + ": " + m_message;
  30 + return message.c_str();
  31 +}
  32 +
  33 +
  34 +/***********************************************************************//**
  35 + * @brief Error while opening file
  36 + *
  37 + * @param[in] origin Name of method that has thrown the exception.
  38 + * @param[in] filename Name of file that could not be opened.
  39 + * @param[in] message Optional error message.
  40 + ***************************************************************************/
  41 +GMWLException::file_open_error::file_open_error(std::string origin,
  42 + std::string filename,
  43 + std::string message)
  44 +{
  45 + m_origin = origin;
  46 + m_message = "Unable to open file \""+filename+"\". "+message;
  47 + return;
  48 +}
  49 +
  50 +
  51 +/***********************************************************************//**
  52 + * @brief File has invalid format
  53 + *
  54 + * @param[in] origin Name of method that has thrown the exception.
  55 + * @param[in] message Optional error message.
  56 + ***************************************************************************/
  57 +GMWLException::bad_file_format::bad_file_format(std::string origin,
  58 + std::string message)
  59 +{
  60 + m_origin = origin;
  61 + m_message = "File has invalid format. "+message;
  62 + return;
  63 +}
... ...
inst/mwl/src/GMWLInstDir.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLInstDir.cpp - Multi-wavelength instrument direction class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLInstDir.cpp
  15 + * @brief GMWLInstDir class implementation.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include "GMWLInstDir.hpp"
  24 +
  25 +/* __ Method name definitions ____________________________________________ */
  26 +
  27 +/* __ Macros _____________________________________________________________ */
  28 +
  29 +/* __ Coding definitions _________________________________________________ */
  30 +
  31 +/* __ Debug definitions __________________________________________________ */
  32 +
  33 +/* __ Prototypes _________________________________________________________ */
  34 +
  35 +/*==========================================================================
  36 + = =
  37 + = Constructors/destructors =
  38 + = =
  39 + ==========================================================================*/
  40 +
  41 +/***********************************************************************//**
  42 + * @brief Void constructor
  43 + ***************************************************************************/
  44 +GMWLInstDir::GMWLInstDir(void) : GInstDir()
  45 +{
  46 + // Initialise class members
  47 + init_members();
  48 +
  49 + // Return
  50 + return;
  51 +}
  52 +
  53 +
  54 +/***********************************************************************//**
  55 + * @brief Copy constructor
  56 + *
  57 + * @param[in] dir Instrument direction.
  58 + ***************************************************************************/
  59 +GMWLInstDir::GMWLInstDir(const GMWLInstDir& dir) : GInstDir(dir)
  60 +{
  61 + // Initialise class members
  62 + init_members();
  63 +
  64 + // Copy members
  65 + copy_members(dir);
  66 +
  67 + // Return
  68 + return;
  69 +}
  70 +
  71 +
  72 +/***********************************************************************//**
  73 + * @brief Destructor
  74 + ***************************************************************************/
  75 +GMWLInstDir::~GMWLInstDir(void)
  76 +{
  77 + // Free members
  78 + free_members();
  79 +
  80 + // Return
  81 + return;
  82 +}
  83 +
  84 +
  85 +/*==========================================================================
  86 + = =
  87 + = Operators =
  88 + = =
  89 + ==========================================================================*/
  90 +
  91 +/***********************************************************************//**
  92 + * @brief Assignment operator
  93 + *
  94 + * @param[in] dir Instrument direction.
  95 + ***************************************************************************/
  96 +GMWLInstDir& GMWLInstDir::operator= (const GMWLInstDir& dir)
  97 +{
  98 + // Execute only if object is not identical
  99 + if (this != &dir) {
  100 +
  101 + // Copy base class members
  102 + this->GInstDir::operator=(dir);
  103 +
  104 + // Free members
  105 + free_members();
  106 +
  107 + // Initialise private members
  108 + init_members();
  109 +
  110 + // Copy members
  111 + copy_members(dir);
  112 +
  113 + } // endif: object was not identical
  114 +
  115 + // Return this object
  116 + return *this;
  117 +}
  118 +
  119 +
  120 +/*==========================================================================
  121 + = =
  122 + = Public methods =
  123 + = =
  124 + ==========================================================================*/
  125 +
  126 +/***********************************************************************//**
  127 + * @brief Clear sky direction
  128 + ***************************************************************************/
  129 +void GMWLInstDir::clear(void)
  130 +{
  131 + // Free members
  132 + free_members();
  133 +
  134 + // Initialise private members
  135 + init_members();
  136 +
  137 + // Return
  138 + return;
  139 +}
  140 +
  141 +
  142 +/***********************************************************************//**
  143 + * @brief Clone instance
  144 + ***************************************************************************/
  145 +GMWLInstDir* GMWLInstDir::clone(void) const
  146 +{
  147 + return new GMWLInstDir(*this);
  148 +}
  149 +
  150 +
  151 +/*==========================================================================
  152 + = =
  153 + = Private methods =
  154 + = =
  155 + ==========================================================================*/
  156 +
  157 +/***********************************************************************//**
  158 + * @brief Initialise class members
  159 + ***************************************************************************/
  160 +void GMWLInstDir::init_members(void)
  161 +{
  162 + // Return
  163 + return;
  164 +}
  165 +
  166 +
  167 +/***********************************************************************//**
  168 + * @brief Copy class members
  169 + *
  170 + * @param[in] dir Instrument direction.
  171 + ***************************************************************************/
  172 +void GMWLInstDir::copy_members(const GMWLInstDir& dir)
  173 +{
  174 + // Return
  175 + return;
  176 +}
  177 +
  178 +
  179 +/***********************************************************************//**
  180 + * @brief Delete class members
  181 + ***************************************************************************/
  182 +void GMWLInstDir::free_members(void)
  183 +{
  184 + // Return
  185 + return;
  186 +}
  187 +
  188 +
  189 +/*==========================================================================
  190 + = =
  191 + = Friends =
  192 + = =
  193 + ==========================================================================*/
... ...
inst/mwl/src/GMWLObservation.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLObservation.cpp - Multi-wavelength observation class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLObservation.cpp
  15 + * @brief GMWLObservation class implementation.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <iostream>
  24 +#include "GLog.hpp"
  25 +#include "GTools.hpp"
  26 +#include "GMWLObservation.hpp"
  27 +#include "GMWLSpectrum.hpp"
  28 +
  29 +/* __ Method name definitions ____________________________________________ */
  30 +
  31 +/* __ Macros _____________________________________________________________ */
  32 +
  33 +/* __ Coding definitions _________________________________________________ */
  34 +
  35 +/* __ Debug definitions __________________________________________________ */
  36 +
  37 +
  38 +/*==========================================================================
  39 + = =
  40 + = Constructors/destructors =
  41 + = =
  42 + ==========================================================================*/
  43 +
  44 +/***********************************************************************//**
  45 + * @brief Void constructor
  46 + *
  47 + * Creates instance of an undefined observation.
  48 + ***************************************************************************/
  49 +GMWLObservation::GMWLObservation(void) : GObservation()
  50 +{
  51 + // Initialise class members for clean destruction
  52 + init_members();
  53 +
  54 + // Return
  55 + return;
  56 +}
  57 +
  58 +
  59 +/***********************************************************************//**
  60 + * @brief File constructor
  61 + *
  62 + * @param[in] filename Filename.
  63 + *
  64 + * Creates instance from file.
  65 + ***************************************************************************/
  66 +GMWLObservation::GMWLObservation(const std::string& filename) : GObservation()
  67 +{
  68 + // Initialise class members for clean destruction
  69 + init_members();
  70 +
  71 + // Load observation
  72 + load(filename);
  73 +
  74 + // Return
  75 + return;
  76 +}
  77 +
  78 +
  79 +/***********************************************************************//**
  80 + * @brief Copy constructor
  81 + *
  82 + * @param[in] obs Observation.
  83 + *
  84 + * Creates instance by copying an existing observation.
  85 + ***************************************************************************/
  86 +GMWLObservation::GMWLObservation(const GMWLObservation& obs) : GObservation(obs)
  87 +{
  88 + // Initialise class members for clean destruction
  89 + init_members();
  90 +
  91 + // Copy members
  92 + copy_members(obs);
  93 +
  94 + // Return
  95 + return;
  96 +}
  97 +
  98 +
  99 +/***********************************************************************//**
  100 + * @brief Destructor
  101 + *
  102 + * Destroy instance.
  103 + ***************************************************************************/
  104 +GMWLObservation::~GMWLObservation(void)
  105 +{
  106 + // Free members
  107 + free_members();
  108 +
  109 + // Return
  110 + return;
  111 +}
  112 +
  113 +
  114 +/*==========================================================================
  115 + = =
  116 + = Operators =
  117 + = =
  118 + ==========================================================================*/
  119 +
  120 +/***********************************************************************//**
  121 + * @brief Assignment operator
  122 + *
  123 + * @param[in] obs Observation.
  124 + *
  125 + * Copies observation into the instance.
  126 + ***************************************************************************/
  127 +GMWLObservation& GMWLObservation::operator= (const GMWLObservation& obs)
  128 +{
  129 + // Execute only if object is not identical
  130 + if (this != &obs) {
  131 +
  132 + // Copy base class members
  133 + this->GObservation::operator=(obs);
  134 +
  135 + // Free members
  136 + free_members();
  137 +
  138 + // Initialise private members for clean destruction
  139 + init_members();
  140 +
  141 + // Copy members
  142 + copy_members(obs);
  143 +
  144 + } // endif: object was not identical
  145 +
  146 + // Return this object
  147 + return *this;
  148 +}
  149 +
  150 +
  151 +/*==========================================================================
  152 + = =
  153 + = Public methods =
  154 + = =
  155 + ==========================================================================*/
  156 +
  157 +/***********************************************************************//**
  158 + * @brief Clear instance
  159 + *
  160 + * This method properly resets the instance to an initial state.
  161 + ***************************************************************************/
  162 +void GMWLObservation::clear(void)
  163 +{
  164 + // Free class members (base and derived classes, derived class first)
  165 + free_members();
  166 + this->GObservation::free_members();
  167 +
  168 + // Initialise members
  169 + this->GObservation::init_members();
  170 + init_members();
  171 +
  172 + // Return
  173 + return;
  174 +}
  175 +
  176 +
  177 +/***********************************************************************//**
  178 + * @brief Clone instance
  179 +***************************************************************************/
  180 +GMWLObservation* GMWLObservation::clone(void) const
  181 +{
  182 + return new GMWLObservation(*this);
  183 +}
  184 +
  185 +
  186 +/***********************************************************************//**
  187 + * @brief Set response function (dummy)
  188 + *
  189 + * @param[in] rspname Name of response function.
  190 + * @param[in] caldb Optional name of calibration database.
  191 + *
  192 + * This method does nothing.
  193 + ***************************************************************************/
  194 +void GMWLObservation::response(const std::string& rspname, std::string caldb)
  195 +{
  196 + // Return
  197 + return;
  198 +}
  199 +
  200 +
  201 +/***********************************************************************//**
  202 + * @brief Returns pointer to response function (dummy)
  203 + *
  204 + * @param[in] time Time.
  205 + *
  206 + * Returns NULL pointer.
  207 + ***************************************************************************/
  208 +GResponse* GMWLObservation::response(const GTime& time) const
  209 +{
  210 + // Return NULL pointer
  211 + return NULL;
  212 +}
  213 +
  214 +
  215 +/***********************************************************************//**
  216 + * @brief Returns pointer to pointing (dummy)
  217 + *
  218 + * @param[in] time Time.
  219 + *
  220 + * Returns NULL pointer.
  221 + ***************************************************************************/
  222 +GPointing* GMWLObservation::pointing(const GTime& time) const
  223 +{
  224 + // Return NULL pointer
  225 + return NULL;
  226 +}
  227 +
  228 +
  229 +/***********************************************************************//**
  230 + * @brief Load observation
  231 + *
  232 + * @param[in] filename File name.
  233 + *
  234 + * @todo Extract energy boundaries from spectrum.
  235 + *
  236 + * @todo Set good time intervals covering observation interval.
  237 + ***************************************************************************/
  238 +void GMWLObservation::load(const std::string& filename)
  239 +{
  240 + // Clear observation
  241 + clear();
  242 +
  243 + // Allocate spectrum
  244 + GMWLSpectrum* spec = new GMWLSpectrum;
  245 + m_events = spec;
  246 +
  247 + // Load spectrum
  248 + spec->load(filename);
  249 +
  250 + // Set observation name
  251 + obsname("Multi-wavelength observation");
  252 +
  253 + // Extract energy boundaries from spectrum
  254 +
  255 + // Set good time intervals
  256 +
  257 + // Return
  258 + return;
  259 +}
  260 +
  261 +
  262 +/***********************************************************************//**
  263 + * @brief Print multi-wavelength information
  264 + ***************************************************************************/
  265 +std::string GMWLObservation::print(void) const
  266 +{
  267 + // Initialise result string
  268 + std::string result;
  269 +
  270 + // Append header
  271 + result.append("=== GMWLObservation ===\n");
  272 + result.append(parformat("Name")+obsname()+"\n");
  273 + result.append(parformat("Instrument")+instrument()+"\n");
  274 + result.append(parformat("Time range")+"\n");
  275 + result.append(parformat("Energy range"));
  276 +
  277 + // Append events
  278 + if (m_events != NULL)
  279 + result.append("\n"+((GMWLSpectrum*)m_events)->print());
  280 +
  281 + // Return result
  282 + return result;
  283 +}
  284 +
  285 +
  286 +/*==========================================================================
  287 + = =
  288 + = Private methods =
  289 + = =
  290 + ==========================================================================*/
  291 +
  292 +/***********************************************************************//**
  293 + * @brief Initialise class members
  294 + ***************************************************************************/
  295 +void GMWLObservation::init_members(void)
  296 +{
  297 + // Initialise members
  298 + m_instrument.clear();
  299 +
  300 + // Overwrite base class statistics
  301 + m_statistics = "Gaussian";
  302 +
  303 + // Return
  304 + return;
  305 +}
  306 +
  307 +
  308 +/***********************************************************************//**
  309 + * @brief Copy class members
  310 + *
  311 + * @param[in] obs Observation to be copied
  312 + ***************************************************************************/
  313 +void GMWLObservation::copy_members(const GMWLObservation& obs)
  314 +{
  315 + // Copy members
  316 + m_instrument = obs.m_instrument;
  317 +
  318 + // Return
  319 + return;
  320 +}
  321 +
  322 +
  323 +/***********************************************************************//**
  324 + * @brief Delete class members
  325 + ***************************************************************************/
  326 +void GMWLObservation::free_members(void)
  327 +{
  328 + // Return
  329 + return;
  330 +}
  331 +
  332 +
  333 +/*==========================================================================
  334 + = =
  335 + = Friends =
  336 + = =
  337 + ==========================================================================*/
  338 +
  339 +/***********************************************************************//**
  340 + * @brief Output operator
  341 + *
  342 + * @param[in] os Output stream.
  343 + * @param[in] obs Observation.
  344 + ***************************************************************************/
  345 +std::ostream& operator<< (std::ostream& os, const GMWLObservation& obs)
  346 +{
  347 + // Write observation in output stream
  348 + os << obs.print();
  349 +
  350 + // Return output stream
  351 + return os;
  352 +}
  353 +
  354 +
  355 +/***********************************************************************//**
  356 + * @brief Log operator
  357 + *
  358 + * @param[in] log Logger.
  359 + * @param[in] obs Observation.
  360 + ***************************************************************************/
  361 +GLog& operator<< (GLog& log, const GMWLObservation& obs)
  362 +{
  363 + // Write observation into logger
  364 + log << obs.print();
  365 +
  366 + // Return logger
  367 + return log;
  368 +}
... ...
inst/mwl/src/GMWLSpectrum.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GMWLSpectrum.cpp - Multi-wavelength spectrum class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file GMWLSpectrum.cpp
  15 + * @brief GMWLSpectrum class implementation.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <iostream>
  24 +#include "GLog.hpp"
  25 +#include "GTools.hpp"
  26 +#include "GFits.hpp"
  27 +#include "GFitsTable.hpp"
  28 +#include "GException.hpp"
  29 +#include "GMWLException.hpp"
  30 +#include "GMWLSpectrum.hpp"
  31 +
  32 +/* __ Method name definitions ____________________________________________ */
  33 +#define G_POINTER "GMWLSpectrum::pointer(int)"
  34 +#define G_LOAD_FITS "GMWLSpectrum::load_fits(std::string&, int)"
  35 +
  36 +/* __ Macros _____________________________________________________________ */
  37 +
  38 +/* __ Coding definitions _________________________________________________ */
  39 +
  40 +/* __ Debug definitions __________________________________________________ */
  41 +
  42 +
  43 +
  44 +/*==========================================================================
  45 + = =
  46 + = Constructors/destructors =
  47 + = =
  48 + ==========================================================================*/
  49 +
  50 +/***********************************************************************//**
  51 + * @brief Void constructor
  52 + *
  53 + * Creates instance of an undefined spectrum.
  54 + ***************************************************************************/
  55 +GMWLSpectrum::GMWLSpectrum(void) : GEventCube()
  56 +{
  57 + // Initialise class members for clean destruction
  58 + init_members();
  59 +
  60 + // Return
  61 + return;
  62 +}
  63 +
  64 +
  65 +/***********************************************************************//**
  66 + * @brief File constructor
  67 + *
  68 + * @param[in] filename Filename.
  69 + *
  70 + * Creates instance from file.
  71 + ***************************************************************************/
  72 +GMWLSpectrum::GMWLSpectrum(const std::string& filename) : GEventCube()
  73 +{
  74 + // Initialise class members for clean destruction
  75 + init_members();
  76 +
  77 + // Load spectrum
  78 + load(filename);
  79 +
  80 + // Return
  81 + return;
  82 +}
  83 +
  84 +
  85 +/***********************************************************************//**
  86 + * @brief Copy constructor
  87 + *
  88 + * @param[in] spec Spectrum.
  89 + *
  90 + * Creates instance by copying an existing spectrum.
  91 + ***************************************************************************/
  92 +GMWLSpectrum::GMWLSpectrum(const GMWLSpectrum& spec) : GEventCube(spec)
  93 +{
  94 + // Initialise class members for clean destruction
  95 + init_members();
  96 +
  97 + // Copy members
  98 + copy_members(spec);
  99 +
  100 + // Return
  101 + return;
  102 +}
  103 +
  104 +
  105 +/***********************************************************************//**
  106 + * @brief Destructor
  107 + *
  108 + * Destroy instance.
  109 + ***************************************************************************/
  110 +GMWLSpectrum::~GMWLSpectrum(void)
  111 +{
  112 + // Free members
  113 + free_members();
  114 +
  115 + // Return
  116 + return;
  117 +}
  118 +
  119 +
  120 +/*==========================================================================
  121 + = =
  122 + = Operators =
  123 + = =
  124 + ==========================================================================*/
  125 +
  126 +/***********************************************************************//**
  127 + * @brief Assignment operator
  128 + *
  129 + * @param[in] spec Spectrum.
  130 + *
  131 + * Copies spectrum into the instance.
  132 + ***************************************************************************/
  133 +GMWLSpectrum& GMWLSpectrum::operator= (const GMWLSpectrum& spec)
  134 +{
  135 + // Execute only if object is not identical
  136 + if (this != &spec) {
  137 +
  138 + // Copy base class members
  139 + this->GEventCube::operator=(spec);
  140 +
  141 + // Free members
  142 + free_members();
  143 +
  144 + // Initialise private members for clean destruction
  145 + init_members();
  146 +
  147 + // Copy members
  148 + copy_members(spec);
  149 +
  150 + } // endif: object was not identical
  151 +
  152 + // Return this object
  153 + return *this;
  154 +}
  155 +
  156 +
  157 +/*==========================================================================
  158 + = =
  159 + = Public methods =
  160 + = =
  161 + ==========================================================================*/
  162 +
  163 +/***********************************************************************//**
  164 + * @brief Clear object
  165 + *
  166 + * This method properly resets the object to an initial state.
  167 + ***************************************************************************/
  168 +void GMWLSpectrum::clear(void)
  169 +{
  170 + // Free class members (base and derived classes, derived class first)
  171 + free_members();
  172 + this->GEventCube::free_members();
  173 + this->GEvents::free_members();
  174 +
  175 + // Initialise members
  176 + this->GEvents::init_members();
  177 + this->GEventCube::init_members();
  178 + init_members();
  179 +
  180 + // Return
  181 + return;
  182 +}
  183 +
  184 +
  185 +/***********************************************************************//**
  186 + * @brief Clone instance
  187 +***************************************************************************/
  188 +GMWLSpectrum* GMWLSpectrum::clone(void) const
  189 +{
  190 + return new GMWLSpectrum(*this);
  191 +}
  192 +
  193 +
  194 +/***********************************************************************//**
  195 + * @brief Return number of points in spectrum
  196 + ***************************************************************************/
  197 +int GMWLSpectrum::size(void) const
  198 +{
  199 + // Return
  200 + return (m_data.size());
  201 +}
  202 +
  203 +
  204 +/***********************************************************************//**
  205 + * @brief Load spectrum
  206 + *
  207 + * @param[in] filename File name
  208 + *
  209 + * This method loads a spectrum from a variety of file types. The method
  210 + * analyses the format of the file that is presented and choses then the
  211 + * appropriate method to load the specific format. The following file
  212 + * formats are supported: FITS, TBW ...
  213 + *
  214 + * @todo Not yet implemented.
  215 + ***************************************************************************/
  216 +void GMWLSpectrum::load(const std::string& filename)
  217 +{
  218 + // Load from FITS file
  219 + load_fits(filename);
  220 +
  221 + // Return
  222 + return;
  223 +}
  224 +
  225 +
  226 +/***********************************************************************//**
  227 + * @brief Load spectrum from FITS file
  228 + *
  229 + * @param[in] filename File name.
  230 + * @param[in] extno Extension number of table (optional).
  231 + *
  232 + * @exception GMWLException::file_open_error
  233 + * No table found in file.
  234 + *
  235 + * Loads the spectrum from a FITS table found in the specified extension.
  236 + * In no extension number if specified (or if extno=0) then the spectrum
  237 + * is loaded from the first table extension that is found in the file.
  238 + ***************************************************************************/
  239 +void GMWLSpectrum::load_fits(const std::string& filename, int extno)
  240 +{
  241 + // Clear object
  242 + clear();
  243 +
  244 + // Open FITS file
  245 + GFits file(filename);
  246 +
  247 + // If the extension number is 0 then load first FITS table in file.
  248 + if (extno == 0) {
  249 + for (int i = 0; i < file.size(); ++i) {
  250 + if (file.hdu(i)->exttype() == GFitsHDU::HT_ASCII_TABLE ||
  251 + file.hdu(i)->exttype() == GFitsHDU::HT_BIN_TABLE) {
  252 + extno = i;
  253 + break;
  254 + }
  255 + }
  256 + }
  257 +
  258 + // If we found no table then throw an exception
  259 + if (extno == 0)
  260 + throw GMWLException::file_open_error(G_LOAD_FITS, filename,
  261 + "No table found in file.");
  262 +
  263 + // Get table pointer
  264 + GFitsTable* table = file.table(extno);
  265 +
  266 + // Read spectrum from table
  267 + read_fits(table);
  268 +
  269 + // Close FITS file
  270 + file.close();
  271 +
  272 + // Return
  273 + return;
  274 +}
  275 +
  276 +
  277 +/***********************************************************************//**
  278 + * @brief Load spectrum from FITS file
  279 + *
  280 + * @param[in] filename File name.
  281 + * @param[in] extname Extension name.
  282 + *
  283 + * Loads the spectrum from a FITS table with a given extension name.
  284 + ***************************************************************************/
  285 +void GMWLSpectrum::load_fits(const std::string& filename,
  286 + const std::string& extname)
  287 +{
  288 + // Clear object
  289 + clear();
  290 +
  291 + // Open FITS file
  292 + GFits file(filename);
  293 +
  294 + // Get table pointer
  295 + GFitsTable* table = file.table(extname);
  296 +
  297 + // Read spectrum from table
  298 + read_fits(table);
  299 +
  300 + // Close FITS file
  301 + file.close();
  302 +
  303 + // Return
  304 + return;
  305 +}
  306 +
  307 +
  308 +/***********************************************************************//**
  309 + * @brief Returns pointer to spectral point
  310 + *
  311 + * @param[in] index Spectral point index (starting from 0).
  312 + *
  313 + * @exception GException::out_of_range
  314 + * Spectral point index not in valid range.
  315 + ***************************************************************************/
  316 +GMWLDatum* GMWLSpectrum::pointer(int index)
  317 +{
  318 + // Optionally check if the index is valid
  319 + #if defined(G_RANGE_CHECK)
  320 + if (index < 0 || index >= m_data.size())
  321 + throw GException::out_of_range(G_POINTER, index, 0, m_data.size()-1);
  322 + #endif
  323 +
  324 + // Return pointer
  325 + return &(m_data[index]);
  326 +}
  327 +
  328 +
  329 +/***********************************************************************//**
  330 + * @brief Return number of point in spectrum
  331 + *
  332 + * @todo Obsolete, but still needed as it is pure virtual in the base class.
  333 + * Better use size().
  334 + ***************************************************************************/
  335 +int GMWLSpectrum::number(void) const
  336 +{
  337 + // Return
  338 + return (size());
  339 +}
  340 +
  341 +
  342 +/***********************************************************************//**
  343 + * @brief Print spectrum
  344 + ***************************************************************************/
  345 +std::string GMWLSpectrum::print(void) const
  346 +{
  347 + // Initialise result string
  348 + std::string result;
  349 +
  350 + // Append header
  351 + result.append("=== GMWLObservation ===\n");
  352 + result.append(parformat("Number of points")+str(size()));
  353 +
  354 + // Append spectral points
  355 + for (int i = 0; i < size(); ++i) {
  356 + result.append("\n"+parformat("Datum "+str(i)));
  357 + result.append(((GMWLSpectrum*)this)->pointer(i)->print());
  358 + }
  359 +
  360 + // Return result
  361 + return result;
  362 +}
  363 +
  364 +
  365 +/*==========================================================================
  366 + = =
  367 + = Private methods =
  368 + = =
  369 + ==========================================================================*/
  370 +
  371 +/***********************************************************************//**
  372 + * @brief Initialise class members
  373 + ***************************************************************************/
  374 +void GMWLSpectrum::init_members(void)
  375 +{
  376 + // Initialise members
  377 + m_data.clear();
  378 +
  379 + // Return
  380 + return;
  381 +}
  382 +
  383 +
  384 +/***********************************************************************//**
  385 + * @brief Copy class members
  386 + *
  387 + * @param[in] spec Instance to be copied.
  388 + ***************************************************************************/
  389 +void GMWLSpectrum::copy_members(const GMWLSpectrum& spec)
  390 +{
  391 + // Copy members
  392 + m_data = spec.m_data;
  393 +
  394 + // Return
  395 + return;
  396 +}
  397 +
  398 +
  399 +/***********************************************************************//**
  400 + * @brief Delete class members
  401 + ***************************************************************************/
  402 +void GMWLSpectrum::free_members(void)
  403 +{
  404 + // Return
  405 + return;
  406 +}
  407 +
  408 +
  409 +/***********************************************************************//**
  410 + * @brief Read spectrum from FITS file
  411 + *
  412 + * @param[in] table File table.
  413 + *
  414 + * @exception GMWLException::bad_file_format
  415 + * Table has invalid format
  416 + *
  417 + * Reads spectrum from FITS table. Three different formats are supported:
  418 + * 2 columns: energy, flux
  419 + * 3 columns: energy, flux, e_flux
  420 + * >3 columns: energy, e_energy, flux, e_flux, ...
  421 + *
  422 + * @todo Finish implementation
  423 + ***************************************************************************/
  424 +#define G_READ_FITS "GMWLSpectrum::read_fits(GFitsTable*)"
  425 +void GMWLSpectrum::read_fits(const GFitsTable* table)
  426 +{
  427 + // Initialise column pointers columns
  428 + GFitsTableCol* c_energy = NULL;
  429 + GFitsTableCol* c_energy_err = NULL;
  430 + GFitsTableCol* c_flux = NULL;
  431 + GFitsTableCol* c_flux_err = NULL;
  432 +
  433 + // Extract column pointers
  434 + if (table->ncols() == 2) {
  435 + c_energy = ((GFitsTable*)table)->column(0);
  436 + c_flux = ((GFitsTable*)table)->column(1);
  437 + }
  438 + else if (table->ncols() == 3) {
  439 + c_energy = ((GFitsTable*)table)->column(0);
  440 + c_flux = ((GFitsTable*)table)->column(1);
  441 + c_flux_err = ((GFitsTable*)table)->column(2);
  442 + }
  443 + else if (table->ncols() > 3) {
  444 + c_energy = ((GFitsTable*)table)->column(0);
  445 + c_energy_err = ((GFitsTable*)table)->column(1);
  446 + c_flux = ((GFitsTable*)table)->column(2);
  447 + c_flux_err = ((GFitsTable*)table)->column(3);
  448 + }
  449 + else {
  450 + throw GMWLException::bad_file_format(G_READ_FITS,
  451 + "At least 2 columns are expected is table \""+
  452 + table->extname()+"\".");
  453 + }
  454 +
  455 + // Return
  456 + return;
  457 +}
  458 +
  459 +
  460 +
  461 +
  462 +/*==========================================================================
  463 + = =
  464 + = GMWLSpectrum friends =
  465 + = =
  466 + ==========================================================================*/
  467 +
  468 +/***********************************************************************//**
  469 + * @brief Output operator
  470 + *
  471 + * @param[in] os Output stream.
  472 + * @param[in] spec Spectrum.
  473 + ***************************************************************************/
  474 +std::ostream& operator<< (std::ostream& os, const GMWLSpectrum& spec)
  475 +{
  476 + // Write spectrum in output stream
  477 + os << spec.print();
  478 +
  479 + // Return output stream
  480 + return os;
  481 +}
  482 +
  483 +
  484 +/***********************************************************************//**
  485 + * @brief Log operator
  486 + *
  487 + * @param[in] log Logger.
  488 + * @param[in] spec Spectrum.
  489 + ***************************************************************************/
  490 +GLog& operator<< (GLog& log, const GMWLSpectrum& spec)
  491 +{
  492 + // Write spectrum into logger
  493 + log << spec.print();
  494 +
  495 + // Return logger
  496 + return log;
  497 +}
... ...
inst/mwl/test/data/crab.fits 0 → 100644
No preview for this file type
inst/mwl/test/test_MWL.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * test_MWL.cpp - test multi-wavelength classes *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2010 by Jurgen Knodlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software; you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation; either version 2 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + ***************************************************************************/
  13 +/**
  14 + * @file test_MWL.cpp
  15 + * @brief Testing of MWL classes.
  16 + * @author J. Knodlseder
  17 + */
  18 +
  19 +/* __ Includes ___________________________________________________________ */
  20 +#ifdef HAVE_CONFIG_H
  21 +#include <config.h>
  22 +#endif
  23 +#include <stdlib.h>
  24 +#include <iostream>
  25 +#include "GMWLLib.hpp"
  26 +
  27 +/* __ Namespaces _________________________________________________________ */
  28 +
  29 +/* __ Globals ____________________________________________________________ */
  30 +
  31 +/* __ Constants __________________________________________________________ */
  32 +const std::string lat_crab_fits = "../inst/mwl/test/data/crab.fits";
  33 +
  34 +
  35 +/***********************************************************************//**
  36 + * @brief Test observation handling
  37 + ***************************************************************************/
  38 +void test_obs(void)
  39 +{
  40 + // Write header
  41 + std::cout << "Test observation handling: ";
  42 +
  43 + // Construct observation
  44 + try {
  45 + GMWLObservation run1;
  46 + GMWLObservation run2(lat_crab_fits);
  47 + GMWLObservation run3 = run2;
  48 + }
  49 + catch (std::exception &e) {
  50 + std::cout << std::endl
  51 + << "TEST ERROR: Unable to construct GMWLObservation."
  52 + << std::endl;
  53 + std::cout << e.what() << std::endl;
  54 + throw;
  55 + }
  56 + std::cout << ".";
  57 +
  58 + // Load observation
  59 + try {
  60 + GMWLObservation run;
  61 + run.load(lat_crab_fits);
  62 + //std::cout << run << std::endl;
  63 + }
  64 + catch (std::exception &e) {
  65 + std::cout << std::endl
  66 + << "TEST ERROR: Unable to load GMWLObservation."
  67 + << std::endl;
  68 + std::cout << e.what() << std::endl;
  69 + throw;
  70 + }
  71 + std::cout << ".";
  72 +
  73 + // Add observation to container
  74 + try {
  75 + GMWLObservation run;
  76 + run.load(lat_crab_fits);
  77 + GObservations obs;
  78 + obs.append(run);
  79 + obs.append(run);
  80 + obs.append(run);
  81 + }
  82 + catch (std::exception &e) {
  83 + std::cout << std::endl
  84 + << "TEST ERROR: Unable to append GMWLObservation to GObservations."
  85 + << std::endl;
  86 + std::cout << e.what() << std::endl;
  87 + throw;
  88 + }
  89 + std::cout << ".";
  90 +
  91 + // Notify final test success
  92 + std::cout << " ok." << std::endl;
  93 +
  94 + // Exit test
  95 + return;
  96 +
  97 +}
  98 +
  99 +
  100 +/***********************************************************************//**
  101 + * @brief Test binned optimizer.
  102 + ***************************************************************************/
  103 +void test_optimizer(void)
  104 +{
  105 + // Write header
  106 + std::cout << "Test optimizer: ";
  107 +/*
  108 + // Number of observations in data
  109 + int nobs = 1;
  110 +
  111 + // Declare observations
  112 + GObservations obs;
  113 + GCTAObservation run;
  114 +
  115 + // Load binned CTA observation
  116 + try {
  117 + run.load_binned(cta_cntmap);
  118 + run.response(cta_irf,cta_caldb);
  119 + obs.append(run);
  120 + }
  121 + catch (std::exception &e) {
  122 + std::cout << std::endl << "TEST ERROR: Unable to load CTA run."
  123 + << std::endl;
  124 + std::cout << e.what() << std::endl;
  125 + throw;
  126 + }
  127 + std::cout << ".";
  128 +
  129 + // Setup GModels for optimizing
  130 + GModels models = crab_plaw();
  131 + obs.models(models);
  132 +
  133 + // Perform LM optimization
  134 + GOptimizerLM opt;
  135 + try {
  136 + opt.max_iter(1000);
  137 + obs.optimize(opt);
  138 + }
  139 + catch (std::exception &e) {
  140 + std::cout << std::endl
  141 + << "TEST ERROR: Unable to perform LM optimization."
  142 + << std::endl;
  143 + std::cout << e.what() << std::endl;
  144 + throw;
  145 + }
  146 + std::cout << ".";
  147 + std::cout << opt;
  148 + std::cout << obs << std::endl;
  149 +*/
  150 + // Plot final test success
  151 + std::cout << " ok." << std::endl;
  152 +
  153 + // Exit test
  154 + return;
  155 +
  156 +}
  157 +
  158 +
  159 +/***********************************************************************//**
  160 + * @brief Main test function .
  161 + ***************************************************************************/
  162 +int main(void)
  163 +{
  164 + // Dump header
  165 + std::cout << std::endl;
  166 + std::cout << "**********************************" << std::endl;
  167 + std::cout << "* Multi-wavelength class testing *" << std::endl;
  168 + std::cout << "**********************************" << std::endl;
  169 +
  170 + // Execute the tests
  171 + test_obs();
  172 + test_optimizer();
  173 +
  174 + // Return
  175 + return 0;
  176 +}
... ...