source: ntrip/trunk/BNC/src/ephemeris.cpp@ 8931

Last change on this file since 8931 was 8931, checked in by stuerze, 4 years ago

GPS fit intervall: different specifications in differet RINEX versions are now considerred

File size: 47.9 KB
RevLine 
[1025]1#include <sstream>
[2234]2#include <iostream>
[1025]3#include <iomanip>
[1239]4#include <cstring>
[1025]5
[2234]6#include <newmatio.h>
7
[1025]8#include "ephemeris.h"
[2221]9#include "bncutils.h"
[2285]10#include "bnctime.h"
[5070]11#include "bnccore.h"
[5839]12#include "bncutils.h"
[6141]13#include "satObs.h"
[6044]14#include "pppInclude.h"
[6400]15#include "pppModel.h"
[1025]16
17using namespace std;
18
[5749]19// Constructor
20////////////////////////////////////////////////////////////////////////////
21t_eph::t_eph() {
[6518]22 _checkState = unchecked;
23 _orbCorr = 0;
24 _clkCorr = 0;
[5749]25}
[7278]26// Destructor
27////////////////////////////////////////////////////////////////////////////
28t_eph::~t_eph() {
29 if (_orbCorr)
30 delete _orbCorr;
31 if (_clkCorr)
32 delete _clkCorr;
33}
[5749]34
[7481]35//
[5749]36////////////////////////////////////////////////////////////////////////////
[6141]37void t_eph::setOrbCorr(const t_orbCorr* orbCorr) {
[7888]38 if (_orbCorr) {
39 delete _orbCorr;
40 _orbCorr = 0;
41 }
[6141]42 _orbCorr = new t_orbCorr(*orbCorr);
[5749]43}
44
[7481]45//
[5749]46////////////////////////////////////////////////////////////////////////////
[6141]47void t_eph::setClkCorr(const t_clkCorr* clkCorr) {
[7888]48 if (_clkCorr) {
49 delete _clkCorr;
50 _clkCorr = 0;
51 }
[6141]52 _clkCorr = new t_clkCorr(*clkCorr);
[5749]53}
54
[7481]55//
[5749]56////////////////////////////////////////////////////////////////////////////
[6109]57t_irc t_eph::getCrd(const bncTime& tt, ColumnVector& xc, ColumnVector& vv, bool useCorr) const {
[6518]58
[8419]59 if (_checkState == bad ||
[8618]60 _checkState == unhealthy ||
61 _checkState == outdated) {
[6518]62 return failure;
63 }
[8903]64
[8542]65 xc.ReSize(6);
[5749]66 vv.ReSize(3);
[6213]67 if (position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data()) != success) {
68 return failure;
69 }
[5789]70 if (useCorr) {
[5839]71 if (_orbCorr && _clkCorr) {
[5849]72 double dtO = tt - _orbCorr->_time;
[6556]73 if (_orbCorr->_updateInt) {
[8903]74 dtO -= (0.5 * ssrUpdateInt[_orbCorr->_updateInt]);
[6556]75 }
[5839]76 ColumnVector dx(3);
[5849]77 dx[0] = _orbCorr->_xr[0] + _orbCorr->_dotXr[0] * dtO;
78 dx[1] = _orbCorr->_xr[1] + _orbCorr->_dotXr[1] * dtO;
79 dx[2] = _orbCorr->_xr[2] + _orbCorr->_dotXr[2] * dtO;
80
[7133]81 RSW_to_XYZ(xc.Rows(1,3), vv.Rows(1,3), dx, dx);
[5849]82
[5839]83 xc[0] -= dx[0];
84 xc[1] -= dx[1];
85 xc[2] -= dx[2];
[5849]86
[7133]87 ColumnVector dv(3);
88 RSW_to_XYZ(xc.Rows(1,3), vv.Rows(1,3), _orbCorr->_dotXr, dv);
89
90 vv[0] -= dv[0];
91 vv[1] -= dv[1];
92 vv[2] -= dv[2];
93
[5849]94 double dtC = tt - _clkCorr->_time;
[6556]95 if (_clkCorr->_updateInt) {
[8903]96 dtC -= (0.5 * ssrUpdateInt[_clkCorr->_updateInt]);
[6556]97 }
[7014]98 xc[3] += _clkCorr->_dClk + _clkCorr->_dotDClk * dtC + _clkCorr->_dotDotDClk * dtC * dtC;
[5839]99 }
100 else {
101 return failure;
102 }
[5749]103 }
104 return success;
105}
106
[6801]107//
108//////////////////////////////////////////////////////////////////////////////
109QString t_eph::rinexDateStr(const bncTime& tt, const t_prn& prn, double version) {
110 QString prnStr(prn.toString().c_str());
111 return rinexDateStr(tt, prnStr, version);
112}
113
114//
115//////////////////////////////////////////////////////////////////////////////
116QString t_eph::rinexDateStr(const bncTime& tt, const QString& prnStr, double version) {
117
118 QString datStr;
119
120 unsigned year, month, day, hour, min;
121 double sec;
122 tt.civil_date(year, month, day);
123 tt.civil_time(hour, min, sec);
124
125 QTextStream out(&datStr);
126
127 if (version < 3.0) {
128 QString prnHlp = prnStr.mid(1,2); if (prnHlp[0] == '0') prnHlp[0] = ' ';
129 out << prnHlp << QString(" %1 %2 %3 %4 %5%6")
130 .arg(year % 100, 2, 10, QChar('0'))
131 .arg(month, 2)
132 .arg(day, 2)
133 .arg(hour, 2)
134 .arg(min, 2)
135 .arg(sec, 5, 'f',1);
136 }
137 else {
138 out << prnStr << QString(" %1 %2 %3 %4 %5 %6")
139 .arg(year, 4)
140 .arg(month, 2, 10, QChar('0'))
141 .arg(day, 2, 10, QChar('0'))
142 .arg(hour, 2, 10, QChar('0'))
143 .arg(min, 2, 10, QChar('0'))
144 .arg(int(sec), 2, 10, QChar('0'));
145 }
146
147 return datStr;
148}
149
150// Constructor
151//////////////////////////////////////////////////////////////////////////////
152t_ephGPS::t_ephGPS(float rnxVersion, const QStringList& lines) {
153
154 const int nLines = 8;
155
156 if (lines.size() != nLines) {
157 _checkState = bad;
158 return;
159 }
160
161 // RINEX Format
162 // ------------
163 int fieldLen = 19;
164
165 int pos[4];
166 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
167 pos[1] = pos[0] + fieldLen;
168 pos[2] = pos[1] + fieldLen;
169 pos[3] = pos[2] + fieldLen;
170
171 // Read eight lines
172 // ----------------
173 for (int iLine = 0; iLine < nLines; iLine++) {
174 QString line = lines[iLine];
175
176 if ( iLine == 0 ) {
[8204]177 QTextStream in(line.left(pos[1]).toLatin1());
[6801]178 int year, month, day, hour, min;
179 double sec;
180
[7139]181 QString prnStr, n;
[6880]182 in >> prnStr;
[7639]183
184 if (prnStr.size() == 1 &&
[8168]185 (prnStr[0] == 'G' ||
186 prnStr[0] == 'J' ||
187 prnStr[0] == 'I')) {
[7139]188 in >> n;
189 prnStr.append(n);
[6880]190 }
[7639]191
[6880]192 in >> year >> month >> day >> hour >> min >> sec;
[6801]193 if (prnStr.at(0) == 'G') {
194 _prn.set('G', prnStr.mid(1).toInt());
195 }
196 else if (prnStr.at(0) == 'J') {
197 _prn.set('J', prnStr.mid(1).toInt());
198 }
[8168]199 else if (prnStr.at(0) == 'I') {
200 _prn.set('I', prnStr.mid(1).toInt());
201 }
[6801]202 else {
203 _prn.set('G', prnStr.toInt());
204 }
205
206 if (year < 80) {
207 year += 2000;
208 }
209 else if (year < 100) {
210 year += 1900;
211 }
212
213 _TOC.set(year, month, day, hour, min, sec);
214
215 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
216 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
217 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
218 _checkState = bad;
219 return;
220 }
221 }
222
223 else if ( iLine == 1 ) {
224 if ( readDbl(line, pos[0], fieldLen, _IODE ) ||
225 readDbl(line, pos[1], fieldLen, _Crs ) ||
226 readDbl(line, pos[2], fieldLen, _Delta_n) ||
227 readDbl(line, pos[3], fieldLen, _M0 ) ) {
228 _checkState = bad;
229 return;
230 }
231 }
232
233 else if ( iLine == 2 ) {
234 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
235 readDbl(line, pos[1], fieldLen, _e ) ||
236 readDbl(line, pos[2], fieldLen, _Cus ) ||
237 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
238 _checkState = bad;
239 return;
240 }
241 }
242
243 else if ( iLine == 3 ) {
244 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
245 readDbl(line, pos[1], fieldLen, _Cic ) ||
246 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
247 readDbl(line, pos[3], fieldLen, _Cis ) ) {
248 _checkState = bad;
249 return;
250 }
251 }
252
253 else if ( iLine == 4 ) {
254 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
255 readDbl(line, pos[1], fieldLen, _Crc ) ||
256 readDbl(line, pos[2], fieldLen, _omega ) ||
257 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
258 _checkState = bad;
259 return;
260 }
261 }
262
[8168]263 else if ( iLine == 5 && type() != t_eph::IRNSS) {
[6801]264 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
265 readDbl(line, pos[1], fieldLen, _L2Codes) ||
266 readDbl(line, pos[2], fieldLen, _TOEweek ) ||
267 readDbl(line, pos[3], fieldLen, _L2PFlag) ) {
268 _checkState = bad;
269 return;
270 }
271 }
[8168]272 else if ( iLine == 5 && type() == t_eph::IRNSS) {
273 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
274 readDbl(line, pos[2], fieldLen, _TOEweek) ) {
275 _checkState = bad;
276 return;
277 }
278 }
[6801]279
[8168]280 else if ( iLine == 6 && type() != t_eph::IRNSS) {
[6801]281 if ( readDbl(line, pos[0], fieldLen, _ura ) ||
282 readDbl(line, pos[1], fieldLen, _health) ||
283 readDbl(line, pos[2], fieldLen, _TGD ) ||
284 readDbl(line, pos[3], fieldLen, _IODC ) ) {
285 _checkState = bad;
286 return;
287 }
288 }
[8168]289 else if ( iLine == 6 && type() == t_eph::IRNSS) {
290 if ( readDbl(line, pos[0], fieldLen, _ura ) ||
291 readDbl(line, pos[1], fieldLen, _health) ||
292 readDbl(line, pos[2], fieldLen, _TGD ) ) {
293 _checkState = bad;
294 return;
295 }
296 }
[6801]297 else if ( iLine == 7 ) {
298 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
299 _checkState = bad;
300 return;
301 }
[8927]302 // fitInterval is not valid for IRNSS
303 if (type() != t_eph::IRNSS) {
304 double fitIntervalRnx;
305 readDbl(line, pos[1], fieldLen, fitIntervalRnx);
[8931]306 if (type() == t_eph::GPS) {
307 if (rnxVersion < 3.03) {// specified as flag for GPS
308 _fitInterval = fitIntervalFromFlag(fitIntervalRnx, _IODC, t_eph::GPS);
309 } else { // specified as time period for GPS since 3.03
310 _fitInterval = fitIntervalRnx;
311 }
[8927]312 } else if (type() == t_eph::QZSS) { // specified as flag for QZSS
313 _fitInterval = fitIntervalFromFlag(fitIntervalRnx, _IODC, t_eph::QZSS);
314 }
[8925]315 }
[6801]316 }
317 }
318}
319
[8931]320
[2222]321// Compute GPS Satellite Position (virtual)
[1025]322////////////////////////////////////////////////////////////////////////////
[6213]323t_irc t_ephGPS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[1025]324
[1098]325 static const double omegaEarth = 7292115.1467e-11;
[5277]326 static const double gmGRS = 398.6005e12;
[1025]327
[8542]328 memset(xc, 0, 6*sizeof(double));
[1025]329 memset(vv, 0, 3*sizeof(double));
330
331 double a0 = _sqrt_A * _sqrt_A;
332 if (a0 == 0) {
[6213]333 return failure;
[1025]334 }
335
[5277]336 double n0 = sqrt(gmGRS/(a0*a0*a0));
[4018]337
338 bncTime tt(GPSweek, GPSweeks);
[4543]339 double tk = tt - bncTime(int(_TOEweek), _TOEsec);
[4018]340
[1025]341 double n = n0 + _Delta_n;
342 double M = _M0 + n*tk;
343 double E = M;
344 double E_last;
[8368]345 int nLoop = 0;
[1025]346 do {
347 E_last = E;
348 E = M + _e*sin(E);
[8368]349
350 if (++nLoop == 100) {
351 return failure;
352 }
353 } while ( fabs(E-E_last)*a0 > 0.001);
[1025]354 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
355 double u0 = v + _omega;
356 double sin2u0 = sin(2*u0);
357 double cos2u0 = cos(2*u0);
358 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
359 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
360 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
361 double xp = r*cos(u);
362 double yp = r*sin(u);
[7481]363 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
[4018]364 omegaEarth*_TOEsec;
[7278]365
[1025]366 double sinom = sin(OM);
367 double cosom = cos(OM);
368 double sini = sin(i);
369 double cosi = cos(i);
370 xc[0] = xp*cosom - yp*cosi*sinom;
371 xc[1] = xp*sinom + yp*cosi*cosom;
[7481]372 xc[2] = yp*sini;
373
[4018]374 double tc = tt - _TOC;
[2429]375 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
[1025]376
377 // Velocity
378 // --------
379 double tanv2 = tan(v/2);
380 double dEdM = 1 / (1 - _e*cos(E));
[7278]381 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
[1025]382 * dEdM * n;
383 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
384 double dotom = _OMEGADOT - omegaEarth;
385 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
[7278]386 double dotr = a0 * _e*sin(E) * dEdM * n
[1025]387 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
388 double dotx = dotr*cos(u) - r*sin(u)*dotu;
389 double doty = dotr*sin(u) + r*cos(u)*dotu;
390
391 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
392 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
393 + yp*sini*sinom*doti; // dX / di
394
395 vv[1] = sinom *dotx + cosi*cosom *doty
396 + xp*cosom*dotom - yp*cosi*sinom*dotom
397 - yp*sini*cosom*doti;
398
399 vv[2] = sini *doty + yp*cosi *doti;
[2429]400
401 // Relativistic Correction
402 // -----------------------
[7481]403 // correspondent to IGS convention and GPS ICD (and SSR standard)
[2429]404 xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
[6213]405
[8542]406 xc[4] = _clock_drift + _clock_driftrate*tc;
407 xc[5] = _clock_driftrate;
[8581]408
[6213]409 return success;
[1025]410}
411
[6801]412// RINEX Format String
413//////////////////////////////////////////////////////////////////////////////
414QString t_ephGPS::toString(double version) const {
[2221]415
[6801]416 QString rnxStr = rinexDateStr(_TOC, _prn, version);
[2221]417
[6801]418 QTextStream out(&rnxStr);
[2221]419
[6801]420 out << QString("%1%2%3\n")
421 .arg(_clock_bias, 19, 'e', 12)
422 .arg(_clock_drift, 19, 'e', 12)
423 .arg(_clock_driftrate, 19, 'e', 12);
[2221]424
[6801]425 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
[2221]426
[6801]427 out << QString(fmt)
428 .arg(_IODE, 19, 'e', 12)
429 .arg(_Crs, 19, 'e', 12)
430 .arg(_Delta_n, 19, 'e', 12)
431 .arg(_M0, 19, 'e', 12);
432
433 out << QString(fmt)
434 .arg(_Cuc, 19, 'e', 12)
435 .arg(_e, 19, 'e', 12)
436 .arg(_Cus, 19, 'e', 12)
437 .arg(_sqrt_A, 19, 'e', 12);
438
439 out << QString(fmt)
440 .arg(_TOEsec, 19, 'e', 12)
441 .arg(_Cic, 19, 'e', 12)
442 .arg(_OMEGA0, 19, 'e', 12)
443 .arg(_Cis, 19, 'e', 12);
444
445 out << QString(fmt)
446 .arg(_i0, 19, 'e', 12)
447 .arg(_Crc, 19, 'e', 12)
448 .arg(_omega, 19, 'e', 12)
449 .arg(_OMEGADOT, 19, 'e', 12);
450
[8800]451 if (type() == t_eph::IRNSS) {
[8168]452 out << QString(fmt)
453 .arg(_IDOT, 19, 'e', 12)
[8800]454 .arg(0.0, 19, 'e', 12)
455 .arg(_TOEweek, 19, 'e', 12)
456 .arg(0.0, 19, 'e', 12);
457 }
458 else {
459 out << QString(fmt)
460 .arg(_IDOT, 19, 'e', 12)
[8168]461 .arg(_L2Codes, 19, 'e', 12)
462 .arg(_TOEweek, 19, 'e', 12)
463 .arg(_L2PFlag, 19, 'e', 12);
[8800]464 }
[6801]465
[8168]466 if (type() == t_eph::IRNSS) {
467 out << QString(fmt)
468 .arg(_ura, 19, 'e', 12)
469 .arg(_health, 19, 'e', 12)
470 .arg(_TGD, 19, 'e', 12)
[8790]471 .arg(0.0, 19, 'e', 12);
[8168]472 }
473 else {
474 out << QString(fmt)
475 .arg(_ura, 19, 'e', 12)
476 .arg(_health, 19, 'e', 12)
477 .arg(_TGD, 19, 'e', 12)
478 .arg(_IODC, 19, 'e', 12);
479 }
[6801]480
[7922]481 double tot = _TOT;
482 if (tot == 0.9999e9 && version < 3.0) {
483 tot = 0.0;
484 }
[8927]485 // fitInterval
486 if (type() == t_eph::IRNSS) { // not valid for IRNSS
[8800]487 out << QString(fmt)
[8168]488 .arg(tot, 19, 'e', 12)
[8800]489 .arg(0.0, 19, 'e', 12)
490 .arg("", 19, QChar(' '))
491 .arg("", 19, QChar(' '));
492 }
493 else {
[8931]494 double fitIntervalRnx;
495 if (type() == t_eph::GPS) {
496 if (version < 3.03) { // specified as flag)
497 (_fitInterval == 4.0) ? fitIntervalRnx = 0.0 : fitIntervalRnx = 1.0;
498 }
499 else {
500 fitIntervalRnx = _fitInterval; // specified as time period in hours
501 }
502 }
503 else if (type() == t_eph::QZSS) { // specified as flag
[8925]504 (_fitInterval == 2.0) ? fitIntervalRnx = 0.0 : fitIntervalRnx = 1.0;
505 }
[8800]506 out << QString(fmt)
[8925]507 .arg(tot, 19, 'e', 12)
508 .arg(fitIntervalRnx, 19, 'e', 12)
509 .arg("", 19, QChar(' '))
510 .arg("", 19, QChar(' '));
[8800]511 }
[6801]512 return rnxStr;
[2221]513}
514
[6801]515// Constructor
516//////////////////////////////////////////////////////////////////////////////
517t_ephGlo::t_ephGlo(float rnxVersion, const QStringList& lines) {
[2221]518
[6801]519 const int nLines = 4;
520
521 if (lines.size() != nLines) {
522 _checkState = bad;
523 return;
[6518]524 }
525
[6801]526 // RINEX Format
527 // ------------
528 int fieldLen = 19;
[2221]529
[6801]530 int pos[4];
531 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
532 pos[1] = pos[0] + fieldLen;
533 pos[2] = pos[1] + fieldLen;
534 pos[3] = pos[2] + fieldLen;
[2221]535
[6801]536 // Read four lines
537 // ---------------
538 for (int iLine = 0; iLine < nLines; iLine++) {
539 QString line = lines[iLine];
[2221]540
[6801]541 if ( iLine == 0 ) {
[8204]542 QTextStream in(line.left(pos[1]).toLatin1());
[6213]543
[6801]544 int year, month, day, hour, min;
545 double sec;
[2221]546
[7139]547 QString prnStr, n;
[6880]548 in >> prnStr;
[7639]549 if (prnStr.size() == 1 && prnStr[0] == 'R') {
[7139]550 in >> n;
551 prnStr.append(n);
[6880]552 }
553 in >> year >> month >> day >> hour >> min >> sec;
[6801]554 if (prnStr.at(0) == 'R') {
555 _prn.set('R', prnStr.mid(1).toInt());
556 }
557 else {
558 _prn.set('R', prnStr.toInt());
559 }
[2221]560
[6801]561 if (year < 80) {
562 year += 2000;
563 }
564 else if (year < 100) {
565 year += 1900;
566 }
[2221]567
[6801]568 _gps_utc = gnumleap(year, month, day);
[2221]569
[6801]570 _TOC.set(year, month, day, hour, min, sec);
571 _TOC = _TOC + _gps_utc;
[8800]572 int nd = int((_TOC.gpssec())) / (24.0*60.0*60.0);
[6801]573 if ( readDbl(line, pos[1], fieldLen, _tau ) ||
574 readDbl(line, pos[2], fieldLen, _gamma) ||
575 readDbl(line, pos[3], fieldLen, _tki ) ) {
576 _checkState = bad;
577 return;
578 }
[8800]579 _tki -= nd * 86400.0;
580 _tau = -_tau;
[6801]581 }
582
583 else if ( iLine == 1 ) {
584 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
585 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
586 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
587 readDbl(line, pos[3], fieldLen, _health ) ) {
588 _checkState = bad;
589 return;
590 }
591 }
592
593 else if ( iLine == 2 ) {
594 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
595 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
596 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
597 readDbl(line, pos[3], fieldLen, _frequency_number) ) {
598 _checkState = bad;
599 return;
600 }
601 }
602
603 else if ( iLine == 3 ) {
604 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
605 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
606 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
607 readDbl(line, pos[3], fieldLen, _E ) ) {
608 _checkState = bad;
609 return;
610 }
611 }
612 }
613
614 // Initialize status vector
615 // ------------------------
616 _tt = _TOC;
[8698]617 _xv.ReSize(6); _xv = 0.0;
[6801]618 _xv(1) = _x_pos * 1.e3;
619 _xv(2) = _y_pos * 1.e3;
620 _xv(3) = _z_pos * 1.e3;
621 _xv(4) = _x_velocity * 1.e3;
622 _xv(5) = _y_velocity * 1.e3;
623 _xv(6) = _z_velocity * 1.e3;
[2221]624}
625
[6801]626// Compute Glonass Satellite Position (virtual)
[2771]627////////////////////////////////////////////////////////////////////////////
[6801]628t_irc t_ephGlo::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[2771]629
[6801]630 static const double nominalStep = 10.0;
[2771]631
[8542]632 memset(xc, 0, 6*sizeof(double));
[2771]633 memset(vv, 0, 3*sizeof(double));
634
[6801]635 double dtPos = bncTime(GPSweek, GPSweeks) - _tt;
636
[8698]637 if (fabs(dtPos) > 24 * 3600.0) {
[6213]638 return failure;
[2771]639 }
640
[6801]641 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
642 double step = dtPos / nSteps;
[4018]643
[6801]644 double acc[3];
645 acc[0] = _x_acceleration * 1.e3;
646 acc[1] = _y_acceleration * 1.e3;
647 acc[2] = _z_acceleration * 1.e3;
[8456]648
[6801]649 for (int ii = 1; ii <= nSteps; ii++) {
650 _xv = rungeKutta4(_tt.gpssec(), _xv, step, acc, glo_deriv);
651 _tt = _tt + step;
652 }
[4018]653
[6801]654 // Position and Velocity
655 // ---------------------
656 xc[0] = _xv(1);
657 xc[1] = _xv(2);
658 xc[2] = _xv(3);
[2771]659
[6801]660 vv[0] = _xv(4);
661 vv[1] = _xv(5);
662 vv[2] = _xv(6);
[2771]663
[6801]664 // Clock Correction
665 // ----------------
666 double dtClk = bncTime(GPSweek, GPSweeks) - _TOC;
667 xc[3] = -_tau + _gamma * dtClk;
[2771]668
[8542]669 xc[4] = _gamma;
670 xc[5] = 0.0;
[8483]671
[6213]672 return success;
[2771]673}
674
[6801]675// RINEX Format String
[3659]676//////////////////////////////////////////////////////////////////////////////
[6801]677QString t_ephGlo::toString(double version) const {
[3664]678
[8800]679 QString rnxStr = rinexDateStr(_TOC -_gps_utc, _prn, version);
680 int nd = int((_TOC - _gps_utc).gpssec()) / (24.0*60.0*60.0);
[6801]681 QTextStream out(&rnxStr);
[3664]682
[6801]683 out << QString("%1%2%3\n")
[8800]684 .arg(-_tau, 19, 'e', 12)
685 .arg(_gamma, 19, 'e', 12)
686 .arg(_tki+nd*86400.0, 19, 'e', 12);
[3668]687
[6801]688 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
[3664]689
[6801]690 out << QString(fmt)
691 .arg(_x_pos, 19, 'e', 12)
692 .arg(_x_velocity, 19, 'e', 12)
693 .arg(_x_acceleration, 19, 'e', 12)
694 .arg(_health, 19, 'e', 12);
[3664]695
[6801]696 out << QString(fmt)
697 .arg(_y_pos, 19, 'e', 12)
698 .arg(_y_velocity, 19, 'e', 12)
699 .arg(_y_acceleration, 19, 'e', 12)
700 .arg(_frequency_number, 19, 'e', 12);
[3666]701
[6801]702 out << QString(fmt)
703 .arg(_z_pos, 19, 'e', 12)
704 .arg(_z_velocity, 19, 'e', 12)
705 .arg(_z_acceleration, 19, 'e', 12)
706 .arg(_E, 19, 'e', 12);
[3666]707
[6801]708 return rnxStr;
[3659]709}
710
[6801]711// Derivative of the state vector using a simple force model (static)
712////////////////////////////////////////////////////////////////////////////
713ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv,
714 double* acc) {
[3659]715
[6801]716 // State vector components
717 // -----------------------
718 ColumnVector rr = xv.rows(1,3);
719 ColumnVector vv = xv.rows(4,6);
[3699]720
[6801]721 // Acceleration
[3699]722 // ------------
[6801]723 static const double gmWGS = 398.60044e12;
724 static const double AE = 6378136.0;
725 static const double OMEGA = 7292115.e-11;
726 static const double C20 = -1082.6257e-6;
[3699]727
[8903]728 double rho = rr.NormFrobenius();
[6801]729 double t1 = -gmWGS/(rho*rho*rho);
730 double t2 = 3.0/2.0 * C20 * (gmWGS*AE*AE) / (rho*rho*rho*rho*rho);
731 double t3 = OMEGA * OMEGA;
732 double t4 = 2.0 * OMEGA;
733 double z2 = rr(3) * rr(3);
[3699]734
[6801]735 // Vector of derivatives
736 // ---------------------
737 ColumnVector va(6);
738 va(1) = vv(1);
739 va(2) = vv(2);
740 va(3) = vv(3);
741 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2) + acc[0];
742 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1) + acc[1];
743 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3) + acc[2];
[3699]744
[6801]745 return va;
746}
[3699]747
[6801]748// IOD of Glonass Ephemeris (virtual)
749////////////////////////////////////////////////////////////////////////////
[7169]750unsigned int t_ephGlo::IOD() const {
[6801]751 bncTime tMoscow = _TOC - _gps_utc + 3 * 3600.0;
[7054]752 return (unsigned long)tMoscow.daysec() / 900;
[3659]753}
754
[8187]755// Health status of Glonass Ephemeris (virtual)
756////////////////////////////////////////////////////////////////////////////
757unsigned int t_ephGlo::isUnhealthy() const {
[8215]758
[8217]759 if (_almanac_health_availablility_indicator) {
[8215]760 if ((_health == 0 && _almanac_health == 0) ||
761 (_health == 1 && _almanac_health == 0) ||
762 (_health == 1 && _almanac_health == 1)) {
763 return 1;
764 }
[8187]765 }
[8217]766 else if (!_almanac_health_availablility_indicator) {
767 if (_health) {
768 return 1;
769 }
770 }
[8215]771 return 0; /* (_health == 0 && _almanac_health == 1) or (_health == 0) */
[8187]772}
773
[8217]774
[3659]775// Constructor
776//////////////////////////////////////////////////////////////////////////////
[4891]777t_ephGal::t_ephGal(float rnxVersion, const QStringList& lines) {
[6809]778 int year, month, day, hour, min;
779 double sec;
780 QString prnStr;
[4891]781 const int nLines = 8;
782 if (lines.size() != nLines) {
[6518]783 _checkState = bad;
[4891]784 return;
785 }
786
787 // RINEX Format
788 // ------------
789 int fieldLen = 19;
[6792]790 double SVhealth = 0.0;
791 double datasource = 0.0;
[6798]792
[4891]793 int pos[4];
794 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
795 pos[1] = pos[0] + fieldLen;
796 pos[2] = pos[1] + fieldLen;
797 pos[3] = pos[2] + fieldLen;
798
799 // Read eight lines
800 // ----------------
801 for (int iLine = 0; iLine < nLines; iLine++) {
802 QString line = lines[iLine];
803
804 if ( iLine == 0 ) {
[8204]805 QTextStream in(line.left(pos[1]).toLatin1());
[7140]806 QString n;
[6880]807 in >> prnStr;
[7639]808 if (prnStr.size() == 1 && prnStr[0] == 'E') {
[7139]809 in >> n;
810 prnStr.append(n);
[6880]811 }
812 in >> year >> month >> day >> hour >> min >> sec;
[4891]813 if (year < 80) {
814 year += 2000;
815 }
816 else if (year < 100) {
817 year += 1900;
818 }
819
820 _TOC.set(year, month, day, hour, min, sec);
821
822 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
823 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
824 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
[6518]825 _checkState = bad;
[4891]826 return;
827 }
828 }
829
830 else if ( iLine == 1 ) {
831 if ( readDbl(line, pos[0], fieldLen, _IODnav ) ||
832 readDbl(line, pos[1], fieldLen, _Crs ) ||
833 readDbl(line, pos[2], fieldLen, _Delta_n) ||
834 readDbl(line, pos[3], fieldLen, _M0 ) ) {
[6518]835 _checkState = bad;
[4891]836 return;
837 }
838 }
839
840 else if ( iLine == 2 ) {
841 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
842 readDbl(line, pos[1], fieldLen, _e ) ||
843 readDbl(line, pos[2], fieldLen, _Cus ) ||
844 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
[6518]845 _checkState = bad;
[4891]846 return;
847 }
848 }
849
850 else if ( iLine == 3 ) {
851 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
852 readDbl(line, pos[1], fieldLen, _Cic ) ||
853 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
854 readDbl(line, pos[3], fieldLen, _Cis ) ) {
[6518]855 _checkState = bad;
[4891]856 return;
857 }
858 }
859
860 else if ( iLine == 4 ) {
861 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
862 readDbl(line, pos[1], fieldLen, _Crc ) ||
863 readDbl(line, pos[2], fieldLen, _omega ) ||
864 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
[6518]865 _checkState = bad;
[4891]866 return;
867 }
868 }
869
870 else if ( iLine == 5 ) {
[6792]871 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
872 readDbl(line, pos[1], fieldLen, datasource) ||
873 readDbl(line, pos[2], fieldLen, _TOEweek ) ) {
[6518]874 _checkState = bad;
[4891]875 return;
[6792]876 } else {
877 if (int(datasource) & (1<<8)) {
[6812]878 _fnav = true;
879 _inav = false;
[6792]880 } else if (int(datasource) & (1<<9)) {
[6812]881 _fnav = false;
882 _inav = true;
[6792]883 }
[6892]884 _TOEweek -= 1024.0;
[4891]885 }
886 }
887
888 else if ( iLine == 6 ) {
889 if ( readDbl(line, pos[0], fieldLen, _SISA ) ||
[6792]890 readDbl(line, pos[1], fieldLen, SVhealth) ||
[4891]891 readDbl(line, pos[2], fieldLen, _BGD_1_5A) ||
892 readDbl(line, pos[3], fieldLen, _BGD_1_5B) ) {
[6518]893 _checkState = bad;
[4891]894 return;
[6792]895 } else {
896 // Bit 0
[6812]897 _e1DataInValid = (int(SVhealth) & (1<<0));
[6792]898 // Bit 1-2
[6802]899 _E1_bHS = double((int(SVhealth) >> 1) & 0x3);
[6792]900 // Bit 3
[6812]901 _e5aDataInValid = (int(SVhealth) & (1<<3));
[6792]902 // Bit 4-5
[6802]903 _E5aHS = double((int(SVhealth) >> 4) & 0x3);
[6792]904 // Bit 6
[6812]905 _e5bDataInValid = (int(SVhealth) & (1<<6));
[6792]906 // Bit 7-8
[6802]907 _E5bHS = double((int(SVhealth) >> 7) & 0x3);
[6809]908
909 if (prnStr.at(0) == 'E') {
[7140]910 _prn.set('E', prnStr.mid(1).toInt(), _inav ? 1 : 0);
[6809]911 }
[4891]912 }
913 }
914
915 else if ( iLine == 7 ) {
916 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
[6518]917 _checkState = bad;
[4891]918 return;
919 }
920 }
921 }
[3659]922}
[4013]923
[6801]924// Compute Galileo Satellite Position (virtual)
925////////////////////////////////////////////////////////////////////////////
926t_irc t_ephGal::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[4013]927
[6801]928 static const double omegaEarth = 7292115.1467e-11;
[8212]929 static const double gmWGS = 398.6004418e12;
[4023]930
[8542]931 memset(xc, 0, 6*sizeof(double));
[6801]932 memset(vv, 0, 3*sizeof(double));
[4023]933
[6801]934 double a0 = _sqrt_A * _sqrt_A;
935 if (a0 == 0) {
936 return failure;
937 }
[4023]938
[6801]939 double n0 = sqrt(gmWGS/(a0*a0*a0));
[4023]940
[6801]941 bncTime tt(GPSweek, GPSweeks);
942 double tk = tt - bncTime(_TOC.gpsw(), _TOEsec);
[4023]943
[6801]944 double n = n0 + _Delta_n;
945 double M = _M0 + n*tk;
946 double E = M;
947 double E_last;
[8368]948 int nLoop = 0;
[6801]949 do {
950 E_last = E;
951 E = M + _e*sin(E);
[8368]952
953 if (++nLoop == 100) {
954 return failure;
955 }
[6801]956 } while ( fabs(E-E_last)*a0 > 0.001 );
957 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
958 double u0 = v + _omega;
959 double sin2u0 = sin(2*u0);
960 double cos2u0 = cos(2*u0);
961 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
962 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
963 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
964 double xp = r*cos(u);
965 double yp = r*sin(u);
966 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
967 omegaEarth*_TOEsec;
[4023]968
[6801]969 double sinom = sin(OM);
970 double cosom = cos(OM);
971 double sini = sin(i);
972 double cosi = cos(i);
973 xc[0] = xp*cosom - yp*cosi*sinom;
974 xc[1] = xp*sinom + yp*cosi*cosom;
975 xc[2] = yp*sini;
[4023]976
[6801]977 double tc = tt - _TOC;
978 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
[4023]979
[6801]980 // Velocity
981 // --------
982 double tanv2 = tan(v/2);
983 double dEdM = 1 / (1 - _e*cos(E));
984 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
985 * dEdM * n;
986 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
987 double dotom = _OMEGADOT - omegaEarth;
988 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
989 double dotr = a0 * _e*sin(E) * dEdM * n
990 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
991 double dotx = dotr*cos(u) - r*sin(u)*dotu;
992 double doty = dotr*sin(u) + r*cos(u)*dotu;
[4023]993
[6801]994 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
995 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
996 + yp*sini*sinom*doti; // dX / di
997
998 vv[1] = sinom *dotx + cosi*cosom *doty
999 + xp*cosom*dotom - yp*cosi*sinom*dotom
1000 - yp*sini*cosom*doti;
1001
1002 vv[2] = sini *doty + yp*cosi *doti;
1003
1004 // Relativistic Correction
1005 // -----------------------
[7481]1006 // correspondent to Galileo ICD and to SSR standard
1007 xc[3] -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
1008 // correspondent to IGS convention
1009 //xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
[6801]1010
[8542]1011 xc[4] = _clock_drift + _clock_driftrate*tc;
1012 xc[5] = _clock_driftrate;
[8581]1013
[6801]1014 return success;
[4023]1015}
1016
[8187]1017// Health status of Galileo Ephemeris (virtual)
1018////////////////////////////////////////////////////////////////////////////
1019unsigned int t_ephGal::isUnhealthy() const {
1020 if (_E5aHS && _E5bHS && _E1_bHS) {
1021 return 1;
1022 }
1023 return 0;
1024}
1025
[4023]1026// RINEX Format String
1027//////////////////////////////////////////////////////////////////////////////
1028QString t_ephGal::toString(double version) const {
1029
[4029]1030 QString rnxStr = rinexDateStr(_TOC, _prn, version);
[4023]1031
1032 QTextStream out(&rnxStr);
1033
1034 out << QString("%1%2%3\n")
1035 .arg(_clock_bias, 19, 'e', 12)
1036 .arg(_clock_drift, 19, 'e', 12)
1037 .arg(_clock_driftrate, 19, 'e', 12);
1038
1039 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1040
1041 out << QString(fmt)
1042 .arg(_IODnav, 19, 'e', 12)
1043 .arg(_Crs, 19, 'e', 12)
1044 .arg(_Delta_n, 19, 'e', 12)
1045 .arg(_M0, 19, 'e', 12);
1046
1047 out << QString(fmt)
1048 .arg(_Cuc, 19, 'e', 12)
1049 .arg(_e, 19, 'e', 12)
1050 .arg(_Cus, 19, 'e', 12)
1051 .arg(_sqrt_A, 19, 'e', 12);
1052
1053 out << QString(fmt)
1054 .arg(_TOEsec, 19, 'e', 12)
1055 .arg(_Cic, 19, 'e', 12)
1056 .arg(_OMEGA0, 19, 'e', 12)
1057 .arg(_Cis, 19, 'e', 12);
1058
1059 out << QString(fmt)
1060 .arg(_i0, 19, 'e', 12)
1061 .arg(_Crc, 19, 'e', 12)
1062 .arg(_omega, 19, 'e', 12)
1063 .arg(_OMEGADOT, 19, 'e', 12);
1064
[6792]1065 int dataSource = 0;
1066 int SVhealth = 0;
1067 double BGD_1_5A = _BGD_1_5A;
1068 double BGD_1_5B = _BGD_1_5B;
[6812]1069 if (_fnav) {
[6792]1070 dataSource |= (1<<1);
1071 dataSource |= (1<<8);
1072 BGD_1_5B = 0.0;
1073 // SVhealth
1074 // Bit 3 : E5a DVS
[6812]1075 if (_e5aDataInValid) {
[6792]1076 SVhealth |= (1<<3);
1077 }
1078 // Bit 4-5: E5a HS
1079 if (_E5aHS == 1.0) {
1080 SVhealth |= (1<<4);
1081 }
1082 else if (_E5aHS == 2.0) {
1083 SVhealth |= (1<<5);
1084 }
1085 else if (_E5aHS == 3.0) {
1086 SVhealth |= (1<<4);
1087 SVhealth |= (1<<5);
1088 }
1089 }
[6812]1090 else if(_inav) {
[6803]1091 // Bit 2 and 0 are set because from MT1046 the data source cannot be determined
1092 // and RNXv3.03 says both can be set if the navigation messages were merged
[5539]1093 dataSource |= (1<<0);
[6792]1094 dataSource |= (1<<2);
[5540]1095 dataSource |= (1<<9);
[6792]1096 // SVhealth
1097 // Bit 0 : E1-B DVS
[6812]1098 if (_e1DataInValid) {
[6792]1099 SVhealth |= (1<<0);
1100 }
1101 // Bit 1-2: E1-B HS
1102 if (_E1_bHS == 1.0) {
1103 SVhealth |= (1<<1);
1104 }
1105 else if (_E1_bHS == 2.0) {
1106 SVhealth |= (1<<2);
1107 }
[6803]1108 else if (_E1_bHS == 3.0) {
[6792]1109 SVhealth |= (1<<1);
1110 SVhealth |= (1<<2);
1111 }
[6802]1112 // Bit 3 : E5a DVS
[6812]1113 if (_e5aDataInValid) {
[6802]1114 SVhealth |= (1<<3);
1115 }
1116 // Bit 4-5: E5a HS
1117 if (_E5aHS == 1.0) {
1118 SVhealth |= (1<<4);
1119 }
1120 else if (_E5aHS == 2.0) {
1121 SVhealth |= (1<<5);
1122 }
[6803]1123 else if (_E5aHS == 3.0) {
[6802]1124 SVhealth |= (1<<4);
1125 SVhealth |= (1<<5);
1126 }
[6792]1127 // Bit 6 : E5b DVS
[6812]1128 if (_e5bDataInValid) {
[6792]1129 SVhealth |= (1<<6);
1130 }
1131 // Bit 7-8: E5b HS
1132 if (_E5bHS == 1.0) {
1133 SVhealth |= (1<<7);
1134 }
1135 else if (_E5bHS == 2.0) {
1136 SVhealth |= (1<<8);
1137 }
[6803]1138 else if (_E5bHS == 3.0) {
[6792]1139 SVhealth |= (1<<7);
1140 SVhealth |= (1<<8);
1141 }
[5539]1142 }
[6792]1143
[4023]1144 out << QString(fmt)
[5532]1145 .arg(_IDOT, 19, 'e', 12)
1146 .arg(double(dataSource), 19, 'e', 12)
[6892]1147 .arg(_TOEweek + 1024.0, 19, 'e', 12)
[5532]1148 .arg(0.0, 19, 'e', 12);
[4023]1149
1150 out << QString(fmt)
[6798]1151 .arg(_SISA, 19, 'e', 12)
[6792]1152 .arg(double(SVhealth), 19, 'e', 12)
1153 .arg(BGD_1_5A, 19, 'e', 12)
1154 .arg(BGD_1_5B, 19, 'e', 12);
[4023]1155
[7922]1156
1157 double tot = _TOT;
1158 if (tot == 0.9999e9 && version < 3.0) {
1159 tot = 0.0;
1160 }
[4023]1161 out << QString(fmt)
[7922]1162 .arg(tot, 19, 'e', 12)
[4024]1163 .arg("", 19, QChar(' '))
1164 .arg("", 19, QChar(' '))
1165 .arg("", 19, QChar(' '));
[4023]1166
1167 return rnxStr;
1168}
1169
[6385]1170// Constructor
1171//////////////////////////////////////////////////////////////////////////////
[6390]1172t_ephSBAS::t_ephSBAS(float rnxVersion, const QStringList& lines) {
1173
1174 const int nLines = 4;
1175
1176 if (lines.size() != nLines) {
[6518]1177 _checkState = bad;
[6390]1178 return;
1179 }
1180
1181 // RINEX Format
1182 // ------------
1183 int fieldLen = 19;
1184
1185 int pos[4];
1186 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1187 pos[1] = pos[0] + fieldLen;
1188 pos[2] = pos[1] + fieldLen;
1189 pos[3] = pos[2] + fieldLen;
1190
1191 // Read four lines
1192 // ---------------
1193 for (int iLine = 0; iLine < nLines; iLine++) {
1194 QString line = lines[iLine];
1195
1196 if ( iLine == 0 ) {
[8204]1197 QTextStream in(line.left(pos[1]).toLatin1());
[6390]1198
1199 int year, month, day, hour, min;
1200 double sec;
[6880]1201
[7139]1202 QString prnStr, n;
[6880]1203 in >> prnStr;
[7639]1204 if (prnStr.size() == 1 && prnStr[0] == 'S') {
[7139]1205 in >> n;
1206 prnStr.append(n);
[6880]1207 }
1208 in >> year >> month >> day >> hour >> min >> sec;
[6390]1209 if (prnStr.at(0) == 'S') {
1210 _prn.set('S', prnStr.mid(1).toInt());
1211 }
1212 else {
1213 _prn.set('S', prnStr.toInt());
1214 }
1215
1216 if (year < 80) {
1217 year += 2000;
1218 }
1219 else if (year < 100) {
1220 year += 1900;
1221 }
1222
1223 _TOC.set(year, month, day, hour, min, sec);
1224
1225 if ( readDbl(line, pos[1], fieldLen, _agf0 ) ||
1226 readDbl(line, pos[2], fieldLen, _agf1 ) ||
[8456]1227 readDbl(line, pos[3], fieldLen, _TOT ) ) {
[6518]1228 _checkState = bad;
[6390]1229 return;
1230 }
1231 }
1232
1233 else if ( iLine == 1 ) {
1234 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
1235 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
1236 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
1237 readDbl(line, pos[3], fieldLen, _health ) ) {
[6518]1238 _checkState = bad;
[6390]1239 return;
1240 }
1241 }
1242
1243 else if ( iLine == 2 ) {
1244 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
1245 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
1246 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
1247 readDbl(line, pos[3], fieldLen, _ura ) ) {
[6518]1248 _checkState = bad;
[6390]1249 return;
1250 }
1251 }
1252
1253 else if ( iLine == 3 ) {
[6536]1254 double iodn;
[6390]1255 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
1256 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
1257 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
[6536]1258 readDbl(line, pos[3], fieldLen, iodn ) ) {
[6518]1259 _checkState = bad;
[6390]1260 return;
[6891]1261 } else {
[6536]1262 _IODN = int(iodn);
[6390]1263 }
1264 }
1265 }
1266
[7278]1267 _x_pos *= 1.e3;
1268 _y_pos *= 1.e3;
1269 _z_pos *= 1.e3;
1270 _x_velocity *= 1.e3;
1271 _y_velocity *= 1.e3;
1272 _z_velocity *= 1.e3;
1273 _x_acceleration *= 1.e3;
1274 _y_acceleration *= 1.e3;
1275 _z_acceleration *= 1.e3;
[6385]1276}
1277
[7054]1278// IOD of SBAS Ephemeris (virtual)
1279////////////////////////////////////////////////////////////////////////////
1280
[7169]1281unsigned int t_ephSBAS::IOD() const {
[7054]1282 unsigned char buffer[80];
1283 int size = 0;
1284 int numbits = 0;
1285 long long bitbuffer = 0;
1286 unsigned char *startbuffer = buffer;
1287
1288 SBASADDBITSFLOAT(30, this->_x_pos, 0.08)
1289 SBASADDBITSFLOAT(30, this->_y_pos, 0.08)
1290 SBASADDBITSFLOAT(25, this->_z_pos, 0.4)
1291 SBASADDBITSFLOAT(17, this->_x_velocity, 0.000625)
1292 SBASADDBITSFLOAT(17, this->_y_velocity, 0.000625)
1293 SBASADDBITSFLOAT(18, this->_z_velocity, 0.004)
1294 SBASADDBITSFLOAT(10, this->_x_acceleration, 0.0000125)
1295 SBASADDBITSFLOAT(10, this->_y_acceleration, 0.0000125)
1296 SBASADDBITSFLOAT(10, this->_z_acceleration, 0.0000625)
1297 SBASADDBITSFLOAT(12, this->_agf0, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
1298 SBASADDBITSFLOAT(8, this->_agf1, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<10))
1299 SBASADDBITS(5,0); // the last byte is filled by 0-bits to obtain a length of an integer multiple of 8
1300
1301 return CRC24(size, startbuffer);
1302}
1303
[6385]1304// Compute SBAS Satellite Position (virtual)
1305////////////////////////////////////////////////////////////////////////////
1306t_irc t_ephSBAS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[6386]1307
1308 bncTime tt(GPSweek, GPSweeks);
1309 double dt = tt - _TOC;
1310
[7278]1311 xc[0] = _x_pos + _x_velocity * dt + _x_acceleration * dt * dt / 2.0;
1312 xc[1] = _y_pos + _y_velocity * dt + _y_acceleration * dt * dt / 2.0;
1313 xc[2] = _z_pos + _z_velocity * dt + _z_acceleration * dt * dt / 2.0;
[6386]1314
1315 vv[0] = _x_velocity + _x_acceleration * dt;
1316 vv[1] = _y_velocity + _y_acceleration * dt;
1317 vv[2] = _z_velocity + _z_acceleration * dt;
1318
1319 xc[3] = _agf0 + _agf1 * dt;
1320
[8542]1321 xc[4] = _agf1;
1322 xc[5] = 0.0;
[8483]1323
[6386]1324 return success;
[6385]1325}
1326
1327// RINEX Format String
1328//////////////////////////////////////////////////////////////////////////////
[6388]1329QString t_ephSBAS::toString(double version) const {
1330
1331 QString rnxStr = rinexDateStr(_TOC, _prn, version);
1332
1333 QTextStream out(&rnxStr);
1334
1335 out << QString("%1%2%3\n")
[6390]1336 .arg(_agf0, 19, 'e', 12)
1337 .arg(_agf1, 19, 'e', 12)
[8456]1338 .arg(_TOT, 19, 'e', 12);
[6388]1339
1340 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1341
1342 out << QString(fmt)
1343 .arg(1.e-3*_x_pos, 19, 'e', 12)
1344 .arg(1.e-3*_x_velocity, 19, 'e', 12)
1345 .arg(1.e-3*_x_acceleration, 19, 'e', 12)
[6390]1346 .arg(_health, 19, 'e', 12);
[6388]1347
1348 out << QString(fmt)
1349 .arg(1.e-3*_y_pos, 19, 'e', 12)
1350 .arg(1.e-3*_y_velocity, 19, 'e', 12)
1351 .arg(1.e-3*_y_acceleration, 19, 'e', 12)
[6390]1352 .arg(_ura, 19, 'e', 12);
[6388]1353
1354 out << QString(fmt)
1355 .arg(1.e-3*_z_pos, 19, 'e', 12)
1356 .arg(1.e-3*_z_velocity, 19, 'e', 12)
1357 .arg(1.e-3*_z_acceleration, 19, 'e', 12)
[6536]1358 .arg(double(_IODN), 19, 'e', 12);
[6388]1359
1360 return rnxStr;
[6385]1361}
[6400]1362
1363// Constructor
1364//////////////////////////////////////////////////////////////////////////////
[6600]1365t_ephBDS::t_ephBDS(float rnxVersion, const QStringList& lines) {
[6400]1366
1367 const int nLines = 8;
1368
1369 if (lines.size() != nLines) {
[6518]1370 _checkState = bad;
[6400]1371 return;
1372 }
1373
1374 // RINEX Format
1375 // ------------
1376 int fieldLen = 19;
1377
1378 int pos[4];
1379 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1380 pos[1] = pos[0] + fieldLen;
1381 pos[2] = pos[1] + fieldLen;
1382 pos[3] = pos[2] + fieldLen;
1383
1384 // Read eight lines
1385 // ----------------
1386 for (int iLine = 0; iLine < nLines; iLine++) {
1387 QString line = lines[iLine];
1388
1389 if ( iLine == 0 ) {
[8204]1390 QTextStream in(line.left(pos[1]).toLatin1());
[6400]1391
1392 int year, month, day, hour, min;
1393 double sec;
[6880]1394
[7139]1395 QString prnStr, n;
[6880]1396 in >> prnStr;
[7639]1397 if (prnStr.size() == 1 && prnStr[0] == 'C') {
[7139]1398 in >> n;
1399 prnStr.append(n);
[6880]1400 }
1401 in >> year >> month >> day >> hour >> min >> sec;
[6400]1402 if (prnStr.at(0) == 'C') {
1403 _prn.set('C', prnStr.mid(1).toInt());
1404 }
1405 else {
1406 _prn.set('C', prnStr.toInt());
1407 }
1408
1409 if (year < 80) {
1410 year += 2000;
1411 }
1412 else if (year < 100) {
1413 year += 1900;
1414 }
1415
[6812]1416 _TOC.setBDS(year, month, day, hour, min, sec);
[6400]1417
1418 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1419 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1420 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
[6518]1421 _checkState = bad;
[6400]1422 return;
1423 }
1424 }
1425
1426 else if ( iLine == 1 ) {
1427 double aode;
1428 if ( readDbl(line, pos[0], fieldLen, aode ) ||
1429 readDbl(line, pos[1], fieldLen, _Crs ) ||
1430 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1431 readDbl(line, pos[3], fieldLen, _M0 ) ) {
[6518]1432 _checkState = bad;
[6400]1433 return;
1434 }
1435 _AODE = int(aode);
1436 }
1437
1438 else if ( iLine == 2 ) {
1439 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1440 readDbl(line, pos[1], fieldLen, _e ) ||
1441 readDbl(line, pos[2], fieldLen, _Cus ) ||
1442 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
[6518]1443 _checkState = bad;
[6400]1444 return;
1445 }
1446 }
1447
1448 else if ( iLine == 3 ) {
[6812]1449 if ( readDbl(line, pos[0], fieldLen, _TOEsec ) ||
[6400]1450 readDbl(line, pos[1], fieldLen, _Cic ) ||
1451 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1452 readDbl(line, pos[3], fieldLen, _Cis ) ) {
[6518]1453 _checkState = bad;
[6400]1454 return;
1455 }
1456 }
1457
1458 else if ( iLine == 4 ) {
1459 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
1460 readDbl(line, pos[1], fieldLen, _Crc ) ||
1461 readDbl(line, pos[2], fieldLen, _omega ) ||
1462 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
[6518]1463 _checkState = bad;
[6400]1464 return;
1465 }
1466 }
1467
1468 else if ( iLine == 5 ) {
1469 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
[6812]1470 readDbl(line, pos[2], fieldLen, _TOEweek)) {
[6518]1471 _checkState = bad;
[6400]1472 return;
1473 }
1474 }
1475
1476 else if ( iLine == 6 ) {
1477 double SatH1;
[6755]1478 if ( readDbl(line, pos[0], fieldLen, _URA ) ||
1479 readDbl(line, pos[1], fieldLen, SatH1) ||
[6400]1480 readDbl(line, pos[2], fieldLen, _TGD1) ||
1481 readDbl(line, pos[3], fieldLen, _TGD2) ) {
[6518]1482 _checkState = bad;
[6400]1483 return;
1484 }
1485 _SatH1 = int(SatH1);
1486 }
1487
1488 else if ( iLine == 7 ) {
1489 double aodc;
[6812]1490 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
[6400]1491 readDbl(line, pos[1], fieldLen, aodc) ) {
[6518]1492 _checkState = bad;
[6400]1493 return;
1494 }
[6812]1495 if (_TOT == 0.9999e9) { // 0.9999e9 means not known (RINEX standard)
1496 _TOT = _TOEsec;
[6400]1497 }
1498 _AODC = int(aodc);
1499 }
1500 }
1501
[7138]1502 _TOE.setBDS(int(_TOEweek), _TOEsec);
1503
[6400]1504 // remark: actually should be computed from second_tot
1505 // but it seems to be unreliable in RINEX files
[6843]1506 //_TOT = _TOC.bdssec();
[6400]1507}
1508
[7054]1509// IOD of BDS Ephemeris (virtual)
1510////////////////////////////////////////////////////////////////////////////
[7169]1511unsigned int t_ephBDS::IOD() const {
[8410]1512 return (int(_TOEsec)/720) % 240;
[7054]1513}
1514
[6601]1515// Compute BDS Satellite Position (virtual)
[6400]1516//////////////////////////////////////////////////////////////////////////////
[6600]1517t_irc t_ephBDS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[6400]1518
[6602]1519 static const double gmBDS = 398.6004418e12;
1520 static const double omegaBDS = 7292115.0000e-11;
[6400]1521
1522 xc[0] = xc[1] = xc[2] = xc[3] = 0.0;
1523 vv[0] = vv[1] = vv[2] = 0.0;
1524
1525 bncTime tt(GPSweek, GPSweeks);
1526
1527 if (_sqrt_A == 0) {
1528 return failure;
1529 }
1530 double a0 = _sqrt_A * _sqrt_A;
1531
[6602]1532 double n0 = sqrt(gmBDS/(a0*a0*a0));
[6400]1533 double tk = tt - _TOE;
1534 double n = n0 + _Delta_n;
1535 double M = _M0 + n*tk;
1536 double E = M;
1537 double E_last;
1538 int nLoop = 0;
1539 do {
1540 E_last = E;
1541 E = M + _e*sin(E);
1542
1543 if (++nLoop == 100) {
1544 return failure;
1545 }
1546 } while ( fabs(E-E_last)*a0 > 0.001 );
1547
1548 double v = atan2(sqrt(1-_e*_e) * sin(E), cos(E) - _e);
1549 double u0 = v + _omega;
1550 double sin2u0 = sin(2*u0);
1551 double cos2u0 = cos(2*u0);
1552 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
1553 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
1554 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
1555 double xp = r*cos(u);
1556 double yp = r*sin(u);
1557 double toesec = (_TOE.gpssec() - 14.0);
1558 double sinom = 0;
1559 double cosom = 0;
1560 double sini = 0;
1561 double cosi = 0;
[7278]1562
[7481]1563 // Velocity
1564 // --------
1565 double tanv2 = tan(v/2);
1566 double dEdM = 1 / (1 - _e*cos(E));
1567 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2)
1568 / (1 + tanv2*tanv2) * dEdM * n;
1569 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
1570 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
1571 double dotr = a0 * _e*sin(E) * dEdM * n
1572 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
1573
1574 double dotx = dotr*cos(u) - r*sin(u)*dotu;
1575 double doty = dotr*sin(u) + r*cos(u)*dotu;
1576
[6400]1577 const double iMaxGEO = 10.0 / 180.0 * M_PI;
1578
1579 // MEO/IGSO satellite
1580 // ------------------
1581 if (_i0 > iMaxGEO) {
[6602]1582 double OM = _OMEGA0 + (_OMEGADOT - omegaBDS)*tk - omegaBDS*toesec;
[6400]1583
1584 sinom = sin(OM);
1585 cosom = cos(OM);
1586 sini = sin(i);
1587 cosi = cos(i);
1588
1589 xc[0] = xp*cosom - yp*cosi*sinom;
1590 xc[1] = xp*sinom + yp*cosi*cosom;
[7278]1591 xc[2] = yp*sini;
[7481]1592
1593 // Velocity
1594 // --------
1595
1596 double dotom = _OMEGADOT - t_CST::omega;
1597
1598 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
1599 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
1600 + yp*sini*sinom*doti; // dX / di
1601
1602 vv[1] = sinom *dotx + cosi*cosom *doty
1603 + xp*cosom*dotom - yp*cosi*sinom*dotom
1604 - yp*sini*cosom*doti;
1605
1606 vv[2] = sini *doty + yp*cosi *doti;
1607
[6400]1608 }
1609
1610 // GEO satellite
1611 // -------------
1612 else {
[6602]1613 double OM = _OMEGA0 + _OMEGADOT*tk - omegaBDS*toesec;
1614 double ll = omegaBDS*tk;
[6400]1615
1616 sinom = sin(OM);
1617 cosom = cos(OM);
1618 sini = sin(i);
1619 cosi = cos(i);
1620
1621 double xx = xp*cosom - yp*cosi*sinom;
1622 double yy = xp*sinom + yp*cosi*cosom;
[7278]1623 double zz = yp*sini;
[6400]1624
[7487]1625 Matrix RX = BNC_PPP::t_astro::rotX(-5.0 / 180.0 * M_PI);
1626 Matrix RZ = BNC_PPP::t_astro::rotZ(ll);
[6400]1627
1628 ColumnVector X1(3); X1 << xx << yy << zz;
[7487]1629 ColumnVector X2 = RZ*RX*X1;
[6400]1630
1631 xc[0] = X2(1);
1632 xc[1] = X2(2);
1633 xc[2] = X2(3);
[7278]1634
[7481]1635 double dotom = _OMEGADOT;
[6400]1636
[7481]1637 double vx = cosom *dotx - cosi*sinom *doty
1638 - xp*sinom*dotom - yp*cosi*cosom*dotom
1639 + yp*sini*sinom*doti;
[6400]1640
[7481]1641 double vy = sinom *dotx + cosi*cosom *doty
1642 + xp*cosom*dotom - yp*cosi*sinom*dotom
1643 - yp*sini*cosom*doti;
[7278]1644
[7501]1645 double vz = sini *doty + yp*cosi *doti;
[6400]1646
[7501]1647 ColumnVector V(3); V << vx << vy << vz;
[7481]1648
[7487]1649 Matrix RdotZ(3,3);
[7481]1650 double C = cos(ll);
1651 double S = sin(ll);
1652 Matrix UU(3,3);
1653 UU[0][0] = -S; UU[0][1] = +C; UU[0][2] = 0.0;
1654 UU[1][0] = -C; UU[1][1] = -S; UU[1][2] = 0.0;
1655 UU[2][0] = 0.0; UU[2][1] = 0.0; UU[2][2] = 0.0;
[7487]1656 RdotZ = omegaBDS * UU;
[7481]1657
1658 ColumnVector VV(3);
[7487]1659 VV = RZ*RX*V + RdotZ*RX*X1;
[7481]1660
1661 vv[0] = VV(1);
1662 vv[1] = VV(2);
1663 vv[2] = VV(3);
1664 }
1665
1666 double tc = tt - _TOC;
1667 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
1668
[7278]1669 // dotC = _clock_drift + _clock_driftrate*tc
[6400]1670 // - 4.442807633e-10*_e*sqrt(a0)*cos(E) * dEdM * n;
1671
[7481]1672 // Relativistic Correction
1673 // -----------------------
1674 // correspondent to BDS ICD and to SSR standard
1675 xc[3] -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
1676 // correspondent to IGS convention
1677 // xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
1678
[8542]1679 xc[4] = _clock_drift + _clock_driftrate*tc;
1680 xc[5] = _clock_driftrate;
[6400]1681 return success;
1682}
1683
1684// RINEX Format String
1685//////////////////////////////////////////////////////////////////////////////
[6600]1686QString t_ephBDS::toString(double version) const {
[8419]1687
[6812]1688 QString rnxStr = rinexDateStr(_TOC-14.0, _prn, version);
[6400]1689
1690 QTextStream out(&rnxStr);
1691
1692 out << QString("%1%2%3\n")
1693 .arg(_clock_bias, 19, 'e', 12)
1694 .arg(_clock_drift, 19, 'e', 12)
1695 .arg(_clock_driftrate, 19, 'e', 12);
1696
1697 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1698
1699 out << QString(fmt)
1700 .arg(double(_AODE), 19, 'e', 12)
1701 .arg(_Crs, 19, 'e', 12)
1702 .arg(_Delta_n, 19, 'e', 12)
1703 .arg(_M0, 19, 'e', 12);
1704
1705 out << QString(fmt)
1706 .arg(_Cuc, 19, 'e', 12)
1707 .arg(_e, 19, 'e', 12)
1708 .arg(_Cus, 19, 'e', 12)
1709 .arg(_sqrt_A, 19, 'e', 12);
1710
[6843]1711 double toes = 0.0;
1712 if (_TOEweek > -1.0) {// RINEX input
1713 toes = _TOEsec;
1714 }
1715 else {// RTCM stream input
[6812]1716 toes = _TOE.bdssec();
[6755]1717 }
[6400]1718 out << QString(fmt)
[6843]1719 .arg(toes, 19, 'e', 12)
[6755]1720 .arg(_Cic, 19, 'e', 12)
1721 .arg(_OMEGA0, 19, 'e', 12)
1722 .arg(_Cis, 19, 'e', 12);
[6400]1723
1724 out << QString(fmt)
1725 .arg(_i0, 19, 'e', 12)
1726 .arg(_Crc, 19, 'e', 12)
1727 .arg(_omega, 19, 'e', 12)
1728 .arg(_OMEGADOT, 19, 'e', 12);
1729
[6843]1730 double toew = 0.0;
1731 if (_TOEweek > -1.0) {// RINEX input
1732 toew = _TOEweek;
1733 }
1734 else {// RTCM stream input
1735 toew = double(_TOE.bdsw());
1736 }
[6400]1737 out << QString(fmt)
[6843]1738 .arg(_IDOT, 19, 'e', 12)
1739 .arg(0.0, 19, 'e', 12)
1740 .arg(toew, 19, 'e', 12)
1741 .arg(0.0, 19, 'e', 12);
[6400]1742
1743 out << QString(fmt)
[6798]1744 .arg(_URA, 19, 'e', 12)
[6400]1745 .arg(double(_SatH1), 19, 'e', 12)
1746 .arg(_TGD1, 19, 'e', 12)
1747 .arg(_TGD2, 19, 'e', 12);
1748
[6843]1749 double tots = 0.0;
1750 if (_TOEweek > -1.0) {// RINEX input
1751 tots = _TOT;
1752 }
1753 else {// RTCM stream input
[6812]1754 tots = _TOE.bdssec();
[6755]1755 }
[6400]1756 out << QString(fmt)
[6792]1757 .arg(tots, 19, 'e', 12)
[6755]1758 .arg(double(_AODC), 19, 'e', 12)
1759 .arg("", 19, QChar(' '))
1760 .arg("", 19, QChar(' '));
[6400]1761 return rnxStr;
1762}
Note: See TracBrowser for help on using the repository browser.