source: ntrip/branches/BNC_2.12/src/ephemeris.cpp@ 9291

Last change on this file since 9291 was 9291, checked in by stuerze, 3 years ago

minor changes

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