GLONASSTime.cpp
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 
39 #include <math.h>
40 #include "GLONASSTime.hpp"
41 #include "TimeConverters.hpp"
42 
43 namespace gnsstk
44 {
46  GLONASSTime(unsigned leapCount,
47  unsigned days,
48  double instant,
49  TimeSystem ts)
50  : TimeTag(ts),
51  epoch(leapCount),
52  day(days),
53  sod(instant)
54  {
55  }
56 
57 
60  {
61  try
62  {
63  // day of year within the current year
64  unsigned doy;
65  // current year number in the four year interval, see ICD A.3.1.3
66  unsigned J;
67  // epoch (N4) 27 corresponds to year 2100 which is not a leap year
68  unsigned lastDay = (epoch == 27 ? 365 : 366);
69  if (day <= lastDay)
70  {
71  J = 1;
72  doy = day;
73  }
74  else if (day <= (lastDay + 365))
75  {
76  J = 2;
77  doy = day - lastDay;
78  }
79  else if (day <= (lastDay + 730))
80  {
81  J = 3;
82  doy = day - (lastDay + 365);
83  }
84  else
85  {
86  J = 4;
87  doy = day - (lastDay + 730);
88  }
89  unsigned year = 1996 + 4*(epoch-1) + (J - 1);
90  long jday = convertCalendarToJD(year, 1, 1) + doy - 1;
96  double tmp = 1461.0 * (epoch-1.0) + day + GLO_EPOCH_JD
97  - ((day - 3.0)/25.0);
98  CommonTime ct;
99  return ct.set(jday, sod, timeSystem);
100  }
101  catch (InvalidParameter& ip)
102  {
103  InvalidRequest ir(ip);
104  GNSSTK_THROW(ir);
105  }
106  }
107 
108 
109  void GLONASSTime ::
111  {
112  long jday = 0, secDay = 0;
113  double fsecDay = 0.0;
114  ct.get(jday, secDay, fsecDay, timeSystem);
115  sod = static_cast<double>(secDay) + fsecDay;
116 
117  int cvtYear = 0, cvtMonth = 0, cvtDay = 0;
118  convertJDtoCalendar(jday, cvtYear, cvtMonth, cvtDay);
119  if (cvtYear < 1996)
120  {
121  InvalidRequest ir("Unable to represent years < 1996 in GLONASS time");
122  GNSSTK_THROW(ir);
123  }
124  epoch = 1 + ((cvtYear - 1996) >> 2); // integer divide by 4.
125  // current year within the four year interval, starting from
126  // 0 instead of 1 as per usual.
127  unsigned J = ((cvtYear-1996) % 4);
128  day = J * 365;
129  if (J > 0)
130  {
131  unsigned leapYear = cvtYear - (cvtYear % 4);
132  unsigned leapDay = (((leapYear % 400) == 0) ||
133  ((leapYear % 100) != 0));
134  // First day of the current year. Possibly adding 1 to
135  // account for leap year (J=0).
136  day = leapDay + (J * 365);
137  }
138  day += jday - convertCalendarToJD(cvtYear, 1, 1) + 1;
139  }
140 
141 
142  bool GLONASSTime ::
143  operator==(const GLONASSTime& right) const
144  {
146  return ((epoch == right.epoch) &&
147  (day == right.day) &&
148  (fabs(sod - right.sod) < CommonTime::eps));
149  }
150 
151 
152  bool GLONASSTime ::
153  operator!=(const GLONASSTime& right) const
154  {
155  return !operator==(right);
156  }
157 
158 
159  bool GLONASSTime ::
160  operator<(const GLONASSTime& right) const
161  {
163  if (epoch < right.epoch) return true;
164  if (right.epoch < epoch) return false;
165  if (day < right.day) return true;
166  if (right.day < day) return false;
167  if (sod < right.sod) return true;
168  return false;
169  }
170 
171 
172  bool GLONASSTime ::
173  operator>(const GLONASSTime& right) const
174  {
176  if (right.epoch < epoch) return true;
177  if (epoch < right.epoch) return false;
178  if (right.day < day) return true;
179  if (day < right.day) return false;
180  if (right.sod < sod) return true;
181  return false;
182  }
183 
184 
185  bool GLONASSTime ::
186  operator<=(const GLONASSTime& right) const
187  {
189  if (epoch < right.epoch) return true;
190  if (right.epoch < epoch) return false;
191  if (day < right.day) return true;
192  if (right.day < day) return false;
193  if (sod < right.sod) return true;
194  if (right.sod < sod) return false;
195  return true;
196  }
197 
198 
199  bool GLONASSTime ::
200  operator>=(const GLONASSTime& right) const
201  {
203  if (right.epoch < epoch) return true;
204  if (epoch < right.epoch) return false;
205  if (right.day < day) return true;
206  if (day < right.day) return false;
207  if (right.sod < sod) return true;
208  if (sod < right.sod) return false;
209  return true;
210  }
211 
212 
213  bool GLONASSTime ::
214  isValid() const
215  {
216  // I think this is right, 1461 = 4 years.
217  return ((day <= 1461) && (sod >= 0.0) && (sod < 86400.0));
218  }
219 
220  void GLONASSTime ::
222  {
223  epoch = 0;
224  day = 0;
225  sod = 0;
227  }
228 
229 } // namespace gnsstk
gnsstk::CommonTime::eps
static const GNSSTK_EXPORT double eps
Default tolerance for time equality in days.
Definition: CommonTime.hpp:107
gnsstk::GLONASSTime::operator>
bool operator>(const GLONASSTime &right) const
Definition: GLONASSTime.cpp:173
gnsstk::GLONASSTime::epoch
unsigned epoch
Number of leap years since 1996 (aka N4).
Definition: GLONASSTime.hpp:164
example6.day
day
Definition: example6.py:66
gnsstk::GLONASSTime::operator==
bool operator==(const GLONASSTime &right) const
Definition: GLONASSTime.cpp:143
gnsstk::GLONASSTime::convertToCommonTime
CommonTime convertToCommonTime() const override
As it says, convert to a CommonTime object.
Definition: GLONASSTime.cpp:59
example6.year
year
Definition: example6.py:64
gnsstk::GLONASSTime::day
unsigned day
Definition: GLONASSTime.hpp:167
gnsstk::GLONASSTime::convertFromCommonTime
void convertFromCommonTime(const CommonTime &ct) override
As it says, convert from a CommonTime object.
Definition: GLONASSTime.cpp:110
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::TimeTag::timeSystem
TimeSystem timeSystem
time system (representation) of the data
Definition: TimeTag.hpp:204
gnsstk::GLONASSTime
Definition: GLONASSTime.hpp:59
gnsstk::TimeTag
Definition: TimeTag.hpp:58
gnsstk::convertJDtoCalendar
void convertJDtoCalendar(long jd, int &iyear, int &imonth, int &iday)
Definition: TimeConverters.cpp:52
gnsstk::GLONASSTime::isValid
bool isValid() const override
Returns true if this object's members are valid, false otherwise.
Definition: GLONASSTime.cpp:214
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::GLONASSTime::operator>=
bool operator>=(const GLONASSTime &right) const
Definition: GLONASSTime.cpp:200
example5.epoch
epoch
Definition: example5.py:24
gnsstk::GLONASSTime::reset
void reset() override
Reset this object to the default state.
Definition: GLONASSTime.cpp:221
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
gnsstk::CommonTime::get
void get(long &day, long &sod, double &fsod, TimeSystem &timeSystem) const
Definition: CommonTime.cpp:213
TimeConverters.hpp
gnsstk::TimeSystem::GLO
@ GLO
GLONASS system time (aka UTC(SU))
GLONASSTime.hpp
example6.sod
sod
Definition: example6.py:103
gnsstk::GLONASSTime::operator<
bool operator<(const GLONASSTime &right) const
Definition: GLONASSTime.cpp:160
gnsstk::GLONASSTime::sod
double sod
Time of day (seconds of day, aka tb).
Definition: GLONASSTime.hpp:169
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::convertCalendarToJD
long convertCalendarToJD(int yy, int mm, int dd)
Definition: TimeConverters.cpp:100
gnsstk::GLONASSTime::operator<=
bool operator<=(const GLONASSTime &right) const
Definition: GLONASSTime.cpp:186
gnsstk::GLONASSTime::GLONASSTime
GLONASSTime(unsigned leapCount=0, unsigned days=0, double instant=0., TimeSystem ts=TimeSystem::GLO)
Definition: GLONASSTime.cpp:46
gnsstk::TimeTag::checkTimeSystem
static void checkTimeSystem(TimeSystem ts1, TimeSystem ts2)
Definition: TimeTag.cpp:207
gnsstk::GLONASSTime::operator!=
bool operator!=(const GLONASSTime &right) const
Definition: GLONASSTime.cpp:153
gnsstk::GLO_EPOCH_JD
const double GLO_EPOCH_JD
'Julian day' of GLONASS epoch (Jan. 1, 1996).
Definition: TimeConstants.hpp:134
gnsstk::CommonTime::set
CommonTime & set(long day, long sod, double fsod=0.0, TimeSystem timeSystem=TimeSystem::Unknown)
Definition: CommonTime.cpp:87


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