TimeSystemCorr.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 "TimeSystemCorr.hpp"
40 #include "BDSWeekSecond.hpp"
41 
42 namespace gnsstk
43 {
46  : type(Unknown), frTS(TimeSystem::Unknown), toTS(TimeSystem::Unknown)
47  {
48  init();
49  }
50 
51 
53  TimeSystemCorrection(std::string str)
54  {
55  init();
56  this->fromString(str);
57  }
58 
59  // Set members to known (even if invalid) values
62  {
63  A0 = 0.0;
64  A1 = 0.0;
66  geoProvider = "";
67  geoUTCid = 0;
68  }
69 
71  fromString(const std::string& str)
72  {
73  std::string STR(gnsstk::StringUtils::upperCase(str));
74  if(STR == std::string("GPUT"))
75  {
76  type = GPUT;
79  }
80  else if(STR == std::string("GAUT"))
81  {
82  type = GAUT;
85  }
86  else if(STR == std::string("SBUT"))
87  // TD ??
88  {
89  type = SBUT;
92  }
93  else if(STR == std::string("GLUT"))
94  {
95  type = GLUT;
98  }
99  else if(STR == std::string("GPGA") || STR == std::string("GAGP")) // R3.04 A5
100  {
101  type = GPGA;
104  }
105  else if(STR == std::string("GLGP"))
106  {
107  type = GLGP;
110  }
111  else if(STR == std::string("QZGP"))
112  {
113  type = QZGP;
116  }
117  else if(STR == std::string("QZUT"))
118  {
119  type = QZUT;
122  }
123  else if(STR == std::string("BDUT"))
124  {
125  type = BDUT;
128  }
129  else if(STR == std::string("BDGP"))
130  {
131  type = BDGP;
134  }
135  else if(STR == std::string("IRUT"))
136  {
137  type = IRUT;
140  }
141  else if(STR == std::string("IRGP"))
142  {
143  type = IRGP;
146  }
147  else
148  {
149  Exception e("Unknown TimeSystemCorrection type: " + str);
150  GNSSTK_THROW(e);
151  }
152  }
153 
154 
158  {
160  switch (src)
161  {
162  case TimeSystem::BDT:
163  switch (tgt)
164  {
165  case TimeSystem::UTC:
167  break;
168  case TimeSystem::GPS:
170  break;
171  default:
172  break;
173  }
174  break;
175  case TimeSystem::GAL:
176  switch (tgt)
177  {
178  case TimeSystem::UTC:
180  break;
181  case TimeSystem::GPS:
183  break;
184  default:
185  break;
186  }
187  break;
188  case TimeSystem::GLO:
189  switch (tgt)
190  {
191  case TimeSystem::UTC:
193  break;
194  case TimeSystem::GPS:
196  break;
197  default:
198  break;
199  }
200  break;
201  case TimeSystem::GPS:
202  switch (tgt)
203  {
204  case TimeSystem::UTC:
206  break;
207  case TimeSystem::GAL:
209  break;
210  default:
211  break;
212  }
213  break;
214  case TimeSystem::IRN:
215  switch (tgt)
216  {
217  case TimeSystem::UTC:
219  break;
220  case TimeSystem::GPS:
222  break;
223  default:
224  break;
225  }
226  break;
227  case TimeSystem::QZS:
228  switch (tgt)
229  {
230  case TimeSystem::UTC:
232  break;
233  case TimeSystem::GPS:
235  break;
236  default:
237  break;
238  }
239  break;
240  default:
241  break;
242  }
243  return (ct != TimeSystemCorrection::Unknown);
244  }
245 
246 
247  std::string TimeSystemCorrection ::
248  asString() const
249  {
250  switch (type)
251  {
252  case GPUT: return std::string("GPS to UTC");
253  case GAUT: return std::string("GAL to UTC");
254  case SBUT: return std::string("SBAS to UTC");
255  case GLUT: return std::string("GLO to UTC");
256  case GPGA: return std::string("GPS to GAL");
257  case GLGP: return std::string("GLO to GPS");
258  case QZGP: return std::string("QZS to GPS");
259  case QZUT: return std::string("QZS to UTC");
260  case BDUT: return std::string("BDT to UTC");
261  case BDGP: return std::string("BDT to GPS");
262  case IRUT: return std::string("IRN to UTC");
263  case IRGP: return std::string("IRN to GPS");
264  default: return std::string("ERROR");
265  }
266  }
267 
268 
269  std::string TimeSystemCorrection ::
270  asString4() const
271  {
272  switch(type) {
273  case GPUT: return std::string("GPUT");
274  case GAUT: return std::string("GAUT");
275  case SBUT: return std::string("SBUT");
276  case GLUT: return std::string("GLUT");
277  case GPGA: return std::string("GPGA");
278  case GLGP: return std::string("GLGP");
279  case QZGP: return std::string("QZGP");
280  case QZUT: return std::string("QZUT");
281  case BDUT: return std::string("BDUT");
282  case BDGP: return std::string("BDGP");
283  case IRUT: return std::string("IRUT");
284  case IRGP: return std::string("IRGP");
285  default: return std::string("ERROR");
286  }
287  }
288 
289 
291  dump(std::ostream& s) const
292  {
293  s << "Time system correction for " << asString4() << ": "
294  << asString() << std::scientific << std::setprecision(12);
295  BDSWeekSecond bdt;
296  GPSWeekSecond gps;
297  CivilTime civ;
298  switch(type) {
299  case GPUT:
300  gps = refTime;
301  s << ", A0 = " << A0 << ", A1 = " << A1
302  << ", RefTime = week/sow " << gps.week << "/" << int(gps.sow);
303  break;
304  case GAUT:
305  gps = refTime;
306  s << ", A0 = " << A0 << ", A1 = " << A1
307  << ", RefTime = week/sow " << gps.week << "/" << int(gps.sow);
308  break;
309  case SBUT:
310  gps = refTime;
311  s << ", A0 = " << A0 << ", A1 = " << A1
312  << ", RefTime = week/sow " << gps.week << "/" << int(gps.sow)
313  << ", provider " << geoProvider << ", UTC ID = " << geoUTCid;
314  break;
315  case GLUT:
316  gps = refTime;
317  s << ", -TauC = " << A0
318  << ", RefTime = week/sow " << gps.week << "/" << int(gps.sow);
319  break;
320  case GPGA:
321  gps = refTime;
322  s << ", A0G = " << A0 << ", A1G = " << A1
323  << ", RefTime = week/sow " << gps.week << "/" << int(gps.sow);
324  break;
325  case GLGP:
326  civ = refTime;
327  s << ", TauGPS = " << A0 << " sec, RefTime = yr/mon/day "
328  << civ.year << "/" << civ.month << "/" << civ.day;
329  break;
330  case QZGP:
331  gps = refTime;
332  s << ", A0 = " << A0 << ", A1 = " << A1
333  << ", RefTime = week/sow " << gps.week << "/" << int(gps.sow);
334  break;
335  case QZUT:
336  gps = refTime;
337  s << ", A0 = " << A0 << ", A1 = " << A1
338  << ", RefTime = week/sow " << gps.week << "/" << int(gps.sow);
339  break;
340  case BDUT:
341  bdt = refTime;
342  s << ", A0 = " << A0 << ", A1 = " << A1
343  << ", RefTime = week/sow " << bdt.week << "/" << int(bdt.sow);
344  break;
345  case BDGP:
346  bdt = refTime;
347  s << ", A0 = " << A0 << ", A1 = " << A1
348  << ", RefTime = week/sow " << bdt.week << "/" << int(bdt.sow);
349  break;
350  case IRUT:
351  gps = refTime;
352  s << ", A0 = " << A0 << ", A1 = " << A1
353  << ", RefTime = week/sow " << gps.week << "/" << int(gps.sow);
354  break;
355  case IRGP:
356  gps = refTime;
357  s << ", A0 = " << A0 << ", A1 = " << A1
358  << ", RefTime = week/sow " << gps.week << "/" << int(gps.sow);
359  default:
360  break;
361  }
362  //s << std::endl;
363  }
364 
365 
367  isConverterFor(const TimeSystem& ts1, const TimeSystem& ts2) const
368  {
369  if(ts1 == ts2)
370  {
371  Exception e("Identical time systems");
372  GNSSTK_THROW(e);
373  }
374  if(ts1 == TimeSystem::Unknown || ts2 == TimeSystem::Unknown)
375  {
376  Exception e("Unknown time systems");
377  GNSSTK_THROW(e);
378  }
379  if((ts1 == frTS && ts2 == toTS) || (ts2 == frTS && ts1 == toTS))
380  {
381  return true;
382  }
383  return false;
384  }
385 
386 
388  Correction(const CommonTime& ct) const
389  {
390  double corr(0.0), dt;
391  TimeSystem fromTS(ct.getTimeSystem());
392  CommonTime rtc(refTime); // copy of ref time to allow time system change
393  Exception e("Unable to compute correction - wrong TimeSystem");
394  Exception eSBAS("TimeSystemCorrection SBAS <=> UTC has not been implemented");
395  rtc.setTimeSystem(fromTS);
396 
397  switch(type)
398  {
399  case GPUT:
400  if(fromTS != TimeSystem::GPS && fromTS != TimeSystem::UTC)
401  {
402  GNSSTK_THROW(e);
403  }
404 
405  // dt = fromTime - refTime
406  dt = ct - rtc;
407 
408  if(fromTS == TimeSystem::GPS) // GPS => UTC
409  corr = -A0-A1*dt;
410  else // UTC => GPS
411  corr = A0+A1*dt;
412 
413  break;
414 
415  case GAUT:
416  if(fromTS != TimeSystem::GAL && fromTS != TimeSystem::UTC)
417  {
418  GNSSTK_THROW(e);
419  }
420 
421  // dt = fromTime - rtc
422  dt = ct - rtc;
423 
424  if(fromTS == TimeSystem::GAL) // GAL => UTC
425  corr = -A0-A1*dt;
426  else // UTC => GAL
427  corr = A0+A1*dt;
428 
429  break;
430 
431  case SBUT:
432  GNSSTK_THROW(eSBAS);
433  break;
434 
435  case GLUT:
436  if(fromTS != TimeSystem::GLO && fromTS != TimeSystem::UTC)
437  {
438  GNSSTK_THROW(e);
439  }
440 
441  if(fromTS == TimeSystem::GLO) // GLO => UTC
442  corr = -A0;
443  else // UTC => GLO
444  corr = A0;
445 
446  break;
447 
448  case GPGA:
449  if(fromTS != TimeSystem::GPS && fromTS != TimeSystem::GAL)
450  {
451  GNSSTK_THROW(e);
452  }
453 
454  // dt = fromTime - rtc
455  dt = ct - rtc;
456 
457  if(fromTS == TimeSystem::GPS) // GPS => GAL
458  corr = A0+A1*dt;
459  else // GAL => GPS
460  corr = -A0-A1*dt;
461 
462  break;
463 
464  case GLGP:
465  if(fromTS != TimeSystem::GLO && fromTS != TimeSystem::GPS)
466  {
467  GNSSTK_THROW(e);
468  }
469 
470  if(fromTS == TimeSystem::GLO) // GLO => GPS
471  corr = A0;
472  else // GPS => GLO
473  corr = -A0;
474 
475  break;
476 
477  case QZGP:
478  if(fromTS != TimeSystem::QZS && fromTS != TimeSystem::GPS)
479  {
480  GNSSTK_THROW(e);
481  }
482 
483  if(fromTS == TimeSystem::QZS) // QZS => GPS
484  corr = 0.0; // TD?
485  else // GPS => QZS
486  corr = 0.0; // TD?
487 
488  break;
489 
490  case QZUT:
491  if(fromTS != TimeSystem::QZS && fromTS != TimeSystem::UTC)
492  {
493  GNSSTK_THROW(e);
494  }
495 
496  // dt = fromTime - rtc
497  dt = ct - rtc;
498 
499  if(fromTS == TimeSystem::QZS) // QZS => UTC
500  corr = -A0-A1*dt;
501  else // UTC => QZS
502  corr = A0+A1*dt;
503 
504  break;
505 
506  case BDUT:
507  if(fromTS != TimeSystem::BDT && fromTS != TimeSystem::UTC)
508  {
509  GNSSTK_THROW(e);
510  }
511 
512  // dt = fromTime - rtc
513  dt = ct - rtc;
514 
515  if(fromTS == TimeSystem::BDT) // BDT => UTC
516  corr = -A0-A1*dt;
517  else // UTC => BDT
518  corr = A0+A1*dt;
519 
520  break;
521 
522  case BDGP:
523  if(fromTS != TimeSystem::BDT && fromTS != TimeSystem::GPS)
524  {
525  GNSSTK_THROW(e);
526  }
527 
528  // dt = fromTime - rtc
529  dt = ct - rtc;
530 
531  if(fromTS == TimeSystem::BDT) // BDT => GPS
532  corr = A0;
533  else // GPS => BDT
534  corr = -A0;
535 
536  break;
537 
538  case IRUT:
539  if(fromTS != TimeSystem::IRN && fromTS != TimeSystem::UTC)
540  {
541  GNSSTK_THROW(e);
542  }
543 
544  // dt = fromTime - rtc
545  dt = ct - rtc;
546 
547  if(fromTS == TimeSystem::IRN) // GPS => UTC
548  corr = -A0-A1*dt;
549  else // UTC => GPS
550  corr = A0+A1*dt;
551 
552  break;
553 
554  case IRGP:
555  if(fromTS != TimeSystem::IRN && fromTS != TimeSystem::GPS)
556  {
557  GNSSTK_THROW(e);
558  }
559 
560  dt = ct - rtc;
561 
562  if(fromTS == TimeSystem::IRN) // IRN => GPS
563  corr = -A0-A1*dt;
564  else // GPS => IRn
565  corr = A0+A1*dt;
566 
567  break;
568 
569  default:
570  Exception e("TimeSystemCorrection is not defined.");
571  GNSSTK_THROW(e);
572  break;
573  }
574 
575  return corr;
576  }
577 
578 
581  {
582  switch (type)
583  {
584  case GPUT:
586  break;
587  case GLUT:
589  break;
590  case GAUT:
592  break;
593  case BDUT:
595  break;
596  case QZUT:
598  break;
599  case IRUT:
601  break;
602  case SBUT:
604  break;
605  case GLGP:
607  break;
608  case GAGP:
610  break;
611  case QZGP:
613  break;
614  case IRGP:
616  break;
617  case GPGA:
619  break;
620  case BDGP:
622  break;
623  default:
625  break;
626  }
627  }
628 
629 } // namespace gnsstk
gnsstk::TimeSystemCorrection::GPGA
@ GPGA
GPS to GAL using A0 = A0G , A1 = A1G.
Definition: TimeSystemCorr.hpp:71
gnsstk::StringUtils::upperCase
std::string & upperCase(std::string &s)
Definition: StringUtils.hpp:2117
gnsstk::TimeSystemCorrection::dump
void dump(std::ostream &s) const
dump
Definition: TimeSystemCorr.cpp:291
gnsstk::CivilTime::year
int year
Definition: CivilTime.hpp:198
gnsstk::TimeSystemCorrection::SBUT
@ SBUT
SBAS to UTC using A0, A1, incl. provider and UTC ID.
Definition: TimeSystemCorr.hpp:69
gnsstk::TimeSystemCorrection::GLGP
@ GLGP
GLO to GPS using A0 = TauGPS, A1 = 0.
Definition: TimeSystemCorr.hpp:73
gnsstk::TimeSystemCorrection::type
CorrType type
Definition: TimeSystemCorr.hpp:164
gnsstk::TimeSystemCorrection::A1
double A1
Definition: TimeSystemCorr.hpp:166
gnsstk::TimeSystemCorrection::refTime
CommonTime refTime
reference time for polynominal
Definition: TimeSystemCorr.hpp:167
gnsstk::TimeSystemCorrection::A0
double A0
Definition: TimeSystemCorr.hpp:166
gnsstk::CivilTime::day
int day
Definition: CivilTime.hpp:200
gnsstk::CommonTime::setTimeSystem
CommonTime & setTimeSystem(TimeSystem timeSystem)
Definition: CommonTime.hpp:195
gnsstk::CommonTime::BEGINNING_OF_TIME
static const GNSSTK_EXPORT CommonTime BEGINNING_OF_TIME
earliest representable CommonTime
Definition: CommonTime.hpp:102
gnsstk::TimeSystemCorrection::IRUT
@ IRUT
IRN to UTC using A0, A1.
Definition: TimeSystemCorr.hpp:78
gnsstk::TimeSystemCorrection::fromString
void fromString(const std::string &str)
Definition: TimeSystemCorr.cpp:71
gnsstk::TimeSystem::Unknown
@ Unknown
unknown time frame; for legacy code compatibility
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::TimeSystemCorrection::isConverterFor
bool isConverterFor(const TimeSystem &ts1, const TimeSystem &ts2) const
Definition: TimeSystemCorr.cpp:367
gnsstk::IonexStoreStrategy::Unknown
@ Unknown
Unknown or uninitialized stategy value.
gnsstk::TimeSystemCorrection::CorrType
CorrType
Supported time system correction types, cf. RINEX version 3 spec.
Definition: TimeSystemCorr.hpp:64
gnsstk::GPSWeekSecond
Definition: GPSWeekSecond.hpp:56
gnsstk::TimeSystemCorrection::TimeSystemCorrection
TimeSystemCorrection()
Empty constructor.
Definition: TimeSystemCorr.cpp:45
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::TimeSystemCorrection::Unknown
@ Unknown
Definition: TimeSystemCorr.hpp:66
gnsstk::TimeSystemCorrection::asString4
std::string asString4() const
Return 4-char string version of CorrType.
Definition: TimeSystemCorr.cpp:270
gnsstk::TimeSystemCorrection::geoUTCid
int geoUTCid
Definition: TimeSystemCorr.hpp:169
gnsstk::TimeSystem::IRN
@ IRN
IRNSS system Time.
gnsstk::TimeSystem::QZS
@ QZS
QZSS system Time.
gnsstk::TimeSystem::GAL
@ GAL
Galileo system time.
gnsstk::TimeSystemCorrection::IRGP
@ IRGP
IRN to GPS using A0, A1.
Definition: TimeSystemCorr.hpp:79
gnsstk::TimeSystemCorrection::QZGP
@ QZGP
QZS to GPS using A0, A1.
Definition: TimeSystemCorr.hpp:74
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::WeekSecond::sow
double sow
Definition: WeekSecond.hpp:155
gnsstk::TimeSystemCorrection::toTS
TimeSystem toTS
Definition: TimeSystemCorr.hpp:165
gnsstk::TimeSystemCorrection::GPUT
@ GPUT
GPS to UTC using A0, A1.
Definition: TimeSystemCorr.hpp:67
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
gnsstk::Week::week
int week
Full week number.
Definition: Week.hpp:267
gnsstk::TimeSystem::GLO
@ GLO
GLONASS system time (aka UTC(SU))
gnsstk::TimeSystem::UTC
@ UTC
Coordinated Universal Time (e.g., from NTP)
gnsstk::CivilTime
Definition: CivilTime.hpp:55
gnsstk::TimeSystemCorrection::convertTimeSystemToCorrType
static bool convertTimeSystemToCorrType(TimeSystem src, TimeSystem tgt, TimeSystemCorrection::CorrType &ct)
Definition: TimeSystemCorr.cpp:156
gnsstk::TimeSystemCorrection::QZUT
@ QZUT
QZS to UTC using A0, A1.
Definition: TimeSystemCorr.hpp:75
gnsstk::CommonTime::getTimeSystem
TimeSystem getTimeSystem() const
Obtain time system info (enum).
Definition: CommonTime.cpp:288
gnsstk::TimeSystem::GPS
@ GPS
GPS system time.
gnsstk::CivilTime::month
int month
Definition: CivilTime.hpp:199
gnsstk::TimeSystemCorrection::GAGP
@ GAGP
GPS to GAL using A0 = A0G , A1 = A1G.
Definition: TimeSystemCorr.hpp:72
gnsstk::TimeSystemCorrection::Correction
double Correction(const CommonTime &ct) const
Definition: TimeSystemCorr.cpp:388
BDSWeekSecond.hpp
gnsstk::TimeSystemCorrection::BDGP
@ BDGP
BDT to GPS using A0, A1 !! not in RINEX.
Definition: TimeSystemCorr.hpp:77
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::BDSWeekSecond
Definition: BDSWeekSecond.hpp:56
gnsstk::TimeSystemCorrection::init
void init()
Definition: TimeSystemCorr.cpp:61
TimeSystemCorr.hpp
gnsstk::TimeSystemCorrection::frTS
TimeSystem frTS
Definition: TimeSystemCorr.hpp:165
gnsstk::TimeSystemCorrection::BDUT
@ BDUT
BDT to UTC using A0, A1.
Definition: TimeSystemCorr.hpp:76
gnsstk::TimeSystem::BDT
@ BDT
BeiDou system Time.
gnsstk::TimeSystemCorrection::geoProvider
std::string geoProvider
string 'EGNOS' 'WAAS' or 'MSAS'
Definition: TimeSystemCorr.hpp:168
gnsstk::TimeSystemCorrection::GLUT
@ GLUT
GLO to UTC using A0 = -TauC , A1 = 0.
Definition: TimeSystemCorr.hpp:70
gnsstk::TimeSystemCorrection::fixTimeSystem
void fixTimeSystem()
Definition: TimeSystemCorr.cpp:580
gnsstk::TimeSystemCorrection::GAUT
@ GAUT
GAL to UTC using A0, A1.
Definition: TimeSystemCorr.hpp:68
gnsstk::TimeSystemCorrection::asString
std::string asString() const
Return readable string version of CorrType.
Definition: TimeSystemCorr.cpp:248


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