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

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

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

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