GPSZcount.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 <limits>
45 
46 #include "GPSZcount.hpp"
47 #include "StringUtils.hpp"
48 
49 using namespace std;
51 
52 namespace gnsstk
53 {
54  const long GPSZcount::ZCOUNT_MINUTE = 40;
55  const long GPSZcount::ZCOUNT_HOUR = 2400;
56  const long GPSZcount::ZCOUNT_DAY = 57600;
57  const long GPSZcount::ZCOUNT_WEEK = 403200;
58 
59  GPSZcount::GPSZcount(short inWeek,
60  long inZcount)
61  {
62  try
63  {
64  setWeek(inWeek);
65  setZcount(inZcount);
66  }
67  catch(gnsstk::InvalidParameter& ip)
68  {
69  GNSSTK_RETHROW(ip);
70  }
71  }
72 
73  GPSZcount::GPSZcount(long inFullZcount)
74  {
75  try
76  {
77  setFullZcount(inFullZcount);
78  }
79  catch(gnsstk::InvalidParameter& ip)
80  {
81  GNSSTK_RETHROW(ip);
82  }
83  }
84 
85  GPSZcount::GPSZcount(const GPSZcount& right)
86  {
87  operator=(right);
88  }
89 
90  GPSZcount& GPSZcount::setWeek(short inWeek)
91  {
92  if( inWeek < 0 )
93  {
94  gnsstk::InvalidParameter ip("GPS Week invalid: " +
95  asString<short>(inWeek)) ;
96  GNSSTK_THROW(ip);
97  }
98  week = inWeek;
99  return *this;
100  }
101 
102  GPSZcount& GPSZcount::setZcount(long inZcount)
103  {
104  if(validZcount(inZcount) != 0)
105  {
106  gnsstk::InvalidParameter ip("GPS Z-count invalid: " +
107  asString<long>(inZcount));
108  GNSSTK_THROW(ip);
109  }
110  zcount = inZcount;
111  return *this;
112  }
113 
114  GPSZcount& GPSZcount::setFullZcount(long inZcount)
115  {
116  try
117  {
118  setZcount(inZcount & 0x7FFFFL); // 19-bit mask
119 
120  // A 10-bit value will always be within constraints for a GPS week, so
121  // there's no need to test it.
122  setWeek((inZcount >> 19) & 0x3FFL); // 10-bit mask
123 
124  }
125  catch(gnsstk::InvalidParameter& ip)
126  {
127  ip.addText("GPS Full Z-count invalid: " + asString<long>(inZcount)) ;
128  GNSSTK_RETHROW(ip);
129  }
130  return *this;
131  }
132 
133  GPSZcount& GPSZcount::addWeeks(short inWeeks)
134  {
135  if (inWeeks == 0)
136  {
137  return *this;
138  }
139 
140  try
141  {
142  return setWeek(week + inWeeks);
143  }
144  catch(gnsstk::InvalidParameter& ip)
145  {
146  gnsstk::InvalidRequest ir(ip) ;
147  ir.addText("Addition of " + asString(inWeeks) +
148  " weeks renders this object invalid.");
149  GNSSTK_THROW(ir);
150  }
151  }
152 
153  GPSZcount& GPSZcount::addZcounts(long inZcounts)
154  {
155  if (inZcounts == 0)
156  {
157  return *this;
158  }
159 
160  short originalWeek(week);
161  long originalZcount(zcount);
162 
163  try
164  {
165  // First, do week modifications.
166  addWeeks(inZcounts / ZCOUNT_WEEK);
167 
168  // Now, take care of Z-counts.
169  long tmp = zcount + (inZcounts % ZCOUNT_WEEK);
170 
171  if (tmp < 0)
172  {
173  addWeeks(-1);
174  tmp += ZCOUNT_WEEK;
175  }
176  else if (tmp >= ZCOUNT_WEEK)
177  {
178  addWeeks(1);
179  tmp -= ZCOUNT_WEEK;
180  }
181 
182  setZcount(tmp);
183  return *this;
184 
185  }
186  catch(gnsstk::InvalidRequest& ir)
187  {
188  setWeek(originalWeek);
189  setZcount(originalZcount);
190  ir.addText("Did not add " + asString(inZcounts) + " Z-counts.") ;
191  GNSSTK_RETHROW(ir);
192 
193  }
194  catch(gnsstk::InvalidParameter& ip)
195  {
196  setWeek(originalWeek);
197  setZcount(originalZcount);
198  gnsstk::InvalidRequest ir(ip);
199  ir.addText("Did not add " + asString(inZcounts) + " Z-counts.") ;
200  GNSSTK_THROW(ir);
201  }
202  }
203 
205  {
206  GPSZcount temp = *this;
207  ++(*this);
208  return temp;
209  }
210 
212  {
213  return addZcounts(1);
214  }
215 
217  {
218  GPSZcount temp = *this;
219  --(*this);
220  return temp ;
221  }
222 
224  {
225  return addZcounts(-1);
226  }
227 
228  GPSZcount GPSZcount::operator+(long inZcounts) const
229  {
230  return GPSZcount(*this).addZcounts(inZcounts);
231  }
232 
233  GPSZcount GPSZcount::operator-(long inZcounts) const
234  {
235  return operator+(-inZcounts);
236  }
237 
238  double GPSZcount::operator-(const GPSZcount& right) const
239  {
240  return (double(week) - right.week) * ZCOUNT_WEEK
241  + (zcount - right.zcount) ;
242  }
243 
244  long GPSZcount::operator%(const long right) const
245  {
246  return zcount % right;
247  }
248 
249  GPSZcount& GPSZcount::operator+=(long inZcounts)
250  {
251  return addZcounts(inZcounts);
252  }
253 
254  GPSZcount& GPSZcount::operator-=(long inZcounts)
255  {
256  return addZcounts(-inZcounts);
257  }
258 
259  GPSZcount& GPSZcount::operator=(const GPSZcount& right)
260  {
261  week = right.week;
262  zcount = right.zcount;
263  return *this;
264  }
265 
266  bool GPSZcount::operator<(const GPSZcount& right) const
267  {
268  if (week < right.week)
269  {
270  return true;
271  }
272  if (week == right.week &&
273  zcount < right.zcount)
274  {
275  return true;
276  }
277  return false;
278  }
279 
280  bool GPSZcount::operator>(const GPSZcount& right) const
281  {
282  if (week > right.week)
283  {
284  return true;
285  }
286  if (week == right.week &&
287  zcount > right.zcount)
288  {
289  return true;
290  }
291  return false;
292  }
293 
294  bool GPSZcount::operator==(const GPSZcount& right) const
295  {
296  if (week == right.week &&
297  zcount == right.zcount)
298  {
299  return true;
300  }
301  return false;
302  }
303 
304  bool GPSZcount::operator!=(const GPSZcount& right) const
305  {
306  return (! operator==(right));
307  }
308 
309  bool GPSZcount::operator<=(const GPSZcount& right) const
310  {
311  return (! operator>(right));
312  }
313 
314  bool GPSZcount::operator>=(const GPSZcount& right) const
315  {
316  return (! operator<(right));
317  }
318 
319  GPSZcount::operator std::string() const
320  {
321  return asString<short>(week) + "w" + asString<long>(zcount) + "z";
322  }
323 
324  bool GPSZcount::inSameTimeBlock(const GPSZcount& other,
325  unsigned long inZcountBlock,
326  unsigned long inZcountOffset)
327  {
328  if ((long)inZcountBlock < ZCOUNT_WEEK)
329  {
330  // Make sure that we're in the same week, and then check to see if
331  // we're in the same time block
332  if ( (getWeek() == other.getWeek()) &&
333  (((getZcount() - inZcountOffset) / inZcountBlock) ==
334  ((other.getZcount() - inZcountOffset) / inZcountBlock)) )
335  {
336  return true;
337  }
338  }
339  else // inZcountBlock >= ZCOUNT_WEEK
340  {
341  // Compare using the total number of Z-counts.
342  if (long((getTotalZcounts() - inZcountOffset) / inZcountBlock) ==
343  long((other.getTotalZcounts() - inZcountOffset) / inZcountBlock))
344  {
345  return true;
346  }
347  }
348 
349  return false;
350  }
351 
352  void GPSZcount::dump(std::ostream& out,
353  short level) const
354  {
355  switch(level)
356  {
357  case 0:
358  out << week << "w" << zcount << "z" << flush;
359  break;
360  case 1:
361  default:
362  out << "GPS Full Week: " << setw(6) << week << endl
363  << "GPS Z-count: " << setw(6) << zcount << endl;
364  break;
365  }
366  }
367 
368  long GPSZcount::validZcount(long z)
369  {
370  if (z < 0)
371  {
372  return z;
373  }
374  if (z >= GPSZcount::ZCOUNT_WEEK)
375  {
376  return (z - (GPSZcount::ZCOUNT_WEEK - 1));
377  }
378  return 0; // z is OK
379  }
380 
381  std::ostream& operator<<(std::ostream& s,
382  const gnsstk::GPSZcount& z)
383  {
384  z.dump(s, 0);
385  return s;
386  }
387 
388 } // namespace gnsstk
gnsstk::GPSZcount::zcount
long zcount
GPS Z-count. (0 <= zcount <= 403199)
Definition: GPSZcount.hpp:321
gnsstk::dump
void dump(vector< SatPass > &SatPassList, ostream &os, bool rev, bool dbug)
Definition: SatPassUtilities.cpp:59
gnsstk::operator==
bool operator==(const IonexData::IonexValType &x, const IonexData::IonexValType &y)
operator == for IonexData::IonexValType
Definition: IonexData.hpp:253
gnsstk::GPSZcount::addZcounts
GPSZcount & addZcounts(long inZcounts)
Definition: GPSZcount.cpp:153
StringUtils.hpp
gnsstk::GPSZcount::getZcount
long getZcount() const
GPS Z-count accessor.
Definition: GPSZcount.hpp:117
GPSZcount.hpp
gnsstk::operator+
SparseMatrix< T > operator+(const SparseMatrix< T > &L, const SparseMatrix< T > &R)
Matrix addition: SparseMatrix = SparseMatrix + SparseMatrix : copy, += SM.
Definition: SparseMatrix.hpp:1608
gnsstk::StringUtils::asString
std::string asString(IonexStoreStrategy e)
Convert a IonexStoreStrategy to a whitespace-free string name.
Definition: IonexStoreStrategy.cpp:46
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
example4.temp
temp
Definition: example4.py:35
gnsstk::GPSZcount
Definition: GPSZcount.hpp:75
gnsstk::GPSZcount::getWeek
short getWeek() const
GPS week accessor.
Definition: GPSZcount.hpp:113
gnsstk::GPSZcount::week
short week
GPS full week. (0 <= week)
Definition: GPSZcount.hpp:320
gnsstk::operator--
FileSpec::FileSpecType & operator--(FileSpec::FileSpecType &fst, int)
Operator– for FileSpecType.
Definition: FileSpec.cpp:57
GNSSTK_RETHROW
#define GNSSTK_RETHROW(exc)
Definition: Exception.hpp:369
gnsstk::operator!=
bool operator!=(const IonexData::IonexValType &x, const IonexData::IonexValType &y)
operator != for IonexData::IonexValType
Definition: IonexData.hpp:259
std::operator<<
std::ostream & operator<<(std::ostream &s, gnsstk::StringUtils::FFLead v)
Definition: FormattedDouble_T.cpp:44
gnsstk::operator<
bool operator<(const IonexData::IonexValType &x, const IonexData::IonexValType &y)
operator < for IonexData::IonexValType
Definition: IonexData.hpp:265
gnsstk::GPSZcount::getTotalZcounts
double getTotalZcounts() const
Definition: GPSZcount.hpp:131
std
Definition: Angle.hpp:142
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::operator-
SparseMatrix< T > operator-(const SparseMatrix< T > &L, const SparseMatrix< T > &R)
Matrix subtraction: SparseMatrix = SparseMatrix - SparseMatrix.
Definition: SparseMatrix.hpp:1451
gnsstk::GPSZcount::dump
void dump(std::ostream &out, short level=0) const
Definition: GPSZcount.cpp:352
gnsstk::operator++
FileSpec::FileSpecType & operator++(FileSpec::FileSpecType &fst, int)
Operator++ for FileSpecType.
Definition: FileSpec.cpp:64


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