ANSITime.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 
40 
41 #include <cmath>
42 #include "ANSITime.hpp"
43 #include "TimeConstants.hpp"
44 
45 namespace gnsstk
46 {
48  {
49  time = right.time;
50  timeSystem = right.timeSystem;
51  return *this;
52  }
53 
55  {
56  try
57  {
58  CommonTime ct;
59  return ct.set( ( MJD_JDAY + UNIX_MJD + time / SEC_PER_DAY ),
60  ( time % SEC_PER_DAY ),
61  0.,
62  timeSystem );
63  }
64  catch (InvalidParameter& ip)
65  {
66  InvalidRequest ir(ip);
67  GNSSTK_THROW(ir);
68  }
69  }
70 
72  {
75  static const CommonTime MIN_CT = ANSITime(0, TimeSystem::Any);
78  static const CommonTime MAX_CT = ANSITime(2147483647, TimeSystem::Any);
79 
80  if ( ct < MIN_CT || ct > MAX_CT )
81  {
82  InvalidRequest ir("Unable to convert given CommonTime to ANSITime.");
83  GNSSTK_THROW(ir);
84  }
85 
86  long jday, sod;
87  double fsod;
88  ct.get( jday, sod, fsod, timeSystem );
89 
90  time =
91  static_cast<time_t>((jday - MJD_JDAY - UNIX_MJD) * SEC_PER_DAY + sod);
92  }
93 
94  std::string ANSITime::printf( const std::string& fmt) const
95  {
96  try
97  {
99  std::string rv( fmt );
100 
101  rv = formattedPrint( rv, getFormatPrefixInt() + "K",
102  "Klu", time );
103  rv = formattedPrint( rv, getFormatPrefixInt() + "P",
104  "Ps", StringUtils::asString(timeSystem).c_str() );
105  return rv;
106  }
107  catch( StringUtils::StringException& se )
108  {
109  GNSSTK_RETHROW( se );
110  }
111  }
112 
113  std::string ANSITime::printError( const std::string& fmt) const
114  {
115  try
116  {
118  std::string rv( fmt );
119 
120  rv = formattedPrint( rv, getFormatPrefixInt() + "K",
121  "Ks", getError().c_str() );
122  rv = formattedPrint( rv, getFormatPrefixInt() + "P",
123  "Ps", getError().c_str() );
124  return rv;
125  }
126  catch( StringUtils::StringException& se )
127  {
128  GNSSTK_RETHROW( se );
129  }
130  }
131 
132  bool ANSITime::setFromInfo( const IdToValue& info )
133  {
134  using namespace StringUtils;
135 
136  for( IdToValue::const_iterator i = info.begin(); i != info.end(); i++ )
137  {
138  switch( i->first )
139  {
140  case 'K':
141  time = asInt( i->second );
142  break;
143 
144  case 'P':
146  break;
147 
148  default:
149  // do nothing
150  break;
151  };
152  }
153 
154  return true;
155  }
156 
157  bool ANSITime::isValid() const
158  {
159  ANSITime temp;
160  temp.convertFromCommonTime( convertToCommonTime() );
161  if( *this == temp )
162  {
163  return true;
164  }
165  return false;
166  }
167 
169  {
170  time = 0;
172  }
173 
174  bool ANSITime::operator==( const ANSITime& right ) const
175  {
177  if ((timeSystem != TimeSystem::Any &&
178  right.timeSystem != TimeSystem::Any) &&
179  timeSystem != right.timeSystem)
180  {
181  return false;
182  }
183  if( fabs(double(time - right.time)) < CommonTime::eps )
184  {
185  return true;
186  }
187  return false;
188  }
189 
190  bool ANSITime::operator!=( const ANSITime& right ) const
191  {
192  return ( !operator==( right ) );
193  }
194 
195  bool ANSITime::operator<( const ANSITime& right ) const
196  {
198  if ((timeSystem != TimeSystem::Any &&
199  right.timeSystem != TimeSystem::Any) &&
200  timeSystem != right.timeSystem)
201  {
202  InvalidRequest ir("CommonTime objects not in same time system, cannot be compared");
203  GNSSTK_THROW(ir);
204  }
205 
206  return ( time < right.time );
207  }
208 
209  bool ANSITime::operator>( const ANSITime& right ) const
210  {
211  return ( !operator<=( right ) );
212  }
213 
214  bool ANSITime::operator<=( const ANSITime& right ) const
215  {
216  return ( operator<( right ) ||
217  operator==( right ) );
218  }
219 
220  bool ANSITime::operator>=( const ANSITime& right ) const
221  {
222  return ( !operator<( right ) );
223  }
224 
225 } // namespace
gnsstk::TimeTag::getFormatPrefixInt
static std::string getFormatPrefixInt()
Definition: TimeTag.hpp:152
gnsstk::ANSITime::operator>
bool operator>(const ANSITime &right) const
Definition: ANSITime.cpp:209
gnsstk::StringUtils::asInt
long asInt(const std::string &s)
Definition: StringUtils.hpp:713
se
double se
obliquity cos, T*cos, sin coefficients
Definition: IERS2003NutationData.hpp:48
gnsstk::CommonTime::eps
static const GNSSTK_EXPORT double eps
Default tolerance for time equality in days.
Definition: CommonTime.hpp:107
TimeConstants.hpp
gnsstk::TimeTag::IdToValue
std::map< char, std::string > IdToValue
Definition: TimeTag.hpp:103
gnsstk::SEC_PER_DAY
const long SEC_PER_DAY
Seconds per day.
Definition: TimeConstants.hpp:63
gnsstk::TimeSystem::Any
@ Any
wildcard; allows comparison with any other type
gnsstk::StringUtils::asString
std::string asString(IonexStoreStrategy e)
Convert a IonexStoreStrategy to a whitespace-free string name.
Definition: IonexStoreStrategy.cpp:46
gnsstk::ANSITime::operator<
bool operator<(const ANSITime &right) const
Definition: ANSITime.cpp:195
gnsstk::TimeTag::getError
static std::string getError()
This returns the default error string for the TimeTag classes.
Definition: TimeTag.hpp:161
gnsstk::MJD_JDAY
const long MJD_JDAY
'Julian day' offset from MJD
Definition: TimeConstants.hpp:53
gnsstk::ANSITime::printf
virtual std::string printf(const std::string &fmt) const
Definition: ANSITime.cpp:94
gnsstk::TimeSystem::Unknown
@ Unknown
unknown time frame; for legacy code compatibility
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::TimeTag::timeSystem
TimeSystem timeSystem
time system (representation) of the data
Definition: TimeTag.hpp:204
example4.temp
temp
Definition: example4.py:35
gnsstk::ANSITime::setFromInfo
virtual bool setFromInfo(const IdToValue &info)
Definition: ANSITime.cpp:132
gnsstk::UNIX_MJD
const long UNIX_MJD
Modified Julian Date of UNIX epoch (Jan. 1, 1970).
Definition: TimeConstants.hpp:55
gnsstk::StringUtils::asTimeSystem
TimeSystem asTimeSystem(const std::string &s)
Convert a string representation of TimeSystem to an enum.
Definition: TimeSystem.cpp:324
gnsstk::ANSITime::printError
virtual std::string printError(const std::string &fmt) const
Definition: ANSITime.cpp:113
gnsstk::ANSITime::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: ANSITime.cpp:71
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::ANSITime::time
time_t time
Definition: ANSITime.hpp:172
gnsstk::CommonTime::get
void get(long &day, long &sod, double &fsod, TimeSystem &timeSystem) const
Definition: CommonTime.cpp:213
GNSSTK_RETHROW
#define GNSSTK_RETHROW(exc)
Definition: Exception.hpp:369
gnsstk::ANSITime::reset
virtual void reset()
Reset this object to the default state.
Definition: ANSITime.cpp:168
gnsstk::ANSITime
Definition: ANSITime.hpp:56
example6.sod
sod
Definition: example6.py:103
gnsstk::ANSITime::operator<=
bool operator<=(const ANSITime &right) const
Definition: ANSITime.cpp:214
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
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::ANSITime::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: ANSITime.cpp:54
gnsstk::ANSITime::isValid
virtual bool isValid() const
Returns true if this object's members are valid, false otherwise.
Definition: ANSITime.cpp:157
gnsstk::ANSITime::operator!=
bool operator!=(const ANSITime &right) const
Definition: ANSITime.cpp:190
gnsstk::ANSITime::ANSITime
ANSITime(time_t t=0, const TimeSystem &ts=TimeSystem::Unknown)
Definition: ANSITime.hpp:68
ANSITime.hpp
gnsstk::ANSITime::operator=
ANSITime & operator=(const ANSITime &right)
Definition: ANSITime.cpp:47
gnsstk::ANSITime::operator==
bool operator==(const ANSITime &right) const
Definition: ANSITime.cpp:174
gnsstk::ANSITime::operator>=
bool operator>=(const ANSITime &right) const
Definition: ANSITime.cpp:220
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:38