1 //==============================================================================
2 //
3 //  This file is part of GPSTk, the GPS Toolkit.
4 //
5 //  The GPSTk 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 GPSTk 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 GPSTk; 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-2020, 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 
39 /// @file EOPPrediction.hpp
40 /// class EOPPrediction encapsulates formulas to predict EOPs from data in
41 ///  NGA 'EOPP###.txt' files.
42 
43 #ifndef CLASS_EOPPREDICTION_INCLUDE
44 #define CLASS_EOPPREDICTION_INCLUDE
45 
46 //------------------------------------------------------------------------------------
47 // system includes
48 #include <iostream>
49 #include <iomanip>
50 #include <string>
51 // GPSTk
52 #include "Exception.hpp"
53 #include "EarthOrientation.hpp"
54 
55 //------------------------------------------------------------------------------------
56 namespace gpstk {
57 
58    //---------------------------------------------------------------------------------
59    /// Earth orientation parameter prediction
60    /// Read data from EOPP###.txt file, available from NGA. The formulas are:
61    ///                       2                           2
62    /// xp(t)= A + B(t-ta) + SUM(Cj sin[2pi(t-ta)/Pj]) + SUM(Dj cos[2pi(t-ta)/Pj])
63    ///                      j=1                         j=1
64    ///
65    ///                       2                           2
66    /// yp(t)= E + F(t-ta) + SUM(Gk sin[2pi(t-ta)/Qk]) + SUM(Hk cos[2pi(t-ta)/Qk])
67    ///                      k=1                         k=1
68    ///
69    ///                          4                           4
70    /// UT1-UTC(t)= I+J(t-tb) + SUM(Km sin[2pi(t-tb)/Rm]) + SUM(Lm cos[2pi(t-tb)/Rm])
71    ///                         m=1                         m=1
72    /// Ref. NGA document 'Earth Orientation Parameter Prediction (EOPP) Description'
73    /// Effective date 08 August 2004
74    /// http://earth-info.nga.mil/GandG/sathtml/eoppdoc.html
75    ///
76    class EOPPrediction {
77    private:
78       /// MJD of beginning of times at which this formula is valid; end time of
79       /// validity is tv+7. In EOPP files, this is an integer.
80       double tv;
81       /// reference times (MJD) used in the formulas
82 	   double ta,tb;
83       /// parameters used in the formulas
84 	   double A,B,C1,C2,D1,D2,E,F,G1,G2,H1,H2,I,J,K1,K2,K3,K4,L1,L2,L3,L4;
85       /// more parameters used in the formulas
86 	   double P1,P2,Q1,Q2,R1,R2,R3,R4;
87 
88    public:
89       /// the difference between TAI and UTC in seconds - not used in the computation
90 	   int TAIUTC;
91       /// the number used in the file name 'EOPP<SN>.txt'
92       int SerialNo;
93       /// information, including the MJD of generation of these parameters.
94       std::string Info;
95 
96       /// access the time (MJD) of validity of these parameters;
97       /// the range of validity is 'this' through 'this'+7.
getValidTime(void) const98       int getValidTime(void) const throw()
99          { return int(tv+0.5); }
100 
101       /// load the EOPPrediction in the given file
102       /// @param filename Name of file to read, including path.
103       /// @return  0 ok, -1 error reading file.
104       /// @throw FileMissingException if filename cannot be opened.
105       int loadFile(std::string filename);
106 
107       /// Generate serial number (NGA files are named EOPP<SN>.txt) from epoch.
108       /// SN (3 digit) = YWW : year (1 digit), week of year (2 digit)
109       /// @param mjd Time (MJD) at which to compute the serial number
110       /// @return the serial number.
111       /// @throw Exception
112       static int getSerialNumber(int mjd);
113 
114 	   /// Compute and return the Earth orientation parameters at the given MJD.
115       /// TD how to warn if input is outside limits of validity?
116       /// @param imjd integer MJD at which to compute the earth orientation parameters
117       /// @return the EarthOrientation at imjd.
118       /// @throw Exception
computeEOP(int & imjd) const119       EarthOrientation computeEOP(int& imjd) const
120       {
121          double dmjd(static_cast<double>(imjd));
122          return computeEOP(dmjd);
123       }
124 
125 	   /// Compute and return the Earth orientation parameters at the given epoch.
126       /// TD how to warn if input is outside limits of validity?
127       /// @param mjd Time (MJD) at which to compute the earth orientation parameters.
128       /// @return the EarthOrientation object at mjd.
129       EarthOrientation computeEOP(double& mjd) const
130          throw();
131 
132       /// Stream output for the EOPPrediction, in format of EOPP###.txt files.
133       /// @param os stream to append formatted EOPPrediction to.
134       /// @return reference to the input stream.
135       friend std::ostream& operator<<(std::ostream& s, const EOPPrediction&);
136 
137    }; // end class EOPPrediction
138 
139 }  // end namespace gpstk
140 
141 #endif // CLASS_EOPPREDICTION_INCLUDE
142