WeekSecond.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 #include "WeekSecond.hpp"
43 #include "TimeConstants.hpp"
44 #include "MJD.hpp"
45 
46 namespace gnsstk
47 {
49  {
50  Week::operator=(right);
51  sow = right.sow;
52  return *this;
53  }
54 
56  {
57  try
58  {
59  //int dow = static_cast<int>( sow * DAY_PER_SEC );
60  // Appears to have rounding issues on 32-bit platforms
61 
62  int dow = static_cast<int>( sow / SEC_PER_DAY );
63  // NB this assumes MJDEpoch is an integer - what if epoch H:M:S != 0:0:0 ?
64  long jday = MJD_JDAY + MJDEpoch() + (7 * week) + dow;
65  double sod(sow - SEC_PER_DAY * dow);
66  CommonTime ct;
67  return ct.set( jday,
68  static_cast<long>(sod),
69  sod - static_cast<long>(sod),
70  timeSystem );
71  }
72  catch (InvalidParameter& ip)
73  {
74  GNSSTK_RETHROW(ip);
75  }
76  }
77 
79  {
80  if(static_cast<MJD>(ct).mjd < MJDEpoch())
81  {
82  InvalidRequest ir("Unable to convert to Week/Second - before Epoch.");
83  GNSSTK_THROW(ir);
84  }
85 
86  long jday, sod;
87  double fsod;
88  ct.get( jday, sod, fsod, timeSystem );
89  // find the number of days since the beginning of the Epoch
90  jday -= MJD_JDAY + MJDEpoch();
91  // find out how many weeks that is
92  week = static_cast<int>( jday / 7 );
93  // find out what the day of week is
94  jday %= 7;
95 
96  sow = static_cast<double>( jday * SEC_PER_DAY + sod ) + fsod;
97  }
98 
99  bool WeekSecond::isValid() const
100  {
101  return ( Week::isValid() &&
102  sow < FULLWEEK );
103  }
104 
106  {
107  Week::reset();
108  sow = 0.0;
109  }
110 
111  bool WeekSecond::operator==( const WeekSecond& right ) const
112  {
113  return ( Week::operator==(right) &&
114  sow == right.sow );
115  }
116 
117  bool WeekSecond::operator!=( const WeekSecond& right ) const
118  {
119  return ( !operator==( right ) );
120  }
121 
122  bool WeekSecond::operator<( const WeekSecond& right ) const
123  {
124  if( Week::operator<(right) )
125  {
126  return true;
127  }
128  if( Week::operator>(right) )
129  {
130  return false;
131  }
132  if( sow < right.sow )
133  {
134  return true;
135  }
136  return false;
137  }
138 
139  bool WeekSecond::operator>( const WeekSecond& right ) const
140  {
141  return ( !operator<=( right ) );
142  }
143 
144  bool WeekSecond::operator<=( const WeekSecond& right ) const
145  {
146  return ( operator<( right ) || operator==( right ) );
147  }
148 
149  bool WeekSecond::operator>=( const WeekSecond& right ) const
150  {
151  return ( !operator<( right ) );
152  }
153 
154 } // namespace
gnsstk::WeekSecond::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: WeekSecond.cpp:55
TimeConstants.hpp
example6.mjd
mjd
Definition: example6.py:102
gnsstk::Week::operator=
Week & operator=(const Week &right)
Assignment Operator.
Definition: Week.cpp:46
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::Week::isValid
virtual bool isValid() const
Returns true if this object's members are valid, false otherwise.
Definition: Week.hpp:253
gnsstk::WeekSecond::operator>=
bool operator>=(const WeekSecond &right) const
Definition: WeekSecond.cpp:149
gnsstk::FULLWEEK
const long FULLWEEK
Seconds per whole week.
Definition: TimeConstants.hpp:60
gnsstk::MJD_JDAY
const long MJD_JDAY
'Julian day' offset from MJD
Definition: TimeConstants.hpp:53
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
MJD.hpp
gnsstk::TimeTag::timeSystem
TimeSystem timeSystem
time system (representation) of the data
Definition: TimeTag.hpp:204
gnsstk::WeekSecond::reset
virtual void reset()
Reset this object to the default state.
Definition: WeekSecond.cpp:105
gnsstk::WeekSecond::isValid
virtual bool isValid() const
Returns true if this object's members are valid, false otherwise.
Definition: WeekSecond.cpp:99
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::WeekSecond::sow
double sow
Definition: WeekSecond.hpp:155
gnsstk::CommonTime::get
void get(long &day, long &sod, double &fsod, TimeSystem &timeSystem) const
Definition: CommonTime.cpp:213
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_RETHROW
#define GNSSTK_RETHROW(exc)
Definition: Exception.hpp:369
gnsstk::WeekSecond
Definition: WeekSecond.hpp:60
WeekSecond.hpp
gnsstk::WeekSecond::operator>
bool operator>(const WeekSecond &right) const
Definition: WeekSecond.cpp:139
example6.sod
sod
Definition: example6.py:103
gnsstk::Week::MJDEpoch
virtual long MJDEpoch(void) const =0
gnsstk::MJD
Definition: MJD.hpp:54
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::Week::reset
virtual void reset()
Reset this object to the default state.
Definition: Week.hpp:258
gnsstk::WeekSecond::operator<=
bool operator<=(const WeekSecond &right) const
Definition: WeekSecond.cpp:144
gnsstk::WeekSecond::operator=
WeekSecond & operator=(const WeekSecond &right)
Definition: WeekSecond.cpp:48
gnsstk::WeekSecond::operator!=
bool operator!=(const WeekSecond &right) const
Definition: WeekSecond.cpp:117
gnsstk::CommonTime::set
CommonTime & set(long day, long sod, double fsod=0.0, TimeSystem timeSystem=TimeSystem::Unknown)
Definition: CommonTime.cpp:87


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