GPSWeekSecond.hpp
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 
42 #ifndef GPSWEEKSECOND_HPP
43 #define GPSWEEKSECOND_HPP
44 
45 #include "WeekSecond.hpp"
46 
47 namespace gnsstk
48 {
50 
51 
56  class GPSWeekSecond : public WeekSecond
57  {
58  public:
59 
61  GPSWeekSecond(unsigned int w = 0,
62  double s = 0.,
64  : WeekSecond(w,s)
65  { timeSystem = ts; }
66 
68  GPSWeekSecond( const CommonTime& right )
69  {
70  convertFromCommonTime( right );
71  }
72 
75 
78  int Nbits(void) const
79  {
80  static const int n=10;
81  return n;
82  }
83 
85  int bitmask(void) const
86  {
87  static const int bm=0x3FF;
88  return bm;
89  }
90 
92  long MJDEpoch(void) const
93  {
94  static const long e=GPS_EPOCH_MJD;
95  return e;
96  }
97 
104  inline bool operator==( const GPSWeekSecond& right ) const
105  {
106  return WeekSecond::operator==( right );
107  }
108  inline bool operator!=( const GPSWeekSecond& right ) const
109  {
110  return WeekSecond::operator!=( right );
111  }
112  inline bool operator<( const GPSWeekSecond& right ) const
113  {
114  return WeekSecond::operator<( right );
115  }
116  inline bool operator>( const GPSWeekSecond& right ) const
117  {
118  return WeekSecond::operator>( right );
119  }
120  inline bool operator<=( const GPSWeekSecond& right ) const
121  {
122  return WeekSecond::operator<=( right );
123  }
124  inline bool operator>=( const GPSWeekSecond& right ) const
125  {
126  return WeekSecond::operator>=( right );
127  }
129 
132  virtual std::string getPrintChars() const
133  {
134  return "EFGwgP";
135  }
136 
138  virtual std::string getDefaultFormat() const
139  {
140  return "%F %g %P";
141  }
142 
145  virtual std::string printf(const std::string& fmt) const
146  {
147  try {
149 
150  std::string rv = fmt;
151  rv = formattedPrint( rv, getFormatPrefixInt() + "E",
152  "Eu", getEpoch() );
153  rv = formattedPrint( rv, getFormatPrefixInt() + "F",
154  "Fu", week );
155  rv = formattedPrint( rv, getFormatPrefixInt() + "G",
156  "Gu", getModWeek() );
157  rv = formattedPrint( rv, getFormatPrefixInt() + "w",
158  "wu", getDayOfWeek() );
159  rv = formattedPrint( rv, getFormatPrefixFloat() + "g",
160  "gf", sow );
161  rv = formattedPrint( rv, getFormatPrefixInt() + "P",
162  "Ps", StringUtils::asString(timeSystem).c_str() );
163  return rv;
164  }
165  catch(gnsstk::StringUtils::StringException& e)
166  { GNSSTK_RETHROW(e); }
167  }
168 
171  virtual std::string printError(const std::string& fmt) const
172  {
173  try {
175  std::string rv = fmt;
176 
177  rv = formattedPrint( rv, getFormatPrefixInt() + "E",
178  "Es", "BadGPSepoch");
179  rv = formattedPrint( rv, getFormatPrefixInt() + "F",
180  "Fs", "BadGPSfweek");
181  rv = formattedPrint( rv, getFormatPrefixInt() + "G",
182  "Gs", "BadGPSmweek");
183  rv = formattedPrint( rv, getFormatPrefixInt() + "w",
184  "ws", "BadGPSdow");
185  rv = formattedPrint( rv, getFormatPrefixFloat() + "g",
186  "gs", "BadGPSsow");
187  rv = formattedPrint( rv, getFormatPrefixInt() + "P",
188  "Ps", "BadGPSsys");
189  return rv;
190  }
191  catch(gnsstk::StringUtils::StringException& e)
192  { GNSSTK_RETHROW(e); }
193  }
194 
199  bool setFromInfo( const IdToValue& info )
200  {
201  for( IdToValue::const_iterator i = info.begin(); i != info.end(); i++ )
202  {
203  // based on the character, we know what to do...
204  switch ( i->first )
205  {
206  case 'E':
207  setEpoch( gnsstk::StringUtils::asInt( i->second ) );
208  break;
209  case 'F':
210  week = gnsstk::StringUtils::asInt( i->second );
211  break;
212  case 'G':
213  setModWeek( gnsstk::StringUtils::asInt( i->second ) );
214  break;
215  case 'w':
216  sow = static_cast<double>(gnsstk::StringUtils::asInt(i->second))*SEC_PER_DAY;
217  break;
218  case 'g':
219  sow = gnsstk::StringUtils::asDouble( i->second );
220  break;
221  case 'P':
223  break;
224  default:
225  // do nothing
226  break;
227  };
228 
229  } // end of for loop
230 
231  return true;
232  }
233 
234 
236  {
237  double diff = sow - refTime.sow;
238  if (diff < -HALFWEEK)
239  {
240  week = refTime.week + 1;
241  }
242  else if (diff > HALFWEEK)
243  {
244  week = refTime.week - 1;
245  }
246  else
247  {
248  week = refTime.week;
249  }
250  return *this;
251  }
252 
253  }; // end class GPSWeekSecond
254 
256 
257 } // namespace
258 
259 #endif // GPSWEEKSECOND_HPP
gnsstk::TimeTag::getFormatPrefixInt
static std::string getFormatPrefixInt()
Definition: TimeTag.hpp:152
gnsstk::StringUtils::asInt
long asInt(const std::string &s)
Definition: StringUtils.hpp:713
gnsstk::GPSWeekSecond::Nbits
int Nbits(void) const
Definition: GPSWeekSecond.hpp:78
gnsstk::HALFWEEK
const long HALFWEEK
Seconds per half week.
Definition: TimeConstants.hpp:58
gnsstk::Week::getEpoch
virtual unsigned int getEpoch() const
Definition: Week.hpp:188
gnsstk::TimeTag::IdToValue
std::map< char, std::string > IdToValue
Definition: TimeTag.hpp:103
gnsstk::WeekSecond::operator==
bool operator==(const WeekSecond &right) const
Definition: WeekSecond.cpp:111
gnsstk::SEC_PER_DAY
const long SEC_PER_DAY
Seconds per day.
Definition: TimeConstants.hpp:63
gnsstk::WeekSecond::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: WeekSecond.cpp:78
gnsstk::WeekSecond::operator>=
bool operator>=(const WeekSecond &right) const
Definition: WeekSecond.cpp:149
gnsstk::GPSWeekSecond::weekRolloverAdj
GPSWeekSecond & weekRolloverAdj(const GPSWeekSecond &refTime)
Definition: GPSWeekSecond.hpp:235
gnsstk::GPSWeekSecond::setFromInfo
bool setFromInfo(const IdToValue &info)
Definition: GPSWeekSecond.hpp:199
gnsstk::StringUtils::asString
std::string asString(IonexStoreStrategy e)
Convert a IonexStoreStrategy to a whitespace-free string name.
Definition: IonexStoreStrategy.cpp:46
gnsstk::GPSWeekSecond::GPSWeekSecond
GPSWeekSecond(const CommonTime &right)
Constructor from CommonTime.
Definition: GPSWeekSecond.hpp:68
gnsstk::GPSWeekSecond::operator>=
bool operator>=(const GPSWeekSecond &right) const
Definition: GPSWeekSecond.hpp:124
gnsstk::Week::setEpoch
virtual void setEpoch(unsigned int e)
Definition: Week.hpp:200
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::GPSWeekSecond::bitmask
int bitmask(void) const
Return the bitmask used to get the ModWeek from the full week.
Definition: GPSWeekSecond.hpp:85
gnsstk::GPSWeekSecond::printError
virtual std::string printError(const std::string &fmt) const
Definition: GPSWeekSecond.hpp:171
gnsstk::GPSWeekSecond
Definition: GPSWeekSecond.hpp:56
gnsstk::TimeTag::timeSystem
TimeSystem timeSystem
time system (representation) of the data
Definition: TimeTag.hpp:204
gnsstk::WeekSecond::getDayOfWeek
virtual unsigned int getDayOfWeek() const
Force this interface on this classes descendants.
Definition: WeekSecond.hpp:134
gnsstk::GPSWeekSecond::operator!=
bool operator!=(const GPSWeekSecond &right) const
Definition: GPSWeekSecond.hpp:108
gnsstk::Week::setModWeek
virtual void setModWeek(unsigned int w)
Definition: Week.hpp:206
gnsstk::GPSWeekSecond::MJDEpoch
long MJDEpoch(void) const
Return the Modified Julian Date (MJD) of epoch for this system.
Definition: GPSWeekSecond.hpp:92
gnsstk::GPSWeekSecond::operator<
bool operator<(const GPSWeekSecond &right) const
Definition: GPSWeekSecond.hpp:112
gnsstk::TimeTag::getFormatPrefixFloat
static std::string getFormatPrefixFloat()
Definition: TimeTag.hpp:157
gnsstk::StringUtils::asTimeSystem
TimeSystem asTimeSystem(const std::string &s)
Convert a string representation of TimeSystem to an enum.
Definition: TimeSystem.cpp:324
gnsstk::GPSWeekSecond::operator>
bool operator>(const GPSWeekSecond &right) const
Definition: GPSWeekSecond.hpp:116
gnsstk::GPS_EPOCH_MJD
const long GPS_EPOCH_MJD
Modified Julian Date of GPS epoch (Jan. 6, 1980).
Definition: TimeConstants.hpp:83
gnsstk::GPSWeekSecond::~GPSWeekSecond
~GPSWeekSecond()
Destructor.
Definition: GPSWeekSecond.hpp:74
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::WeekSecond::sow
double sow
Definition: WeekSecond.hpp:155
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
gnsstk::WeekSecond::operator<
bool operator<(const WeekSecond &right) const
Definition: WeekSecond.cpp:122
gnsstk::Week::week
int week
Full week number.
Definition: Week.hpp:267
gnsstk::StringUtils::asDouble
double asDouble(const std::string &s)
Definition: StringUtils.hpp:705
GNSSTK_RETHROW
#define GNSSTK_RETHROW(exc)
Definition: Exception.hpp:369
gnsstk::GPSWeekSecond::operator<=
bool operator<=(const GPSWeekSecond &right) const
Definition: GPSWeekSecond.hpp:120
gnsstk::WeekSecond
Definition: WeekSecond.hpp:60
gnsstk::GPSWeekSecond::getPrintChars
virtual std::string getPrintChars() const
Definition: GPSWeekSecond.hpp:132
WeekSecond.hpp
gnsstk::WeekSecond::operator>
bool operator>(const WeekSecond &right) const
Definition: WeekSecond.cpp:139
gnsstk::TimeSystem::GPS
@ GPS
GPS system time.
gnsstk::GPSWeekSecond::printf
virtual std::string printf(const std::string &fmt) const
Definition: GPSWeekSecond.hpp:145
gnsstk::GPSWeekSecond::GPSWeekSecond
GPSWeekSecond(unsigned int w=0, double s=0., TimeSystem ts=TimeSystem::GPS)
Constructor.
Definition: GPSWeekSecond.hpp:61
gnsstk::GPSWeekSecond::getDefaultFormat
virtual std::string getDefaultFormat() const
Return a string containing the default format to use in printing.
Definition: GPSWeekSecond.hpp:138
gnsstk::StringUtils::formattedPrint
std::string formattedPrint(const std::string &fmt, const std::string &pat, const std::string &rep, T to)
Definition: StringUtils.hpp:2020
gnsstk::WeekSecond::operator<=
bool operator<=(const WeekSecond &right) const
Definition: WeekSecond.cpp:144
gnsstk::GPSWeekSecond::operator==
bool operator==(const GPSWeekSecond &right) const
Definition: GPSWeekSecond.hpp:104
gnsstk::Week::getModWeek
virtual unsigned int getModWeek() const
Definition: Week.hpp:183
gnsstk::WeekSecond::operator!=
bool operator!=(const WeekSecond &right) const
Definition: WeekSecond.cpp:117


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