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

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

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

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