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

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

bug fixed: RINEX 3.04 QZSS fit interval is specified as flag

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