NewNavToRinex_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 "DebugTrace.hpp"
40 #include "BasicFramework.hpp"
41 #include "RinexNavDataFactory.hpp"
42 #include "NewNavToRinex.hpp"
43 #include "TimeString.hpp"
44 
45 using namespace std;
46 using namespace gnsstk;
47 
50 {
51 public:
52  bool process(const NavDataPtr& navOut) override
53  {
55  DEBUGTRACE("signal=" << navOut->signal);
56  if (navOut->signal.messageType == NavMessageType::Health)
57  {
58  DEBUGTRACE(printTime(navOut->timeStamp,
59  "time=%Y/%02m/%02d %02H:%02M:%02S"));
60  //navOut->dump(cerr, DumpDetail::Full);
61  healthGet.healthMap[navOut->signal][navOut->timeStamp] = navOut;
62  }
63  ndlist.push_back(navOut);
64  return true;
65  }
66 
69 };
70 
77 {
78 public:
79  NewNavToRinex_T(const string& applName);
80 
81  bool initialize(int argc, char *argv[], bool pretty=true) noexcept override;
82 
83  void process() override;
84 
86 };
87 
88 
90 NewNavToRinex_T(const string& applName)
91  : BasicFramework(applName, "Execute a basic round-trip conversion using"
92  " NewNavToRinex"),
93  restOpt("input-file output-file", true)
94 {
96 }
97 
98 
100 initialize(int argc, char *argv[], bool pretty) noexcept
101 {
102  if (!BasicFramework::initialize(argc, argv, pretty))
103  {
104  return false;
105  }
106  if (debugLevel)
107  {
109  }
110  if (restOpt.getCount() != 2)
111  {
112  cerr << "Must have exactly two file arguments specified." << endl;
113  exitCode = BasicFramework::OPTION_ERROR;
114  return false;
115  }
116  return true;
117 }
118 
119 
122 {
123  Rinex3NavStream strm;
124  RinexNavDataFactory fact;
125  NavDataStore store;
126  NewNavToRinex writer;
127  // Just use the ones needed for RINEX conversion
128  fact.setTypeFilter({NavMessageType::Ephemeris,
129  NavMessageType::Iono,
130  NavMessageType::TimeOffset,
131  NavMessageType::Health});
132  // Get the header for re-use in the output.
133  strm.open(restOpt.getValue()[0].c_str(), ios::in);
134  if (!strm)
135  {
136  cerr << "Could not open \"" << restOpt.getValue()[0] << "\" for input"
137  << endl;
138  exitCode = BasicFramework::EXIST_ERROR;
139  return;
140  }
141  strm >> writer.header;
142  if (!strm)
143  {
144  cerr << "Failed to read RINEX header from \"" << restOpt.getValue()[0]
145  << endl;
146  exitCode = BasicFramework::GENERAL_ERROR;
147  return;
148  }
149  strm.close();
150  if (!fact.process(restOpt.getValue()[0], store))
151  {
152  cerr << "Unable to process RINEX input file \"" << restOpt.getValue()[0]
153  << "\"" << endl
154  << "Is it valid RINEX?" << endl;
155  exitCode = BasicFramework::OPTION_ERROR;
156  return;
157  }
158  cerr << "Stored " << store.ndlist.size() << " NavData objects" << endl;
159  if (!writer.translate(store.ndlist, store.healthGet))
160  {
161  cerr << "Failed to translate data back into RINEX" << endl;
162  exitCode = BasicFramework::GENERAL_ERROR;
163  return;
164  }
165  if (!writer.write(restOpt.getValue()[1]))
166  {
167  cerr << "Failed to write RINEX output file \"" << restOpt.getValue()[1]
168  << "\"" << endl;
169  exitCode = BasicFramework::GENERAL_ERROR;
170  return;
171  }
172  cout << "Done." << endl;
173 }
174 
175 
176 int main(int argc, char *argv[])
177 {
178  try
179  {
180  NewNavToRinex_T app(argv[0]);
181  if (!app.initialize(argc, argv))
182  {
183  return app.exitCode;
184  }
185  app.run();
186  return app.exitCode;
187  }
188  catch(gnsstk::Exception& e)
189  {
190  cout << e << endl;
191  }
192  catch(std::exception& e)
193  {
194  cout << e.what() << endl;
195  }
196  catch(...)
197  {
198  cout << "unknown error" << endl;
199  }
200  // only reach this point if an exception was caught
202 }
gnsstk::NavDataPtr
std::shared_ptr< NavData > NavDataPtr
Factories instantiate these in response to find() requests.
Definition: NavData.hpp:62
NewNavToRinex_T::NewNavToRinex_T
NewNavToRinex_T(const string &applName)
Definition: NewNavToRinex_T.cpp:90
gnsstk::NewNavToRinex
Definition: NewNavToRinex.hpp:103
main
int main(int argc, char *argv[])
Definition: NewNavToRinex_T.cpp:176
NewNavToRinex_T
Definition: NewNavToRinex_T.cpp:76
gnsstk::Rinex3NavStream
Definition: Rinex3NavStream.hpp:62
gnsstk::NewNavToRinex::translate
bool translate(const NavDataPtrList &data, HealthGetter &healthGet)
Definition: NewNavToRinex.cpp:59
NewNavToRinex_T::process
void process() override
Definition: NewNavToRinex_T.cpp:121
DEBUGTRACE
#define DEBUGTRACE(EXPR)
Definition: DebugTrace.hpp:119
gnsstk::CommandOptionRest
CommandOption to take the rest of the command line.
Definition: CommandOption.hpp:457
gnsstk::NewNavToRinex::header
Rinex3NavHeader header
The header that will be used by translate() and write().
Definition: NewNavToRinex.hpp:226
gnsstk::Exception::what
std::string what() const
Dump to a string.
Definition: Exception.cpp:193
gnsstk::NavDataPtrList
std::list< NavDataPtr > NavDataPtrList
Definition: NavData.hpp:75
gnsstk::NewNavToRinex::write
bool write(const std::string &filename)
Definition: NewNavToRinex.cpp:101
gnsstk::BasicFramework::EXCEPTION_ERROR
static const int EXCEPTION_ERROR
Definition: BasicFramework.hpp:392
gnsstk::Rinex3NavStream::open
virtual void open(const char *fn, std::ios::openmode mode)
overrides open to reset the header
Definition: Rinex3NavStream.cpp:70
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
NewNavToRinex_T::restOpt
CommandOptionRest restOpt
Definition: NewNavToRinex_T.cpp:85
NavDataStore::ndlist
NavDataPtrList ndlist
Definition: NewNavToRinex_T.cpp:67
gnsstk::NavDataFactoryCallback
Definition: NavDataFactoryCallback.hpp:54
gnsstk::Exception
Definition: Exception.hpp:151
NewNavToRinex.hpp
initialize
int initialize(string &errors)
Definition: RinEdit.cpp:513
gnsstk::BasicFramework
Definition: BasicFramework.hpp:387
NewNavToRinex_T::initialize
bool initialize(int argc, char *argv[], bool pretty=true) noexcept override
Definition: NewNavToRinex_T.cpp:100
gnsstk::BasicFramework::run
bool run() noexcept
Definition: BasicFramework.cpp:126
gnsstk::HealthGetter
Definition: NewNavToRinex.hpp:57
gnsstk::printTime
std::string printTime(const CommonTime &t, const std::string &fmt)
Definition: TimeString.cpp:64
DebugTrace.hpp
BasicFramework.hpp
std
Definition: Angle.hpp:142
DEBUGTRACE_ENABLE
#define DEBUGTRACE_ENABLE()
Definition: DebugTrace.hpp:107
gnsstk::BasicFramework::exitCode
int exitCode
Definition: BasicFramework.hpp:450
gnsstk::CommandOption::getValue
const std::vector< std::string > & getValue() const
Definition: CommandOption.hpp:194
gnsstk::RinexNavDataFactory
Definition: RinexNavDataFactory.hpp:57
gnsstk::RinexNavDataFactory::process
bool process(const std::string &filename, NavDataFactoryCallback &cb) override
Definition: RinexNavDataFactory.cpp:116
DEBUGTRACE_FUNCTION
#define DEBUGTRACE_FUNCTION()
Definition: DebugTrace.hpp:117
NavDataStore::process
bool process(const NavDataPtr &navOut) override
Definition: NewNavToRinex_T.cpp:52
NavDataStore::healthGet
HealthGetter healthGet
Definition: NewNavToRinex_T.cpp:68
gnsstk::NavDataFactory::setTypeFilter
virtual void setTypeFilter(const NavMessageTypeSet &nmts)
Definition: NavDataFactory.hpp:139
TimeString.hpp
NavDataStore
Simple storage callback for use by NewNavToRinex.
Definition: NewNavToRinex_T.cpp:49
gnsstk::CommandOption::setMaxCount
CommandOption & setMaxCount(const unsigned long l)
Definition: CommandOption.hpp:164
RinexNavDataFactory.hpp


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