TimeSystemCorr_T.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 "CivilTime.hpp"
40 #include "CommonTime.hpp"
41 #include "TimeSystemCorr.hpp"
42 #include "TestUtil.hpp"
43 #include <iostream>
44 #include <sstream>
45 #include <cmath>
46 
48 {
49 public:
50  // Default Constructor, set the precision value
52  { eps = 1E-12; }
53 
56  unsigned initializationTest();
57 
62  unsigned operatorTest();
63 
64  unsigned correctionTest();
65 
66  gnsstk::TimeSystemCorrection buildObject(const std::string& str);
67 
68 private:
69  double eps;
70 
71  double A0;
72  double A1;
73  double deltaT;
75 };
76 
77 
78 unsigned TimeSystemCorr_T ::
80 {
81  TUDEF("TimeSystemCorr", "Constructor");
82 
86 
87  gnsstk::TimeSystemCorrection cIRGP("IRGP");
92  TUASSERTFE(0.0, cIRGP.A0);
93  TUASSERTFE(0.0, cIRGP.A1);
95  cIRGP.refTime);
96  TUASSERTE(int, 0, cIRGP.geoUTCid);
97 
98  TURETURN();
99 }
100 
101 
102 unsigned TimeSystemCorr_T ::
104 {
105  TUDEF("TimeSystemCorr", "operator<");
106 
107  // Build a complete set of correction objects
109  gnsstk::TimeSystemCorrection cGPUT("GPUT");
110  gnsstk::TimeSystemCorrection cGAUT("GAUT");
111  gnsstk::TimeSystemCorrection cSBUT("SBUT");
112  gnsstk::TimeSystemCorrection cGLUT("GLUT");
113  gnsstk::TimeSystemCorrection cGPGA("GPGA");
114  gnsstk::TimeSystemCorrection cGLGP("GLGP");
115  gnsstk::TimeSystemCorrection cQZGP("QZGP");
116  gnsstk::TimeSystemCorrection cQZUT("QZUT");
117  gnsstk::TimeSystemCorrection cBDUT("BDUT");
118  gnsstk::TimeSystemCorrection cBDGP("BDGP");
119  gnsstk::TimeSystemCorrection cIRUT("IRUT");
120  gnsstk::TimeSystemCorrection cIRGP("IRGP");
121 
122  TUCSM("operator==");
123  TUASSERT( !(cUnknown==cGPUT));
124  TUASSERT( !(cGPUT==cGAUT));
125  TUASSERT( !(cGAUT==cSBUT));
126  TUASSERT( !(cSBUT==cGLUT));
127  TUASSERT( !(cGLUT==cGPGA));
128  TUASSERT( !(cGPGA==cGLGP));
129  TUASSERT( !(cGLGP==cQZGP));
130  TUASSERT( !(cQZGP==cQZUT));
131  TUASSERT( !(cQZUT==cBDUT));
132  TUASSERT( !(cBDUT==cBDGP));
133  TUASSERT( !(cBDGP==cIRUT));
134  TUASSERT( !(cIRUT==cIRGP));
135 
136  TUCSM("operator<");
137  TUASSERT(cUnknown < cGPUT);
138  TUASSERT(cGPUT < cGAUT);
139  TUASSERT(cGAUT < cSBUT);
140  TUASSERT(cSBUT < cGLUT);
141  TUASSERT(cGLUT < cGPGA);
142  TUASSERT(cGPGA < cGLGP);
143  TUASSERT(cGLGP < cQZGP);
144  TUASSERT(cQZGP < cQZUT);
145  TUASSERT(cQZUT < cBDUT);
146  TUASSERT(cBDUT < cBDGP);
147  TUASSERT(cBDGP < cIRUT);
148  TUASSERT(cIRUT < cIRGP);
149 
150  TURETURN();
151 }
152 
153 
154 unsigned TimeSystemCorr_T ::
156 {
157  TUDEF("TimeSystemCorr", "Correction");
158 
159  // Define a representative A0 and A1. Define an epoch time and
160  // a reasonable refernce time.
161  // Use these values throughout the set of tests.
162  // Test at least one conversion for each conversion type.
163  A0 = 1.0e-7;
164  A1 = 1.0e-12;
165  deltaT = -10000; // 10,000 sec is a nice round number for prpogation
166  tscRefTime = gnsstk::CivilTime(2016, 1, 3, 0, 0, 0.0);
167 
168  gnsstk::CommonTime timeOfInterest = tscRefTime + deltaT;
169  double forwardResult = A0 + A1 * deltaT;
170  forwardResult = forwardResult * -1.0; // This is a CORRECTION, not an error
171  double corrVal = 0.0;
172 
173  gnsstk::TimeSystemCorrection tscTest = buildObject("GPUT");
174  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::GPS);
175  corrVal = tscTest.Correction(timeOfInterest);
176  TUASSERTFEPS(forwardResult, corrVal, eps);
177 
178  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::UTC);
179  corrVal = tscTest.Correction(timeOfInterest);
180  TUASSERTFEPS(-forwardResult, corrVal, eps);
181 
182  tscTest = buildObject("GAUT");
183  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::GAL);
184  corrVal = tscTest.Correction(timeOfInterest);
185  TUASSERTFEPS(forwardResult, corrVal, eps);
186 
187  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::UTC);
188  corrVal = tscTest.Correction(timeOfInterest);
189  TUASSERTFEPS(-forwardResult, corrVal, eps);
190 
191  tscTest = buildObject("QZUT");
192  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::QZS);
193  corrVal = tscTest.Correction(timeOfInterest);
194  TUASSERTFEPS(forwardResult, corrVal, eps);
195 
196  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::UTC);
197  corrVal = tscTest.Correction(timeOfInterest);
198  TUASSERTFEPS(-forwardResult, corrVal, eps);
199 
200  tscTest = buildObject("BDUT");
201  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::BDT);
202  corrVal = tscTest.Correction(timeOfInterest);
203  TUASSERTFEPS(forwardResult, corrVal, eps);
204 
205  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::UTC);
206  corrVal = tscTest.Correction(timeOfInterest);
207  TUASSERTFEPS(-forwardResult, corrVal, eps);
208 
209  tscTest = buildObject("IRUT");
210  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::IRN);
211  corrVal = tscTest.Correction(timeOfInterest);
212  TUASSERTFEPS(forwardResult, corrVal, eps);
213 
214  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::UTC);
215  corrVal = tscTest.Correction(timeOfInterest);
216  TUASSERTFEPS(-forwardResult, corrVal, eps);
217 
218  // GLONASS is a little different in that the A1 term is not used
219  A1 = 0;
220  forwardResult = A0 + A1 * deltaT;
221  forwardResult = forwardResult * -1.0; // This is a CORRECTION, not an error
222  tscTest = buildObject("GLUT");
223  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::GLO);
224  corrVal = tscTest.Correction(timeOfInterest);
225  TUASSERTFEPS(forwardResult, corrVal, eps);
226 
227  timeOfInterest.setTimeSystem(gnsstk::TimeSystem::UTC);
228  corrVal = tscTest.Correction(timeOfInterest);
229  TUASSERTFEPS(-forwardResult, corrVal, eps);
230 
231  TURETURN();
232 }
233 
235 buildObject(const std::string& str)
236 {
238  tsc.refTime = tscRefTime;
239  tsc.A0 = A0;
240  tsc.A1 = A1;
241 
242  return tsc;
243 }
244 
245 
246 int main() //Main function to initialize and run all tests above
247 {
248  TimeSystemCorr_T testClass;
249  unsigned errorTotal = 0;
250 
251  errorTotal += testClass.initializationTest();
252  errorTotal += testClass.operatorTest();
253  errorTotal += testClass.correctionTest();
254 
255  std::cout << "Total Failures for " << __FILE__ << ": " << errorTotal
256  << std::endl;
257 
258  return errorTotal; //Return the total number of errors
259 }
TUCSM
#define TUCSM(METHOD)
Definition: TestUtil.hpp:59
TimeSystemCorr_T::operatorTest
unsigned operatorTest()
Definition: TimeSystemCorr_T.cpp:103
gnsstk::TimeSystemCorrection
Definition: TimeSystemCorr.hpp:60
main
int main()
Definition: TimeSystemCorr_T.cpp:246
gnsstk::TimeSystemCorrection::type
CorrType type
Definition: TimeSystemCorr.hpp:164
gnsstk::TimeSystemCorrection::A1
double A1
Definition: TimeSystemCorr.hpp:166
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
gnsstk::TimeSystemCorrection::refTime
CommonTime refTime
reference time for polynominal
Definition: TimeSystemCorr.hpp:167
gnsstk::TimeSystemCorrection::A0
double A0
Definition: TimeSystemCorr.hpp:166
TimeSystemCorr_T::correctionTest
unsigned correctionTest()
Definition: TimeSystemCorr_T.cpp:155
gnsstk::CommonTime::setTimeSystem
CommonTime & setTimeSystem(TimeSystem timeSystem)
Definition: CommonTime.hpp:195
TimeSystemCorr_T::eps
double eps
Definition: TimeSystemCorr_T.cpp:69
gnsstk::CommonTime::BEGINNING_OF_TIME
static const GNSSTK_EXPORT CommonTime BEGINNING_OF_TIME
earliest representable CommonTime
Definition: CommonTime.hpp:102
gnsstk::TimeSystemCorrection::CorrType
CorrType
Supported time system correction types, cf. RINEX version 3 spec.
Definition: TimeSystemCorr.hpp:64
TimeSystemCorr_T
Definition: TimeSystemCorr_T.cpp:47
gnsstk::TimeSystemCorrection::Unknown
@ Unknown
Definition: TimeSystemCorr.hpp:66
TUASSERT
#define TUASSERT(EXPR)
Definition: TestUtil.hpp:63
gnsstk::TimeSystemCorrection::geoUTCid
int geoUTCid
Definition: TimeSystemCorr.hpp:169
TimeSystemCorr_T::buildObject
gnsstk::TimeSystemCorrection buildObject(const std::string &str)
Definition: TimeSystemCorr_T.cpp:235
TestUtil.hpp
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
gnsstk::TimeSystem::IRN
@ IRN
IRNSS system Time.
gnsstk::TimeSystem::QZS
@ QZS
QZSS system Time.
TimeSystemCorr_T::tscRefTime
gnsstk::CommonTime tscRefTime
Definition: TimeSystemCorr_T.cpp:74
gnsstk::TimeSystem::GAL
@ GAL
Galileo system time.
gnsstk::TimeSystemCorrection::IRGP
@ IRGP
IRN to GPS using A0, A1.
Definition: TimeSystemCorr.hpp:79
TimeSystemCorr_T::TimeSystemCorr_T
TimeSystemCorr_T()
Definition: TimeSystemCorr_T.cpp:51
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::TimeSystemCorrection::toTS
TimeSystem toTS
Definition: TimeSystemCorr.hpp:165
TimeSystemCorr_T::A0
double A0
Definition: TimeSystemCorr_T.cpp:71
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
TUASSERTFEPS
#define TUASSERTFEPS(EXP, GOT, EPS)
Definition: TestUtil.hpp:126
CivilTime.hpp
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
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
TimeSystemCorr_T::A1
double A1
Definition: TimeSystemCorr_T.cpp:72
gnsstk::TimeSystem::GPS
@ GPS
GPS system time.
CommonTime.hpp
TimeSystemCorr_T::initializationTest
unsigned initializationTest()
Definition: TimeSystemCorr_T.cpp:79
gnsstk::TimeSystemCorrection::Correction
double Correction(const CommonTime &ct) const
Definition: TimeSystemCorr.cpp:388
TUASSERTFE
#define TUASSERTFE(EXP, GOT)
Definition: TestUtil.hpp:103
TimeSystemCorr.hpp
gnsstk::TimeSystemCorrection::frTS
TimeSystem frTS
Definition: TimeSystemCorr.hpp:165
gnsstk::TimeSystem::BDT
@ BDT
BeiDou system Time.
TimeSystemCorr_T::deltaT
double deltaT
Definition: TimeSystemCorr_T.cpp:73


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