[3176] | 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 | *
|
---|
[8084] | 14 | * Changes:
|
---|
[3176] | 15 | *
|
---|
| 16 | * -----------------------------------------------------------------------*/
|
---|
| 17 |
|
---|
| 18 | #include <iomanip>
|
---|
[6331] | 19 | #include <sstream>
|
---|
[3176] | 20 | #include <math.h>
|
---|
| 21 |
|
---|
| 22 | #include "bncsp3.h"
|
---|
| 23 | #include "bncutils.h"
|
---|
| 24 |
|
---|
| 25 | using namespace std;
|
---|
| 26 |
|
---|
| 27 | // Constructor
|
---|
| 28 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6331] | 29 | bncSP3::bncSP3(const QString& fileName) : bncoutf(QString(), QString(), 0) {
|
---|
| 30 | _inpOut = input;
|
---|
| 31 | _currEpoch = 0;
|
---|
| 32 | _prevEpoch = 0;
|
---|
| 33 |
|
---|
[8204] | 34 | _stream.open(fileName.toLatin1().data());
|
---|
[6331] | 35 | if (!_stream.good()) {
|
---|
| 36 | throw "t_sp3File: cannot open file " + fileName;
|
---|
[8084] | 37 | }
|
---|
[6331] | 38 |
|
---|
| 39 | while (_stream.good()) {
|
---|
| 40 | getline(_stream, _lastLine);
|
---|
| 41 | if (_lastLine[0] == '*') {
|
---|
| 42 | break;
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | // Constructor
|
---|
| 48 | ////////////////////////////////////////////////////////////////////////////
|
---|
[8084] | 49 | bncSP3::bncSP3(const QString& sklFileName, const QString& intr, int sampl)
|
---|
[3184] | 50 | : bncoutf(sklFileName, intr, sampl) {
|
---|
[6331] | 51 | _inpOut = output;
|
---|
| 52 | _currEpoch = 0;
|
---|
| 53 | _prevEpoch = 0;
|
---|
[3176] | 54 | }
|
---|
| 55 |
|
---|
| 56 | // Destructor
|
---|
| 57 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 58 | bncSP3::~bncSP3() {
|
---|
[6331] | 59 | delete _currEpoch;
|
---|
| 60 | delete _prevEpoch;
|
---|
[3176] | 61 | }
|
---|
| 62 |
|
---|
| 63 | // Write One Epoch
|
---|
| 64 | ////////////////////////////////////////////////////////////////////////////
|
---|
[8084] | 65 | t_irc bncSP3::write(int GPSweek, double GPSweeks, const QString& prn,
|
---|
[8483] | 66 | const ColumnVector& xCoM, double sp3Clk,
|
---|
| 67 | const ColumnVector& v, double sp3ClkRate) {
|
---|
[3176] | 68 |
|
---|
[3184] | 69 | if (reopen(GPSweek, GPSweeks) == success) {
|
---|
[3176] | 70 |
|
---|
[4296] | 71 | bncTime epoTime(GPSweek, GPSweeks);
|
---|
| 72 |
|
---|
| 73 | if (epoTime != _lastEpoTime) {
|
---|
| 74 |
|
---|
| 75 | // Check the sampling interval (print empty epochs)
|
---|
| 76 | // ------------------------------------------------
|
---|
[4298] | 77 | if (_lastEpoTime.valid() && _sampl > 0) {
|
---|
[4296] | 78 | for (bncTime ep = _lastEpoTime +_sampl; ep < epoTime; ep = ep +_sampl) {
|
---|
[4297] | 79 | _out << "* " << ep.datestr(' ') << ' ' << ep.timestr(8, ' ') << endl;
|
---|
[4296] | 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[8084] | 83 | // Print the new epoch
|
---|
[4296] | 84 | // -------------------
|
---|
[4297] | 85 | _out << "* " << epoTime.datestr(' ') << ' ' << epoTime.timestr(8, ' ') << endl;
|
---|
[4296] | 86 |
|
---|
| 87 | _lastEpoTime = epoTime;
|
---|
[3176] | 88 | }
|
---|
[4296] | 89 |
|
---|
[8204] | 90 | _out << "P" << prn.toLatin1().data()
|
---|
[8483] | 91 | << setw(14) << setprecision(6) << xCoM(1) / 1000.0 // [km]
|
---|
| 92 | << setw(14) << setprecision(6) << xCoM(2) / 1000.0 // [km]
|
---|
| 93 | << setw(14) << setprecision(6) << xCoM(3) / 1000.0 // [km]
|
---|
| 94 | << setw(14) << setprecision(6) << sp3Clk * 1e6 // microseconds
|
---|
| 95 | << endl;
|
---|
[8084] | 96 |
|
---|
[8483] | 97 | if (sp3ClkRate) {
|
---|
| 98 | _out << "V" << prn.toLatin1().data()
|
---|
| 99 | << setw(14) << setprecision(6) << v(1) * 10.0 // [dm/s]
|
---|
| 100 | << setw(14) << setprecision(6) << v(2) * 10.0 // [dm/s]
|
---|
| 101 | << setw(14) << setprecision(6) << v(3) * 10.0 // [dm/s]
|
---|
| 102 | << setw(14) << setprecision(6) << sp3ClkRate * 1e2 // 10^⁻4 microseconds/sec
|
---|
| 103 | << endl;
|
---|
| 104 | }
|
---|
[3176] | 105 | return success;
|
---|
| 106 | }
|
---|
| 107 | else {
|
---|
| 108 | return failure;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | // Close File (write last line)
|
---|
| 113 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 114 | void bncSP3::closeFile() {
|
---|
| 115 | _out << "EOF" << endl;
|
---|
| 116 | bncoutf::closeFile();
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | // Write Header
|
---|
| 120 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 121 | void bncSP3::writeHeader(const QDateTime& datTim) {
|
---|
| 122 |
|
---|
| 123 | int GPSWeek;
|
---|
| 124 | double GPSWeeks;
|
---|
| 125 | GPSweekFromDateAndTime(datTim, GPSWeek, GPSWeeks);
|
---|
| 126 |
|
---|
| 127 | double sec = fmod(GPSWeeks, 60.0);
|
---|
| 128 |
|
---|
| 129 | int mjd;
|
---|
| 130 | double dayfrac;
|
---|
| 131 | mjdFromDateAndTime(datTim, mjd, dayfrac);
|
---|
[8084] | 132 |
|
---|
[4382] | 133 | int numEpo = _numSec;
|
---|
| 134 | if (_sampl > 0) {
|
---|
| 135 | numEpo /= _sampl;
|
---|
| 136 | }
|
---|
[3176] | 137 |
|
---|
[8204] | 138 | _out << "#aP" << datTim.toString("yyyy MM dd hh mm").toLatin1().data()
|
---|
[3176] | 139 | << setw(12) << setprecision(8) << sec
|
---|
[8084] | 140 | << " " << setw(7) << numEpo << " ORBIT IGS14 HLM IGS" << endl;
|
---|
[3176] | 141 |
|
---|
[8084] | 142 | _out << "## "
|
---|
[3176] | 143 | << setw(4) << GPSWeek
|
---|
| 144 | << setw(16) << setprecision(8) << GPSWeeks
|
---|
| 145 | << setw(15) << setprecision(8) << double(_sampl)
|
---|
| 146 | << setw(6) << mjd
|
---|
| 147 | << setw(16) << setprecision(13) << dayfrac << endl;
|
---|
| 148 |
|
---|
[3714] | 149 | _out << "+ 56 G01G02G03G04G05G06G07G08G09G10G11G12G13G14G15G16G17\n"
|
---|
| 150 | << "+ G18G19G20G21G22G23G24G25G26G27G28G29G30G31G32R01R02\n"
|
---|
| 151 | << "+ R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19\n"
|
---|
| 152 | << "+ R20R21R22R23R24 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
---|
[3176] | 153 | << "+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
---|
| 154 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
---|
| 155 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
---|
| 156 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
---|
| 157 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
---|
| 158 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
---|
| 159 | << "%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc\n"
|
---|
| 160 | << "%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc\n"
|
---|
| 161 | << "%f 0.0000000 0.000000000 0.00000000000 0.000000000000000\n"
|
---|
| 162 | << "%f 0.0000000 0.000000000 0.00000000000 0.000000000000000\n"
|
---|
| 163 | << "%i 0 0 0 0 0 0 0 0 0\n"
|
---|
| 164 | << "%i 0 0 0 0 0 0 0 0 0\n"
|
---|
| 165 | << "/* \n"
|
---|
| 166 | << "/* \n"
|
---|
| 167 | << "/* \n"
|
---|
| 168 | << "/* \n";
|
---|
| 169 | }
|
---|
| 170 |
|
---|
[6331] | 171 | // Read Next Epoch
|
---|
| 172 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 173 | const bncSP3::t_sp3Epoch* bncSP3::nextEpoch() {
|
---|
| 174 |
|
---|
| 175 | delete _prevEpoch; _prevEpoch = _currEpoch; _currEpoch = 0;
|
---|
| 176 |
|
---|
[6354] | 177 | if (_lastLine[0] == '*') {
|
---|
| 178 | _currEpoch = new t_sp3Epoch();
|
---|
| 179 | istringstream in(_lastLine.substr(1).c_str());
|
---|
| 180 | int YY, MM, DD, hh, mm;
|
---|
| 181 | double ss;
|
---|
| 182 | in >> YY >> MM >> DD >> hh >> mm >> ss;
|
---|
| 183 | _currEpoch->_tt.set(YY, MM, DD, hh, mm, ss);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[6440] | 186 | while (_stream.good()) {
|
---|
[6331] | 187 | getline(_stream, _lastLine);
|
---|
| 188 | if (_stream.eof() || _lastLine.find("EOF") == 0) {
|
---|
[6440] | 189 | _stream.close();
|
---|
[6331] | 190 | break;
|
---|
| 191 | }
|
---|
| 192 | if (_lastLine[0] == '*') {
|
---|
| 193 | break;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | t_sp3Sat* sp3Sat = new t_sp3Sat();
|
---|
| 197 | istringstream in(_lastLine.substr(1).c_str());
|
---|
[8084] | 198 | in >> sp3Sat->_prn >> sp3Sat->_xyz(1) >> sp3Sat->_xyz(2) >> sp3Sat->_xyz(3) >> sp3Sat->_clk;
|
---|
[6331] | 199 |
|
---|
[6533] | 200 | if (sp3Sat->_xyz.norm_Frobenius() == 0.0) {
|
---|
| 201 | delete sp3Sat;
|
---|
| 202 | continue;
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[6331] | 205 | sp3Sat->_xyz *= 1.e3;
|
---|
[6351] | 206 | if (sp3Sat->_clk == 999999.999999) {
|
---|
| 207 | sp3Sat->_clkValid = false;
|
---|
| 208 | sp3Sat->_clk = 0.0;
|
---|
| 209 | }
|
---|
| 210 | else {
|
---|
| 211 | sp3Sat->_clkValid = true;
|
---|
| 212 | sp3Sat->_clk *= t_CST::c * 1.e-6;
|
---|
| 213 | }
|
---|
[6331] | 214 |
|
---|
| 215 | _currEpoch->_sp3Sat.push_back(sp3Sat);
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | return _currEpoch;
|
---|
| 219 | }
|
---|