99 #include "NewNavInc.h"
100 #include <gnsstk/FileFilterFrameWithHeader.hpp>
101 #include <gnsstk/Rinex3ObsStream.hpp>
102 #include <gnsstk/Rinex3ObsFilterOperators.hpp>
103 #include <gnsstk/TimeString.hpp>
105 #include "DiffFrame.hpp"
107 #include <gnsstk/YDSTime.hpp>
116 static const int EXIST_ERROR = 2;
118 static const int DIFFS_CODE = 1;
120 : DiffFrame(arg0,
std::string(
"RINEX Obs")),
121 precisionOption(
'p',
"precision",
"Limit data comparison to n decimal"
122 " places. Default = 5")
124 virtual bool initialize(
int argc,
char* argv[])
throw();
127 virtual void process();
132 static const int DEFAULT_PRECISION = 5;
141 if (precisionOption.getCount())
143 precision = atoi(precisionOption.getValue()[0].c_str());
147 precision = DEFAULT_PRECISION;
155 ff1(inputFileOption.getValue()[0]), ff2(inputFileOption.getValue()[1]);
159 if (ff1.emptyHeader())
161 cerr <<
"No header information for " << inputFileOption.getValue()[0]
166 cerr <<
"No header information for " << inputFileOption.getValue()[1]
171 cerr <<
"Check that files exist." << endl;
172 cerr <<
"diff failed." << endl;
173 exitCode = EXIST_ERROR;
181 ros2(inputFileOption.getValue()[1]);
188 if (header1.version != header2.version)
190 cout <<
"File 1 and file 2 are not the same RINEX version" << endl;
195 if (header1.version < 3 && header2.version >= 3)
199 for (
const auto& r2it : header1.R2ObsTypes)
201 r3ov.push_back(header2.mapSysR2toR3ObsID[
"G"][r2it]);
203 header1.mapObsTypes[
"G"] = r3ov;
204 ff1.frontHeader().mapObsTypes[
"G"] = r3ov;
206 else if (header2.version < 3 && header1.version >= 3)
208 header1.prepareVer2Write();
210 for (
const auto& r2it : header2.R2ObsTypes)
212 r3ov.push_back(header1.mapSysR2toR3ObsID[
"G"][r2it]);
214 header2.mapObsTypes[
"G"] = r3ov;
221 cout <<
"Comparing the following fields:" << endl;
224 for (
const auto& mit : header1.mapObsTypes)
226 string sysChar = mit.first;
227 cout << sysChar <<
": ";
228 for (
const auto& id1 : mit.second)
232 header2.getObsIndex(sysChar, id1);
233 intersectRom[sysChar].push_back(id1);
234 cout <<
" " << id1.asString();
238 diffRom[sysChar].push_back(id1);
246 for (
const auto& mit : header2.mapObsTypes)
248 string sysChar = mit.first;
249 for (
const auto& id2 : mit.second)
253 header1.getObsIndex(sysChar, id2);
257 diffRom[sysChar].push_back(id2);
263 if (!diffRom.empty())
265 cout <<
"Ignoring unshared obs:" << endl;
266 for (
const auto& mit : diffRom)
268 string sysChar = mit.first;
269 cout << sysChar <<
": ";
270 for (
const auto&
id : mit.second)
272 cout <<
id.asString() <<
" ";
278 std::list<Rinex3ObsData> a =
281 std::list<Rinex3ObsData> b =
285 pair< list<Rinex3ObsData>, list<Rinex3ObsData> > difflist =
286 pair< list<Rinex3ObsData>, list<Rinex3ObsData> >( a, b);
288 if (difflist.first.empty() && difflist.second.empty())
292 cout <<
"For the observation types that were compared, "
293 <<
"no differences were found." << endl;
299 exitCode = DIFFS_CODE;
301 auto firstDiffItr = difflist.first.begin();
302 auto secondDiffItr = difflist.second.begin();
303 while ((firstDiffItr != difflist.first.end()) ||
304 (secondDiffItr != difflist.second.end()))
308 if ((firstDiffItr != difflist.first.end()) &&
309 ((secondDiffItr == difflist.second.end()) ||
310 (firstDiffItr->time < secondDiffItr->time)))
312 for (
const auto& firstObsItr : firstDiffItr->obs)
314 cout <<
"<" << setw(3) << (
static_cast<YDSTime>(firstDiffItr->time))
315 <<
' ' << setw(2) << firstObsItr.first <<
' ';
316 string sysString = string(1,firstObsItr.first.systemChar());
317 for (
const auto& romIt : intersectRom[sysString])
319 size_t idx = header1.getObsIndex(sysString, romIt);
320 cout << setw(15) << setprecision(3) << fixed
321 << firstObsItr.second[idx].data <<
' ' << romIt.asString()
329 else if ((secondDiffItr != difflist.second.end()) &&
330 ((firstDiffItr == difflist.first.end()) ||
331 (secondDiffItr->time < firstDiffItr->time)))
333 for (
const auto& secondObsItr : secondDiffItr->obs)
335 cout <<
">" << setw(3)
336 << (
static_cast<YDSTime>(secondDiffItr->time))
337 <<
' ' << setw(2) << secondObsItr.first <<
' ';
338 string sysString = string(1,secondObsItr.first.systemChar());
339 for (
const auto& romIt : intersectRom[sysString])
341 size_t idx = header2.getObsIndex(sysString, romIt);
342 cout << setw(15) << setprecision(3) << fixed
343 << secondObsItr.second[idx].data <<
' '
344 << romIt.asString() <<
' ';
350 else if (firstDiffItr->time == secondDiffItr->time)
352 auto firstObsItr = firstDiffItr->obs.begin();
353 auto secondObsItr = secondDiffItr->obs.begin();
355 while ((firstObsItr != firstDiffItr->obs.end()) ||
356 (secondObsItr != secondDiffItr->obs.end()))
359 if (firstObsItr->first == secondObsItr->first)
361 string sysString = string(1,firstObsItr->first.systemChar());
362 cout <<
"-" << setw(3)
363 << (
static_cast<YDSTime>(firstDiffItr->time))
364 <<
' ' << setw(2) << firstObsItr->first <<
' ';
365 for (
const auto& romIt : intersectRom[sysString])
367 size_t idx1 = header1.getObsIndex(sysString, romIt);
368 size_t idx2 = header2.getObsIndex(sysString, romIt);
369 cout << setw(15) << setprecision(3) << fixed
370 << (firstObsItr->second[idx1].data -
371 secondObsItr->second[idx2].data)
372 <<
' ' << romIt.asString() <<
' ';
378 else if ((firstObsItr != firstDiffItr->obs.end()) &&
379 ((secondObsItr == secondDiffItr->obs.end()) ||
380 (firstObsItr->first.id < secondObsItr->first.id)))
382 string sysString = string(1,firstObsItr->first.systemChar());
383 cout <<
"<" << setw(3)
384 << (
static_cast<YDSTime>(firstDiffItr->time))
385 <<
' ' << setw(2) << firstObsItr->first <<
' ';
386 for (
const auto& romIt : intersectRom[sysString])
388 size_t idx = header1.getObsIndex(sysString, romIt);
389 cout << setw(15) << setprecision(3) << fixed
390 << firstObsItr->second[idx].data <<
' '
391 << romIt.asString() <<
' ';
396 else if (secondObsItr != secondDiffItr->obs.end())
398 string sysString = string(1,secondObsItr->first.systemChar());
399 cout <<
">" << setw(3)
400 << (
static_cast<YDSTime>(secondDiffItr->time))
401 <<
' ' << setw(2) << secondObsItr->first <<
' ';
402 for (
const auto& romIt : intersectRom[sysString])
404 size_t idx = header2.getObsIndex(sysString, romIt);
405 cout << setw(15) << setprecision(3) << fixed
406 << secondObsItr->second[idx].data <<
' '
407 << romIt.asString() <<
' ';
420 int main(
int argc,
char* argv[])
422 #include "NewNavInit.h"
437 catch(std::exception& e)
439 cout << e.
what() << endl;
443 cout <<
"unknown error" << endl;
446 return BasicFramework::EXCEPTION_ERROR;