Epoch.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
40 
41 #ifndef GNSSTK_EPOCH_HPP
42 #define GNSSTK_EPOCH_HPP
43 
44 #include "MathBase.hpp"
45 #include "Exception.hpp"
46 #include "StringUtils.hpp"
47 
48 #include "GPSZcount.hpp"
49 #include "CommonTime.hpp"
50 #include "TimeTag.hpp"
51 #include "SystemTime.hpp"
52 
53 #include "JulianDate.hpp"
54 #include "MJD.hpp"
55 #include "YDSTime.hpp"
56 #include "CivilTime.hpp"
57 #include "GPSWeekZcount.hpp"
58 #include "GPSWeekSecond.hpp"
59 #include "BDSWeekSecond.hpp"
60 #include "GALWeekSecond.hpp"
61 #include "QZSWeekSecond.hpp"
62 
63 namespace gnsstk
64 {
67 
123  class Epoch
124  {
125  public:
132  NEW_EXCEPTION_CLASS(EpochException, gnsstk::Exception);
133 
138  NEW_EXCEPTION_CLASS(FormatException, gnsstk::Exception);
139 
147  static const double ONE_NSEC_TOLERANCE;
150  static const double ONE_USEC_TOLERANCE;
152  static const double ONE_MSEC_TOLERANCE;
154  static const double ONE_SEC_TOLERANCE;
156  static const double ONE_MIN_TOLERANCE;
158  static const double ONE_HOUR_TOLERANCE;
159 
161  static double EPOCH_TOLERANCE;
162 
164  static const Epoch BEGINNING_OF_TIME;
166  static const Epoch END_OF_TIME;
167 
169  static std::string PRINT_FORMAT;
171 
173 
174  static double setEpochTolerance(double tol)
176  noexcept
177  { return EPOCH_TOLERANCE = tol; }
178 
180  static double getEpochTolerance()
181  noexcept
182  { return EPOCH_TOLERANCE; }
183 
191  Epoch& setTolerance(double tol)
192  noexcept;
193 
198  double getTolerance() const noexcept
199  { return tolerance; }
201 
203 
204 
216  Epoch(const TimeTag& tt = SystemTime());
217 
222  Epoch(const CommonTime& ct)
223  noexcept;
224 
235  Epoch(const WeekSecond& tt,
236  short year);
237 
241  Epoch(const GPSZcount& gzc)
242  noexcept;
243 
244  // Other Constructors:
245  // gps 29-bit zcount w/ epoch determined by current system time
246  // (GPSZcount29 + SystemTime)
247 
250  noexcept
251  {}
253 
255 
256  Epoch(const Epoch &right)
258  noexcept;
259 
261  Epoch& operator=(const Epoch& right)
262  noexcept;
264 
266 
267 
272  double operator-(const Epoch& right) const
273  noexcept;
274 
281  Epoch operator+(double sec) const;
282 
289  Epoch operator-(double sec) const;
290 
296  Epoch& operator+=(double sec);
297 
303  Epoch& operator-=(double sec);
304 
310  Epoch& addSeconds(double seconds);
311 
317  Epoch& addSeconds(long seconds);
318 
324  Epoch& addMilliSeconds(long msec);
325 
331  Epoch& addMicroSeconds(long usec);
333 
335 
336  bool operator==(const Epoch &right) const
337  noexcept;
338  bool operator!=(const Epoch &right) const
339  noexcept;
340  bool operator<(const Epoch &right) const
341  noexcept;
342  bool operator>(const Epoch &right) const
343  noexcept;
344  bool operator<=(const Epoch &right) const
345  noexcept;
346  bool operator>=(const Epoch &right) const
347  noexcept;
349 
351 
352  template <class TimeTagType>
357  TimeTagType get() const;
358 
363  inline long double JD() const;
364 
369  inline long double MJD() const;
370 
373  inline short year() const;
374 
377  inline short month() const;
378 
381  inline short day() const;
382 
385  inline short dow() const;
386 
389  inline short hour() const;
390 
393  inline short minute() const;
394 
397  inline double second() const;
398 
401  inline double sod() const;
402 
405  inline short GPSModWeek() const;
406 
409  inline short GPSweek10() const;
410 
413  inline long GPSzcount() const;
414 
417  inline long GPSzcountFloor() const;
418 
425  inline unsigned long GPSzcount32() const;
426 
429  inline unsigned long GPSzcount32Floor() const;
430 
433  inline double GPSsow() const;
434 
437  inline short GPSweek() const;
438 
441  inline double BDSsow() const;
442 
445  inline short BDSweek() const;
446 
449  inline short BDSModWeek() const;
450 
453  inline double QZSsow() const;
454 
457  inline short QZSweek() const;
458 
461  inline short QZSModWeek() const;
462 
465  inline double GALsow() const;
466 
469  inline short GALweek() const;
470 
473  inline short GALModWeek() const;
474 
477  inline short doy() const;
478 
481  inline struct timeval unixTime() const;
482 
485  operator GPSZcount() const;
486 
488  operator CommonTime() const
489  noexcept;
490 
494 
501  Epoch& set(const TimeTag& tt = SystemTime());
502 
509  Epoch& set(const WeekSecond& tt,
510  short year);
511 
518  noexcept;
519 
524  Epoch& set(const GPSZcount& z);
525 
534 
543 
549  Epoch& setLocalTime();
550 
551  // other sets:
552  // ymdhms
553  // week and sow (if week is 10-bit, set epoch from system time)
554  // week and zcount (if week is 10-bit, set epoch from system time)
555  // week, zcount, year (if week is 10-bit, set epoch from given year)
556  // week, sow, year (if week is 10-bit, set epoch from given year)
557  // gps 29-bit zcount (epoch determined by system time)
558  // gps full week and sow
559  // gps full week and zcount
560  // year, doy, sod
561  // long double mjd
562  // double mjd
563  // Unix struct timeval
564  // ANSI time
565  // YMD, (year/doy) w/ time unchanged
566  // HMS, sod w/ date unchanged
568 
570 
571 
629  Epoch& scanf(const std::string& str,
630  const std::string& fmt);
631 
632  // if you can see this, ignore the \'s below, as they are for
633  // the nasty html-ifying of doxygen. Browsers try and
634  // interpret the % and they get all messed up.
691  std::string printf(const std::string& fmt = PRINT_FORMAT) const;
693 
694  private:
696 
700 
702  double tolerance;
703 
705  }; // end class Epoch
706 
713  std::ostream& operator<<( std::ostream& s,
714  const Epoch& t );
716 
717 
718  template <class TimeTagType>
719  TimeTagType Epoch::get() const
720  {
721  try { return TimeTagType(core); }
722  catch( Exception& e)
723  {
724  EpochException ee(e);
725  GNSSTK_THROW(ee);
726  }
727  }
728 
732  long double Epoch::JD() const
733  {
734  return get<JulianDate>().jd;
735  }
736 
740  long double Epoch::MJD() const
741  {
742  return get<gnsstk::MJD>().mjd; // gnsstk to distinguish from Epoch::MJD
743  }
744 
746  short Epoch::year() const
747  {
748  return static_cast<short>(get<CivilTime>().year);
749  }
750 
752  short Epoch::month() const
753  {
754  return static_cast<short>(get<CivilTime>().month);
755  }
756 
758  short Epoch::day() const
759  {
760  return static_cast<short>(get<CivilTime>().day);
761  }
762 
764  short Epoch::dow() const
765  {
766  return (((static_cast<long>(JD()) % 7) + 1) % 7) ;
767  }
768 
770  short Epoch::hour() const
771  {
772  return static_cast<short>(get<CivilTime>().hour);
773  }
774 
776  short Epoch::minute() const
777  {
778  return static_cast<short>(get<CivilTime>().minute);
779  }
780 
782  double Epoch::second() const
783  {
784  return get<CivilTime>().second;
785  }
786 
788  double Epoch::sod() const
789  {
790  return get<YDSTime>().sod;
791  }
792 
794  short Epoch::GPSweek10() const
795  {
796  return GPSModWeek();
797  }
798 
800  short Epoch::GPSModWeek() const
801  {
802  return static_cast<short>(get<GPSWeekSecond>().getModWeek());
803  }
804 
806  long Epoch::GPSzcount() const
807  {
808  return get<GPSWeekZcount>().zcount;
809  }
810 
813  {
814  Epoch e = *this + .75; // add half a zcount
815  return e.get<GPSWeekZcount>().zcount;
816  }
817 
821  unsigned long Epoch::GPSzcount32() const
822  {
823  return get<GPSWeekZcount>().getZcount32();
824  }
825 
827  unsigned long Epoch::GPSzcount32Floor() const
828  {
829  Epoch e = *this + .75; // add half a zcount
830  return e.get<GPSWeekZcount>().getZcount32();
831  }
832 
834  double Epoch::GPSsow() const
835  {
836  return get<GPSWeekSecond>().sow;
837  }
838 
840  short Epoch::GPSweek() const
841  {
842  return static_cast<short>(get<GPSWeekSecond>().week);
843  }
844 
846  double Epoch::BDSsow() const
847  {
848  return get<BDSWeekSecond>().sow;
849  }
850 
852  short Epoch::BDSweek() const
853  {
854  return static_cast<short>(get<BDSWeekSecond>().week);
855  }
856 
858  short Epoch::BDSModWeek() const
859  {
860  return static_cast<short>(get<BDSWeekSecond>().getModWeek());
861  }
862 
864  double Epoch::QZSsow() const
865  {
866  return get<QZSWeekSecond>().sow;
867  }
868 
870  short Epoch::QZSweek() const
871  {
872  return static_cast<short>(get<QZSWeekSecond>().week);
873  }
874 
876  short Epoch::QZSModWeek() const
877  {
878  return static_cast<short>(get<QZSWeekSecond>().getModWeek());
879  }
880 
882  double Epoch::GALsow() const
883  {
884  return get<GALWeekSecond>().sow;
885  }
886 
888  short Epoch::GALweek() const
889  {
890  return static_cast<short>(get<GALWeekSecond>().week);
891  }
892 
894  short Epoch::GALModWeek() const
895  {
896  return static_cast<short>(get<GALWeekSecond>().getModWeek());
897  }
898 
900  short Epoch::doy() const
901  {
902  return static_cast<short>(get<YDSTime>().doy);
903  }
904 
906  struct timeval Epoch::unixTime() const
907  {
908  return get<UnixTime>().tv;
909  }
910 
911 } // namespace gnsstk
912 
913 #endif // GNSSTK_EPOCH_HPP
gnsstk::Epoch::ONE_SEC_TOLERANCE
static const double ONE_SEC_TOLERANCE
One second tolerance.
Definition: Epoch.hpp:154
GPSWeekZcount.hpp
YDSTime.hpp
gnsstk::Epoch::setDate
Epoch & setDate(const CommonTime &ct)
Definition: Epoch.cpp:385
gnsstk::Epoch::operator<
bool operator<(const Epoch &right) const noexcept
Definition: Epoch.cpp:280
gnsstk::Epoch::QZSweek
short QZSweek() const
Get full QZS week.
Definition: Epoch.hpp:870
gnsstk::Epoch::ONE_NSEC_TOLERANCE
static const double ONE_NSEC_TOLERANCE
One nanosecond tolerance.
Definition: Epoch.hpp:148
gnsstk::Epoch::PRINT_FORMAT
static std::string PRINT_FORMAT
This is how an Epoch is printed by default.
Definition: Epoch.hpp:169
gnsstk::Epoch::operator==
bool operator==(const Epoch &right) const noexcept
Definition: Epoch.cpp:264
gnsstk::Epoch::core
CommonTime core
Definition: Epoch.hpp:699
gnsstk::Epoch::addMicroSeconds
Epoch & addMicroSeconds(long usec)
Definition: Epoch.cpp:245
gnsstk::Epoch::operator-
double operator-(const Epoch &right) const noexcept
Definition: Epoch.cpp:159
gnsstk::Epoch::~Epoch
~Epoch() noexcept
Destructor.
Definition: Epoch.hpp:249
const
#define const
Definition: getopt.c:43
StringUtils.hpp
gnsstk::Epoch::operator+
Epoch operator+(double sec) const
Definition: Epoch.cpp:168
gnsstk::Epoch::printf
std::string printf(const std::string &fmt=PRINT_FORMAT) const
Definition: Epoch.cpp:433
gnsstk::Epoch::EPOCH_TOLERANCE
static double EPOCH_TOLERANCE
Default tolerance for time equality in days.
Definition: Epoch.hpp:161
gnsstk::Epoch::doy
short doy() const
Get day of year.
Definition: Epoch.hpp:900
GPSZcount.hpp
gnsstk::Epoch::sod
double sod() const
Get seconds of day.
Definition: Epoch.hpp:788
gnsstk::Epoch::operator-=
Epoch & operator-=(double sec)
Definition: Epoch.cpp:190
gnsstk::Epoch::getEpochTolerance
static double getEpochTolerance() noexcept
Returns the current EPOCH_TOLERANCE.
Definition: Epoch.hpp:180
gnsstk::Epoch::second
double second() const
Get seconds of minute.
Definition: Epoch.hpp:782
gnsstk::Epoch::hour
short hour() const
Get hour of day.
Definition: Epoch.hpp:770
gnsstk::Epoch::setTolerance
Epoch & setTolerance(double tol) noexcept
Definition: Epoch.cpp:85
gnsstk::Epoch::operator=
Epoch & operator=(const Epoch &right) noexcept
Assignment operator.
Definition: Epoch.cpp:148
gnsstk::Epoch::operator<=
bool operator<=(const Epoch &right) const noexcept
Definition: Epoch.cpp:296
gnsstk::Epoch::month
short month() const
Get month of year.
Definition: Epoch.hpp:752
gnsstk::Epoch::GPSweek10
short GPSweek10() const
Get 10-bit GPS week. Deprecated, used GPSModWeek()
Definition: Epoch.hpp:794
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
MJD.hpp
gnsstk::Epoch::GPSzcount
long GPSzcount() const
Get normal (19 bit) zcount.
Definition: Epoch.hpp:806
gnsstk::Epoch::ONE_MIN_TOLERANCE
static const double ONE_MIN_TOLERANCE
One minute tolerance.
Definition: Epoch.hpp:156
gnsstk::Epoch::QZSModWeek
short QZSModWeek() const
Get mod (short) QZS week.
Definition: Epoch.hpp:876
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::Epoch::ONE_HOUR_TOLERANCE
static const double ONE_HOUR_TOLERANCE
One hour tolerance.
Definition: Epoch.hpp:158
gnsstk::Epoch::Epoch
Epoch(const TimeTag &tt=SystemTime())
Definition: Epoch.cpp:93
gnsstk::Epoch::setLocalTime
Epoch & setLocalTime()
Definition: Epoch.cpp:404
gnsstk::Epoch::JD
long double JD() const
Definition: Epoch.hpp:732
gnsstk::TimeTag
Definition: TimeTag.hpp:58
gnsstk::Epoch::scanf
Epoch & scanf(const std::string &str, const std::string &fmt)
Definition: Epoch.cpp:418
gnsstk::Epoch::BDSsow
double BDSsow() const
Get BDS second of week.
Definition: Epoch.hpp:846
JulianDate.hpp
gnsstk::GPSZcount
Definition: GPSZcount.hpp:75
gnsstk::Epoch::addMilliSeconds
Epoch & addMilliSeconds(long msec)
Definition: Epoch.cpp:229
SystemTime.hpp
gnsstk::Epoch::GPSzcount32Floor
unsigned long GPSzcount32Floor() const
Same as fullZcount() but without rounding to nearest zcount.
Definition: Epoch.hpp:827
gnsstk::Epoch::GPSzcountFloor
long GPSzcountFloor() const
Same as GPSzcount() but without rounding to nearest zcount.
Definition: Epoch.hpp:812
gnsstk::SystemTime
Definition: SystemTime.hpp:54
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::Epoch::tolerance
double tolerance
double tolerance used in comparisons (seconds)
Definition: Epoch.hpp:702
gnsstk::Epoch::year
short year() const
Get year.
Definition: Epoch.hpp:746
gnsstk::Epoch::GALweek
short GALweek() const
Get full GAL week.
Definition: Epoch.hpp:888
gnsstk::Epoch::ONE_USEC_TOLERANCE
static const double ONE_USEC_TOLERANCE
One microsecond tolerance.
Definition: Epoch.hpp:150
CivilTime.hpp
gnsstk::Epoch::getTolerance
double getTolerance() const noexcept
Definition: Epoch.hpp:198
TimeTag.hpp
gnsstk::Epoch::GPSweek
short GPSweek() const
Get full (>10 bits) week.
Definition: Epoch.hpp:840
gnsstk::Epoch::get
TimeTagType get() const
Definition: Epoch.hpp:719
gnsstk::Epoch::GPSModWeek
short GPSModWeek() const
Get 10-bit GPS week.
Definition: Epoch.hpp:800
gnsstk::WeekSecond
Definition: WeekSecond.hpp:60
gnsstk::GPSWeekZcount
Definition: GPSWeekZcount.hpp:55
gnsstk::Epoch::operator!=
bool operator!=(const Epoch &right) const noexcept
Definition: Epoch.cpp:273
gnsstk::Epoch::setEpochTolerance
static double setEpochTolerance(double tol) noexcept
Changes the EPOCH_TOLERANCE for all Epoch objects.
Definition: Epoch.hpp:175
gnsstk::Epoch::day
short day() const
Get day of month.
Definition: Epoch.hpp:758
gnsstk::Epoch::minute
short minute() const
Get minutes of hour.
Definition: Epoch.hpp:776
gnsstk::Epoch::END_OF_TIME
static const Epoch END_OF_TIME
Latest Representable Epoch.
Definition: Epoch.hpp:166
gnsstk::Epoch::MJD
long double MJD() const
Definition: Epoch.hpp:740
gnsstk::Epoch::unixTime
struct timeval unixTime() const
Get object time in UNIX timeval structure.
Definition: Epoch.hpp:906
gnsstk::Epoch::GALsow
double GALsow() const
Get GAL second of week.
Definition: Epoch.hpp:882
gnsstk::Epoch::GPSsow
double GPSsow() const
Get GPS second of week.
Definition: Epoch.hpp:834
GPSWeekSecond.hpp
gnsstk::Epoch::QZSsow
double QZSsow() const
Get QZS second of week.
Definition: Epoch.hpp:864
Exception.hpp
CommonTime.hpp
std
Definition: Angle.hpp:142
gnsstk::Epoch::BDSweek
short BDSweek() const
Get full BDS week.
Definition: Epoch.hpp:852
gnsstk::Epoch::ONE_MSEC_TOLERANCE
static const double ONE_MSEC_TOLERANCE
One millisecond tolerance.
Definition: Epoch.hpp:152
BDSWeekSecond.hpp
gnsstk::Epoch
Definition: Epoch.hpp:123
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::Epoch::GALModWeek
short GALModWeek() const
Get mod (short) GAL week.
Definition: Epoch.hpp:894
gnsstk::Epoch::set
Epoch & set(const TimeTag &tt=SystemTime())
Definition: Epoch.cpp:315
gnsstk::Epoch::dow
short dow() const
Get day of week.
Definition: Epoch.hpp:764
gnsstk::Epoch::GPSzcount32
unsigned long GPSzcount32() const
Definition: Epoch.hpp:821
gnsstk::Epoch::BEGINNING_OF_TIME
static const Epoch BEGINNING_OF_TIME
Earliest representable Epoch.
Definition: Epoch.hpp:164
MathBase.hpp
gnsstk::Epoch::operator+=
Epoch & operator+=(double sec)
Definition: Epoch.cpp:183
gnsstk::Epoch::BDSModWeek
short BDSModWeek() const
Get mod (short) BDS week.
Definition: Epoch.hpp:858
QZSWeekSecond.hpp
GALWeekSecond.hpp
gnsstk::Epoch::operator>
bool operator>(const Epoch &right) const noexcept
Definition: Epoch.cpp:288
gnsstk::Epoch::setTime
Epoch & setTime(const CommonTime &ct)
Definition: Epoch.cpp:367
gnsstk::Epoch::operator>=
bool operator>=(const Epoch &right) const noexcept
Definition: Epoch.cpp:303
gnsstk::Epoch::NEW_EXCEPTION_CLASS
NEW_EXCEPTION_CLASS(EpochException, gnsstk::Exception)
gnsstk::Epoch::addSeconds
Epoch & addSeconds(double seconds)
Definition: Epoch.cpp:197


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39