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 EOPStore.hpp
40 /// class gpstk::EOPStore encapsulates input, storage and retreval of
41 /// Earth Orientation Parameters (EOPs - cf. class EarthOrientation).
42 
43 #ifndef CLASS_EARTHORIENTSTORE_INCLUDE
44 #define CLASS_EARTHORIENTSTORE_INCLUDE
45 
46 //------------------------------------------------------------------------------------
47 // system includes
48 #include <iostream>
49 #include <iomanip>
50 #include <string>
51 #include <map>
52 // GPSTk
53 #include "Exception.hpp"
54 #include "IERSConvention.hpp"
55 #include "EOPPrediction.hpp"
56 #include "EarthOrientation.hpp"
57 
58 //------------------------------------------------------------------------------------
59 namespace gpstk {
60 
61    /// Earth orientation parameter store. Store EarthOrientation objects in a map
62    /// with key = integer MJD at which the EOPs are computed. Access the store
63    /// with any MJD(UTC), interpolating the stored EOPs to the given epoch using the
64    /// algorithm in class EarthOrientation.
65    class EOPStore
66    {
67       /// key is MJD at which the Earth orientation parameters apply
68       std::map<int, EarthOrientation> mapMJD_EOP;
69 
70       /// first and last times in the store, -1 if store is empty.
71       int begMJD,endMJD;
72 
73    public:
74       /// Constructor
EOPStore()75       EOPStore() : begMJD(-1), endMJD(-1) { }
76 
77       /// Add to the store directly
78       void addEOP(int MJD, EarthOrientation& eop)
79          throw();
80 
81       /// Add to the store by computing using an EOPPrediction
82       /// @param MJD integer MJD at which to add EOPs
83       /// @return non-0 if MJD is outside range
84       /// @throw Exception if MJD is invalid
85       int addEOP(int MJD, EOPPrediction& eopp);
86 
87       /// Add EOPs to the store via an input file: either an EOPP file
88       /// or a flat file produced by the IERS and available at USNO
89       /// (see http://maia.usno.navy.mil/ and get either file
90       /// 'finals.data' or 'finals2000A.data').
91       /// @param filename Name of file to read, including path.
92       /// @throw FileMissingException if file is not found.
93       void addFile(const std::string& filename);
94 
95       /// Add EOPs to the store via an EOPP file using class EOPPrediction.
96       /// Read the EOPP file and compute EOPs for all days within the valid range.
97       /// @param filename Name of file to read, including path.
98       /// @throw FileMissingException if file is not found.
99       void addEOPPFile(const std::string& filename);
100 
101       /// Add EOPs to the store via a flat IERS file; e.g. finals2000A.data from USNO.
102       /// @param filename Name of file to read, including path.
103       /// @throw FileMissingException if file is not found.
104       void addIERSFile(const std::string& filename);
105 
106       /// Edit the store by deleting all entries before(after)
107       /// the given min(max) MJDs (TimeSystem UTC).
108       /// If mjdmin is later than mjdmax, the two are switched.
109       /// @param mjdmin integer MJD desired earliest store time.
110       /// @param mjdmax integer MJD desired latest store time.
111       void edit(int mjdmin, int mjdmax)
112          throw();
113 
114       /// return the number of entries in the store
size(void)115       int size(void) throw()
116          { return mapMJD_EOP.size(); }
117 
118       /// clear the store
clear(void)119       void clear(void) throw()
120          { mapMJD_EOP.clear(); begMJD = endMJD = -1; }
121 
122       /// Dump the store to cout.
123       /// @param detail determines how much detail to include in the output
124       ///  0 start and stop times (MJD), and number of EOPs.
125       ///  1 list of all times and EOPs.
126       void dump(short detail=0, std::ostream& s=std::cout) const
127          throw();
128 
129       /// Return first time (MJD) in the store.
getFirstTimeMJD(void)130       int getFirstTimeMJD(void) throw()
131          { return begMJD; }
132 
133       /// Return last time (MJD) in the store.
getLastTimeMJD(void)134       int getLastTimeMJD(void) throw()
135          { return endMJD; }
136 
137       /// Get the EOP at the given epoch. This involves interpolation and corrections
138       /// as prescribed by the appropriate IERS convention, using code in class
139       /// EarthOrientation. This routine pulls data from the map for 4 entries
140       /// surrounding the input time; this array of data is passed to class
141       /// EarthOrientation to perform the interpolation and corrections.
142       /// @param mjd MJD(UTC) time of interest
143       /// @param conv IERSConvention to be used.
144       /// @throw InvalidRequest if the integer MJD falls outside the store,
145       ///   or if the store contains fewer than 4 entries
146       /// @return EarthOrientation EOPs at mjd.
147       EarthOrientation getEOP(const double& mjd, const IERSConvention& conv);
148 
149    };    // end class EOPStore
150 
151 }  // end namespace gpstk
152 
153 #endif   // CLASS_EARTHORIENTSTORE_INCLUDE
154