| 1 |
|
|---|
| 2 | /* -------------------------------------------------------------------------
|
|---|
| 3 | * BKG NTRIP Server
|
|---|
| 4 | * -------------------------------------------------------------------------
|
|---|
| 5 | *
|
|---|
| 6 | * Class: bncSP3
|
|---|
| 7 | *
|
|---|
| 8 | * Purpose: writes SP3 files
|
|---|
| 9 | *
|
|---|
| 10 | * Author: L. Mervart
|
|---|
| 11 | *
|
|---|
| 12 | * Created: 25-Apr-2008
|
|---|
| 13 | *
|
|---|
| 14 | * Changes:
|
|---|
| 15 | *
|
|---|
| 16 | * -----------------------------------------------------------------------*/
|
|---|
| 17 |
|
|---|
| 18 | #include <iomanip>
|
|---|
| 19 | #include <sstream>
|
|---|
| 20 | #include <iostream>
|
|---|
| 21 | #include <math.h>
|
|---|
| 22 |
|
|---|
| 23 | #include "bncsp3.h"
|
|---|
| 24 | #include "bncutils.h"
|
|---|
| 25 |
|
|---|
| 26 | using namespace std;
|
|---|
| 27 |
|
|---|
| 28 | // Constructor
|
|---|
| 29 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 30 | bncSP3::bncSP3(const QString& fileName) : bncoutf(QString(), QString(), 0) {
|
|---|
| 31 | _inpOut = input;
|
|---|
| 32 | _currEpoch = 0;
|
|---|
| 33 | _prevEpoch = 0;
|
|---|
| 34 |
|
|---|
| 35 | _stream.open(fileName.toLatin1().data());
|
|---|
| 36 | if (!_stream.good()) {
|
|---|
| 37 | throw "t_sp3File: cannot open file " + fileName;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | while (_stream.good()) {
|
|---|
| 41 | getline(_stream, _lastLine);
|
|---|
| 42 | if (_lastLine[0] == '*') {
|
|---|
| 43 | break;
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | // Constructor
|
|---|
| 49 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 50 | bncSP3::bncSP3(const QString& sklFileName, const QString& intr, int sampl)
|
|---|
| 51 | : bncoutf(sklFileName, intr, sampl) {
|
|---|
| 52 | _inpOut = output;
|
|---|
| 53 | _currEpoch = 0;
|
|---|
| 54 | _prevEpoch = 0;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | // Destructor
|
|---|
| 58 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 59 | bncSP3::~bncSP3() {
|
|---|
| 60 | delete _currEpoch;
|
|---|
| 61 | delete _prevEpoch;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | // Write One Epoch
|
|---|
| 65 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 66 | t_irc bncSP3::write(int GPSweek, double GPSweeks, const QString& prn,
|
|---|
| 67 | const ColumnVector& xCoM, double sp3Clk,
|
|---|
| 68 | const ColumnVector& v, double sp3ClkRate) {
|
|---|
| 69 |
|
|---|
| 70 | _oStr.setf(ios::fixed);
|
|---|
| 71 |
|
|---|
| 72 | if (reopen(GPSweek, GPSweeks) == success) {
|
|---|
| 73 |
|
|---|
| 74 | bncTime epoTime(GPSweek, GPSweeks);
|
|---|
| 75 |
|
|---|
| 76 | if (epoTime != _lastEpoTime) {
|
|---|
| 77 |
|
|---|
| 78 | // print out epoch before
|
|---|
| 79 | if (_lastEpoTime.valid()) {
|
|---|
| 80 | _out << _oStr.str();
|
|---|
| 81 | if (_lastEpoTime.daysec() != 0.0) {
|
|---|
| 82 | _oStr.str(std::string());
|
|---|
| 83 | }
|
|---|
| 84 | // Check the sampling interval (print empty epochs)
|
|---|
| 85 | // ------------------------------------------------
|
|---|
| 86 | if (_sampl > 0) {
|
|---|
| 87 | for (bncTime ep = _lastEpoTime +_sampl; ep < epoTime; ep = ep +_sampl) {
|
|---|
| 88 | _oStr << "\n* " << ep.datestr(' ') << ' ' << ep.timestr(8, ' ');
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | // Print the new epoch
|
|---|
| 94 | // -------------------
|
|---|
| 95 | _oStr << "\n* " << epoTime.datestr(' ') << ' ' << epoTime.timestr(8, ' ');
|
|---|
| 96 |
|
|---|
| 97 | _lastEpoTime = epoTime;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | _oStr << "\nP" << prn.toLatin1().data()
|
|---|
| 101 | << setw(14) << setprecision(6) << xCoM(1) / 1000.0 // [km]
|
|---|
| 102 | << setw(14) << setprecision(6) << xCoM(2) / 1000.0 // [km]
|
|---|
| 103 | << setw(14) << setprecision(6) << xCoM(3) / 1000.0 // [km]
|
|---|
| 104 | << setw(14) << setprecision(6) << sp3Clk * 1e6; // microseconds
|
|---|
| 105 |
|
|---|
| 106 | if (sp3ClkRate) {
|
|---|
| 107 | _oStr << "\nV" << prn.toLatin1().data()
|
|---|
| 108 | << setw(14) << setprecision(6) << v(1) * 10.0 // [dm/s]
|
|---|
| 109 | << setw(14) << setprecision(6) << v(2) * 10.0 // [dm/s]
|
|---|
| 110 | << setw(14) << setprecision(6) << v(3) * 10.0 // [dm/s]
|
|---|
| 111 | << setw(14) << setprecision(6) << sp3ClkRate * 1e2; // 10^⁻4 microseconds/sec
|
|---|
| 112 | }
|
|---|
| 113 | return success;
|
|---|
| 114 | }
|
|---|
| 115 | else {
|
|---|
| 116 | return failure;
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | // Close File (write last line)
|
|---|
| 121 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 122 | void bncSP3::closeFile() {
|
|---|
| 123 | _out << "\nEOF" << endl;
|
|---|
| 124 | bncoutf::closeFile();
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | // Write Header
|
|---|
| 128 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 129 | void bncSP3::writeHeader(const QDateTime& datTim) {
|
|---|
| 130 |
|
|---|
| 131 | int GPSWeek;
|
|---|
| 132 | double GPSWeeks;
|
|---|
| 133 | GPSweekFromDateAndTime(datTim, GPSWeek, GPSWeeks);
|
|---|
| 134 |
|
|---|
| 135 | double sec = fmod(GPSWeeks, 60.0);
|
|---|
| 136 |
|
|---|
| 137 | int mjd;
|
|---|
| 138 | double dayfrac;
|
|---|
| 139 | mjdFromDateAndTime(datTim, mjd, dayfrac);
|
|---|
| 140 |
|
|---|
| 141 | int numEpo = _numSec;
|
|---|
| 142 | if (_sampl > 0) {
|
|---|
| 143 | numEpo /= _sampl;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | _out << "#dP" << datTim.toString("yyyy MM dd hh mm").toLatin1().data()
|
|---|
| 147 | << setw(12) << setprecision(8) << sec
|
|---|
| 148 | << " " << setw(7) << numEpo << " ORBIT IGS20 HLM IGS" << endl;
|
|---|
| 149 |
|
|---|
| 150 | _out << "## "
|
|---|
| 151 | << setw(4) << GPSWeek
|
|---|
| 152 | << setw(16) << setprecision(8) << GPSWeeks
|
|---|
| 153 | << setw(15) << setprecision(8) << double(_sampl)
|
|---|
| 154 | << setw(6) << mjd
|
|---|
| 155 | << setw(16) << setprecision(13) << dayfrac << endl;
|
|---|
| 156 |
|
|---|
| 157 | _out << "+ 177 G01G02G03G04G05G06G07G08G09G10G11G12G13G14G15G16G17\n"
|
|---|
| 158 | << "+ G18G19G20G21G22G23G24G25G26G27G28G29G30G31G32R01R02\n"
|
|---|
| 159 | << "+ R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19\n"
|
|---|
| 160 | << "+ R20R21R22R23R24R25R26E01E02E03E04E05E06E07E08E09E10\n"
|
|---|
| 161 | << "+ E11E12E13E14E15E16E17E18E19E20E21E22E23E24E25E26E27\n"
|
|---|
| 162 | << "+ E28E29E30E31E32E33E34E35E36C01C02C03C04C05C06C07C08\n"
|
|---|
| 163 | << "+ C09C10C11C12C13C14C15C16C17C18C19C20C21C22C23C24C25\n"
|
|---|
| 164 | << "+ C26C27C28C29C30C31C32C33C34C35C36C37C38C39C40C41C42\n"
|
|---|
| 165 | << "+ C43C44C45C46C47C48C49C50C51C52C53C54C55C56C57C58C59\n"
|
|---|
| 166 | << "+ C60C61C62C63J01J02J03J04I01I02I03I04I05I06I07S20S24\n"
|
|---|
| 167 | << "+ S27S28S29S33S35S37S38 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 168 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 169 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 170 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 171 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 172 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 173 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 174 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 175 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 176 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 177 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 178 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 179 | << "%c M cc GPS ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc\n"
|
|---|
| 180 | << "%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc\n"
|
|---|
| 181 | << "%f 0.0000000 0.000000000 0.00000000000 0.000000000000000\n"
|
|---|
| 182 | << "%f 0.0000000 0.000000000 0.00000000000 0.000000000000000\n"
|
|---|
| 183 | << "%i 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 184 | << "%i 0 0 0 0 0 0 0 0 0\n"
|
|---|
| 185 | << "/* \n"
|
|---|
| 186 | << "/* \n"
|
|---|
| 187 | << "/* \n"
|
|---|
| 188 | << "/* ";
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | // Read Next Epoch
|
|---|
| 192 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 193 | const bncSP3::t_sp3Epoch* bncSP3::nextEpoch() {
|
|---|
| 194 |
|
|---|
| 195 | delete _prevEpoch; _prevEpoch = _currEpoch; _currEpoch = 0;
|
|---|
| 196 |
|
|---|
| 197 | if (_lastLine[0] == '*') {
|
|---|
| 198 | _currEpoch = new t_sp3Epoch();
|
|---|
| 199 | istringstream in(_lastLine.substr(1).c_str());
|
|---|
| 200 | int YY, MM, DD, hh, mm;
|
|---|
| 201 | double ss;
|
|---|
| 202 | in >> YY >> MM >> DD >> hh >> mm >> ss;
|
|---|
| 203 | _currEpoch->_tt.set(YY, MM, DD, hh, mm, ss);
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | while (_stream.good()) {
|
|---|
| 207 | getline(_stream, _lastLine);
|
|---|
| 208 | if (_stream.eof() || _lastLine.find("EOF") == 0) {
|
|---|
| 209 | _stream.close();
|
|---|
| 210 | break;
|
|---|
| 211 | }
|
|---|
| 212 | if (_lastLine[0] == '*') {
|
|---|
| 213 | break;
|
|---|
| 214 | }
|
|---|
| 215 | if (_lastLine[0] == 'V') {
|
|---|
| 216 | continue;
|
|---|
| 217 | }
|
|---|
| 218 | t_sp3Sat* sp3Sat = new t_sp3Sat();
|
|---|
| 219 | istringstream in(_lastLine.substr(1).c_str());
|
|---|
| 220 | in >> sp3Sat->_prn >> sp3Sat->_xyz(1) >> sp3Sat->_xyz(2) >> sp3Sat->_xyz(3) >> sp3Sat->_clk;
|
|---|
| 221 | sp3Sat->_xyz *= 1.e3;
|
|---|
| 222 |
|
|---|
| 223 | // Simple Check - check satellite radial distance
|
|---|
| 224 | double rr = sp3Sat->_xyz.NormFrobenius();
|
|---|
| 225 | const double MINDIST = 2.e7;
|
|---|
| 226 | const double MAXDIST = 6.e7;
|
|---|
| 227 | if (rr < MINDIST || rr > MAXDIST || std::isnan(rr)) {
|
|---|
| 228 | delete sp3Sat;
|
|---|
| 229 | continue;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | // Simple Check - clock valid
|
|---|
| 233 | if (sp3Sat->_clk == 999999.999999 ||
|
|---|
| 234 | sp3Sat->_clk == 0.0) {
|
|---|
| 235 | sp3Sat->_clkValid = false;
|
|---|
| 236 | sp3Sat->_clk = 0.0;
|
|---|
| 237 | }
|
|---|
| 238 | else {
|
|---|
| 239 | sp3Sat->_clkValid = true;
|
|---|
| 240 | sp3Sat->_clk *= t_CST::c * 1.e-6;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | _currEpoch->_sp3Sat.push_back(sp3Sat);
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | return _currEpoch;
|
|---|
| 247 | }
|
|---|