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