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