RinexUtilities.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 
41 
42 // system includes
43 #include <map>
44 
45 // GNSSTk includes
46 #include "RinexObsStream.hpp"
47 #include "RinexObsHeader.hpp"
48 #include "RinexNavStream.hpp"
49 #include "RinexNavHeader.hpp"
50 #include "RinexNavData.hpp"
51 
52 #include "Rinex3ObsStream.hpp"
53 #include "Rinex3ObsHeader.hpp"
54 #include "Rinex3NavStream.hpp"
55 #include "Rinex3NavHeader.hpp"
56 #include "Rinex3NavData.hpp"
57 
58 #include "SP3Stream.hpp"
59 #include "SP3Header.hpp"
60 
61 #include "RinexUtilities.hpp"
62 
63 namespace gnsstk {
64 
65 using namespace std;
66 using namespace gnsstk;
67 
68 //------------------------------------------------------------------------------
70 {
71 try {
72  unsigned int EPPS = //0x60
74  unsigned int L1L2 = //0x06
76  unsigned int P1P2 = //0x18
78  unsigned int EPEP=RinexObsType::EPdepend;//0x20
79  unsigned int PELL=EPPS | L1L2;//0x66
80  unsigned int PEPP=EPPS | P1P2;//0x78
81  unsigned int PsLs=L1L2 | P1P2;//0x1E
82  unsigned int L1P1 = //0x0A
84  unsigned int L2P2 = //0x14
86  int j;
87  j = RegisterExtendedRinexObsType("ER","Ephemeris range", "meters", EPPS);
88  if(j) return j;
89  j = RegisterExtendedRinexObsType("RI","Iono Delay, Range", "meters", P1P2);
90  if(j) return j;
91  j = RegisterExtendedRinexObsType("PI","Iono Delay, Phase", "meters", L1L2);
92  if(j) return j;
93  j = RegisterExtendedRinexObsType("TR","Tropospheric Delay", "meters", EPPS);
94  if(j) return j;
95  j = RegisterExtendedRinexObsType("RL","Relativity Correct.", "meters", EPEP);
96  if(j) return j;
97  j = RegisterExtendedRinexObsType("SC","SV Clock Bias", "meters", EPEP);
98  if(j) return j;
99  j = RegisterExtendedRinexObsType("EL","Elevation Angle", "degrees",EPPS);
100  if(j) return j;
101  j = RegisterExtendedRinexObsType("AZ","Azimuth Angle", "degrees",EPPS);
102  if(j) return j;
103  j = RegisterExtendedRinexObsType("SR","Slant TEC (PR)", "TECU", P1P2);
104  if(j) return j;
105  j = RegisterExtendedRinexObsType("SP","Slant TEC (Ph)", "TECU", L1L2);
106  if(j) return j;
107  j = RegisterExtendedRinexObsType("VR","Vertical TEC (PR)", "TECU", PEPP);
108  if(j) return j;
109  j = RegisterExtendedRinexObsType("VP","Vertical TEC (Ph)", "TECU", PELL);
110  if(j) return j;
111  j = RegisterExtendedRinexObsType("LA","Lat Iono Intercept", "degrees",EPPS);
112  if(j) return j;
113  j = RegisterExtendedRinexObsType("LO","Lon Iono Intercept", "degrees",EPPS);
114  if(j) return j;
115  j = RegisterExtendedRinexObsType("P3","TFC(IF) Pseudorange", "meters", P1P2);
116  if(j) return j;
117  j = RegisterExtendedRinexObsType("L3","TFC(IF) Phase", "meters", L1L2);
118  if(j) return j;
119  j = RegisterExtendedRinexObsType("PF","GeoFree Pseudorange", "meters", P1P2);
120  if(j) return j;
121  j = RegisterExtendedRinexObsType("LF","GeoFree Phase", "meters", L1L2);
122  if(j) return j;
123  j = RegisterExtendedRinexObsType("PW","WideLane Pseudorange","meters", P1P2);
124  if(j) return j;
125  j = RegisterExtendedRinexObsType("LW","WideLane Phase", "meters", L1L2);
126  if(j) return j;
127  j = RegisterExtendedRinexObsType("MP","Multipath (=M3)", "meters", PsLs);
128  if(j) return j;
129  j = RegisterExtendedRinexObsType("R1","(P1 + L1)/2" ,"meters", L1P1);
130  if(j) return j;
131  j = RegisterExtendedRinexObsType("R2","(P2 + L2)/2" ,"meters", L2P2);
132  if(j) return j;
133  j = RegisterExtendedRinexObsType("M1","L1 Range minus Phase","meters", L1P1);
134  if(j) return j;
135  j = RegisterExtendedRinexObsType("M2","L2 Range minus Phase","meters", L2P2);
136  if(j) return j;
137  j = RegisterExtendedRinexObsType("M3","IF Range minus Phase","meters", PsLs);
138  if(j) return j;
139  j = RegisterExtendedRinexObsType("M4","GF Range minus Phase","meters", PsLs);
140  if(j) return j;
141  j = RegisterExtendedRinexObsType("M5","WL Range minus Phase","meters", PsLs);
142  if(j) return j;
143  j = RegisterExtendedRinexObsType("XR","Non-dispersive Range","meters", PsLs);
144  if(j) return j;
145  j = RegisterExtendedRinexObsType("XI","Ionospheric delay", "meters", PsLs);
146  if(j) return j;
147  j = RegisterExtendedRinexObsType("X1","Range Error L1", "meters", PsLs);
148  if(j) return j;
149  j = RegisterExtendedRinexObsType("X2","Range Error L2", "meters", PsLs);
150  if(j) return j;
151  j = RegisterExtendedRinexObsType("SX","Satellite ECEF-X", "meters", EPEP);
152  if(j) return j;
153  j = RegisterExtendedRinexObsType("SY","Satellite ECEF-Y", "meters", EPEP);
154  if(j) return j;
155  j = RegisterExtendedRinexObsType("SZ","Satellite ECEF-Z", "meters", EPEP);
156  if(j) return j;
157  return 0;
158 }
159 catch(Exception& e) { GNSSTK_RETHROW(e); }
160 catch(std::exception& e) { Exception E("std except: "+string(e.what())); GNSSTK_THROW(E); }
161 catch(...) { Exception e("Unknown exception"); GNSSTK_THROW(e); }
162 }
163 
164 //------------------------------------------------------------------------------------
165 bool isSP3File(const string& file)
166 {
167  try
168  {
170  SP3Stream strm(file.c_str());
171  strm.exceptions(fstream::failbit);
172  try
173  {
174  strm >> header;
175  }
176  catch(Exception& e)
177  {
178  return false;
179  }
180  strm.close();
181  return true;
182  }
183  catch(Exception& e)
184  {
185  GNSSTK_RETHROW(e);
186  }
187  catch(std::exception& e)
188  {
189  Exception E("std except: "+string(e.what()));
190  GNSSTK_THROW(E);
191  }
192  catch(...)
193  {
194  Exception e("Unknown exception");
195  GNSSTK_THROW(e);
196  }
197 }
198 
199 //------------------------------------------------------------------------------------
200 bool isRinexNavFile(const string& file)
201 {
202  try
203  {
205  RinexNavStream rnstream;
206  try {
207  rnstream.open(file.c_str(),ios::in);
208  if(!rnstream)
209  return false;
210  rnstream.exceptions(fstream::failbit);
211  }
212  catch(Exception& e) { return false; }
213  catch(std::exception& e) { return false;}
214  try {
215  rnstream >> header;
216  }
217  catch(Exception& e) { return false; }
218  catch(std::exception& e) { return false; }
219 
220  rnstream.close();
221  return true;
222  }
223  catch(Exception& e) { GNSSTK_RETHROW(e); }
224  catch(std::exception& e) {
225  Exception E("std except: "+string(e.what()));
226  GNSSTK_THROW(E);
227  }
228  catch(...) {
229  Exception e("Unknown exception");
230  GNSSTK_THROW(e);
231  }
232 }
233 
234 //------------------------------------------------------------------------------------
235 bool isRinex3NavFile(const string& file)
236 {
237  try
238  {
240  Rinex3NavStream rnstream;
241  try {
242  rnstream.open(file.c_str(),ios::in);
243  if(!rnstream)
244  return false;
245  rnstream.exceptions(fstream::failbit);
246  }
247  catch(Exception& e) { return false; }
248  catch(std::exception& e) { return false; }
249  try {
250  rnstream >> header;
251  }
252  catch(Exception& e) { return false; }
253  catch(std::exception& e) { return false; }
254 
255  rnstream.close();
256  return true;
257  }
258  catch(Exception& e)
259  {
260  GNSSTK_RETHROW(e);
261  }
262  catch(std::exception& e)
263  {
264  Exception E("std except: "+string(e.what()));
265  GNSSTK_THROW(E);
266  }
267  catch(...)
268  {
269  Exception e("Unknown exception");
270  GNSSTK_THROW(e);
271  }
272 }
273 
274 //------------------------------------------------------------------------------------
275 bool isRinexObsFile(const string& file)
276 {
277  try
278  {
280  RinexObsStream rostream;
281  try {
282  rostream.open(file.c_str(),ios::in);
283  if(!rostream)
284  return false;
285  rostream.exceptions(fstream::failbit);
286  }
287  catch(Exception& e) { return false; }
288  catch(std::exception& e) { return false; }
289 
290  try {
291  rostream >> header;
292  }
293  catch(Exception& e) { return false; }
294  catch(std::exception& e) { return false; }
295 
296  rostream.close();
297  return true;
298  }
299  catch(Exception& e) { GNSSTK_RETHROW(e); }
300  catch(std::exception& e) {
301  Exception E("std except: "+string(e.what()));
302  GNSSTK_THROW(E);
303  }
304  catch(...) {
305  Exception e("Unknown exception");
306  GNSSTK_THROW(e);
307  }
308 }
309 
310 //------------------------------------------------------------------------------------
311 bool isRinex3ObsFile(const string& file)
312 {
313  try
314  {
316  Rinex3ObsStream rostream;
317  try {
318  rostream.open(file.c_str(),ios::in);
319  if(!rostream)
320  return false;
321  rostream.exceptions(fstream::failbit);
322  }
323  catch(Exception& e) { return false; }
324  catch(std::exception& e) { return false; }
325 
326  try {
327  rostream >> header;
328  }
329  catch(Exception& e) { return false; }
330  catch(std::exception& e) { return false; }
331 
332  rostream.close();
333  return true;
334  }
335  catch(Exception& e) { GNSSTK_RETHROW(e); }
336  catch(std::exception& e) {
337  Exception E("std except: "+string(e.what()));
338  GNSSTK_THROW(E);
339  }
340  catch(...) {
341  Exception e("Unknown exception");
342  GNSSTK_THROW(e);
343  }
344 }
345 
346 //------------------------------------------------------------------------------------
347 string sortRinexObsFiles(vector<string>& files)
348 {
349 try {
350  string msg;
351  if(files.size() <= 1) return msg;
352 
353  // build a hash with key = start time, value = filename
354  multimap<CommonTime,string> hash;
355  for(size_t n=0; n<files.size(); n++) {
356  try {
358  RinexObsStream rostream(files[n].c_str());
359  if(!rostream.is_open()) {
360  msg += "Error - Could not open file " + files[n] + "\n";
361  continue;
362  }
363  rostream.exceptions(fstream::failbit);
364  rostream >> header;
365  rostream.close();
366  if(!header.isValid()) {
367  msg += "Error - Invalid header in file " + files[n] + "\n";
368  continue;
369  }
370  //hash[header.firstObs] = files[n];
371  hash.insert(multimap<CommonTime, string>::value_type(header.firstObs,
372  files[n]));
373  }
374  catch(Exception& e) {
375  //msg += "Exception " + e.what() + " in file " + files[n] + "\n";
376  msg += "Error - File "+files[n]+" is not a valid RINEX observation file.\n";
377  continue;
378  }
379  }
380 
381  // return the sorted file names
382  files.clear();
383  multimap<CommonTime,string>::const_iterator it = hash.begin();
384  while(it != hash.end()) {
385  files.push_back(it->second);
386  it++;
387  }
388 
389  string::size_type pos(msg.length());
390  if(pos > 0) msg.erase(pos-1);
391  return msg;
392 }
393 catch(Exception& e) { GNSSTK_RETHROW(e); }
394 catch(std::exception& e) { Exception E("std except: "+string(e.what())); GNSSTK_THROW(E); }
395 catch(...) { Exception e("Unknown exception"); GNSSTK_THROW(e); }
396 }
397 
398 //------------------------------------------------------------------------------------
399 string sortRinex3ObsFiles(vector<string>& files)
400 {
401  string msg;
402  if(files.size() <= 1) { msg = string("No input files!"); return msg; }
403 
404  try
405  {
406  // build a hash with key = start time, value = filename
407  multimap<CommonTime,string> hash;
408  for(size_t n = 0; n < files.size(); n++)
409  {
410  try {
412  Rinex3ObsStream rostream(files[n].c_str());
413  if(!rostream.is_open()) {
414  msg += "Error - Could not open file " + files[n] + "\n";
415  continue;
416  }
417  rostream.exceptions(fstream::failbit);
418  rostream >> header;
419  rostream.close();
420  if(!header.isValid()) {
421  msg += "Error - Invalid header in file " + files[n] + "\n";
422  continue;
423  }
424  hash.insert(
425  multimap<CommonTime, string>::value_type(header.firstObs, files[n])
426  );
427 
428  }
429  catch(Exception& e) {
430  msg += "Exception: " + e.what() + "\n";
431  continue;
432  }
433  }
434 
435  // return the sorted file names
436  files.clear();
437  multimap<CommonTime,string>::const_iterator it = hash.begin();
438  while(it != hash.end()) {
439  files.push_back(it->second);
440  it++;
441  }
442  }
443  catch(Exception& e) { GNSSTK_RETHROW(e); }
444  catch(std::exception& e) {
445  Exception E("std except: "+string(e.what()));
446  GNSSTK_THROW(E);
447  }
448  catch(...) {
449  Exception e("Unknown exception");
450  GNSSTK_THROW(e);
451  }
452 
453  return msg;
454 }
455 
456 } // end namespace gnsstk
457 
458 //------------------------------------------------------------------------------------
459 //------------------------------------------------------------------------------------
gnsstk::RinexObsStream
Definition: RinexObsStream.hpp:67
RinexUtilities.hpp
gnsstk::RinexObsType::L1depend
static const GNSSTK_EXPORT unsigned int L1depend
Definition: RinexObsHeader.hpp:78
Rinex3NavHeader.hpp
SP3Header.hpp
example3.header
header
Definition: example3.py:22
file
page HOWTO subpage DoxygenGuide Documenting Your Code page DoxygenGuide Documenting Your Code todo Flesh out this document section doctips Tips for Documenting When defining make sure that the prototype is identical between the cpp and hpp file
Definition: DOCUMENTING.dox:9
gnsstk::Rinex3ObsStream::open
virtual void open(const char *fn, std::ios::openmode mode)
Definition: Rinex3ObsStream.cpp:80
gnsstk::Rinex3NavStream
Definition: Rinex3NavStream.hpp:62
gnsstk::isRinex3ObsFile
bool isRinex3ObsFile(const string &file)
Definition: RinexUtilities.cpp:311
gnsstk::Rinex3ObsHeader
Definition: Rinex3ObsHeader.hpp:155
gnsstk::RinexObsType::EPdepend
static const GNSSTK_EXPORT unsigned int EPdepend
Definition: RinexObsHeader.hpp:82
gnsstk::Exception::what
std::string what() const
Dump to a string.
Definition: Exception.cpp:193
RinexObsStream.hpp
gnsstk::Rinex3NavStream::open
virtual void open(const char *fn, std::ios::openmode mode)
overrides open to reset the header
Definition: Rinex3NavStream.cpp:70
RinexNavHeader.hpp
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
Rinex3NavStream.hpp
gnsstk::RegisterExtendedRinexObsType
int RegisterExtendedRinexObsType(string t, string d, string u, unsigned int dep)
Definition: RinexObsHeader.cpp:969
Rinex3NavData.hpp
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::Rinex3NavHeader
Definition: Rinex3NavHeader.hpp:107
gnsstk::SP3Stream
Definition: SP3Stream.hpp:61
gnsstk::RinexObsType::P1depend
static const GNSSTK_EXPORT unsigned int P1depend
Definition: RinexObsHeader.hpp:80
gnsstk::SP3Stream::close
virtual void close(void)
Definition: SP3Stream.cpp:74
files
page HOWTO subpage DoxygenGuide Documenting Your Code page DoxygenGuide Documenting Your Code todo Flesh out this document section doctips Tips for Documenting When defining make sure that the prototype is identical between the cpp and hpp including both the namespaces and the parameter names for you have std::string as the return type in the hpp file and string as the return type in the cpp Doxygen may get confused and autolink to the cpp version with no documentation If you don t use the same parameter names between the cpp and hpp files
Definition: DOCUMENTING.dox:9
Rinex3ObsHeader.hpp
gnsstk::SP3Header
Definition: SP3Header.hpp:68
gnsstk::RinexNavHeader
Definition: RinexNavHeader.hpp:63
RinexNavStream.hpp
GNSSTK_RETHROW
#define GNSSTK_RETHROW(exc)
Definition: Exception.hpp:369
example4.pos
pos
Definition: example4.py:125
gnsstk::RinexNavStream
Definition: RinexNavStream.hpp:61
gnsstk::Rinex3ObsStream
Definition: Rinex3ObsStream.hpp:65
RinexObsHeader.hpp
Rinex3ObsStream.hpp
gnsstk::RinexNavStream::open
virtual void open(const char *fn, std::ios::openmode mode)
overrides open to reset the header
Definition: RinexNavStream.cpp:70
gnsstk::RinexObsStream::open
virtual void open(const char *fn, std::ios::openmode mode)
Definition: RinexObsStream.cpp:80
gnsstk::isSP3File
bool isSP3File(const string &file)
Definition: RinexUtilities.cpp:165
std
Definition: Angle.hpp:142
gnsstk::RinexObsType::L2depend
static const GNSSTK_EXPORT unsigned int L2depend
Definition: RinexObsHeader.hpp:79
SP3Stream.hpp
gnsstk::CarrierBand::L1L2
@ L1L2
GPS L1+L2.
gnsstk::sortRinexObsFiles
string sortRinexObsFiles(vector< string > &files)
Definition: RinexUtilities.cpp:347
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::RinexObsHeader
Definition: RinexObsHeader.hpp:107
RinexNavData.hpp
gnsstk::RinexObsType::PSdepend
static const GNSSTK_EXPORT unsigned int PSdepend
Definition: RinexObsHeader.hpp:83
gnsstk::isRinex3NavFile
bool isRinex3NavFile(const string &file)
Definition: RinexUtilities.cpp:235
gnsstk::RinexObsType::P2depend
static const GNSSTK_EXPORT unsigned int P2depend
Definition: RinexObsHeader.hpp:81
gnsstk::isRinexNavFile
bool isRinexNavFile(const string &file)
Definition: RinexUtilities.cpp:200
gnsstk::RegisterARLUTExtendedTypes
int RegisterARLUTExtendedTypes(void)
Definition: RinexUtilities.cpp:69
gnsstk::isRinexObsFile
bool isRinexObsFile(const string &file)
Definition: RinexUtilities.cpp:275
gnsstk::sortRinex3ObsFiles
string sortRinex3ObsFiles(vector< string > &files)
Definition: RinexUtilities.cpp:399


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