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 | if (reopen(GPSweek, GPSweeks) == success) {
|
---|
71 |
|
---|
72 | bncTime epoTime(GPSweek, GPSweeks);
|
---|
73 |
|
---|
74 | if (epoTime != _lastEpoTime) {
|
---|
75 |
|
---|
76 | // Check the sampling interval (print empty epochs)
|
---|
77 | // ------------------------------------------------
|
---|
78 | if (_lastEpoTime.valid() && _sampl > 0) {
|
---|
79 | for (bncTime ep = _lastEpoTime +_sampl; ep < epoTime; ep = ep +_sampl) {
|
---|
80 | _out << "* " << ep.datestr(' ') << ' ' << ep.timestr(8, ' ') << endl;
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | // Print the new epoch
|
---|
85 | // -------------------
|
---|
86 | _out << "* " << epoTime.datestr(' ') << ' ' << epoTime.timestr(8, ' ') << endl;
|
---|
87 |
|
---|
88 | _lastEpoTime = epoTime;
|
---|
89 | }
|
---|
90 |
|
---|
91 | _out << "P" << prn.toLatin1().data()
|
---|
92 | << setw(14) << setprecision(6) << xCoM(1) / 1000.0 // [km]
|
---|
93 | << setw(14) << setprecision(6) << xCoM(2) / 1000.0 // [km]
|
---|
94 | << setw(14) << setprecision(6) << xCoM(3) / 1000.0 // [km]
|
---|
95 | << setw(14) << setprecision(6) << sp3Clk * 1e6 // microseconds
|
---|
96 | << endl;
|
---|
97 |
|
---|
98 | if (sp3ClkRate) {
|
---|
99 | _out << "V" << prn.toLatin1().data()
|
---|
100 | << setw(14) << setprecision(6) << v(1) * 10.0 // [dm/s]
|
---|
101 | << setw(14) << setprecision(6) << v(2) * 10.0 // [dm/s]
|
---|
102 | << setw(14) << setprecision(6) << v(3) * 10.0 // [dm/s]
|
---|
103 | << setw(14) << setprecision(6) << sp3ClkRate * 1e2 // 10^⁻4 microseconds/sec
|
---|
104 | << endl;
|
---|
105 | }
|
---|
106 | return success;
|
---|
107 | }
|
---|
108 | else {
|
---|
109 | return failure;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | // Close File (write last line)
|
---|
114 | ////////////////////////////////////////////////////////////////////////////
|
---|
115 | void bncSP3::closeFile() {
|
---|
116 | _out << "EOF" << endl;
|
---|
117 | bncoutf::closeFile();
|
---|
118 | }
|
---|
119 |
|
---|
120 | // Write Header
|
---|
121 | ////////////////////////////////////////////////////////////////////////////
|
---|
122 | void bncSP3::writeHeader(const QDateTime& datTim) {
|
---|
123 |
|
---|
124 | int GPSWeek;
|
---|
125 | double GPSWeeks;
|
---|
126 | GPSweekFromDateAndTime(datTim, GPSWeek, GPSWeeks);
|
---|
127 |
|
---|
128 | double sec = fmod(GPSWeeks, 60.0);
|
---|
129 |
|
---|
130 | int mjd;
|
---|
131 | double dayfrac;
|
---|
132 | mjdFromDateAndTime(datTim, mjd, dayfrac);
|
---|
133 |
|
---|
134 | int numEpo = _numSec;
|
---|
135 | if (_sampl > 0) {
|
---|
136 | numEpo /= _sampl;
|
---|
137 | }
|
---|
138 |
|
---|
139 | _out << "#aP" << datTim.toString("yyyy MM dd hh mm").toLatin1().data()
|
---|
140 | << setw(12) << setprecision(8) << sec
|
---|
141 | << " " << setw(7) << numEpo << " ORBIT IGS14 HLM IGS" << endl;
|
---|
142 |
|
---|
143 | _out << "## "
|
---|
144 | << setw(4) << GPSWeek
|
---|
145 | << setw(16) << setprecision(8) << GPSWeeks
|
---|
146 | << setw(15) << setprecision(8) << double(_sampl)
|
---|
147 | << setw(6) << mjd
|
---|
148 | << setw(16) << setprecision(13) << dayfrac << endl;
|
---|
149 |
|
---|
150 | _out << "+ 56 G01G02G03G04G05G06G07G08G09G10G11G12G13G14G15G16G17\n"
|
---|
151 | << "+ G18G19G20G21G22G23G24G25G26G27G28G29G30G31G32R01R02\n"
|
---|
152 | << "+ R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19\n"
|
---|
153 | << "+ R20R21R22R23R24 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 | << "++ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"
|
---|
160 | << "%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc\n"
|
---|
161 | << "%c cc cc ccc ccc cccc cccc cccc cccc ccccc ccccc ccccc ccccc\n"
|
---|
162 | << "%f 0.0000000 0.000000000 0.00000000000 0.000000000000000\n"
|
---|
163 | << "%f 0.0000000 0.000000000 0.00000000000 0.000000000000000\n"
|
---|
164 | << "%i 0 0 0 0 0 0 0 0 0\n"
|
---|
165 | << "%i 0 0 0 0 0 0 0 0 0\n"
|
---|
166 | << "/* \n"
|
---|
167 | << "/* \n"
|
---|
168 | << "/* \n"
|
---|
169 | << "/* \n";
|
---|
170 | }
|
---|
171 |
|
---|
172 | // Read Next Epoch
|
---|
173 | ////////////////////////////////////////////////////////////////////////////
|
---|
174 | const bncSP3::t_sp3Epoch* bncSP3::nextEpoch() {
|
---|
175 |
|
---|
176 | delete _prevEpoch; _prevEpoch = _currEpoch; _currEpoch = 0;
|
---|
177 |
|
---|
178 | if (_lastLine[0] == '*') {
|
---|
179 | _currEpoch = new t_sp3Epoch();
|
---|
180 | istringstream in(_lastLine.substr(1).c_str());
|
---|
181 | int YY, MM, DD, hh, mm;
|
---|
182 | double ss;
|
---|
183 | in >> YY >> MM >> DD >> hh >> mm >> ss;
|
---|
184 | _currEpoch->_tt.set(YY, MM, DD, hh, mm, ss);
|
---|
185 | }
|
---|
186 |
|
---|
187 | while (_stream.good()) {
|
---|
188 | getline(_stream, _lastLine);
|
---|
189 | if (_stream.eof() || _lastLine.find("EOF") == 0) {
|
---|
190 | _stream.close();
|
---|
191 | break;
|
---|
192 | }
|
---|
193 | if (_lastLine[0] == '*') {
|
---|
194 | break;
|
---|
195 | }
|
---|
196 |
|
---|
197 | t_sp3Sat* sp3Sat = new t_sp3Sat();
|
---|
198 | istringstream in(_lastLine.substr(1).c_str());
|
---|
199 | in >> sp3Sat->_prn >> sp3Sat->_xyz(1) >> sp3Sat->_xyz(2) >> sp3Sat->_xyz(3) >> sp3Sat->_clk;
|
---|
200 |
|
---|
201 | if (sp3Sat->_xyz.NormFrobenius() == 0.0) {
|
---|
202 | delete sp3Sat;
|
---|
203 | continue;
|
---|
204 | }
|
---|
205 |
|
---|
206 | sp3Sat->_xyz *= 1.e3;
|
---|
207 | if (sp3Sat->_clk == 999999.999999) {
|
---|
208 | sp3Sat->_clkValid = false;
|
---|
209 | sp3Sat->_clk = 0.0;
|
---|
210 | }
|
---|
211 | else {
|
---|
212 | sp3Sat->_clkValid = true;
|
---|
213 | sp3Sat->_clk *= t_CST::c * 1.e-6;
|
---|
214 | }
|
---|
215 |
|
---|
216 | _currEpoch->_sp3Sat.push_back(sp3Sat);
|
---|
217 | }
|
---|
218 |
|
---|
219 | return _currEpoch;
|
---|
220 | }
|
---|