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 Rinex3NavData.hpp 40 /// Encapsulates RINEX ver 3.02 Navigation data 41 42 #ifndef GPSTK_RINEXNAVDATA_HPP 43 #define GPSTK_RINEXNAVDATA_HPP 44 45 #include <list> 46 #include <string> 47 48 #include "StringUtils.hpp" 49 #include "CommonTime.hpp" 50 #include "FFStream.hpp" 51 #include "Rinex3NavBase.hpp" 52 #include "Rinex3NavStream.hpp" 53 #include "EngEphemeris.hpp" // GPS only, deprecated 54 #include "GloEphemeris.hpp" 55 #include "GPSEphemeris.hpp" 56 #include "GalEphemeris.hpp" 57 #include "BDSEphemeris.hpp" 58 #include "QZSEphemeris.hpp" 59 #include "RinexSatID.hpp" 60 #include "RinexNavData.hpp" 61 62 namespace gpstk 63 { 64 /// @ingroup FileHandling 65 //@{ 66 67 /** 68 * This class models a RINEX 3 Nav record. 69 * 70 * \sa FunctionalTests/Rinex3NavText for example. 71 * \sa Rinex3NavHeader and Rinex3NavStream classes. 72 */ 73 74 class Rinex3NavData : public Rinex3NavBase 75 { 76 public: 77 /** Constructor 78 * @warning CHECK THE PRNID TO SEE IF THIS DATA IS VALID BEFORE 79 * USING!!!. 80 */ Rinex3NavData(void)81 Rinex3NavData(void) 82 : time(CommonTime::BEGINNING_OF_TIME), PRNID(-1), fitint(4) 83 {} 84 85 /// Initializes the nav data with a GloEphemeris 86 Rinex3NavData(const GloEphemeris& gloe); 87 88 /// Create from a RinexNavData (for backward compatibility) 89 Rinex3NavData(const RinexNavData& rnd); 90 91 /// Initializes the nav data with an EngEphemeris 92 /// EngEphemeris is deprecated; use GPSEphemeris 93 Rinex3NavData(const EngEphemeris& ee); 94 95 /// Initializes the nav data with a GPSEphemeris 96 Rinex3NavData(const GPSEphemeris& gpseph); 97 98 /// Initializes the nav data with a GalEphemeris 99 Rinex3NavData(const GalEphemeris& galeph); 100 101 /// Initializes the nav data with a BDSEphemeris 102 Rinex3NavData(const BDSEphemeris& bdseph); 103 104 /// Initializes the nav data with a QZSEphemeris 105 Rinex3NavData(const QZSEphemeris& qzseph); 106 107 /// Destructor ~Rinex3NavData()108 virtual ~Rinex3NavData() {} 109 110 /// Rinex3NavData is "data" so this function always returns true. isData(void) const111 virtual bool isData(void) const {return true;} 112 113 /// Write selected info (system dependent) as a single line 114 std::string dumpString(void) const; 115 116 /// A debug output function. 117 /// Prints the PRN id and the IODC for this record. 118 virtual void dump(std::ostream& s) const; 119 120 /// deprecated; use GPSEphemeris, GPS-only. 121 /// Converts Rinex3NavData to an EngEphemeris object. 122 operator EngEphemeris() const throw(); 123 124 /// Converts Rinex3NavData to a GPSEphemeris object. 125 operator GPSEphemeris() const throw(); 126 127 /// Converts this Rinex3NavData to a GloEphemeris object. 128 operator GloEphemeris() const throw(); 129 130 /// Converts Rinex3NavData to a GalEphemeris object. 131 operator GalEphemeris() const throw(); 132 133 /// Converts Rinex3NavData to a BDSEphemeris object. 134 operator BDSEphemeris() const throw(); 135 136 /// Converts Rinex3NavData to a QZSEphemeris object. 137 operator QZSEphemeris() const throw(); 138 139 /// Converts the (non-CommonTime) data to an easy list 140 /// for comparison operators. 141 std::list<double> toList() const; 142 143 /// Sort on time, then satellite; for use with Rinex3EphemerisStore operator <(const Rinex3NavData & right) const144 bool operator<(const Rinex3NavData& right) const 145 { 146 CommonTime t(time),r(right.time); 147 t.setTimeSystem(TimeSystem::Any); 148 r.setTimeSystem(TimeSystem::Any); 149 if(t == r) return (sat < right.sat); 150 return (t < r); 151 } 152 fixSF1xmitSOW(unsigned long sow)153 static long fixSF1xmitSOW(unsigned long sow) 154 { return sow - (sow % 30); } 155 156 157 /** @name General Data */ 158 //@{ 159 CommonTime time; ///< Time according to the sat/epoch record (TOC) 160 std::string satSys; ///< Satellite system of Epoch: G,R,E,S,C 161 short PRNID; ///< SV PRN ID 162 RinexSatID sat; ///< RinexSatID (from PRNID & satSys) 163 long xmitTime; ///< Time of subframe 1-3 (sec of week) 164 short weeknum; ///< GPS full week corresponding to HOWtime of SF1 165 ///< (N.B.:in RINEX files, week number corresponds 166 /// >to ToE, not GLO) 167 RNDouble accuracy; ///< SV accuracy (m) 168 short health; ///< SV health 169 //@} 170 171 /** @name GPS Data */ 172 //@{ 173 short codeflgs; ///< L2 codes 174 short L2Pdata; ///< L2 P data flag 175 RNDouble IODC; ///< Index of data-clock 176 RNDouble IODE; ///< Index of data-eph 177 //@} 178 179 /** @name GLO Data */ 180 //@{ 181 RNDouble TauN; ///< SV clock bias (sec) 182 RNDouble GammaN; ///< SV relative frequency bias 183 double MFTraw; ///< Message frame time (sec of UTC week) <double> 184 long MFtime; ///< Message frame time (sec of UTC week) <long> 185 short freqNum; ///< Frequency number (-7..+12) 186 RNDouble ageOfInfo; ///< Age of oper. information (days) 187 //@} 188 189 /** @name GAL Data */ 190 //@{ 191 short datasources; ///< Data sources 192 RNDouble IODnav; ///< Index of data-eph 193 //@} 194 195 /** @name GEO Data */ 196 //@{ 197 RNDouble accCode; ///< Accuracy code (URA, meters) 198 RNDouble IODN; ///< Issue of data navigation, DO229, 199 ///< 8 first bits after Message type if MT9 200 //@} 201 202 /** @name Clock Information */ 203 //@{ 204 double Toc; ///< Time of clock (sec of week) 205 RNDouble af0; ///< SV clock error (sec) 206 RNDouble af1; ///< SV clock drift (sec/sec) 207 RNDouble af2; ///< SV clock drift rate (sec/sec**2) 208 RNDouble Tgd; ///< Group delay diff. (sec) (GPS, BDS:B1/B3 GAL:E5a/E1) 209 RNDouble Tgd2; ///< Group delay differential (sec) (BDS:B2/B3 GAL:E5b/E1) 210 //@} 211 212 /** @name Harmonic Perturbations */ 213 //@{ 214 RNDouble Cuc; ///< Cosine latitude (rad) 215 RNDouble Cus; ///< Sine latitude (rad) 216 RNDouble Crc; ///< Cosine radius (m) 217 RNDouble Crs; ///< Sine radius (m) 218 RNDouble Cic; ///< Cosine inclination (rad) 219 RNDouble Cis; ///< Sine inclination (rad) 220 //@} 221 222 /** @name Major Ephemeris Parameters */ 223 //@{ 224 RNDouble Toe; ///< Ephemeris epoch (sec of week) 225 RNDouble M0; ///< Mean anomaly (rad) 226 RNDouble dn; ///< Correction to mean motion (rad/sec) 227 RNDouble ecc; ///< Eccentricity 228 RNDouble Ahalf; ///< SQRT of semi-major axis (m**1/2) 229 RNDouble OMEGA0; ///< Rt ascension of ascending node (rad) 230 RNDouble i0; ///< Inclination (rad) 231 RNDouble w; ///< Argument of perigee (rad) 232 RNDouble OMEGAdot; ///< Rate of Rt ascension (rad/sec) 233 RNDouble idot; ///< Rate of inclination angle (rad/sec) 234 RNDouble fitint; ///< Fit interval 235 236 //@} 237 238 /** @name Tabular Ephemeris Parameters */ 239 //@{ 240 RNDouble px, py, pz; ///< SV position 241 RNDouble vx, vy, vz; ///< SV velocity 242 RNDouble ax, ay, az; ///< SV acceleration 243 //@} 244 245 246 private: 247 248 /** Parses string \a currentLine to obtain PRN id and epoch. 249 * @param strm RINEX Nav stream 250 * @throw StringUtils::StringException 251 * @throw FFStreamError 252 */ 253 void getPRNEpoch(Rinex3NavStream& strm); 254 255 256 /** Read and parse the nth record after the epoch record 257 * @param int n record number (1-7), for nth record after 258 * the epoch line 259 * @param Rinex3NavStream strm stream to read from 260 * @throw StringUtils::StringException 261 * @throw FFStreamError 262 */ 263 void getRecord(const int& n, Rinex3NavStream& strm); 264 265 /** Generates the PRN/epoch line and outputs it to strm 266 * @param strm RINEX Nav stream 267 * @throw StringUtils::StringException 268 */ 269 void putPRNEpoch(Rinex3NavStream& strm) const; 270 271 272 /** Construct and write the nth record after the epoch record 273 * @param int n Record number (1-7), for nth record 274 * after the epoch line. 275 * @param Rinex3NavStream strm Stream to read from. 276 * @throw StringUtils::StringException 277 * @throw FFStreamError 278 */ 279 void putRecord(const int& n, Rinex3NavStream& strm) const; 280 281 /** Helper routine for constructors of this from 282 * OrbitEph-based Ephemerides */ 283 void loadFrom(const OrbitEph *oeptr); 284 285 /// Helper routine for casts from this to OrbitEph-based Ephemerides 286 void castTo(OrbitEph *oeptr) const; 287 288 protected: 289 290 /** This function retrieves a RINEX 3 NAV record from the given 291 * FFStream. 292 * If an error is encountered in reading from the stream, the stream 293 * is returned to its original position and its fail-bit is set. 294 * @throw std::exception 295 * @throw StringException when a StringUtils function fails. 296 * @throw FFStreamError when exceptions(failbit) is set and a read 297 * or formatting error occurs. This also resets the stream 298 * to its pre-read position. 299 */ 300 virtual void reallyGetRecord(FFStream& s); 301 302 303 /** Outputs the record to the FFStream \a s. 304 * @throw std::exception 305 * @throw StringUtils::StringException 306 * @throw FFStreamError 307 */ 308 virtual void reallyPutRecord(FFStream& s) const; 309 310 }; // End of class 'Rinex3NavData' 311 312 //@} 313 314 } // End of namespace gpstk 315 316 #endif // GPSTK_RINEXNAVDATA_HPP 317