Commit a33eea7d508175b05c6cce6008ca5e8f8923b2e2

Authored by Jürgen Knödlseder
1 parent 5f27985e

Add time reference class.

This class implements a time reference.
include/GTimeReference.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GTimeReference.hpp - Time reference class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2012 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GTimeReference.hpp
  23 + * @brief Time reference class interface definition
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +#ifndef GTIMEREFERENCE_HPP
  28 +#define GTIMEREFERENCE_HPP
  29 +
  30 +/* __ Includes ___________________________________________________________ */
  31 +#include <string>
  32 +#include "GBase.hpp"
  33 +#include "GFitsHDU.hpp"
  34 +
  35 +
  36 +/***********************************************************************//**
  37 + * @class GTimeReference
  38 + *
  39 + * @brief Implements a time reference
  40 + *
  41 + * This class implements the reference of a time with respect to Modified
  42 + * Julian Days. The zero point of the time is specified by the member
  43 + * m_mjdref that is given in Modified Julian Days. A time may be either
  44 + * either given in seconds or in days. Furthermore, the time system needs to
  45 + * be specified. So far, only Terrestrial Time (TT) is supported. Also the
  46 + * reference of the time system needs to be given. So far, only Local is
  47 + * supported.
  48 + *
  49 + * References:
  50 + * http://aa.usno.navy.mil/publications/docs/Circular_179.php
  51 + ***************************************************************************/
  52 +class GTimeReference : public GBase {
  53 +
  54 +public:
  55 + // Constructors and destructors
  56 + GTimeReference(void);
  57 + GTimeReference(const GTimeReference& ref);
  58 + explicit GTimeReference(const double& mrdref,
  59 + const std::string& timeunit,
  60 + const std::string& timesys = "TT",
  61 + const std::string& timeref = "local");
  62 + explicit GTimeReference(const int& mjdrefi,
  63 + const double& mrdreff,
  64 + const std::string& timeunit,
  65 + const std::string& timesys = "TT",
  66 + const std::string& timeref = "local");
  67 + explicit GTimeReference(const GFitsHDU* hdu);
  68 + virtual ~GTimeReference(void);
  69 +
  70 + // Operators
  71 + GTimeReference& operator=(const GTimeReference& ref);
  72 +
  73 + // Methods
  74 + void clear(void);
  75 + GTimeReference* clone(void) const;
  76 + void read(const GFitsHDU* hdu);
  77 + void write(GFitsHDU* hdu) const;
  78 + void set(const double& mrdref,
  79 + const std::string& timeunit,
  80 + const std::string& timesys = "TT",
  81 + const std::string& timeref = "local");
  82 + void set(const int& mjdrefi,
  83 + const double& mjdreff,
  84 + const std::string& timeunit,
  85 + const std::string& timesys = "TT",
  86 + const std::string& timeref = "local");
  87 + const double& mjdref(void) const;
  88 + int mjdrefi(void) const;
  89 + double mjdreff(void) const;
  90 + const std::string& timeunit(void) const;
  91 + const std::string& timesys(void) const;
  92 + const std::string& timeref(void) const;
  93 + double unitseconds(void) const;
  94 + std::string print(void) const;
  95 +
  96 +protected:
  97 + // Protected methods
  98 + void init_members(void);
  99 + void copy_members(const GTimeReference& ref);
  100 + void free_members(void);
  101 +
  102 + // Protected data members
  103 + double m_mjdref; //!< Time MJD reference (days)
  104 + std::string m_timeunit; //!< Time unit
  105 + std::string m_timesys; //!< Time system
  106 + std::string m_timeref; //!< Time reference
  107 + bool m_unit_sec; //!< True: unit is seconds, False: unit is days
  108 +};
  109 +
  110 +#endif /* GTIMEREFERENCE_HPP */
... ...
pyext/GTimeReference.i 0 → 100644
  1 +/***************************************************************************
  2 + * GTimeReference.i - Time reference class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2012 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GTimeReference.i
  23 + * @brief Time reference class interface definition
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +%{
  27 +/* Put headers and other declarations here that are needed for compilation */
  28 +#include "GTimeReference.hpp"
  29 +#include "GTools.hpp"
  30 +%}
  31 +
  32 +
  33 +/***********************************************************************//**
  34 + * @class GTimeReference
  35 + *
  36 + * @brief Implements a time reference
  37 + ***************************************************************************/
  38 +class GTimeReference : public GBase {
  39 +public:
  40 + // Constructors and destructors
  41 + GTimeReference(void);
  42 + GTimeReference(const GTimeReference& ref);
  43 + explicit GTimeReference(const double& mrdref,
  44 + const std::string& timeunit,
  45 + const std::string& timesys = "TT",
  46 + const std::string& timeref = "local");
  47 + explicit GTimeReference(const int& mjdrefi,
  48 + const double& mrdreff,
  49 + const std::string& timeunit,
  50 + const std::string& timesys = "TT",
  51 + const std::string& timeref = "local");
  52 + explicit GTimeReference(const GFitsHDU* hdu);
  53 + virtual ~GTimeReference(void);
  54 +
  55 + // Methods
  56 + void clear(void);
  57 + GTimeReference* clone(void) const;
  58 + void read(const GFitsHDU* hdu);
  59 + void write(GFitsHDU* hdu) const;
  60 + void set(const double& mrdref,
  61 + const std::string& timeunit,
  62 + const std::string& timesys = "TT",
  63 + const std::string& timeref = "local");
  64 + void set(const int& mjdrefi,
  65 + const double& mjdreff,
  66 + const std::string& timeunit,
  67 + const std::string& timesys = "TT",
  68 + const std::string& timeref = "local");
  69 + const double& mjdref(void) const;
  70 + int mjdrefi(void) const;
  71 + double mjdreff(void) const;
  72 + const std::string& timeunit(void) const;
  73 + const std::string& timesys(void) const;
  74 + const std::string& timeref(void) const;
  75 + double unitseconds(void) const;
  76 +};
  77 +
  78 +
  79 +/***********************************************************************//**
  80 + * @brief GTimeReference class extension
  81 + ***************************************************************************/
  82 +%extend GTimeReference {
  83 + char *__str__() {
  84 + return tochar(self->print());
  85 + }
  86 + GTimeReference copy() {
  87 + return (*self);
  88 + }
  89 +};
... ...
pyext/gammalib/obs.i
... ... @@ -38,6 +38,7 @@
38 38 %include "GEnergy.i"
39 39 %include "GTimes.i"
40 40 %include "GTime.i"
  41 +%include "GTimeReference.i"
41 42 %include "GEbounds.i"
42 43 %include "GGti.i"
43 44 %include "GCaldb.i"
... ...
src/obs/GTimeReference.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GTimeReference.cpp - Time reference class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2012 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GTimeReference.cpp
  23 + * @brief Time reference class interface implementation
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#ifdef HAVE_CONFIG_H
  29 +#include <config.h>
  30 +#endif
  31 +#include "GTimeReference.hpp"
  32 +#include "GTools.hpp"
  33 +#include "GException.hpp"
  34 +
  35 +/* __ Constants __________________________________________________________ */
  36 +
  37 +/* __ Method name definitions ____________________________________________ */
  38 +#define G_READ "GTimeReference::read(GFitsHDU*)"
  39 +#define G_SET "GTimeReference::set(double&, std::string&, std::string&, "\
  40 + "std::string&)"
  41 +
  42 +/* __ Macros _____________________________________________________________ */
  43 +
  44 +/* __ Coding definitions _________________________________________________ */
  45 +
  46 +/* __ Debug definitions __________________________________________________ */
  47 +
  48 +
  49 +/*==========================================================================
  50 + = =
  51 + = Constructors/destructors =
  52 + = =
  53 + ==========================================================================*/
  54 +
  55 +/***********************************************************************//**
  56 + * @brief Void constructor
  57 + ***************************************************************************/
  58 +GTimeReference::GTimeReference(void)
  59 +{
  60 + // Initialise private members
  61 + init_members();
  62 +
  63 + // Return
  64 + return;
  65 +}
  66 +
  67 +
  68 +/***********************************************************************//**
  69 + * @brief Copy constructor
  70 + *
  71 + * @param[in] ref Time reference.
  72 + ***************************************************************************/
  73 +GTimeReference::GTimeReference(const GTimeReference& ref)
  74 +{
  75 + // Initialise private members
  76 + init_members();
  77 +
  78 + // Copy members
  79 + copy_members(ref);
  80 +
  81 + // Return
  82 + return;
  83 +}
  84 +
  85 +
  86 +/***********************************************************************//**
  87 + * @brief Time reference constructor
  88 + *
  89 + * @param[in] mjdref Reference MJD (days).
  90 + * @param[in] timeunit Time unit ("sec(s)", "day(s)").
  91 + * @param[in] timesys Time system (ignored so far).
  92 + * @param[in] timeref Time reference (ignored so far).
  93 + *
  94 + * Sets the time reference from a MJD reference day, a time unit, a time
  95 + * system and a time reference.
  96 + ***************************************************************************/
  97 +GTimeReference::GTimeReference(const double& mjdref,
  98 + const std::string& timeunit,
  99 + const std::string& timesys,
  100 + const std::string& timeref)
  101 +{
  102 + // Initialise private members
  103 + init_members();
  104 +
  105 + // Set time reference
  106 + set(mjdref, timeunit, timesys, timeref);
  107 +
  108 + // Return
  109 + return;
  110 +}
  111 +
  112 +
  113 +/***********************************************************************//**
  114 + * @brief Time reference constructor
  115 + *
  116 + * @param[in] mjdrefi Integer part of reference MJD (days).
  117 + * @param[in] mjdreff Fractional part of reference MJD (days).
  118 + * @param[in] timeunit Time unit (sec, days).
  119 + * @param[in] timesys Time system (TT).
  120 + * @param[in] timeref Local time reference.
  121 + *
  122 + * Sets the time reference from a MJD reference day (specified by an integer
  123 + * and a fractional part), a time unit, a time system and a time reference.
  124 + ***************************************************************************/
  125 +GTimeReference::GTimeReference(const int& mjdrefi,
  126 + const double& mjdreff,
  127 + const std::string& timeunit,
  128 + const std::string& timesys,
  129 + const std::string& timeref)
  130 +{
  131 + // Initialise private members
  132 + init_members();
  133 +
  134 + // Set time reference
  135 + set(mjdrefi, mjdreff, timeunit, timesys, timeref);
  136 +
  137 + // Return
  138 + return;
  139 +}
  140 +
  141 +
  142 +/***********************************************************************//**
  143 + * @brief FITS header constructor
  144 + *
  145 + * @param[in] hdu FITS extension.
  146 + *
  147 + * Constructs time reference from the information found in the FITS header.
  148 + * See GTimeReference::read for more information on the expected format.
  149 + ***************************************************************************/
  150 +GTimeReference::GTimeReference(const GFitsHDU* hdu)
  151 +{
  152 + // Initialise private members
  153 + init_members();
  154 +
  155 + // Read reference from FITS header
  156 + read(hdu);
  157 +
  158 + // Return
  159 + return;
  160 +}
  161 +
  162 +
  163 +/***********************************************************************//**
  164 + * @brief Destructor
  165 + ***************************************************************************/
  166 +GTimeReference::~GTimeReference(void)
  167 +{
  168 + // Free members
  169 + free_members();
  170 +
  171 + // Return
  172 + return;
  173 +}
  174 +
  175 +
  176 +/*==========================================================================
  177 + = =
  178 + = Operators =
  179 + = =
  180 + ==========================================================================*/
  181 +
  182 +/***********************************************************************//**
  183 + * @brief Assignment operator
  184 + *
  185 + * @param[in] ref Time reference.
  186 + ***************************************************************************/
  187 +GTimeReference& GTimeReference::operator= (const GTimeReference& ref)
  188 +{
  189 + // Execute only if object is not identical
  190 + if (this != &ref) {
  191 +
  192 + // Free members
  193 + free_members();
  194 +
  195 + // Initialise private members
  196 + init_members();
  197 +
  198 + // Copy members
  199 + copy_members(ref);
  200 +
  201 + } // endif: object was not identical
  202 +
  203 + // Return
  204 + return *this;
  205 +}
  206 +
  207 +
  208 +/*==========================================================================
  209 + = =
  210 + = Public methods =
  211 + = =
  212 + ==========================================================================*/
  213 +
  214 +/***********************************************************************//**
  215 + * @brief Clear time reference
  216 + ***************************************************************************/
  217 +void GTimeReference::clear(void)
  218 +{
  219 + // Free members
  220 + free_members();
  221 +
  222 + // Initialise members
  223 + init_members();
  224 +
  225 + // Return
  226 + return;
  227 +}
  228 +
  229 +
  230 +/***********************************************************************//**
  231 + * @brief Clone object
  232 + *
  233 + * @return Pointer to deep copy of time reference.
  234 + ***************************************************************************/
  235 +GTimeReference* GTimeReference::clone(void) const
  236 +{
  237 + // Clone this image
  238 + return new GTimeReference(*this);
  239 +}
  240 +
  241 +
  242 +/***********************************************************************//**
  243 + * @brief Read time reference from FITS header
  244 + *
  245 + * @param[in] hdu FITS extension.
  246 + *
  247 + * GException::no_valid_time_ref
  248 + * No valid reference MJD found in header.
  249 + *
  250 + * Reads the time reference information from a FITS header. The method
  251 + * requires either the keyword "MJDREF" or the pair of keywords "MJDREFI"
  252 + * and "MJDREFF" to be set. The following keywords are optional (the
  253 + * assumed default values in absent of the keywords is given in parentheses):
  254 + *
  255 + * TIMEUNIT ("s")
  256 + * TIMESYS ("TT")
  257 + * TIMEREF ("LOCAL")
  258 + *
  259 + * Nothing is done if the HDU pointer is NULL.
  260 + ***************************************************************************/
  261 +void GTimeReference::read(const GFitsHDU* hdu)
  262 +{
  263 + // Continue only if HDU is valid
  264 + if (hdu != NULL) {
  265 +
  266 + // Get reference MJD
  267 + double mjdref = (hdu->hascard("MJDREF")) ? hdu->real("MJDREF") : 0.0;
  268 + int mjdrefi = (hdu->hascard("MJDREFI")) ? hdu->integer("MJDREFI") : 0;
  269 + double mjdreff = (hdu->hascard("MJDREFF")) ? hdu->real("MJDREFF") : 0.0;
  270 +
  271 + // Get remaining keywords. To accept a large variety of FITS headers,
  272 + // all keywords are optionally.
  273 + std::string timeunit = (hdu->hascard("TIMEUNIT")) ? hdu->string("TIMEUNIT") : "s";
  274 + std::string timesys = (hdu->hascard("TIMESYS")) ? hdu->string("TIMESYS") : "TT";
  275 + std::string timeref = (hdu->hascard("TIMEREF")) ? hdu->string("TIMEREF") : "LOCAL";
  276 +
  277 + // Set time reference
  278 + if (hdu->hascard("MJDREF")) {
  279 + set(mjdref, timeunit, timesys, timeref);
  280 + }
  281 + else if (hdu->hascard("MJDREFI") && hdu->hascard("MJDREFF")) {
  282 + set(mjdrefi, mjdreff, timeunit, timesys, timeref);
  283 + }
  284 + else {
  285 + throw GException::no_valid_time_ref(G_READ,
  286 + "Require either keyword \"MJDREF\" or keyword pair"
  287 + " \"MJDREFI\" and \"MJDREFF\".");
  288 + }
  289 +
  290 + } // endif: HDU was valid
  291 +
  292 + // Return
  293 + return;
  294 +}
  295 +
  296 +
  297 +/***********************************************************************//**
  298 + * @brief Write time reference into FITS header
  299 + *
  300 + * @param[in] hdu FITS extension.
  301 + *
  302 + * Writes or updates the time reference information in a FITS header.
  303 + * Depending of whether the keyword "MJDREF" or the pair of keywords "MJDREFI"
  304 + * and "MJDREFF" exist already in the header, the method either writes the
  305 + * reference MJD as floating point value, or split into an integer and a
  306 + * fractional part. The following additional keywords are written:
  307 + * TIMEUNIT
  308 + * TIMESYS
  309 + * TIMEREF
  310 + *
  311 + * Nothing is done if the HDU pointer is NULL.
  312 + ***************************************************************************/
  313 +void GTimeReference::write(GFitsHDU* hdu) const
  314 +{
  315 + // Continue only if HDU is valid
  316 + if (hdu != NULL) {
  317 +
  318 + // Case A: use fractional reference MJD
  319 + if (hdu->hascard("MJDREFI") && hdu->hascard("MJDREFF")) {
  320 + hdu->card("MJDREFI", mjdrefi(), "[days] Integer part of time reference MJD");
  321 + hdu->card("MJDREFF", mjdreff(), "[days] Fractional part of time reference MJD");
  322 + hdu->card("TIMEUNIT", timeunit(), "Time unit");
  323 + hdu->card("TIMESYS", timesys(), "Time system");
  324 + hdu->card("TIMEREF", timeref(), "Time reference");
  325 + }
  326 +
  327 + // Case B: use floating point reference MJD
  328 + else {
  329 + hdu->card("MJDREF", mjdref(), "[days] Time reference MJD");
  330 + hdu->card("TIMEUNIT", timeunit(), "Time unit");
  331 + hdu->card("TIMESYS", timesys(), "Time system");
  332 + hdu->card("TIMEREF", timeref(), "Time reference");
  333 + }
  334 +
  335 + } // endif: HDU was valid
  336 +
  337 + // Return
  338 + return;
  339 +}
  340 +
  341 +
  342 +/***********************************************************************//**
  343 + * @brief Set time reference
  344 + *
  345 + * @param[in] mjdref Reference MJD (days).
  346 + * @param[in] timeunit Time unit ("s", "d", "sec(s)", "day(s)").
  347 + * @param[in] timesys Time system.
  348 + * @param[in] timeref Time reference.
  349 + *
  350 + * @exception GException::time_invalid_unit
  351 + * Invalid time unit specified.
  352 + *
  353 + * Sets the time reference from a MJD reference day, a time unit, a time
  354 + * system and a time reference.
  355 + *
  356 + * @todo Implement checking of "timesys" and "timeref" parameters.
  357 + ***************************************************************************/
  358 +void GTimeReference::set(const double& mjdref,
  359 + const std::string& timeunit,
  360 + const std::string& timesys,
  361 + const std::string& timeref)
  362 +{
  363 + // Check timeunit string
  364 + std::string ltimeunit = tolower(timeunit);
  365 + if (ltimeunit == "d" || ltimeunit == "day" || ltimeunit == "days") {
  366 + m_unit_sec = false;
  367 + }
  368 + else if (ltimeunit == "s" || ltimeunit == "sec" || ltimeunit == "secs") {
  369 + m_unit_sec = true;
  370 + }
  371 + else {
  372 + throw GException::time_invalid_unit(G_SET, timeunit,
  373 + "Valid timeunit values are: \"d\", \"day\", \"days\","
  374 + " \"s\", \"sec\" or \"secs\"");
  375 + }
  376 +
  377 + // Set members
  378 + m_mjdref = mjdref;
  379 + m_timeunit = ltimeunit;
  380 + m_timesys = toupper(timesys);
  381 + m_timeref = toupper(timeref);
  382 +
  383 + // Return
  384 + return;
  385 +}
  386 +
  387 +
  388 +/***********************************************************************//**
  389 + * @brief Set time reference
  390 + *
  391 + * @param[in] mjdrefi Integer part of reference MJD (days).
  392 + * @param[in] mjdreff Fractional part of reference MJD (days).
  393 + * @param[in] timeunit Time unit (sec, days).
  394 + * @param[in] timesys Time system (TT).
  395 + * @param[in] timeref Local time reference.
  396 + *
  397 + * Sets the time reference from a MJD reference day (specified by an integer
  398 + * and a fractional part), a time unit, a time system and a time reference.
  399 + ***************************************************************************/
  400 +void GTimeReference::set(const int& mjdrefi,
  401 + const double& mjdreff,
  402 + const std::string& timeunit,
  403 + const std::string& timesys,
  404 + const std::string& timeref)
  405 +{
  406 + // Compute reference MJD
  407 + double mjdref = double(mjdrefi) + mjdreff;
  408 +
  409 + // Set time
  410 + set(mjdref, timeunit, timesys, timeref);
  411 +
  412 + // Return
  413 + return;
  414 +}
  415 +
  416 +
  417 +/***********************************************************************//**
  418 + * @brief Return MJD reference (units: days)
  419 + *
  420 + * @return Modified Julian reference day (days).
  421 + *
  422 + * Returns the Modified Julian reference day.
  423 + ***************************************************************************/
  424 +const double& GTimeReference::mjdref(void) const
  425 +{
  426 + // Return MDJ reference
  427 + return m_mjdref;
  428 +}
  429 +
  430 +
  431 +/***********************************************************************//**
  432 + * @brief Returns integer part of MJD reference (units: days)
  433 + *
  434 + * @return Integer part of Modified Julian reference day (days).
  435 + *
  436 + * Returns the integer part of the Modified Julian reference day.
  437 + ***************************************************************************/
  438 +int GTimeReference::mjdrefi(void) const
  439 +{
  440 + // Return integer part of MJD reference
  441 + return int(m_mjdref);
  442 +}
  443 +
  444 +
  445 +/***********************************************************************//**
  446 + * @brief Returns fractional part of MJD reference (units: days)
  447 + *
  448 + * @return Fractional part of Modified Julian reference day (days).
  449 + *
  450 + * Returns the fractional part of the Modified Julian reference day.
  451 + ***************************************************************************/
  452 +double GTimeReference::mjdreff(void) const
  453 +{
  454 + // Return fractional part of MJD reference
  455 + return (m_mjdref-double(mjdrefi()));
  456 +}
  457 +
  458 +
  459 +/***********************************************************************//**
  460 + * @brief Return time unit
  461 + *
  462 + * @return Time unit.
  463 + *
  464 + * Returns the reference time unit.
  465 + ***************************************************************************/
  466 +const std::string& GTimeReference::timeunit(void) const
  467 +{
  468 + // Return time unit
  469 + return m_timeunit;
  470 +}
  471 +
  472 +
  473 +/***********************************************************************//**
  474 + * @brief Return time system
  475 + *
  476 + * @return Time system.
  477 + *
  478 + * Returns the reference time system.
  479 + ***************************************************************************/
  480 +const std::string& GTimeReference::timesys(void) const
  481 +{
  482 + // Return time system
  483 + return m_timesys;
  484 +}
  485 +
  486 +
  487 +/***********************************************************************//**
  488 + * @brief Return time reference
  489 + *
  490 + * @return Time reference.
  491 + *
  492 + * Returns the reference time reference.
  493 + ***************************************************************************/
  494 +const std::string& GTimeReference::timeref(void) const
  495 +{
  496 + // Return time reference
  497 + return m_timeref;
  498 +}
  499 +
  500 +
  501 +/***********************************************************************//**
  502 + * @brief Return the time unit in seconds
  503 + *
  504 + * @return Time unit in seconds.
  505 + *
  506 + * Returns 1 if the time using is in seconds and 86400 if the time unit is
  507 + * in days.
  508 + ***************************************************************************/
  509 +double GTimeReference::unitseconds(void) const
  510 +{
  511 + // Set time unit in seconds
  512 + double unit = (m_unit_sec) ? 1.0 : sec_in_day;
  513 +
  514 + // Return time unit
  515 + return unit;
  516 +}
  517 +
  518 +
  519 +/***********************************************************************//**
  520 + * @brief Get time in seconds for a specific MJD
  521 + *
  522 + * @param[in] mjdref Reference MJD (days).
  523 + *
  524 + * Returns time in seconds in the specified MJD reference.
  525 + ***************************************************************************/
  526 +/*
  527 +double GTimeReference::time(const double& mjdref) const
  528 +{
  529 + // Retrieve time in seconds
  530 + double time = m_time;
  531 +
  532 + // Add offset due to MJD differences
  533 + if (m_mjdref != mjdref) {
  534 +
  535 + // Compute time offset
  536 + double offset = (m_mjdref - mjdref) * sec_in_day;
  537 +
  538 + // Add offset
  539 + time += offset;
  540 +
  541 + }
  542 +
  543 + // Return time
  544 + return time;
  545 +}
  546 +*/
  547 +
  548 +
  549 +/***********************************************************************//**
  550 + * @brief Print time reference
  551 + *
  552 + * @return String containing the time reference.
  553 + ***************************************************************************/
  554 +std::string GTimeReference::print(void) const
  555 +{
  556 + // Initialise result string
  557 + std::string result;
  558 +
  559 + // Append header
  560 + result.append("=== GTimeReference ===\n");
  561 +
  562 + // Append information
  563 + result.append(parformat("MJD reference time")+str(mjdref())+"\n");
  564 + result.append(parformat("Time unit")+timeunit()+"\n");
  565 + result.append(parformat("Time system")+timesys()+"\n");
  566 + result.append(parformat("Time reference")+timeref()+"\n");
  567 +
  568 + // Return
  569 + return result;
  570 +}
  571 +
  572 +
  573 +/*==========================================================================
  574 + = =
  575 + = Private methods =
  576 + = =
  577 + ==========================================================================*/
  578 +
  579 +/***********************************************************************//**
  580 + * @brief Initialise class members
  581 + ***************************************************************************/
  582 +void GTimeReference::init_members(void)
  583 +{
  584 + // Initialise members
  585 + m_mjdref = 0.0;
  586 + m_timeunit = "secs";
  587 + m_timesys = "TT";
  588 + m_timeref = "local";
  589 + m_unit_sec = true;
  590 +
  591 + // Return
  592 + return;
  593 +}
  594 +
  595 +
  596 +/***********************************************************************//**
  597 + * @brief Copy class members
  598 + *
  599 + * @param[in] ref Time reference.
  600 + ***************************************************************************/
  601 +void GTimeReference::copy_members(const GTimeReference& ref)
  602 +{
  603 + // Copy members
  604 + m_mjdref = ref.m_mjdref;
  605 + m_timeunit = ref.m_timeunit;
  606 + m_timesys = ref.m_timesys;
  607 + m_timeref = ref.m_timeref;
  608 + m_unit_sec = ref.m_unit_sec;
  609 +
  610 + // Return
  611 + return;
  612 +}
  613 +
  614 +
  615 +/***********************************************************************//**
  616 + * @brief Delete class members
  617 + ***************************************************************************/
  618 +void GTimeReference::free_members(void)
  619 +{
  620 + // Return
  621 + return;
  622 +}
... ...