forked from XiaoGongWei/MG_APP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
QReadGPSN.cpp
651 lines (619 loc) · 22.4 KB
/
QReadGPSN.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
#include "QReadGPSN.h"
QReadGPSN::QReadGPSN(void)
{
}
QReadGPSN::~QReadGPSN(void)
{
}
void QReadGPSN::initVar()
{
isReadHead = false;
isReadAllData = false;
m_epochDataNum_Ver2 = 7;
m_leapSec = 0;
m_BaseYear = 2000;
IonAlpha[0] = 0;IonAlpha[1] = 0;IonAlpha[2] = 0;IonAlpha[3] = 0;
IonBeta[0] = 0;IonBeta[1] = 0;IonBeta[2] = 0;IonBeta[3] = 0;
DeltaA01[0] = 0;DeltaA01[1] = 0;
DeltaTW[0] = 0;DeltaTW[1] = 0;
}
QReadGPSN::QReadGPSN(QString NFileName)
{
initVar();
if (NFileName.trimmed().isEmpty())
ErroTrace("File Name is Empty!(QReadGPSN::QReadGPSN(QString NFileName))");
m_NfileName = NFileName;
//Read file header information and parse
getHeadInf();//The file is not closed here
//GLONASS has only three rows and 12
if (FileIdType == 'R') m_epochDataNum_Ver2 = 3;
}
void QReadGPSN::setFileName(QString NFileName)
{
initVar();
if (NFileName.trimmed().isEmpty())
ErroTrace("File Name is Empty!(QReadGPSN::QReadGPSN(QString NFileName))");
m_NfileName = NFileName;
//Read file header information and parse
getHeadInf();//The file is not closed here
//GLONASS has only three rows and has 12 data
if (FileIdType == 'R') m_epochDataNum_Ver2 = 3;
}
//Read the header file of the navigation file
void QReadGPSN::getHeadInf()
{
if (isReadHead) return ;
//open a file
m_readGPSNFile.setFileName(m_NfileName);
if (!m_readGPSNFile.open(QFile::ReadOnly))
ErroTrace("Open file bad!(QReadOFile::QReadOFile(QString OfileName))");
//Read header file
while (!m_readGPSNFile.atEnd())
{
tempLine = m_readGPSNFile.readLine();
if (tempLine.contains("END OF HEADER",Qt::CaseInsensitive))
break;
if (tempLine.contains("RINEX VERSION",Qt::CaseInsensitive))
{
RinexVersion = tempLine.mid(0,10).trimmed().toDouble();
if (tempLine.mid(20,20).contains("GPS",Qt::CaseInsensitive))
FileIdType = 'G';
else if (tempLine.mid(20,20).contains("CMP",Qt::CaseInsensitive))
FileIdType = 'C';
else if (tempLine.mid(20,20).contains("GLONASS",Qt::CaseInsensitive))
FileIdType = 'R';
else
FileIdType = 'G';
}
else if (tempLine.contains("PGM / RUN BY / DATE",Qt::CaseInsensitive))
{
PGM = tempLine.mid(0,20).trimmed();
RUNBY = tempLine.mid(20,20).trimmed();
CreatFileDate = tempLine.mid(40,20).trimmed();
//qDebug()<<CreatFileDate;
}
else if (tempLine.contains("COMMENT",Qt::CaseInsensitive))
{
CommentInfo+=tempLine.mid(0,60).trimmed() + "\n";
//qDebug()<<CommentInfo;
}
else if (tempLine.contains("ION ALPHA",Qt::CaseInsensitive))
{
for(int i = 0;i < 4;i++)
{
QString strReplaceTemp = tempLine.mid(2+i*12,12).replace('D','E').trimmed();
IonAlpha[i] = strReplaceTemp.toDouble();
}
}
else if (tempLine.contains("ION BETA",Qt::CaseInsensitive))
{
for(int i = 0;i < 4;i++)
{
QString strReplaceTemp = tempLine.mid(2+i*12,12).replace('D','E').trimmed();
IonBeta[i] = strReplaceTemp.toDouble();
}
}
else if (tempLine.contains("DELTA-UTC",Qt::CaseInsensitive))
{
for(int i = 0;i < 2;i++)
{
QString strReplaceTemp = tempLine.mid(3+i*19,19).replace('D','E').trimmed();
DeltaA01[i] = strReplaceTemp.toDouble();
DeltaTW[i] = tempLine.mid(41+9*i,9).trimmed().toInt();
}
}
}//End of read header file
isReadHead = true;
}
//Read Rilex 2.X broadcast ephemeris data
void QReadGPSN::readNFileVer2(QVector< BrdData > &allBrdData)
{
if (!isReadHead) getHeadInf();
if (isReadAllData) return ;
tempLine = m_readGPSNFile.readLine();
//Enter data area to read
while (!m_readGPSNFile.atEnd())
{
BrdData epochBrdData;
if (!tempLine.mid(0,2).trimmed().isEmpty())
{
tempLine.replace('D','E');
epochBrdData.PRN = tempLine.mid(0,2).toInt();
epochBrdData.SatType = FileIdType;
epochBrdData.UTCTime.Year = tempLine.mid(3,2).toInt() + m_BaseYear;//m_BaseYear is set to 2000
epochBrdData.UTCTime.Month = tempLine.mid(6,2).toInt();
epochBrdData.UTCTime.Day = tempLine.mid(9,2).toInt();
epochBrdData.UTCTime.Hours = tempLine.mid(12,2).toInt();
epochBrdData.UTCTime.Minutes = tempLine.mid(15,2).toInt();
epochBrdData.UTCTime.Seconds = tempLine.mid(17,5).toDouble();
epochBrdData.TimeDiv = tempLine.mid(22,19).toDouble();
epochBrdData.TimeMove = tempLine.mid(41,19).toDouble();
epochBrdData.TimeMoveSpeed = 0;
if(epochBrdData.SatType != 'R')
{
epochBrdData.TimeMoveSpeed = tempLine.mid(60,19).toDouble();
}
//Read the next row of data
tempLine = m_readGPSNFile.readLine();
tempLine.replace('D','E');
double tempdb = 0.0;
for (int i = 0; i < m_epochDataNum_Ver2;i++)
{
for (int j = 0;j < 4;j++)
{
tempdb = tempLine.mid(3 + j*19,19).toDouble();
epochBrdData.epochNData.append(tempdb);
}
tempLine = m_readGPSNFile.readLine();
tempLine.replace('D','E');
}
allBrdData.append(epochBrdData);//Save a data segment
}
else
{
continue;
}
}//while (!m_readGPSNFile.atEnd())Read to the end of the file
isReadAllData = true;
//Calculating leap seconds
BrdData fistEpoch = allBrdData.at(0);
m_leapSec = getLeapSecond(fistEpoch.UTCTime.Year,fistEpoch.UTCTime.Month,fistEpoch.UTCTime.Day,
fistEpoch.UTCTime.Hours,fistEpoch.UTCTime.Minutes,fistEpoch.UTCTime.Seconds);
}
//Read Rilex 3.X broadcast ephemeris data
void QReadGPSN::readNFileVer3(QVector< BrdData > &allBrdData)
{
int m_epochDataNum_Ver3 = 7;//Store a data segment (GPS and BDS are 28 7 rows GLONASS is 12 3 rows)
if (!isReadHead) getHeadInf();
if (isReadAllData) return ;
tempLine = m_readGPSNFile.readLine();
//Enter data area to read
while (!m_readGPSNFile.atEnd())
{
BrdData epochBrdData;
if (!tempLine.mid(0,3).trimmed().isEmpty())
{
tempLine.replace('D','E');
epochBrdData.SatType = *(tempLine.mid(0,1).toLatin1().data());
epochBrdData.PRN = tempLine.mid(1,2).toInt();
epochBrdData.UTCTime.Year = tempLine.mid(4,4).toInt();
epochBrdData.UTCTime.Month = tempLine.mid(9,2).toInt();
epochBrdData.UTCTime.Day = tempLine.mid(12,2).toInt();
epochBrdData.UTCTime.Hours = tempLine.mid(15,2).toInt();
epochBrdData.UTCTime.Minutes = tempLine.mid(18,2).toInt();
epochBrdData.UTCTime.Seconds = tempLine.mid(21,2).toDouble();
epochBrdData.TimeDiv = tempLine.mid(23,19).toDouble();
epochBrdData.TimeMove = tempLine.mid(42,19).toDouble();
epochBrdData.TimeMoveSpeed = 0;
if(epochBrdData.SatType == 'R')
m_epochDataNum_Ver3 = 3;
else
{
m_epochDataNum_Ver3 = 7;
epochBrdData.TimeMoveSpeed = tempLine.mid(61,19).toDouble();
}
//Read the next row of data
tempLine = m_readGPSNFile.readLine();
tempLine.replace('D','E');
double tempdb = 0.0;
for (int i = 0; i < m_epochDataNum_Ver3;i++)
{
for (int j = 0;j < 4;j++)
{
tempdb = tempLine.mid(4 + j*19,19).toDouble();
epochBrdData.epochNData.append(tempdb);
}
tempLine = m_readGPSNFile.readLine();
tempLine.replace('D','E');
}
allBrdData.append(epochBrdData);//Save a data segment
}
else
{
continue;
}
}//while (!m_readGPSNFile.atEnd())Read to the end of the file
isReadAllData = true;
//Calculating leap seconds
BrdData fistEpoch = allBrdData.at(0);
m_leapSec = getLeapSecond(fistEpoch.UTCTime.Year,fistEpoch.UTCTime.Month,fistEpoch.UTCTime.Day,
fistEpoch.UTCTime.Hours,fistEpoch.UTCTime.Minutes,fistEpoch.UTCTime.Seconds);
}
//Read all broadcast ephemeris data to allBrdData
QVector< BrdData > QReadGPSN::getAllData()
{
if (isReadAllData) return m_allBrdData;
if (RinexVersion < 3.0)
{
readNFileVer2(m_allBrdData);
}
if (RinexVersion >= 3.0)
{
readNFileVer3(m_allBrdData);
}
return m_allBrdData;
}
//Search for the most recent navigation data
int QReadGPSN::SearchNFile(int PRN,char SatType,double GPSOTime)
{//Return matching N navigation message
//Find the distance 2h before the navigation message
int flag = 0;
int lenNHead = m_allBrdData.length();
QVector< int > Fileflag;
QVector< double > FileflagTime;
for (int i = 0;i < lenNHead;i++)
{
BrdData epochNData = m_allBrdData.at(i);
if (PRN != epochNData.PRN || SatType != epochNData.SatType)
continue;
else
{
double GPSNTime = YMD2GPSTime(epochNData.UTCTime.Year,epochNData.UTCTime.Month,epochNData.UTCTime.Day,
epochNData.UTCTime.Hours,epochNData.UTCTime.Minutes,epochNData.UTCTime.Seconds);
Fileflag.append(i);
FileflagTime.append(GPSNTime);
}
}
//Found a minimum time difference <2h
int FileflagLen = Fileflag.length();
if (FileflagLen != FileflagTime.length())
return -1;
int flagMin = 0;
if(FileflagLen == 0)
return -1;
double GPSNTime = FileflagTime.at(0);
double Min = qAbs(GPSOTime - GPSNTime);
for (int i = 0;i < FileflagLen;i++)
{
double tGPSNTime = FileflagTime.at(i);
if (Min > qAbs((GPSOTime - tGPSNTime)))
{
flagMin = i;
Min = GPSOTime - tGPSNTime;
}
}
flag = Fileflag.at(flagMin);
//The following should be added with the absolute value qAbs()
if (qAbs(GPSOTime - FileflagTime.at(flagMin)) > 2*3600+120)
{
flag = -1;
}
return flag;//-1 means not found
}
//PRN: satellite number, SatType: satellite type (G, C, R, E), year, month, day, minute, minute, second, observation time, UTC time (internal automatic conversion of BDS and GLONASS functions)
void QReadGPSN::getSatPos(int PRN,char SatType,double signal_transmission_time,int Year,int Month,int Day,int Hours,int Minutes,
double Seconds,double *StaClock, double *pXYZ,double *pdXYZ)
{
pXYZ[0] = 0;pXYZ[1] = 0;pXYZ[2] = 0;
pdXYZ[0] = 0;pdXYZ[1] = 0;pdXYZ[2] = 0;
if (!isReadAllData) getAllData();
double GPSOTime = YMD2GPSTime(Year,Month,Day,Hours,Minutes,Seconds);
int flag = -1;
flag = SearchNFile(PRN,SatType,GPSOTime);//Match navigation file
if (flag < 0) return ;
BrdData epochBrdData = m_allBrdData.at(flag);
//Calculate multi-system (GPS+BDS+GLONASS) coordinates
double X = 0,Y = 0,Z = 0;//Satellite coordinates
double dX = 0,dY = 0,dZ = 0;//Satellite speed
double t = 0;//GPS time at the time of satellite signal transmission
double Ek = 0;//E to be calculated
if (SatType == 'G' || SatType == 'C' || SatType == 'E')
{
double n0 = qSqrt(M_GM)/qPow(epochBrdData.epochNData.at(7),3);
double n = n0 + epochBrdData.epochNData.at(2);
t = GPSOTime - signal_transmission_time;//The time at which the satellite signals the second of the GPS week
if (SatType == 'C')
{
t -= 14;
}
double dltt_toe = t - epochBrdData.epochNData.at(8);
if (dltt_toe > 302400)
dltt_toe-=604800;
else if (dltt_toe < -302400)
dltt_toe+=604800;
double M = epochBrdData.epochNData.at(3) + n*dltt_toe;
if (M < 0)
M = M + 2*MM_PI;
//Use iteration to calculate E
double eps = 1e-13;
double dv = 9999;
double E0 = M;
while(dv > eps)
{
Ek = M + epochBrdData.epochNData.at(5)*qSin(E0);
dv = qAbs(Ek - E0);
E0 = Ek;
}
//Calculate f
double cosf = (qCos(Ek) - epochBrdData.epochNData.at(5))/(1 - epochBrdData.epochNData.at(5)*qCos(Ek));
double sinf = (qSin(Ek)*qSqrt(1-epochBrdData.epochNData.at(5)*epochBrdData.epochNData.at(5)))/(1 - epochBrdData.epochNData.at(5)*qCos(Ek));
double f = qAtan2(qSin(Ek)*qSqrt(1-epochBrdData.epochNData.at(5)*epochBrdData.epochNData.at(5)), qCos(Ek) - epochBrdData.epochNData.at(5));
//double f = qAtan((qSin(Ek)*qSqrt(1-epochBrdData.epochNData.at(5)*epochBrdData.epochNData.at(5)))/(qCos(Ek) - epochBrdData.epochNData.at(5)));
//Calculate ud
double ud = epochBrdData.epochNData.at(14) + f;
//Calculate perturbation correction
double Cuc = epochBrdData.epochNData.at(4);
double Cus = epochBrdData.epochNData.at(6);
double Crc = epochBrdData.epochNData.at(13);
double Crs = epochBrdData.epochNData.at(1);
double Cic = epochBrdData.epochNData.at(9);
double Cis = epochBrdData.epochNData.at(11);
double dltaU = Cuc*qCos(2*ud) + Cus*qSin(2*ud);
double dltaR = Crc*qCos(2*ud) + Crs*qSin(2*ud);
double dltaI = Cic*qCos(2*ud) + Cis*qSin(2*ud);
double U = ud + dltaU;
double R = epochBrdData.epochNData.at(7)*epochBrdData.epochNData.at(7)*(1 - epochBrdData.epochNData.at(5)*qCos(Ek)) + dltaR;
double I = epochBrdData.epochNData.at(12) + dltaI + epochBrdData.epochNData.at(16)*(t - epochBrdData.epochNData.at(8));
//Calculate the coordinates of the satellite orbital plane
//double dU = qCos(U);
double x = R*qCos(U);
double y = R*qSin(U);
//Calculate the accuracy of the instantaneous ascending point L
//double L = epochNData[10] + (epochNData[15] - M_We)*t - epochNData[15]*epochNData[8];
double L = epochBrdData.epochNData.at(10) + epochBrdData.epochNData.at(15)*(dltt_toe) - M_We*t;
if (SatType == 'C' && PRN < 6)
{//Convert to L below the inertial coordinate system
L = epochBrdData.epochNData.at(10) + epochBrdData.epochNData.at(15)*(dltt_toe) - M_We*epochBrdData.epochNData.at(8);
}
if (L<0)
L = L + 2*MM_PI;
//Calculate satellite instantaneous coordinates
X = x*qCos(L) - y*qCos(I)*qSin(L);
Y = x*qSin(L) + y*qCos(I)*qCos(L);
Z = y*qSin(I);
//Calculating satellite speed
double dM = n;
double dE = dM/(1-epochBrdData.epochNData.at(5)*qCos(Ek));
double df = qSqrt(1-epochBrdData.epochNData.at(5)*epochBrdData.epochNData.at(5))*dE/(1-epochBrdData.epochNData.at(5)*qCos(Ek));
double du = df;
double DdltaU = 2*du*(Cus*qCos(2*ud) - Cuc*qSin(2*ud));
double DdltaR = 2*du*(Crs*qCos(2*ud) - Crc*qSin(2*ud));
double DdltaI = 2*du*(Cis*qCos(2*ud) - Cic*qSin(2*ud));
double dU = du + DdltaU;
double dR = epochBrdData.epochNData.at(7)*epochBrdData.epochNData.at(7)*epochBrdData.epochNData.at(5)*dE*qSin(Ek)+DdltaR;
double dI = epochBrdData.epochNData.at(16) + DdltaI;
double dL = epochBrdData.epochNData.at(15) - M_We;
if (SatType == 'C' && PRN < 6)
{//Convert to L below the inertial coordinate system
dL = epochBrdData.epochNData.at(15);
}
double dx = dR*qCos(U) - R*dU*qSin(U);
double dy = dR*qSin(U) + R*dU*qCos(U);
//Calculation speed
dX = -Y*dL - (dy*qCos(I) - Z*dI)*qSin(L) + dx*qCos(L);
dY = X*dL + (dy*qCos(I) - Z*dI)*qCos(L) + dx*qSin(L);
dZ = dy*qSin(I) + dy*dI*qCos(I);
//Determine if it is BDS 1-5 satellite
if (SatType == 'C' && PRN < 6)
{
//L===============
double Wet_toe = M_We*(dltt_toe);
//Convert coordinates via Rz(Wet_toe) Rx(-5)
Matrix3d Rz,Rx,dRz;
Vector3d Vx3,dVx3;//Position and speed before coordinate conversion
Vector3d VX,dVX;//Post-conversion position and speed
Vx3<<X,Y,Z;
dVx3<<dX,dY,dZ;
Rz<<qCos(Wet_toe),qSin(Wet_toe),0,
-qSin(Wet_toe),qCos(Wet_toe),0,
0,0,1;
dRz<<-qSin(Wet_toe),qCos(Wet_toe),0,
-qCos(Wet_toe),-qSin(Wet_toe),0,
0,0,0;
Rx<<1,0,0,
0,qCos(-5*MM_PI/180),qSin(-5*MM_PI/180),
0,-qSin(-5*MM_PI/180),qCos(-5*MM_PI/180);
VX = Rz*Rx*Vx3;
dVX = Rz*Rx*dVx3 + M_We*dRz*Rx*Vx3;
X = VX(0);Y = VX(1);Z = VX(2);
dX = dVX(0);dY = dVX(1);dZ = dVX(2);
}
}
else if (SatType == 'R')
{
t = GPSOTime - signal_transmission_time;//The time at which the satellite signals the second of the GPS week
double t0 = YMD2GPSTime(epochBrdData.UTCTime.Year,epochBrdData.UTCTime.Month,epochBrdData.UTCTime.Day,
epochBrdData.UTCTime.Hours,epochBrdData.UTCTime.Minutes,epochBrdData.UTCTime.Seconds);
////Calculate GLONASS satellite coordinates using Runge-Kutta/////
Vector3d GLOXYZ,GLOdX;
t = t - m_leapSec;//Convert GPS time to GLONASS time (G file is not GLONASS time, but standard UTC so only one integer hop second)
GLOXYZ = RungeKuttaforGlonass(epochBrdData,t,t0,GLOdX);//Calculate G file coordinates
//Convert to WGS84 based on experience seven parameters
GLOXYZ = GLOXYZ*1000;
GLOdX = GLOdX*1000;
Matrix3d CM;
Vector3d dltaX;
dltaX<<-0.47,-0.51,-1.56;
CM<<1,1.728e-6,-0.0178e-6,
1.728e-6,1,0.076e-6,
0.0178e-6,-0.076e-6,1;
// GLOXYZ = dltaX + (1+22e-9)*CM*GLOXYZ;//PZ-90 is converted to WGS84 coordinates (can be ignored)
X = GLOXYZ(0);Y = GLOXYZ(1);Z = GLOXYZ(2);
dX = GLOdX(0);dY = GLOdX(1);dZ = GLOdX(2);
//Calculating the GLONASS relativistic effect
//GlonassRel = -2*(GLOXYZ(0)*GLOdX(0)+GLOXYZ(1)*GLOdX(1)+GLOXYZ(2)*GLOdX(2))/(M_C);
}
//Calculate satellite clock error
double A[3] ={epochBrdData.TimeDiv,epochBrdData.TimeMove,epochBrdData.TimeMoveSpeed};
double t0 = YMD2GPSTime(epochBrdData.UTCTime.Year, epochBrdData.UTCTime.Month, epochBrdData.UTCTime.Day,
epochBrdData.UTCTime.Hours, epochBrdData.UTCTime.Minutes,epochBrdData.UTCTime.Seconds);
if(StaClock) *StaClock = computeSatClock(A,t,t0);//Multiply by the speed of light to become the distance m
pXYZ[0] = X;pXYZ[1] = Y;pXYZ[2] = Z;
pdXYZ[0] = dX;pdXYZ[1] = dY;pdXYZ[2] = dZ;
}
double QReadGPSN::computeSatClock(double *A,double t,double t0)
{//Calculation clock error
double dltaT = 0;
double c = 299792458.0;
dltaT = A[0] + A[1]*(t - t0) + A[2]*(t-t0)*(t-t0);// - (2*qSqrt(a*u)/(c*c))*(e*qSin(E));//The second half considers that the satellite orbit is not circular
return dltaT*c;
}
//Calculate GPS time
double QReadGPSN::YMD2GPSTime(int Year, int Month, int Day, int HoursInt, int Minutes, double Seconds, int *WeekN)//,int *GPSTimeArray
{
double Hours = HoursInt + ((Minutes * 60) + Seconds)/3600.0;
//Get JD
double JD = 0.0;
if(Month<=2)
JD = (int)(365.25*(Year-1)) + (int)(30.6001*(Month+12+1)) + Day + Hours/24.0 + 1720981.5;
else
JD = (int)(365.25*(Year)) + (int)(30.6001*(Month+1)) + Day + Hours/24.0 + 1720981.5;
//Get GPS Week and Days
int Week = (int)((JD - 2444244.5) / 7);
int N =(int)(JD + 1.5)%7;
if (WeekN) *WeekN = Week;
return (N*24*3600 + HoursInt*3600 + Minutes*60 + Seconds);
}
//Calculate Julian Day
double QReadGPSN::computeJD(int Year,int Month,int Day,int HoursInt,int Minutes,double Seconds)
{
double Hours = HoursInt + ((Minutes * 60) + Seconds)/3600.0;
//Get JD
double JD = 0.0;
if(Month<=2)
JD = (int)(365.25*(Year-1)) + (int)(30.6001*(Month+12+1)) + Day + Hours/24.0 + 1720981.5;
else
JD = (int)(365.25*(Year)) + (int)(30.6001*(Month+1)) + Day + Hours/24.0 + 1720981.5;
return JD;
}
//Calculating leap seconds
// Leap file: ftp://hpiers.obspm.fr/iers/bul/bulc/Leap_Second.dat
double QReadGPSN::getLeapSecond(int Year, int Month, int Day, int Hours/* =0 */, int Minutes/* =0 */, double Seconds/* =0 */)
{// Debug by xiaogongwei 2019.04.03
double jd = computeJD(Year,Month,Day,Hours, Minutes, Seconds);
double leapseconds=0;
double Leap_seconds[50]={0};
double TAImUTCData[50]={0};
Leap_seconds[0]=10;
TAImUTCData[0]=computeJD(1972,1,1,0);
Leap_seconds[1]=11;
TAImUTCData[1]=computeJD(1972,7,1,0);
Leap_seconds[2]=12;
TAImUTCData[2]=computeJD(1973,1,1,0);
Leap_seconds[3]=13;
TAImUTCData[3]=computeJD(1974,1,1,0);
Leap_seconds[4]=14;
TAImUTCData[4]=computeJD(1975,1,1,0);
Leap_seconds[5]=15;
TAImUTCData[5]=computeJD(1976,1,1,0);
Leap_seconds[6]=16;
TAImUTCData[6]=computeJD(1977,1,1,0);
Leap_seconds[7]=17;
TAImUTCData[7]=computeJD(1978,1,1,0);
Leap_seconds[8]=18;
TAImUTCData[8]=computeJD(1979,1,1,0);
Leap_seconds[9]=19;
TAImUTCData[9]=computeJD(1980,1,1,0);
Leap_seconds[10]=20;
TAImUTCData[10]=computeJD(1981,7,1,0);
Leap_seconds[11]=21;
TAImUTCData[11]=computeJD(1982,7,1,0);
Leap_seconds[12]=22;
TAImUTCData[12]=computeJD(1983,7,1,0);
Leap_seconds[13]=23;
TAImUTCData[13]=computeJD(1985,7,1,0);
Leap_seconds[14]=24;
TAImUTCData[14]=computeJD(1988,1,1,0);
Leap_seconds[15]=25;
TAImUTCData[15]=computeJD(1990,1,1,0);
Leap_seconds[16]=26;
TAImUTCData[16]=computeJD(1991,1,1,0);
Leap_seconds[17]=27;
TAImUTCData[17]=computeJD(1992,7,1,0);
Leap_seconds[18]=28;
TAImUTCData[18]=computeJD(1993,7,1,0);
Leap_seconds[19]=29;
TAImUTCData[19]=computeJD(1994,7,1,0);
Leap_seconds[20]=30;
TAImUTCData[20]=computeJD(1996,1,1,0);
Leap_seconds[21]=31;
TAImUTCData[21]=computeJD(1997,7,1,0);
Leap_seconds[22]=32;
TAImUTCData[22]=computeJD(1999,1,1,0);
Leap_seconds[23]=33;
TAImUTCData[23]=computeJD(2006,1,1,0);
Leap_seconds[24]=34;
TAImUTCData[24]=computeJD(2009,1,1,0);
Leap_seconds[25]=35;
TAImUTCData[25]=computeJD(2012,7,1,0);
Leap_seconds[26]=36;
TAImUTCData[26]=computeJD(2015,7,1,0);
Leap_seconds[27]=37;
TAImUTCData[27]=computeJD(2017,1,1,0);
if (jd<TAImUTCData[0])
{
leapseconds=0;
}
else if (jd>TAImUTCData[27])
{
leapseconds=Leap_seconds[27];
}
else
{
int iter=0;
for (int i=1;i<28;i++)
{
if (jd<=TAImUTCData[i] && jd>TAImUTCData[i-1])
{
iter=i;
break;
}
}
leapseconds=Leap_seconds[iter-1];
}
return (leapseconds-19);
}
//Fourth-order Runge-Kutta method
Vector3d QReadGPSN::RungeKuttaforGlonass(const BrdData &epochBrdData,double tk,double t0,Vector3d &dX)
{
Vector3d X0,dX0,ddX0;
X0<<epochBrdData.epochNData.at(0),epochBrdData.epochNData.at(4),epochBrdData.epochNData.at(8);
dX0<<epochBrdData.epochNData.at(1),epochBrdData.epochNData.at(5),epochBrdData.epochNData.at(9);
ddX0<<epochBrdData.epochNData.at(2),epochBrdData.epochNData.at(6),epochBrdData.epochNData.at(10);
double dh = 0;//Defining step size
if (tk > t0)
dh = 30;//(秒s)
else
dh = -30;
if (qAbs(tk - t0) < 30)
dh = tk - t0;
//Calculated using RungeKutta
int n = (int)((tk - t0)/dh);
Vector3d Xtn,Ztn,Xtn1,Ztn1;
Xtn = X0;
Ztn = dX0;
Xtn1.setZero();
Ztn1.setZero();
if (qAbs(tk - t0) < 30)
n = 0;
for (int i = 0;i < n + 1;i++)
{
double h1 = tk - t0 - i*dh;//Judging the remaining step size???????? positive and negative relationship
if (qAbs(h1) < qAbs(dh))
dh = h1;
//Calculate the Runge-Kutta coefficient (refer to the fourth edition of Numerical Analysis, P133, the second order is solved by the equations)
Vector3d L1,L2,L3,L4;
L1 = GlonassFun(Xtn,Ztn,ddX0);
L2 = GlonassFun(Xtn+(dh/2)*Ztn,Ztn+(dh/2)*L1,ddX0);
L3 = GlonassFun(Xtn+(dh/2)*Ztn+(dh*dh/4)*L1,Ztn+(dh/2)*L2,ddX0);
L4 = GlonassFun(Xtn+dh*Ztn+(dh*dh/2)*L2,Ztn+dh*L3,ddX0);
Xtn1 = Xtn + dh*Ztn + (dh*dh/6)*(L1 + L2 + L3);
Ztn1 = Ztn + (dh/6)*(L1 + 2*L2 + 2*L3 + L4);
Xtn = Xtn1;
Ztn = Ztn1;
}
dX = Ztn;
return Xtn;
}
//GLONASS equation of motion
Vector3d QReadGPSN::GlonassFun(Vector3d Xt,Vector3d dXt,Vector3d ddX0)
{
Vector3d ddXt;
Vector3d Xrz;
Vector3d Xwt;
double r = qSqrt(Xt(0)*Xt(0)+Xt(1)*Xt(1)+Xt(2)*Xt(2));
Xrz<<Xt(0)*(1 - 5*Xt(2)*Xt(2)/(r*r)),Xt(1)*(1 - 5*Xt(2)*Xt(2)/(r*r)),Xt(2)*(3 - 5*Xt(2)*Xt(2)/(r*r));
Xwt<<M_We*M_We*Xt(0) + 2*M_We*dXt(1),M_We*M_We*Xt(1) - 2*M_We*dXt(0),0;
ddXt = (-M_GMK/(r*r*r))*Xt + ((1.5*M_GMK*M_ReK*M_ReK*M_C20)*Xrz/(r*r*r*r*r))+ ddX0 + Xwt;
return ddXt;
}