JulianDate.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 "JulianDate.hpp"
43 #include "TimeConstants.hpp"
44 
45 namespace gnsstk
46 {
48  {
49  jd = right.jd;
50  timeSystem = right.timeSystem;
51  return *this;
52  }
53 
55  {
56  try
57  {
58  long double temp_jd( jd + 0.5 );
59  long jday( static_cast<long>( temp_jd ) );
60  long double sod =
61  ( temp_jd - static_cast<long double>( jday ) ) * SEC_PER_DAY;
62 
63  CommonTime ct;
64  return ct.set( jday,
65  static_cast<long>( sod ),
66  static_cast<double>( sod - static_cast<long>( sod ) ),
67  timeSystem );
68  }
69  catch (InvalidParameter& ip)
70  {
71  InvalidRequest ir(ip);
72  GNSSTK_THROW(ir);
73  }
74  }
75 
77  {
78  long jday, sod;
79  double fsod;
80  ct.get( jday, sod, fsod, timeSystem );
81 
82  jd = static_cast<long double>( jday ) +
83  ( static_cast<long double>( sod )
84  + static_cast<long double>( fsod ) ) * DAY_PER_SEC
85  - 0.5;
86  }
87 
88  std::string JulianDate::printf( const std::string& fmt ) const
89  {
90  try
91  {
93  std::string rv( fmt );
94 
95  rv = formattedPrint( rv, getFormatPrefixFloat() + "J",
96  "JLf", jd );
97  rv = formattedPrint( rv, getFormatPrefixInt() + "P",
98  "Ps", StringUtils::asString(timeSystem).c_str() );
99  return rv;
100  }
101  catch( gnsstk::StringUtils::StringException& se )
102  {
103  GNSSTK_RETHROW( se );
104  }
105  }
106 
107  std::string JulianDate::printError( const std::string& fmt ) const
108  {
109  try
110  {
112  std::string rv( fmt );
113 
114  rv = formattedPrint( rv, getFormatPrefixFloat() + "J",
115  "Js", getError().c_str() );
116  rv = formattedPrint( rv, getFormatPrefixInt() + "P",
117  "Ps", getError().c_str() );
118  return rv;
119  }
120  catch( gnsstk::StringUtils::StringException& se )
121  {
122  GNSSTK_RETHROW( se );
123  }
124  }
125 
126  bool JulianDate::setFromInfo( const IdToValue& info )
127  {
128  using namespace gnsstk::StringUtils;
129 
130  for( IdToValue::const_iterator i = info.begin(); i != info.end(); i++ )
131  {
132  switch( i->first )
133  {
134  case 'J':
135  jd = asLongDouble( i->second );
136  break;
137 
138  case 'P':
140  break;
141 
142  default:
143  // do nothing
144  break;
145  };
146  }
147 
148  return true;
149  }
150 
151  bool JulianDate::isValid() const
152  {
154  temp.convertFromCommonTime( convertToCommonTime() );
155  if( *this == temp )
156  {
157  return true;
158  }
159  return false;
160  }
161 
163  {
164  jd = 0.0;
166  }
167 
168  bool JulianDate::operator==( const JulianDate& right ) const
169  {
171  if ((timeSystem != TimeSystem::Any &&
172  right.timeSystem != TimeSystem::Any) &&
173  timeSystem != right.timeSystem)
174  return false;
175 
176  if( std::abs(jd - right.jd) < CommonTime::eps )
177  {
178  return true;
179  }
180  return false;
181  }
182 
183  bool JulianDate::operator!=( const JulianDate& right ) const
184  {
185  return ( !operator==( right ) );
186  }
187 
188  bool JulianDate::operator<( const JulianDate& right ) const
189  {
191  if ((timeSystem != TimeSystem::Any &&
192  right.timeSystem != TimeSystem::Any) &&
193  timeSystem != right.timeSystem)
194  {
195  gnsstk::InvalidRequest ir("CommonTime objects not in same time system, cannot be compared");
196  GNSSTK_THROW(ir);
197  }
198 
199  if( jd < right.jd )
200  {
201  return true;
202  }
203  return false;
204  }
205 
206  bool JulianDate::operator>( const JulianDate& right ) const
207  {
208  return ( !operator<=( right ) );
209  }
210 
211  bool JulianDate::operator<=( const JulianDate& right ) const
212  {
213  return ( operator<( right ) ||
214  operator==( right ) );
215  }
216 
217  bool JulianDate::operator>=( const JulianDate& right ) const
218  {
219  return ( !operator<( right ) );
220  }
221 
222 } // namespace
gnsstk::TimeTag::getFormatPrefixInt
static std::string getFormatPrefixInt()
Definition: TimeTag.hpp:152
gnsstk::JulianDate::operator>
bool operator>(const JulianDate &right) const
Definition: JulianDate.cpp:206
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::JulianDate::reset
virtual void reset()
Reset this object to the default state.
Definition: JulianDate.cpp:162
gnsstk::JulianDate::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: JulianDate.cpp:76
gnsstk::JulianDate::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: JulianDate.cpp:54
gnsstk::JulianDate::setFromInfo
virtual bool setFromInfo(const IdToValue &info)
Definition: JulianDate.cpp:126
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::StringUtils::asLongDouble
long double asLongDouble(const std::string &s)
Definition: StringUtils.hpp:1652
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::TimeTag::getError
static std::string getError()
This returns the default error string for the TimeTag classes.
Definition: TimeTag.hpp:161
gnsstk::JulianDate
Definition: JulianDate.hpp:89
gnsstk::JulianDate::operator==
bool operator==(const JulianDate &right) const
Definition: JulianDate.cpp:168
gnsstk::TimeSystem::Unknown
@ Unknown
unknown time frame; for legacy code compatibility
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::JulianDate::printError
virtual std::string printError(const std::string &fmt) const
Definition: JulianDate.cpp:107
gnsstk::TimeTag::timeSystem
TimeSystem timeSystem
time system (representation) of the data
Definition: TimeTag.hpp:204
example4.temp
temp
Definition: example4.py:35
gnsstk::JulianDate::operator<=
bool operator<=(const JulianDate &right) const
Definition: JulianDate.cpp:211
JulianDate.hpp
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::CommonTime
Definition: CommonTime.hpp:84
gnsstk::JulianDate::operator!=
bool operator!=(const JulianDate &right) const
Definition: JulianDate.cpp:183
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::StringUtils
Definition: IonexStoreStrategy.cpp:44
example6.sod
sod
Definition: example6.py:103
gnsstk::JulianDate::jd
long double jd
Definition: JulianDate.hpp:202
gnsstk::DAY_PER_SEC
const double DAY_PER_SEC
Days per second.
Definition: TimeConstants.hpp:65
gnsstk::JulianDate::isValid
virtual bool isValid() const
Returns true if this object's members are valid, false otherwise.
Definition: JulianDate.cpp:151
gnsstk::JulianDate::operator>=
bool operator>=(const JulianDate &right) const
Definition: JulianDate.cpp:217
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::JulianDate::printf
virtual std::string printf(const std::string &fmt) const
Definition: JulianDate.cpp:88
gnsstk::JulianDate::operator=
JulianDate & operator=(const JulianDate &right)
Definition: JulianDate.cpp:47
gnsstk::JulianDate::operator<
bool operator<(const JulianDate &right) const
Definition: JulianDate.cpp:188
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::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:39