source: ntrip/trunk/BNC/src/RTCM/rtcm_utils.cpp@ 6138

Last change on this file since 6138 was 6109, checked in by mervart, 10 years ago
File size: 3.9 KB
Line 
1#include <iomanip>
2#include <iostream>
3#include <math.h>
4#include <stdio.h>
5#include <rtcm3torinex.h>
6#include <ephemeris.h>
7
8#include "rtcm_utils.h"
9
10using namespace std;
11
12void resolveEpoch (double secsHour,
13 int refWeek, double refSecs,
14 int& epochWeek, double& epochSecs) {
15
16 const double secsPerWeek = 604800.0;
17
18 epochWeek = refWeek;
19 epochSecs = secsHour + 3600.0*(floor((refSecs-secsHour)/3600.0+0.5));
20
21 if (epochSecs<0 ) { epochWeek--; epochSecs+=secsPerWeek; };
22 if (epochSecs>secsPerWeek) { epochWeek++; epochSecs-=secsPerWeek; };
23};
24
25
26int cmpRho(const t_eph* eph,
27 double stax, double stay, double staz,
28 int GPSWeek, double GPSWeeks,
29 double& rho, int& GPSWeek_tot, double& GPSWeeks_tot,
30 double& xSat, double& ySat, double& zSat, double& clkSat) {
31
32 const double omega_earth = 7292115.1467e-11;
33 const double secsPerWeek = 604800.0;
34
35 // Initial values
36 // --------------
37 rho = 0.0;
38 ColumnVector xc(4);
39 ColumnVector vv(3);
40 eph->getCrd(bncTime(GPSWeek, GPSWeeks), xc, vv, false);
41 xSat = xc(1);
42 ySat = xc(2);
43 zSat = xc(3);
44 clkSat = xc(4);
45
46 ////cout << "----- cmpRho -----\n";
47 ////eph->print(cout);
48 ////cout << " pos " << setw(4) << GPSWeek
49 //// << " " << setw(14) << setprecision(6) << GPSWeeks
50 //// << " " << setw(13) << setprecision(3) << xSat
51 //// << " " << setw(13) << setprecision(3) << ySat
52 //// << " " << setw(13) << setprecision(3) << zSat
53 //// << endl;
54
55 // Loop until the correct Time Of Transmission is found
56 // ----------------------------------------------------
57 double rhoLast = 0;
58 do {
59 rhoLast = rho;
60
61 // Correction station position due to Earth Rotation
62 // -------------------------------------------------
63 double dPhi = omega_earth * rho / c_light;
64 double xRec = stax * cos(dPhi) - stay * sin(dPhi);
65 double yRec = stay * cos(dPhi) + stax * sin(dPhi);
66 double zRec = staz;
67
68 double dx = xRec - xSat;
69 double dy = yRec - ySat;
70 double dz = zRec - zSat;
71
72 rho = sqrt(dx*dx + dy*dy + dz*dz);
73
74 GPSWeek_tot = GPSWeek;
75 GPSWeeks_tot = GPSWeeks - rho/c_light;
76 while ( GPSWeeks_tot < 0 ) {
77 GPSWeeks_tot += secsPerWeek;
78 GPSWeek_tot -= 1;
79 }
80 while ( GPSWeeks_tot > secsPerWeek ) {
81 GPSWeeks_tot -= secsPerWeek;
82 GPSWeek_tot += 1;
83 }
84
85 eph->getCrd(bncTime(GPSWeek_tot, GPSWeeks_tot), xc, vv, false);
86 xSat = xc(1);
87 ySat = xc(2);
88 zSat = xc(3);
89 clkSat = xc(4);
90
91 dx = xRec - xSat;
92 dy = yRec - ySat;
93 dz = zRec - zSat;
94
95 rho = sqrt(dx*dx + dy*dy + dz*dz);
96
97 ////cout << " scrd " << setw(4) << GPSWeek_tot
98 //// << " " << setw(15) << setprecision(8) << GPSWeeks_tot
99 //// << " " << setw(13) << setprecision(3) << xSat
100 //// << " " << setw(13) << setprecision(3) << ySat
101 //// << " " << setw(13) << setprecision(3) << zSat
102 //// << " rcv0 " << setw(12) << setprecision(3) << stax
103 //// << " " << setw(12) << setprecision(3) << stay
104 //// << " " << setw(12) << setprecision(3) << staz
105 //// << " rcv " << setw(12) << setprecision(3) << xRec
106 //// << " " << setw(12) << setprecision(3) << yRec
107 //// << " " << setw(12) << setprecision(3) << zRec
108 //// << " dPhi " << scientific << setw(13) << setprecision(10) << dPhi << fixed
109 //// << " rho " << setw(13) << setprecision(3) << rho
110 //// << endl;
111
112
113 ////cout.setf(ios::fixed);
114 ////
115 ////cout << "niter " << setw(3) << ++niter
116 //// << " " << setw(14) << setprecision(3) << rhoLast
117 //// << " " << setw(14) << setprecision(3) << rho
118 //// << endl;
119
120 } while ( fabs(rho - rhoLast) > 1e-4);
121
122 clkSat *= c_light; // satellite clock correction in meters
123
124 return 0;
125}
Note: See TracBrowser for help on using the repository browser.