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

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

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

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