EOPPrediction.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 //------------------------------------------------------------------------------------
45 #include "EOPPrediction.hpp"
46 #include "GNSSconstants.hpp" // for TWO_PI
47 #include "TimeConverters.hpp"
48 
49 //------------------------------------------------------------------------------------
50 using namespace std;
51 
52 namespace gnsstk
53 {
54  /* load the EOPPrediction in the given file
55  return 0 if ok, -1 if error reading file */
56  int EOPPrediction::loadFile(const string& filename)
57  {
58  bool ok;
59  int n;
60  string line, word;
61  ifstream inpf(filename.c_str());
62  if (!inpf)
63  {
64  FileMissingException fme("Could not open EOPP file " + filename);
65  GNSSTK_THROW(fme);
66  }
67 
68  ok = true;
69  n = 0; // n is line number
70  while (!inpf.eof() && inpf.good())
71  {
72  getline(inpf, line);
73  StringUtils::stripTrailing(line, '\r');
74  if (inpf.bad())
75  {
76  break;
77  }
78  if (line.size() > 80)
79  {
80  ok = false;
81  break;
82  }
83  switch (n)
84  {
85  case 0:
86  if (line.size() < 76)
87  {
88  ok = false;
89  break;
90  }
91  word = line.substr(0, 10);
93  word = line.substr(10, 10);
95  word = line.substr(20, 10);
97  word = line.substr(30, 10);
99  word = line.substr(40, 10);
101  word = line.substr(50, 10);
103  word = line.substr(60, 10);
105  word = line.substr(70, 6);
107  break;
108  case 1:
109  if (line.size() < 78)
110  {
111  ok = false;
112  break;
113  }
114  word = line.substr(0, 6);
116  word = line.substr(6, 10);
118  word = line.substr(16, 10);
120  word = line.substr(26, 10);
122  word = line.substr(36, 10);
124  word = line.substr(46, 10);
126  word = line.substr(56, 10);
128  word = line.substr(66, 6);
130  word = line.substr(72, 6);
132  break;
133  case 2:
134  if (line.size() < 70)
135  {
136  ok = false;
137  break;
138  }
139  word = line.substr(0, 10);
141  word = line.substr(10, 10);
143  word = line.substr(20, 10);
145  word = line.substr(30, 10);
147  word = line.substr(40, 10);
149  word = line.substr(50, 10);
151  word = line.substr(60, 10);
153  break;
154  case 3:
155  if (line.size() < 76)
156  {
157  ok = false;
158  break;
159  }
160  word = line.substr(0, 10);
162  word = line.substr(10, 10);
164  word = line.substr(20, 10);
166  word = line.substr(30, 10);
168  word = line.substr(40, 9);
170  word = line.substr(49, 9);
172  word = line.substr(58, 9);
174  word = line.substr(67, 9);
176  break;
177  case 4:
178  if (line.size() < 16)
179  {
180  ok = false;
181  break;
182  }
183  word = line.substr(0, 4);
184  TAIUTC = StringUtils::asInt(word);
185  word = line.substr(4, 5);
186  SerialNo = StringUtils::asInt(word);
187  // this actually integer : mjd of begin valid period
188  word = line.substr(9, 7);
190  Info = line.substr(16, 19);
191  break;
192  } // end switch on n=line number
193  if (!ok)
194  {
195  break;
196  }
197  n++;
198  };
199  inpf.close();
200  if (!ok)
201  {
202  FileMissingException fme("EOPP File " + filename +
203  " is corrupted or wrong format");
204  GNSSTK_THROW(fme);
205  }
206  if (inpf.bad())
207  {
208  return -1;
209  }
210  return 0;
211  }
212 
213  //---------------------------------------------------------------------------------
214  /* generate serial number (NGA files are named EOPP<sn>.txt) from epoch
215  SN = Year (1 digit) + week of year */
216  int EOPPrediction::getSerialNumber(int imjd)
217  {
218  int wk((imjd - GPS_EPOCH_MJD) / 7); // current week
219  int w2 = wk - 1; // the previous week
220  if (w2 < 0)
221  {
222  GNSSTK_THROW(Exception("Invalid week in EOPP file: " +
223  StringUtils::asString<short>(w2)));
224  }
225 
226  int yr, w1;
227  try
228  {
229  long mjdSun = GPS_EPOCH_MJD + w2 * 7; // Sunday of prev week
230  double mjdFri = mjdSun + 5.5; // Friday noon of previous week
231 
232  int mm, dd, dow;
233  long jday = MJD_JDAY + mjdSun + 5; // Friday prev week
234  convertJDtoCalendar(jday, yr, mm, dd); // get the year
235  jday = convertCalendarToJD(yr, 1, 1); // first day of that year
236  jday -= MJD_JDAY + GPS_EPOCH_MJD; // days since GPS epoch (1 Jan 1980)
237  w1 = jday / 7; // GPS week of first day of year
238  dow = jday - 7 * w1; // day of week of first day of year
239  if (dow == 6)
240  {
241  w1++; // week of first Friday of year
242  }
243  yr = yr % 10; // last digit of the year
244  }
245  catch (Exception& e)
246  {
247  GNSSTK_RETHROW(e);
248  }
249 
250  return (100 * yr + w2 - w1 + 1); // SN = Year (1 digit) + week of year
251  }
252 
253  //---------------------------------------------------------------------------------
254  /* 2 2
255  xp(t)= A + B(t-ta) + SUM(Cj sin[2pi(t-ta)/Pj]) + SUM(Dj cos[2pi(t-ta)/Pj])
256  j=1 j=1
257 
258  2 2
259  yp(t)= E + F(t-ta) + SUM(Gk sin[2pi(t-ta)/Qk]) + SUM(Hk cos[2pi(t-ta)/Qk])
260  k=1 k=1
261 
262  4 4
263  UT1-UTC(t)= I+J(t-tb) + SUM(Km sin[2pi(t-tb)/Rm]) + SUM(Lm
264  cos[2pi(t-tb)/Rm])
265  m=1 m=1 */
266  //---------------------------------------------------------------------------------
267  EarthOrientation EOPPrediction::computeEOP(double& mjd) const
268  {
269  double dt, arg;
270  EarthOrientation eo;
271 
272  double t = mjd;
273  // t = ep.MJD() + ep.secOfDay()/86400.0;
274  // if(t < tv || t > tv+7) // TD warn - outside valid range
275  //
276  dt = t - ta;
277  arg = TWO_PI * dt;
278  eo.xp = A + B * dt + C1 * ::sin(arg / P1) + D1 * ::cos(arg / P1) +
279  C2 * ::sin(arg / P2) + D2 * ::cos(arg / P2);
280  eo.yp = E + F * dt + G1 * ::sin(arg / Q1) + H1 * ::cos(arg / Q1) +
281  G2 * ::sin(arg / Q2) + H2 * ::cos(arg / Q2);
282 
283  dt = t - tb;
284  arg = TWO_PI * dt;
285  eo.UT1mUTC = I + J * dt + K1 * ::sin(arg / R1) + L1 * ::cos(arg / R1) +
286  K2 * ::sin(arg / R2) + L2 * ::cos(arg / R2) +
287  K3 * ::sin(arg / R3) + L3 * ::cos(arg / R3) +
288  K4 * ::sin(arg / R4) + L4 * ::cos(arg / R4);
289 
290  return eo;
291  }
292 
293  //---------------------------------------------------------------------------------
294  // straight from the doc
295  ostream& operator<<(ostream& os, const EOPPrediction& eopp)
296  {
297  os << fixed << setw(10) << setprecision(2) << eopp.ta << setw(10)
298  << setprecision(6) << eopp.A << setw(10) << setprecision(6) << eopp.B
299  << setw(10) << setprecision(6) << eopp.C1 << setw(10)
300  << setprecision(6) << eopp.C2 << setw(10) << setprecision(6) << eopp.D1
301  << setw(10) << setprecision(6) << eopp.D2 << setw(6) << setprecision(2)
302  << eopp.P1 << " " << endl;
303  os << setw(6) << setprecision(2) << eopp.P2 << setw(10) << setprecision(6)
304  << eopp.E << setw(10) << setprecision(6) << eopp.F << setw(10)
305  << setprecision(6) << eopp.G1 << setw(10) << setprecision(6) << eopp.G2
306  << setw(10) << setprecision(6) << eopp.H1 << setw(10)
307  << setprecision(6) << eopp.H2 << setw(6) << setprecision(2) << eopp.Q1
308  << setw(6) << setprecision(2) << eopp.Q2 << " " << endl;
309  os << setw(10) << setprecision(2) << eopp.tb << setw(10)
310  << setprecision(6) << eopp.I << setw(10) << setprecision(6) << eopp.J
311  << setw(10) << setprecision(6) << eopp.K1 << setw(10)
312  << setprecision(6) << eopp.K2 << setw(10) << setprecision(6) << eopp.K3
313  << setw(10) << setprecision(6) << eopp.K4 << " " << endl;
314  os << setw(10) << setprecision(6) << eopp.L1 << setw(10)
315  << setprecision(6) << eopp.L2 << setw(10) << setprecision(6) << eopp.L3
316  << setw(10) << setprecision(6) << eopp.L4 << setw(9) << setprecision(4)
317  << eopp.R1 << setw(9) << setprecision(4) << eopp.R2 << setw(9)
318  << setprecision(4) << eopp.R3 << setw(9) << setprecision(4) << eopp.R4
319  << " " << endl;
320  os << setw(4) << eopp.TAIUTC << setw(5) << eopp.SerialNo << setw(6)
321  << int(eopp.tv + 0.5) << " " << eopp.Info << " "
322  << " "
323  << " ";
324  return os;
325  }
326 
327 } // end namespace gnsstk
gnsstk::EOPPrediction::K1
double K1
Definition: EOPPrediction.hpp:92
gnsstk::StringUtils::asInt
long asInt(const std::string &s)
Definition: StringUtils.hpp:713
gnsstk::EOPPrediction::Q1
double Q1
Definition: EOPPrediction.hpp:95
gnsstk::EOPPrediction::R4
double R4
Definition: EOPPrediction.hpp:95
gnsstk::EOPPrediction::L1
double L1
Definition: EOPPrediction.hpp:93
example6.mjd
mjd
Definition: example6.py:102
gnsstk::EOPPrediction::H2
double H2
Definition: EOPPrediction.hpp:92
gnsstk::EOPPrediction::Info
std::string Info
information, including the MJD of generation of these parameters.
Definition: EOPPrediction.hpp:106
gnsstk::EOPPrediction::tv
double tv
Definition: EOPPrediction.hpp:88
gnsstk::EOPPrediction::G2
double G2
Definition: EOPPrediction.hpp:92
gnsstk::CarrierBand::G1
@ G1
GLONASS G1.
gnsstk::StringUtils::word
std::string word(const std::string &s, const std::string::size_type wordNum=0, const char delimiter=' ')
Definition: StringUtils.hpp:1112
L1
gnsstk::Matrix< double > L1
Definition: Matrix_LUDecomp_T.cpp:46
gnsstk::EOPPrediction::L2
double L2
Definition: EOPPrediction.hpp:93
gnsstk::EOPPrediction::F
double F
Definition: EOPPrediction.hpp:92
gnsstk::EOPPrediction::C1
double C1
Definition: EOPPrediction.hpp:92
gnsstk::EOPPrediction::A
double A
parameters used in the formulas
Definition: EOPPrediction.hpp:92
gnsstk::EOPPrediction::P2
double P2
Definition: EOPPrediction.hpp:95
gnsstk::EOPPrediction::I
double I
Definition: EOPPrediction.hpp:92
gnsstk::TWO_PI
const double TWO_PI
GPS value of PI*2.
Definition: GNSSconstants.hpp:68
gnsstk::MJD_JDAY
const long MJD_JDAY
'Julian day' offset from MJD
Definition: TimeConstants.hpp:53
GNSSconstants.hpp
gnsstk::EOPPrediction::K4
double K4
Definition: EOPPrediction.hpp:92
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::EOPPrediction::tb
double tb
Definition: EOPPrediction.hpp:90
P1
gnsstk::Matrix< double > P1
Definition: Matrix_LUDecomp_T.cpp:49
std::sin
double sin(gnsstk::Angle x)
Definition: Angle.hpp:144
gnsstk::EarthOrientation::yp
double yp
Polar motion angle yp, in arcseconds.
Definition: EarthOrientation.hpp:100
gnsstk::EOPPrediction::J
double J
Definition: EOPPrediction.hpp:92
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::StringUtils::stripTrailing
std::string & stripTrailing(std::string &s, const std::string &aString, std::string::size_type num=std::string::npos)
Definition: StringUtils.hpp:1453
gnsstk::EOPPrediction::SerialNo
int SerialNo
the number used in the file name 'EOPP<SN>.txt'
Definition: EOPPrediction.hpp:104
gnsstk::convertJDtoCalendar
void convertJDtoCalendar(long jd, int &iyear, int &imonth, int &iday)
Definition: TimeConverters.cpp:52
P2
gnsstk::Matrix< double > P2
Definition: Matrix_LUDecomp_T.cpp:49
gnsstk::EOPPrediction::E
double E
Definition: EOPPrediction.hpp:92
gnsstk::EOPPrediction::R1
double R1
Definition: EOPPrediction.hpp:95
L3
gnsstk::Matrix< double > L3
Definition: Matrix_LUDecomp_T.cpp:46
gnsstk::GPS_EPOCH_MJD
const long GPS_EPOCH_MJD
Modified Julian Date of GPS epoch (Jan. 6, 1980).
Definition: TimeConstants.hpp:83
gnsstk::EOPPrediction::ta
double ta
reference times (MJD) used in the formulas
Definition: EOPPrediction.hpp:90
arg
double arg
Definition: IERS1996UT1mUTCData.hpp:48
gnsstk::EOPPrediction::G1
double G1
Definition: EOPPrediction.hpp:92
TimeConverters.hpp
std::cos
double cos(gnsstk::Angle x)
Definition: Angle.hpp:146
gnsstk::StringUtils::asDouble
double asDouble(const std::string &s)
Definition: StringUtils.hpp:705
GNSSTK_RETHROW
#define GNSSTK_RETHROW(exc)
Definition: Exception.hpp:369
gnsstk::EOPPrediction::D2
double D2
Definition: EOPPrediction.hpp:92
gnsstk::EOPPrediction::Q2
double Q2
Definition: EOPPrediction.hpp:95
gnsstk::EOPPrediction::L4
double L4
Definition: EOPPrediction.hpp:93
std::operator<<
std::ostream & operator<<(std::ostream &s, gnsstk::StringUtils::FFLead v)
Definition: FormattedDouble_T.cpp:44
gnsstk::EOPPrediction::H1
double H1
Definition: EOPPrediction.hpp:92
gnsstk::EOPPrediction::C2
double C2
Definition: EOPPrediction.hpp:92
gnsstk::EOPPrediction::K3
double K3
Definition: EOPPrediction.hpp:92
std
Definition: Angle.hpp:142
gnsstk::EOPPrediction::R2
double R2
Definition: EOPPrediction.hpp:95
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
gnsstk::convertCalendarToJD
long convertCalendarToJD(int yy, int mm, int dd)
Definition: TimeConverters.cpp:100
gnsstk::EOPPrediction::P1
double P1
more parameters used in the formulas
Definition: EOPPrediction.hpp:95
gnsstk::EOPPrediction::TAIUTC
int TAIUTC
Definition: EOPPrediction.hpp:102
gnsstk::EOPPrediction::L3
double L3
Definition: EOPPrediction.hpp:93
gnsstk::EOPPrediction::R3
double R3
Definition: EOPPrediction.hpp:95
gnsstk::EarthOrientation
Definition: EarthOrientation.hpp:93
EOPPrediction.hpp
L2
gnsstk::Matrix< double > L2
Definition: Matrix_LUDecomp_T.cpp:46
gnsstk::EarthOrientation::xp
double xp
Polar motion angle xp, in arcseconds.
Definition: EarthOrientation.hpp:97
gnsstk::EOPPrediction
Definition: EOPPrediction.hpp:81
gnsstk::EarthOrientation::UT1mUTC
double UT1mUTC
Time offset UT1 minus UTC, in seconds.
Definition: EarthOrientation.hpp:103
gnsstk::EOPPrediction::D1
double D1
Definition: EOPPrediction.hpp:92
gnsstk::EOPPrediction::B
double B
Definition: EOPPrediction.hpp:92
gnsstk::EOPPrediction::K2
double K2
Definition: EOPPrediction.hpp:92
gnsstk::CarrierBand::G2
@ G2
GLONASS G2.


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