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 /**
40  * @file SatDataReader.hpp
41  * File stream for satellite file data in PRN_GPS-like format.
42  */
43 
44 #ifndef GPSTK_SATDATAREADER_HPP
45 #define GPSTK_SATDATAREADER_HPP
46 
47 #include <string>
48 #include <map>
49 #include "FFTextStream.hpp"
50 #include "StringUtils.hpp"
51 #include "CommonTime.hpp"
52 #include "SatID.hpp"
53 
54 
55 namespace gpstk
56 {
57       /// @ingroup formattedfile
58       //@{
59 
60       /** This is a class to read and parse satellite data from
61        *  PRN_GPS-like files.
62        *
63        *
64        * Jet Propulsion Laboratory (JPL) provides a file called "PRN_GPS"
65        * with satellite information such as launch and deactivation dates,
66        * block type GPS number, etc. This information is important for some
67        * precise GPS data processing algorithms, and is used in Gipsy/OASIS
68        * software.
69        *
70        * You may find this file using FTP:
71        *
72        * ftp://sideshow.jpl.nasa.gov:/pub/gipsy_products/gipsy_params
73        *
74        * where the PRN_GPS file resides, usually compressed in .gz format.
75        *
76        * A typical way to use this class follows:
77        *
78        * @code
79        *   SatDataReader satread;
80        *
81        *   SatID prn28(28, SatelliteSystem::GPS);
82        *   CommonTime time(1995, 331, 43200);
83        *
84        *   satread.open("PRN_GPS");
85        *
86        *   string prn28Block = satread.getBlock(prn28, time);
87        *   // From 1992 to 1997, PRN 28 belonged to a block IIA satellite
88        * @endcode
89        *
90        * @warning Be aware that PRN numbers are recycled, so several
91        * different satellites may have the same PRN number at different
92        * epochs. Therefore, you must provide the epoch of interest when
93        * calling get methods.
94        */
95    class SatDataReader : public FFTextStream
96    {
97    public:
98 
99          /// Default constructor
SatDataReader()100       SatDataReader() {}
101 
102          /** Common constructor. It will always open file for read and will
103           * load satellite data in one pass.
104           *
105           * @param fn   Satellite data file to read
106           *
107           */
SatDataReader(const char * fn)108       SatDataReader(const char* fn) : FFTextStream(fn, std::ios::in)
109       { loadData(); }
110 
111 
112          /** Common constructor. It will always open file for read and will
113           * load satellite data in one pass.
114           *
115           * @param fn   Satellite data file to read
116           *
117           */
SatDataReader(const std::string & fn)118       SatDataReader(const std::string& fn) : FFTextStream(fn.c_str(), std::ios::in)
119       { loadData(); }
120 #pragma clang diagnostic push
121 #pragma clang diagnostic ignored "-Woverloaded-virtual"
122 
123          /// Method to open AND load satellite data file.
124       virtual void open(const char* fn);
125 
126 
127          /// Method to open AND load satellite data file.
128       virtual void open(const std::string& fn);
129 #pragma clang diagnostic pop
130 
131          /// Method to clear all previously loaded satellite data.
clearData()132       virtual SatDataReader& clearData()
133       { SatelliteData.clear(); return (*this); };
134 
135 
136          /** Method to get the block type of a given SV at a given epoch.
137           *
138           * @param sat   Satellite ID.
139           * @param epoch Epoch of interest.
140           *
141           * @return String containing satellite's block. If satellite is
142           * not found or epoch is out of proper launch/deactivation bounds,
143           * this method will return an empty string.
144           */
145       virtual std::string getBlock(const SatID& sat,
146                                    const CommonTime& epoch) const;
147 
148 
149          /** Method to get the GPS number of a given SV at a given epoch.
150           *
151           * @param sat   Satellite ID.
152           * @param epoch Epoch of interest.
153           *
154           * @return Integer containing satellite's block. If satellite is
155           * not found or epoch is out of proper launch/deactivation bounds,
156           * this method will return -1.
157           */
158       virtual int getGPSNumber(const SatID& sat,
159                                const CommonTime& epoch) const;
160 
161 
162          /** Method to get the launch date of a given SV.
163           *
164           * @param sat   Satellite ID.
165           * @param epoch Epoch of interest.
166           *
167           * @return CommonTime object containing satellite's launch date. If
168           * satellite is not found or epoch is out of proper
169           * launch/deactivation bounds, this method will return
170           * CommonTime::END_OF_TIME.
171           */
172       virtual CommonTime getLaunchDate(const SatID& sat,
173                                     const CommonTime& epoch) const;
174 
175 
176          /** Method to get the deactivation date of a given SV.
177           *
178           * @param sat   Satellite ID.
179           * @param epoch Epoch of interest.
180           *
181           * @return CommonTime object containing satellite's deactivation date.
182           * If satellite is not found, epoch is out of proper
183           * launch/deactivation bounds or satellite is still active, this
184           * method will return CommonTime::BEGINNING_OF_TIME.
185           */
186       virtual CommonTime getDeactivationDate(const SatID& sat,
187                                           const CommonTime& epoch) const;
188 
189 
190          /// Destructor
~SatDataReader()191       virtual ~SatDataReader() {}
192 
193 
194    private:
195 
196 
197          /// A structure used to store satellite data.
198       struct svData
199       {
200             // Default constructor initializing the data in the structure
svDatagpstk::SatDataReader::svData201          svData() : launchDate(CommonTime::BEGINNING_OF_TIME),
202                     deactivationDate(CommonTime::END_OF_TIME),
203                     gpsNumber(0),
204                     block("") {}
205 
206          CommonTime launchDate;         ///< SV launch date.
207          CommonTime deactivationDate;   ///< SV deactivation date.
208          int gpsNumber;              ///< GPS number.
209          std::string block;               ///< Block the SV belongs to
210       };
211 
212 
213          /// Handy iterator type
214       typedef std::multimap<SatID, svData>::const_iterator satDataIt;
215 
216 
217          /// Map holding the information regarding every satellite
218       std::multimap<SatID, svData> SatelliteData;
219 
220 
221          /** Method to store satellite data in this class' data map
222           * @param sat   Satellite ID.
223           * @param data  svData structure holding the SV data
224           */
setData(const SatID & sat,const svData & data)225       void setData(const SatID& sat,
226                    const svData& data)
227       { SatelliteData.insert(std::pair<const SatID, svData>(sat, data)); }
228 
229 
230          /** Method to load satellite data in this class' data map
231           * @throw FFStreamError
232           * @throw StringUtils::StringException
233           */
234       virtual void loadData(void);
235 
236 
237    }; // End of class 'SatDataReader'
238 
239 
240       //@}
241 
242 }  // End of namespace gpstk
243 
244 #endif  // GPSTK_SATDATAREADER_HPP
245