1 //==============================================================================
2 //
3 //  This file is part of GPSTk, the GPS Toolkit.
4 //
5 //  The GPSTk 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 GPSTk 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 GPSTk; 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-2020, 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 
47 class TimeSystemCorr_T
48 {
49 public:
TimeSystemCorr_T()50    TimeSystemCorr_T(){ eps = 1E-12; }// Default Constructor, set the precision value
~TimeSystemCorr_T()51    ~TimeSystemCorr_T() {} // Default Desructor
52 
53 //==========================================================================
54 // initializationTest ensures the constructors set the values properly
55 // get methods are tested implicitly
56 //==========================================================================
initializationTest(void)57    int initializationTest(void)
58    {
59       gpstk::TestUtil testFramework("TimeSystemCorr", "Constructor", __FILE__, __LINE__);
60       std::string testMesg = "Failed to create default object";
61 
62       gpstk::TimeSystemCorrection cUnknown;
63       testFramework.assert(cUnknown.type==gpstk::TimeSystemCorrection::Unknown, testMesg, __LINE__);
64 
65       testMesg = "Default nitialization failed.";
66       gpstk::TimeSystemCorrection cIRGP("IRGP");
67       testFramework.assert(cIRGP.type==gpstk::TimeSystemCorrection::IRGP, testMesg, __LINE__);
68       testFramework.assert(cIRGP.frTS==gpstk::TimeSystem::IRN, testMesg, __LINE__);
69       testFramework.assert(cIRGP.toTS==gpstk::TimeSystem::GPS, testMesg, __LINE__);
70       testFramework.assert(cIRGP.A0==0.0, testMesg, __LINE__);
71       testFramework.assert(cIRGP.A1==0.0, testMesg, __LINE__);
72       testFramework.assert(cIRGP.refWeek==0, testMesg, __LINE__);
73       testFramework.assert(cIRGP.refSOW==0, testMesg, __LINE__);
74       testFramework.assert(cIRGP.refYr==0, testMesg, __LINE__);
75       testFramework.assert(cIRGP.refMon==0, testMesg, __LINE__);
76       testFramework.assert(cIRGP.refDay==0, testMesg, __LINE__);
77       testFramework.assert(cIRGP.geoUTCid==0, testMesg, __LINE__);
78 
79       return testFramework.countFails();
80    }
81 
82       // operator==() and operator()< only exist in order to support
83       // use of TimeSystemCorr objects as map keys.  In this role, only the
84       // CorrType is checked.   Therefore, it is sufficient
85       // to see that the ordering is maintained without change.
operatorTest(void)86    int operatorTest(void)
87    {
88       gpstk::TestUtil testFramework("TimeSystemCorr", "operator<", __FILE__, __LINE__);
89       std::string testMesg;
90 
91          // Build a complete set of correction objects
92       //std::cout << "Constructing cUnknown" << std::endl;
93       gpstk::TimeSystemCorrection cUnknown;
94       gpstk::TimeSystemCorrection cGPUT("GPUT");
95       gpstk::TimeSystemCorrection cGAUT("GAUT");
96       gpstk::TimeSystemCorrection cSBUT("SBUT");
97       gpstk::TimeSystemCorrection cGLUT("GLUT");
98       gpstk::TimeSystemCorrection cGPGA("GPGA");
99       gpstk::TimeSystemCorrection cGLGP("GLGP");
100       gpstk::TimeSystemCorrection cQZGP("QZGP");
101       gpstk::TimeSystemCorrection cQZUT("QZUT");
102       gpstk::TimeSystemCorrection cBDUT("BDUT");
103       gpstk::TimeSystemCorrection cBDGP("BDGP");
104       gpstk::TimeSystemCorrection cIRUT("IRUT");
105       gpstk::TimeSystemCorrection cIRGP("IRGP");
106 
107       testMesg = "Unequal objects returned True for operator==()";
108       std::cout << "operator==() tests" << std::endl;
109       testFramework.assert( !(cUnknown==cGPUT), testMesg, __LINE__);
110       testFramework.assert( !(cGPUT==cGAUT), testMesg, __LINE__);
111       testFramework.assert( !(cGAUT==cSBUT), testMesg, __LINE__);
112       testFramework.assert( !(cSBUT==cGLUT), testMesg, __LINE__);
113       testFramework.assert( !(cGLUT==cGPGA), testMesg, __LINE__);
114       testFramework.assert( !(cGPGA==cGLGP), testMesg, __LINE__);
115       testFramework.assert( !(cGLGP==cQZGP), testMesg, __LINE__);
116       testFramework.assert( !(cQZGP==cQZUT), testMesg, __LINE__);
117       testFramework.assert( !(cQZUT==cBDUT), testMesg, __LINE__);
118       testFramework.assert( !(cBDUT==cBDGP), testMesg, __LINE__);
119       testFramework.assert( !(cBDGP==cIRUT), testMesg, __LINE__);
120       testFramework.assert( !(cIRUT==cIRGP), testMesg, __LINE__);
121 
122       testMesg = "Greater-than object was not marked as greater by the < operator";
123       std::cout << "operator<() tests" << std::endl;
124       testFramework.assert(cUnknown < cGPUT, testMesg, __LINE__);
125       testFramework.assert(cGPUT < cGAUT, testMesg, __LINE__);
126       testFramework.assert(cGAUT < cSBUT, testMesg, __LINE__);
127       testFramework.assert(cSBUT < cGLUT, testMesg, __LINE__);
128       testFramework.assert(cGLUT < cGPGA, testMesg, __LINE__);
129       testFramework.assert(cGPGA < cGLGP, testMesg, __LINE__);
130       testFramework.assert(cGLGP < cQZGP, testMesg, __LINE__);
131       testFramework.assert(cQZGP < cQZUT, testMesg, __LINE__);
132       testFramework.assert(cQZUT < cBDUT, testMesg, __LINE__);
133       testFramework.assert(cBDUT < cBDGP, testMesg, __LINE__);
134       testFramework.assert(cBDGP < cIRUT, testMesg, __LINE__);
135       testFramework.assert(cIRUT < cIRGP, testMesg, __LINE__);
136 
137       return testFramework.countFails();
138    }
139 
140 /*
141          Unknown=0,
142          GPUT,    ///< GPS  to UTC using A0, A1
143          GAUT,    ///< GAL  to UTC using A0, A1
144          SBUT,    ///< SBAS to UTC using A0, A1, incl. provider and UTC ID
145          GLUT,    ///< GLO  to UTC using A0 = -TauC , A1 = 0
146          GPGA,    ///< GPS  to GAL using A0 = A0G   , A1 = A1G
147          GLGP,    ///< GLO  to GPS using A0 = -TauGPS, A1 = 0
148          QZGP,    ///< QZS  to GPS using A0, A1
149          QZUT,    ///< QZS  to UTC using A0, A1
150          BDUT,    ///< BDT  to UTC using A0, A1
151          BDGP,    ///< BDT  to GPS using A0, A1  // not in RINEX
152          IRUT,    ///< IRN  to UTC using A0, A1
153          IRGP     ///< IRN  to GPS using A0, A1
154 */
correctionTest(void)155    int correctionTest(void)
156    {
157       gpstk::TestUtil testFramework("TimeSystemCorr", "Correction", __FILE__, __LINE__);
158       std::string testMesg = "Incorrect time system correction value ";
159 
160          // Define a representative A0 and A1.  Define an epoch time and 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 = gpstk::CivilTime(2016, 1, 3, 0, 0, 0.0);
167 
168       gpstk::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       gpstk::TimeSystemCorrection tscTest = buildObject("GPUT");
174       timeOfInterest.setTimeSystem(gpstk::TimeSystem::GPS);
175       corrVal = tscTest.Correction(timeOfInterest);
176       testFramework.assert( std::abs(corrVal-forwardResult) < eps, testMesg, __LINE__);
177       timeOfInterest.setTimeSystem(gpstk::TimeSystem::UTC);
178       corrVal = tscTest.Correction(timeOfInterest);
179       testFramework.assert( std::abs(corrVal - (-forwardResult)) < eps, testMesg, __LINE__);
180 
181       tscTest = buildObject("GAUT");
182       timeOfInterest.setTimeSystem(gpstk::TimeSystem::GAL);
183       corrVal = tscTest.Correction(timeOfInterest);
184       testFramework.assert( std::abs(corrVal - forwardResult) < eps, testMesg, __LINE__);
185       timeOfInterest.setTimeSystem(gpstk::TimeSystem::UTC);
186       corrVal = tscTest.Correction(timeOfInterest);
187       testFramework.assert( std::abs(corrVal-(-forwardResult)) < eps, testMesg, __LINE__);
188 
189       tscTest = buildObject("QZUT");
190       timeOfInterest.setTimeSystem(gpstk::TimeSystem::QZS);
191       corrVal = tscTest.Correction(timeOfInterest);
192       testFramework.assert( std::abs(corrVal - forwardResult) < eps, testMesg, __LINE__);
193       timeOfInterest.setTimeSystem(gpstk::TimeSystem::UTC);
194       corrVal = tscTest.Correction(timeOfInterest);
195       testFramework.assert( std::abs(corrVal-(-forwardResult)) < eps, testMesg, __LINE__);
196 
197       tscTest = buildObject("BDUT");
198       timeOfInterest.setTimeSystem(gpstk::TimeSystem::BDT);
199       corrVal = tscTest.Correction(timeOfInterest);
200       testFramework.assert( std::abs(corrVal - forwardResult) < eps, testMesg, __LINE__);
201       timeOfInterest.setTimeSystem(gpstk::TimeSystem::UTC);
202       corrVal = tscTest.Correction(timeOfInterest);
203       testFramework.assert( std::abs(corrVal-(-forwardResult)) < eps, testMesg, __LINE__);
204 
205       tscTest = buildObject("IRUT");
206       timeOfInterest.setTimeSystem(gpstk::TimeSystem::IRN);
207       corrVal = tscTest.Correction(timeOfInterest);
208       testFramework.assert( std::abs(corrVal - forwardResult) < eps, testMesg, __LINE__);
209       timeOfInterest.setTimeSystem(gpstk::TimeSystem::UTC);
210       corrVal = tscTest.Correction(timeOfInterest);
211       testFramework.assert( std::abs(corrVal-(-forwardResult)) < eps, testMesg, __LINE__);
212 
213          // GLONASS is a little different in that the A1 term is not used
214       A1 = 0;
215       forwardResult = A0 + A1 * deltaT;
216       forwardResult = forwardResult * -1.0;    // This is a CORRECTION, not an error
217       tscTest = buildObject("GLUT");
218       timeOfInterest.setTimeSystem(gpstk::TimeSystem::GLO);
219       corrVal = tscTest.Correction(timeOfInterest);
220       testFramework.assert( std::abs(corrVal - forwardResult) < eps, testMesg, __LINE__);
221       timeOfInterest.setTimeSystem(gpstk::TimeSystem::UTC);
222       corrVal = tscTest.Correction(timeOfInterest);
223       testFramework.assert( std::abs(corrVal-(-forwardResult)) < eps, testMesg, __LINE__);
224 
225       return testFramework.countFails();
226    }
227 
buildObject(std::string str)228    gpstk::TimeSystemCorrection buildObject(std::string str)
229    {
230       gpstk::TimeSystemCorrection tsc(str);
231       tsc.refWeek = static_cast<gpstk::GPSWeekSecond>(tscRefTime).week;
232       tsc.refSOW = static_cast<gpstk::GPSWeekSecond>(tscRefTime).sow;
233       tsc.A0 = A0;
234       tsc.A1 = A1;
235 
236       return tsc;
237    }
238 
239 private:
240    double eps;
241 
242    double A0;
243    double A1;
244    double deltaT;
245    gpstk::CommonTime tscRefTime;
246 
247 };
248 
249 
main()250 int main() //Main function to initialize and run all tests above
251 {
252    TimeSystemCorr_T testClass;
253    int check, errorCounter = 0;
254 
255    check = testClass.initializationTest();
256    errorCounter += check;
257 
258    check = testClass.operatorTest();
259    errorCounter += check;
260 
261    check = testClass.correctionTest();
262    errorCounter += check;
263 
264    std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter << std::endl;
265 
266    return errorCounter; //Return the total number of errors
267 }
268