RinexObs_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 "RinexObsBase.hpp"
40 #include "RinexObsData.hpp"
41 #include "RinexObsStream.hpp"
42 #include "RinexObsHeader.hpp"
44 
45 #include "build_config.h"
46 
47 #include "TestUtil.hpp"
48 #include <iostream>
49 #include <string>
50 
51 using namespace gnsstk;
52 
53 //============================================================
54 // Class decalarations
55 //============================================================
56 
58 {
59 public:
60 
61  // constructor
63  {
64  init();
65  }
66 
67  // return values indicate number of failures, i.e., 0=PASS, !0=FAIL
68  void init( void );
69  int headerExceptionTest( void );
70  int hardCodeTest( void );
71  int filterOperatorsTest( void );
72  int dataExceptionsTest( void );
73 
74 private:
75 
76  std::string dataFilePath;
77 
78  std::string dataRinexObsFile;
79  std::string dataIncompleteHeader;
80  std::string dataInvalidLineLength;
82  std::string dataNotObs;
83  std::string dataSystemGeosync;
84  std::string dataSystemGlonass;
85  std::string dataSystemMixed;
86  std::string dataSystemTransit;
87  std::string dataUnSupVersion ;
88  std::string dataRinexContData;
89 
90  std::string dataBadEpochLine;
91  std::string dataBadEpochFlag;
92  std::string dataBadLineSize;
93  std::string dataInvalidTimeFormat;
94 
95  std::string dataFilterTest1;
96  std::string dataFilterTest2;
97  std::string dataFilterTest3;
98  std::string dataFilterTest4;
99 
100  std::string dataTestOutput;
101  std::string dataTestOutput2;
102  std::string dataTestOutput3;
105  std::string dataTestFilterOutput;
106 };
107 
108 //============================================================
109 // Initialize Test Data Filenames
110 //============================================================
111 
112 void RinexObs_T :: init( void )
113 {
114 
115  TestUtil test0;
116  std::string dataFilePath = gnsstk::getPathData();
117  std::string tempFilePath = gnsstk::getPathTestTemp
118  ();
119 
120  //----------------------------------------
121  // Full file paths
122  //----------------------------------------
123  std::string file_sep = getFileSep();
124 
125  dataRinexObsFile = dataFilePath + file_sep +
126  "test_input_rinex_obs_RinexObsFile.06o";
127  dataIncompleteHeader = dataFilePath + file_sep +
128  "test_input_rinex_obs_IncompleteHeader.06o";
129  dataInvalidLineLength = dataFilePath + file_sep +
130  "test_input_rinex_obs_InvalidLineLength.06o";
131  dataInvalidNumPRNWaveFact = dataFilePath + file_sep +
132  "test_input_rinex_obs_InvalidNumPRNWaveFact.06o";
133  dataNotObs = dataFilePath + file_sep +
134  "test_input_rinex_obs_NotObs.06o";
135  dataSystemGeosync = dataFilePath + file_sep +
136  "test_input_rinex_obs_SystemGeosync.06o";
137  dataSystemGlonass = dataFilePath + file_sep +
138  "test_input_rinex_obs_SystemGlonass.06o";
139  dataSystemMixed = dataFilePath + file_sep +
140  "test_input_rinex_obs_SystemMixed.06o";
141  dataSystemTransit = dataFilePath + file_sep +
142  "test_input_rinex_obs_SystemTransit.06o";
143  dataUnSupVersion = dataFilePath + file_sep +
144  "test_input_rinex_obs_UnSupVersion.06o";
145  dataRinexContData = dataFilePath + file_sep +
146  "test_input_rinex_obs_RinexContData.06o";
147 
148  dataBadEpochLine = dataFilePath + file_sep +
149  "test_input_rinex_obs_BadEpochLine.06o";
150  dataBadEpochFlag = dataFilePath + file_sep +
151  "test_input_rinex_obs_BadEpochFlag.06o";
152  dataBadLineSize = dataFilePath + file_sep +
153  "test_input_rinex_obs_BadLineSize.06o";
154  dataInvalidTimeFormat = dataFilePath + file_sep +
155  "test_input_rinex_obs_InvalidTimeFormat.06o";
156 
157  dataFilterTest1 = dataFilePath + file_sep +
158  "test_input_rinex_obs_FilterTest1.06o";
159  dataFilterTest2 = dataFilePath + file_sep +
160  "test_input_rinex_obs_FilterTest2.06o";
161  dataFilterTest3 = dataFilePath + file_sep +
162  "test_input_rinex_obs_FilterTest3.06o";
163  dataFilterTest4 = dataFilePath + file_sep +
164  "test_input_rinex_obs_FilterTest4.06o";
165 
166  dataTestOutput = tempFilePath + file_sep +
167  "test_output_rinex_obs_TestOutput.06o";
168  dataTestOutput2 = tempFilePath + file_sep +
169  "test_output_rinex_obs_TestOutput2.06o";
170  dataTestOutput3 = tempFilePath + file_sep +
171  "test_output_rinex_obs_TestOutput3.06o";
172  dataTestOutputObsDump = tempFilePath + file_sep +
173  "test_output_rinex_obs_ObsDump.06o";
174  dataTestOutputDataException = tempFilePath + file_sep +
175  "test_output_rinex_obs_DataExceptionOutput.06o";
176  dataTestFilterOutput = tempFilePath + file_sep +
177  "test_output_rinex_obs_FilterOutput.txt";
178 
179 }
180 
181 //============================================================
182 // Test Method Definitions
183 //============================================================
184 
185 //------------------------------------------------------------
186 // This tests throws many GNSSTK RinexObsHeader exceptions including
187 // Incomplete headers, invalid line lengths etc
188 // Also an extended obs type is used and dumped within this test.
189 //------------------------------------------------------------
191 {
192 
193  TUDEF( "RinexObsStream", "dump" );
194 
195  std::string msg_test_desc = "RinexObsStream, headerExceptionTest";
196  std::string msg_false_pass = ", threw the wrong number of exceptions.";
197  std::string msg_fail = ", threw an unexpected exception.";
198 
199  try
200  {
201 
202  gnsstk::RinexObsStream RinexObsFile( dataRinexObsFile );
203  gnsstk::RinexObsStream ih( dataIncompleteHeader );
204  gnsstk::RinexObsStream il( dataInvalidLineLength );
205  gnsstk::RinexObsStream inpwf( dataInvalidNumPRNWaveFact );
206  gnsstk::RinexObsStream no( dataNotObs );
207  gnsstk::RinexObsStream ss( dataSystemGeosync );
208  gnsstk::RinexObsStream sr( dataSystemGlonass );
209  gnsstk::RinexObsStream sm( dataSystemMixed );
210  gnsstk::RinexObsStream st( dataSystemTransit );
211  gnsstk::RinexObsStream unsupv( dataUnSupVersion );
212  gnsstk::RinexObsStream contdata( dataRinexContData );
213 
214  gnsstk::RinexObsStream out( dataTestOutput, std::ios::out );
215  gnsstk::RinexObsStream out2( dataTestOutput3, std::ios::out );
216  gnsstk::RinexObsStream dump( dataTestOutputObsDump, std::ios::out );
217 
218  gnsstk::RinexObsHeader RinexObsFileh;
221  gnsstk::RinexObsHeader inpwfh;
227  gnsstk::RinexObsHeader unsupvh;
228  gnsstk::RinexObsHeader contdatah;
229 
230  gnsstk::RegisterExtendedRinexObsType( "ER","Testing Type", "Candela",
231  (unsigned) 2 );
232  gnsstk::RinexObsData RinexObsFiled;
233  gnsstk::RinexObsData contdatad;
234 
235  RinexObsFile >> RinexObsFileh;
236  ih >> ihh;
237  il >> ilh;
238  inpwf >> inpwfh;
239  no >> noh;
240  ss >> ssh;
241  sr >> srh;
242  sm >> smh;
243  unsupv >> unsupvh;
244  contdata >> contdatah;
245 
246  out << RinexObsFileh;
247  out << ihh;
248  out << ilh;
249  out << inpwfh;
250  out << noh;
251  out << ssh;
252  out << srh;
253  out << smh;
254  out << unsupvh;
255  out2 << contdatah;
256  RinexObsFile >> RinexObsFiled;
257  RinexObsFiled.dump( dump );
258 
259  while( RinexObsFile >> RinexObsFiled )
260  {
261  out << RinexObsFiled;
262  }
263 
264  while( contdata >> contdatad )
265  {
266  out2 << contdatad;
267  }
268 
269  RinexObsFileh.dump( dump );
270  contdatah.dump( dump );
271  ilh.dump( dump );
273 
274  testFramework.assert( 39 == RinexObsFileh.NumberHeaderRecordsToBeWritten(),
275  msg_test_desc + msg_false_pass, __LINE__ );
276  }
277  catch(...)
278  {
279  testFramework.assert( false, msg_test_desc + msg_fail, __LINE__ );
280  }
281 
282  return( testFramework.countFails() );
283 }
284 
285 
286 //------------------------------------------------------------
287 // This test checks to make sure that the output
288 // from a read in RinexObsFile matches the input.
289 //------------------------------------------------------------
291 {
292 
293  bool files_equal = false;
294 
295  // Previous comments indicated that these Rinex methods
296  // are not expected to match in the top two lines of the file
297  int num_lines_skip = 2;
298 
299  TUDEF( "RinexObsStream", "dump" );
300 
301  std::string msg_test_desc =
302  "RinexObsStream, read write test, comparing input file and output file";
303  std::string msg_fail_equal = ", input and output do not match.";
304  std::string msg_fail_except = ", threw an unexpected exception.";
305 
306  try
307  {
308  gnsstk::RinexObsStream RinexObsFile( dataRinexObsFile );
309  gnsstk::RinexObsStream out( dataTestOutput2, std::ios::out );
310  gnsstk::RinexObsStream dump( dataTestOutputObsDump, std::ios::out );
311  gnsstk::RinexObsHeader RinexObsFileh;
312  gnsstk::RinexObsData RinexObsFiled;
313 
314  RinexObsFile >> RinexObsFileh;
315  out << RinexObsFileh;
316 
317  while( RinexObsFile >> RinexObsFiled )
318  {
319  out << RinexObsFiled;
320  }
321 
322  RinexObsFiled.dump( dump );
323  RinexObsFileh.dump( dump );
324 
325  files_equal = testFramework.fileEqualTest( dataRinexObsFile, dataTestOutput2,
326  num_lines_skip );
327  testFramework.assert( files_equal, msg_test_desc + msg_fail_equal, __LINE__ );
328  }
329  catch(...)
330  {
331  testFramework.assert( false, msg_test_desc + msg_fail_except, __LINE__ );
332  }
333 
334  return( testFramework.countFails() );
335 }
336 
337 //------------------------------------------------------------
338 // This test throws many GNSSTK exceptions within the
339 // RinexObsData, including BadEpochLine and BadEpochFlag
340 //------------------------------------------------------------
342 {
343 
344  TUDEF( "RinexObsStream", "dump" );
345 
346  std::string msg_test_desc =
347  "RinexObsStream, test various gnsstk exception throws, including BadEpochLine and BadEpochFlag";
348  std::string msg_fail_throw =
349  ", not all gnsstk exceptions were thrown as expected.";
350  std::string msg_fail_except = ", threw an unexpected exception.";
351 
352  try
353  {
354  gnsstk::RinexObsStream BadEpochLine( dataBadEpochLine );
355  gnsstk::RinexObsStream BadEpochFlag( dataBadEpochFlag );
356  gnsstk::RinexObsStream BadLineSize( dataBadLineSize );
357  gnsstk::RinexObsStream InvalidTimeFormat( dataInvalidTimeFormat );
358  gnsstk::RinexObsStream out( dataTestOutputDataException, std::ios::out );
359  gnsstk::RinexObsData BadEpochLined;
360  gnsstk::RinexObsData BadEpochFlagd;
361  gnsstk::RinexObsData BadLineSized;
362  gnsstk::RinexObsData InvalidTimeFormatd;
363 
364  while( BadEpochLine >> BadEpochLined )
365  {
366  out << BadEpochLined;
367  }
368  while( BadEpochFlag >> BadEpochFlagd )
369  {
370  out << BadEpochFlagd;
371  }
372  while( BadLineSize >> BadLineSized )
373  {
374  out << BadLineSized;
375  }
376  while( InvalidTimeFormat >> InvalidTimeFormatd )
377  {
378  out << InvalidTimeFormatd;
379  }
380  testFramework.assert( true, msg_test_desc + msg_fail_throw, __LINE__ );
381  }
382  catch(...)
383  {
384  testFramework.assert( false, msg_test_desc + msg_fail_except, __LINE__ );
385  }
386 
387  return( testFramework.countFails() );
388 
389 }
390 
391 //------------------------------------------------------------
392 // This is the test for several of the members within RinexObsFilterOperators
393 // including merge, LessThanSimple, EqualsSimple, and LessThanFull.
394 //------------------------------------------------------------
396 {
397 
398  TUDEF( "RinexObsStream", "open" );
399 
400  std::string msg_test_desc = "";
401 
402  try
403  {
404  gnsstk::RinexObsStream FilterStream1( dataFilterTest1 );
405  FilterStream1.open( dataFilterTest1, std::ios::in );
406 
407  gnsstk::RinexObsStream FilterStream2( dataFilterTest2 );
408  gnsstk::RinexObsStream FilterStream3( dataFilterTest3 );
409  gnsstk::RinexObsStream FilterStream4( dataFilterTest4 );
410  gnsstk::RinexObsStream out( dataTestFilterOutput, std::ios::out );
411 
412  gnsstk::RinexObsHeader FilterHeader1;
413  gnsstk::RinexObsHeader FilterHeader2;
414  gnsstk::RinexObsHeader FilterHeader3;
415  gnsstk::RinexObsHeader FilterHeader4;
416 
417  gnsstk::RinexObsData FilterData1;
418  gnsstk::RinexObsData FilterData2;
419  gnsstk::RinexObsData FilterData3;
420  gnsstk::RinexObsData FilterData4;
421  gnsstk::RinexObsData rodata;
422 
423 
424  FilterStream1 >> FilterHeader1;
425  FilterStream2 >> FilterHeader2;
426  FilterStream3 >> FilterHeader3;
427  FilterStream4 >> FilterHeader4;
428 
429  while( FilterStream1 >> rodata)
430  {
431  FilterData1 = rodata;
432  }
433  while( FilterStream2 >> rodata)
434  {
435  FilterData2 = rodata;
436  }
437  while( FilterStream3 >> rodata)
438  {
439  FilterData3 = rodata;
440  }
441  while( FilterStream4 >> rodata)
442  {
443  FilterData4 = rodata;
444  }
445 
447  merged( FilterHeader1 );
448  merged( FilterHeader2 );
449 
451  out << merged.theHeader;
452 
454  msg_test_desc =
455  "RinexObsDataOperatorEqualsSimple( FilterData1, FilterData1 ), should evaluate as true";
456  testFramework.assert( EqualsSimple( FilterData1, FilterData1 ), msg_test_desc,
457  __LINE__ );
458 
460  msg_test_desc =
461  "RinexObsDataOperatorLessThanSimple( FilterData1, FilterData1 ) should evaluated as false";
462  testFramework.assert( !LessThanSimple( FilterData1, FilterData1 ),
463  msg_test_desc, __LINE__ );
464 
465  gnsstk::RinexObsDataOperatorLessThanFull LessThanFull( merged.obsSet );
466  msg_test_desc =
467  "RinexObsDataOperator LessThanFull( FilterData1, FilterData1 ) should evaluate as false ";
468  testFramework.assert( !LessThanFull( FilterData1, FilterData1 ) ,
469  msg_test_desc, __LINE__ );
470 
471  msg_test_desc =
472  " RinexObsDataOperator LessThanFull( FilterData1, FilterData2 ) should evaluate as false ";
473  testFramework.assert( !LessThanFull( FilterData1, FilterData2 ) ,
474  msg_test_desc, __LINE__ );
475 
476  }
477  catch(...)
478  {
479  msg_test_desc =
480  "One or more of the tests for RinexObsDataOperator LessThanFull threw an exception when it should not have";
481  testFramework.assert( false, msg_test_desc, __LINE__ );
482  }
483 
484  return( testFramework.countFails() );
485 
486 }
487 
488 //============================================================
489 // Run all the test methods defined above
490 //============================================================
491 
492 int main()
493 {
494  int errorTotal = 0;
495  RinexObs_T testClass;
496 
497  errorTotal += testClass.headerExceptionTest();
498  errorTotal += testClass.hardCodeTest();
499  errorTotal += testClass.dataExceptionsTest();
500  errorTotal += testClass.filterOperatorsTest();
501 
502  std::cout << "Total Failures for " << __FILE__ << ": " << errorTotal
503  << std::endl;
504 
505  return( errorTotal );
506 }
gnsstk::RinexObsStream
Definition: RinexObsStream.hpp:67
RinexObs_T::init
void init(void)
Definition: RinexObs_T.cpp:112
gnsstk::dump
void dump(vector< SatPass > &SatPassList, ostream &os, bool rev, bool dbug)
Definition: SatPassUtilities.cpp:59
gnsstk::RinexObsDataOperatorLessThanSimple
Definition: RinexObsFilterOperators.hpp:161
RinexObs_T::filterOperatorsTest
int filterOperatorsTest(void)
Definition: RinexObs_T.cpp:395
main
int main()
Definition: RinexObs_T.cpp:492
RinexObs_T::dataTestFilterOutput
std::string dataTestFilterOutput
Definition: RinexObs_T.cpp:105
dataFilePath
string dataFilePath
Definition: Rinex3Obs_FromScratch_T.cpp:51
RinexObsStream.hpp
RinexObs_T::dataFilePath
std::string dataFilePath
Definition: RinexObs_T.cpp:76
RinexObs_T
Definition: RinexObs_T.cpp:57
RinexObs_T::dataUnSupVersion
std::string dataUnSupVersion
Definition: RinexObs_T.cpp:87
RinexObs_T::dataInvalidTimeFormat
std::string dataInvalidTimeFormat
Definition: RinexObs_T.cpp:93
RinexObs_T::dataSystemGlonass
std::string dataSystemGlonass
Definition: RinexObs_T.cpp:84
RinexObs_T::dataExceptionsTest
int dataExceptionsTest(void)
Definition: RinexObs_T.cpp:341
RinexObs_T::dataTestOutput3
std::string dataTestOutput3
Definition: RinexObs_T.cpp:102
RinexObsFilterOperators.hpp
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::RegisterExtendedRinexObsType
int RegisterExtendedRinexObsType(string t, string d, string u, unsigned int dep)
Definition: RinexObsHeader.cpp:969
RinexObs_T::dataBadEpochLine
std::string dataBadEpochLine
Definition: RinexObs_T.cpp:90
RinexObs_T::dataSystemGeosync
std::string dataSystemGeosync
Definition: RinexObs_T.cpp:83
RinexObs_T::dataTestOutputObsDump
std::string dataTestOutputObsDump
Definition: RinexObs_T.cpp:103
RinexObs_T::dataBadLineSize
std::string dataBadLineSize
Definition: RinexObs_T.cpp:92
RinexObs_T::dataSystemMixed
std::string dataSystemMixed
Definition: RinexObs_T.cpp:85
TestUtil.hpp
RinexObs_T::dataFilterTest2
std::string dataFilterTest2
Definition: RinexObs_T.cpp:96
gnsstk::RinexObsDataOperatorEqualsSimple
Definition: RinexObsFilterOperators.hpp:177
RinexObs_T::dataTestOutputDataException
std::string dataTestOutputDataException
Definition: RinexObs_T.cpp:104
RinexObs_T::dataRinexContData
std::string dataRinexContData
Definition: RinexObs_T.cpp:88
gnsstk::DisplayExtendedRinexObsTypes
void DisplayExtendedRinexObsTypes(ostream &s)
Definition: RinexObsHeader.cpp:1002
RinexObs_T::dataRinexObsFile
std::string dataRinexObsFile
Definition: RinexObs_T.cpp:78
gnsstk::RinexObsHeaderTouchHeaderMerge
Definition: RinexObsFilterOperators.hpp:198
gnsstk::RinexObsHeaderTouchHeaderMerge::obsSet
std::set< gnsstk::RinexObsType > obsSet
Definition: RinexObsFilterOperators.hpp:255
RinexObs_T::dataTestOutput2
std::string dataTestOutput2
Definition: RinexObs_T.cpp:101
RinexObsBase.hpp
gnsstk::RinexObsHeaderTouchHeaderMerge::theHeader
gnsstk::RinexObsHeader theHeader
Definition: RinexObsFilterOperators.hpp:254
file_sep
string file_sep
Definition: Rinex3Obs_FromScratch_T.cpp:52
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
RinexObsData.hpp
RinexObs_T::RinexObs_T
RinexObs_T()
Definition: RinexObs_T.cpp:62
RinexObsHeader.hpp
RinexObs_T::dataFilterTest4
std::string dataFilterTest4
Definition: RinexObs_T.cpp:98
gnsstk::RinexObsData::dump
virtual void dump(std::ostream &s) const
Definition: RinexObsData.cpp:443
RinexObs_T::dataFilterTest3
std::string dataFilterTest3
Definition: RinexObs_T.cpp:97
RinexObs_T::dataSystemTransit
std::string dataSystemTransit
Definition: RinexObs_T.cpp:86
gnsstk::RinexObsStream::open
virtual void open(const char *fn, std::ios::openmode mode)
Definition: RinexObsStream.cpp:80
RinexObs_T::dataIncompleteHeader
std::string dataIncompleteHeader
Definition: RinexObs_T.cpp:79
RinexObs_T::hardCodeTest
int hardCodeTest(void)
Definition: RinexObs_T.cpp:290
RinexObs_T::dataBadEpochFlag
std::string dataBadEpochFlag
Definition: RinexObs_T.cpp:91
RinexObs_T::dataNotObs
std::string dataNotObs
Definition: RinexObs_T.cpp:82
RinexObs_T::dataTestOutput
std::string dataTestOutput
Definition: RinexObs_T.cpp:100
RinexObs_T::dataFilterTest1
std::string dataFilterTest1
Definition: RinexObs_T.cpp:95
gnsstk::RinexObsHeader
Definition: RinexObsHeader.hpp:107
gnsstk::RinexObsDataOperatorLessThanFull
Definition: RinexObsFilterOperators.hpp:61
gnsstk::RinexObsData
Definition: RinexObsData.hpp:68
RinexObs_T::dataInvalidLineLength
std::string dataInvalidLineLength
Definition: RinexObs_T.cpp:80
gnsstk::TestUtil
Definition: TestUtil.hpp:265
RinexObs_T::headerExceptionTest
int headerExceptionTest(void)
Definition: RinexObs_T.cpp:190
tempFilePath
string tempFilePath
Definition: Rinex3Obs_FromScratch_T.cpp:50
RinexObs_T::dataInvalidNumPRNWaveFact
std::string dataInvalidNumPRNWaveFact
Definition: RinexObs_T.cpp:81


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