SinexBase.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 
44 #include "SinexBase.hpp"
45 #include "YDSTime.hpp"
46 #include "FormattedDouble.hpp"
47 
48 using namespace gnsstk::StringUtils;
49 using namespace std;
50 
51 namespace gnsstk
52 {
53 namespace Sinex
54 {
55 
56  bool
57  isValidObsCode(char c, bool toss)
58  {
59  if (OBS_CODES.find(c) == string::npos)
60  {
61  if (toss)
62  {
63  string errMsg("Invalid Observation Code: ");
64  errMsg += c;
65  Exception err(errMsg);
67  }
68  return false;
69  }
70  return true;
71  }
72 
73 
74  bool
75  isValidConstraintCode(char c, bool toss)
76  {
77  if (CONSTRAINT_CODES.find(c) == string::npos)
78  {
79  if (toss)
80  {
81  string errMsg("Invalid Constraint Code: ");
82  errMsg += c;
83  Exception err(errMsg);
85  }
86  return false;
87  }
88  return true;
89  }
90 
91 
92  bool
93  isValidSolutionType(char c, bool toss)
94  {
95  if (SOLUTION_TYPES.find(c) == string::npos)
96  {
97  if (toss)
98  {
99  string errMsg("Invalid Solution Type: ");
100  errMsg += c;
101  Exception err(errMsg);
102  GNSSTK_THROW(err);
103  }
104  return false;
105  }
106  return true;
107  }
108 
109 
110  bool
111  isValidLineStructure(const std::string& line,
112  size_t minLen,
113  size_t maxLen,
114  int divs[],
115  bool toss)
116  {
117  size_t sz = line.size();
118 
120  if (minLen < MIN_LINE_LEN) minLen = MIN_LINE_LEN;
121  if (sz < minLen)
122  {
123  if (toss)
124  {
125  ostringstream ss;
126  ss << "Missing data; inadequate line length ("
127  << sz << " < " << minLen << ")";
128  Exception err(ss.str() );
129  GNSSTK_THROW(err);
130  }
131  return false;
132  }
133 
135  if (maxLen > MAX_LINE_LEN) maxLen = MAX_LINE_LEN;
136  if (sz > maxLen)
137  {
138  if (toss)
139  {
140  ostringstream ss;
141  ss << "Excessive line length ("
142  << sz << " > " << maxLen << ")";
143  Exception err(ss.str() );
144  GNSSTK_THROW(err);
145  }
146  return false;
147  }
149  if (divs != NULL)
150  {
151  int pos;
152  for (size_t i = 0; (pos = divs[i]) >= 0; ++i)
153  {
154  if ( (pos >= sz) || (line[pos] != FIELD_DIV) )
155  {
156  if (toss)
157  {
158  ostringstream ss;
159  ss << "Field divider '" << FIELD_DIV
160  << "' expected in column " << pos;
161  Exception err(ss.str() );
162  GNSSTK_THROW(err);
163  }
164  return false;
165  }
166  }
167  }
168  return true;
169  }
170 
171 
172  std::string
173  formatStr(const std::string& value, size_t width, bool allowBlank)
174  {
175  if ( (value.size() == 0) && !allowBlank)
176  {
177  return string(width, '-');
178  }
179  else
180  {
181  ostringstream ss;
182  ss << left << setw(width) << value.substr(0, width);
183  return ss.str();
184  }
185  }
186 
187 
188  std::string
189  formatInt(long value, size_t width)
190  {
191  ostringstream ss;
192  ss << right << setw(width) << value;
193  string s = ss.str();
194  if (s.size() > width)
195  {
196  ostringstream msg;
197  msg << "Cannot represent value " << value;
198  msg << " within width " << width;
199  Exception err(msg.str() );
200  GNSSTK_THROW(err);
201  }
202  return s;
203  }
204 
205 
206  std::string
207  formatUint(unsigned long value, size_t width)
208  {
209  ostringstream ss;
210  ss << right << setw(width) << value;
211  string s = ss.str();
212  if (s.size() > width)
213  {
214  ostringstream msg;
215  msg << "Cannot represent value " << value;
216  msg << " within width " << width;
217  Exception err(msg.str() );
218  GNSSTK_THROW(err);
219  }
220  return s;
221  }
222 
223 
224  std::string
225  formatFor(double value, size_t width, size_t expLen)
226  {
227  FormattedDouble fd(value, StringUtils::FFLead::Zero, width-6, expLen,
228  width, 'E');
229  return static_cast<std::string>(fd);
230  }
231 
232  std::string
233  formatFixed(double value, size_t width, size_t precision)
234  {
235  ostringstream ss;
236  ss << fixed << right << setw(width) << setprecision(precision) << value;
237  string s = ss.str();
238 
239  if (s.size() > width)
240  {
242  if ( (s.size() == width+1) && (value < 1.0) && (value > -1.0) )
243  {
244  if (value < 0.0)
245  {
246  s.erase(1, 1);
247  }
248  else
249  {
250  s.erase(0, 1);
251  }
252  }
253  else
254  {
255  ostringstream msg;
256  msg << "Cannot represent value " << value;
257  msg << " within width " << width;
258  msg << " with precision " << precision;
259  Exception err(msg.str() );
260  GNSSTK_THROW(err);
261  }
262  }
263  return s;
264  }
265 
266 
267  Time::operator gnsstk::CommonTime() const
268  {
269  long y = (year > 50) ? (year + 1900) : (year + 2000);
270  gnsstk::YDSTime ydsTime(y, doy, (double)sod);
271  return ydsTime.convertToCommonTime();
272  }
273 
274 
275  Time::operator std::string() const
276  {
277  std::ostringstream ss;
278  ss << setfill('0');
279  ss << setw(2) << (uint16_t)year << ":";
280  ss << setw(3) << doy << ":";
281  ss << setw(5) << sod;
282  return ss.str();
283  }
284 
285 
286  void
287  Time::operator=(const gnsstk::CommonTime& other)
288  {
289  gnsstk::YDSTime ydsTime(other);
290  if (ydsTime.year > 2050)
291  {
292  Exception err("SINEX does not support years past 2050.");
293  GNSSTK_THROW(err);
294  }
295  year = ydsTime.year % 100; // Get last 2 digits of time
296  doy = ydsTime.doy;
297  sod = ydsTime.sod;
298  }
299 
300 
301  void
302  Time::operator=(const std::string& other)
303  {
304  if ( (other.size() < 12) || (other[2] != ':') || (other[6] != ':') )
305  {
306  Exception err("Invalid time syntax: " + other);
307  GNSSTK_THROW(err);
308  }
309  year = asInt(other.substr(0, 2) );
310  doy = asInt(other.substr(3, 3) );
311  sod = asInt(other.substr(7, 5) );
312  }
313 
314 } // namespace Sinex
315 
316 } // namespace gnsstk
gnsstk::StringUtils::asInt
long asInt(const std::string &s)
Definition: StringUtils.hpp:713
YDSTime.hpp
gnsstk::Sinex::formatStr
std::string formatStr(const std::string &value, size_t width, bool allowBlank)
Definition: SinexBase.cpp:173
example6.year
year
Definition: example6.py:64
gnsstk::YDSTime
Definition: YDSTime.hpp:58
gnsstk::Sinex::isValidObsCode
bool isValidObsCode(char c, bool toss)
Definition: SinexBase.cpp:57
gnsstk::Sinex::OBS_CODES
const std::string OBS_CODES("CDLMPR")
SinexBase.hpp
gnsstk::Sinex::formatFixed
std::string formatFixed(double value, size_t width, size_t precision)
Definition: SinexBase.cpp:233
NULL
#define NULL
Definition: getopt1.c:64
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::FormattedDouble
Definition: FormattedDouble.hpp:70
gnsstk::StringUtils::FFLead::Zero
@ Zero
Start with zero, e.g. 0.12345.
y
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 that will also confuse Doxygen Don t put type information in return or param documentation It doesn t really add anything and will often cause Doxygen to complain and not produce the documentation< br > use note Do not put a comma after a param name unless you mean to document multiple parameters< br/> the output stream</code >< br/> y
Definition: DOCUMENTING.dox:15
gnsstk::YDSTime::doy
int doy
Definition: YDSTime.hpp:185
gnsstk::YDSTime::year
int year
Definition: YDSTime.hpp:184
example4.err
err
Definition: example4.py:126
gnsstk::Sinex::MIN_LINE_LEN
const size_t MIN_LINE_LEN
Definition: SinexBase.hpp:66
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::Sinex::isValidLineStructure
bool isValidLineStructure(const std::string &line, size_t minLen, size_t maxLen, int divs[], bool toss)
Definition: SinexBase.cpp:111
FormattedDouble.hpp
gnsstk::YDSTime::sod
double sod
Definition: YDSTime.hpp:186
example4.pos
pos
Definition: example4.py:125
gnsstk::Sinex::isValidConstraintCode
bool isValidConstraintCode(char c, bool toss)
Definition: SinexBase.cpp:75
gnsstk::Sinex::formatFor
std::string formatFor(double value, size_t width, size_t expLen)
Definition: SinexBase.cpp:225
gnsstk::YDSTime::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: YDSTime.cpp:61
gnsstk::Sinex::MAX_LINE_LEN
const size_t MAX_LINE_LEN
Definition: SinexBase.hpp:67
gnsstk::StringUtils
Definition: IonexStoreStrategy.cpp:44
gnsstk::Sinex::isValidSolutionType
bool isValidSolutionType(char c, bool toss)
Definition: SinexBase.cpp:93
example6.sod
sod
Definition: example6.py:103
gnsstk::Sinex::CONSTRAINT_CODES
const std::string CONSTRAINT_CODES("012")
std
Definition: Angle.hpp:142
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::Sinex::formatInt
std::string formatInt(long value, size_t width)
Definition: SinexBase.cpp:189
gnsstk::Sinex::SOLUTION_TYPES
const std::string SOLUTION_TYPES("SOETCA ")
gnsstk::Sinex::formatUint
std::string formatUint(unsigned long value, size_t width)
Definition: SinexBase.cpp:207
gnsstk::Sinex::FIELD_DIV
const char FIELD_DIV
Definition: SinexBase.hpp:65


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