source: ntrip/trunk/clock_and_orbit/readco.c@ 5668

Last change on this file since 5668 was 5668, checked in by stuerze, 8 years ago

small bugfix with respect to the GLONASS code bias generation

File size: 13.6 KB
Line 
1#include "clock_orbit_rtcm.h"
2
3#include <stdio.h>
4#include <string.h>
5#include <stdlib.h>
6#include <math.h>
7
8struct ClockOrbit coIn;
9struct CodeBias cbIn;
10double lasttow_co = -1.0;
11double lasttow_cb = -1.0;
12
13typedef enum {GPS, GLO, GAL, QZSS, SBAS, BDS} SATSYS;
14int GPSUTCdiff = 16;
15char satSYS[6] = { 'G', 'R', 'E', 'J', 'S', 'C' };
16int messageTypeCo[6] = { 1060, 1066, 1243, 1249, 1255, 1261 };
17int messageTypeCb[6] = { 1059, 1065, 1242, 1248, 1254, 1260 };
18
19void printClockOrbit(const char* filename, struct ClockOrbit* clockOrb,
20 char* flag, int ind, char satSys, int offsetGnss);
21void printClockOrbitDiff(const char* filename, struct ClockOrbit* clockOrb1,
22 struct ClockOrbit* clockOrb2, char* flag, int ind, char satSys, int offsetGnss);
23void printCodeBias(const char* filename, struct CodeBias* codeBias,
24 char* flag,int ind, char satSys, int offsetGnss);
25void printCodeBiasDiff(const char* filename, struct CodeBias* codeBias1,
26 struct CodeBias* codeBias2, char* flag, int ind, char satSys,
27 int offsetGnss);
28
29int main(void) {
30 enum COR_SATSYSTEM sys;
31 char* inputFile = "ssr1_cocb_data/CLK801330.14C";
32 for (sys = GPS; sys <= BDS; ++sys) {
33 char *outFilenameRaw, *outFilenameDbg;
34 enum COR_SATSYSTEM CLOCKORBIT_SATGNSS = sys;
35 enum COR_OFFSETS CLOCKORBIT_OFFSETGNSS;
36 switch (sys) {
37 case GPS:
38 outFilenameRaw = "ssr1_cocb_data/outfile_G.raw";
39 outFilenameDbg = "ssr1_cocb_data/outfile_G.dbg";
40 CLOCKORBIT_OFFSETGNSS = CLOCKORBIT_OFFSETGPS;
41 break;
42 case GLO:
43 outFilenameRaw = "ssr1_cocb_data/outfile_R.raw";
44 outFilenameDbg = "ssr1_cocb_data/outfile_R.dbg";
45 CLOCKORBIT_OFFSETGNSS = CLOCKORBIT_OFFSETGLONASS;
46 break;
47 case GAL:
48 outFilenameRaw = "ssr1_cocb_data/outfile_E.raw";
49 outFilenameDbg = "ssr1_cocb_data/outfile_E.dbg";
50 CLOCKORBIT_OFFSETGNSS = CLOCKORBIT_OFFSETGALILEO;
51 break;
52 case QZSS:
53 outFilenameRaw = "ssr1_cocb_data/outfile_J.raw";
54 outFilenameDbg = "ssr1_cocb_data/outfile_J.dbg";
55 CLOCKORBIT_OFFSETGNSS = CLOCKORBIT_OFFSETQZSS;
56 break;
57 case SBAS:
58 outFilenameRaw = "ssr1_cocb_data/outfile_S.raw";
59 outFilenameDbg = "ssr1_cocb_data/outfile_S.dbg";
60 CLOCKORBIT_OFFSETGNSS = CLOCKORBIT_OFFSETSBAS;
61 break;
62 case BDS:
63 outFilenameRaw = "ssr1_cocb_data/outfile_C.raw";
64 outFilenameDbg = "ssr1_cocb_data/outfile_C.dbg";
65 CLOCKORBIT_OFFSETGNSS = CLOCKORBIT_OFFSETBDS;
66 break;
67 }
68 unlink(outFilenameRaw);
69 unlink(outFilenameDbg);
70 FILE *asciiSsr, *f;
71 size_t len = 0;
72 char *buffer = 0, type = satSYS[sys];
73 asciiSsr = fopen(inputFile, "r");
74 if (asciiSsr == NULL) {
75 fprintf(stderr, "ERROR: open file %s\n", inputFile);
76 return 0;
77 }
78 while (getline(&buffer, &len, asciiSsr) > 0) { //fprintf(stderr, "line: %s", buffer);
79 char coBuffer[CLOCKORBIT_BUFFERSIZE];
80 char cbBuffer[CLOCKORBIT_BUFFERSIZE];
81 int MT = 0, messageType = 0, ui = 0, week = 0, prn = 0, iode = 0, ncb = 0;
82 double cbValue[3] = { 0.0 }, clock_a0 = 0.0, clock_a1 = 0.0, clock_a2 = 0.0, d_radial = 0.0;
83 double d_along = 0.0, d_outofplane = 0.0, dd_radial = 0.0, dd_along = 0.0, dd_outofplane = 0.0;
84 enum CodeType cbType[3] = { 0 };
85 static double tow_co, tow_cb;
86 int num = sscanf(buffer, "%d ", &messageType);
87 if (messageType == messageTypeCo[GPS]) {
88 sscanf(buffer,
89 "%d %d %d %lf %c%d %d %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
90 &messageType, &ui, &week, &tow_co, &type, &prn, &iode,
91 &clock_a0, &d_radial, &d_along, &d_outofplane,
92 &clock_a1, &dd_radial, &dd_along, &dd_outofplane,
93 &clock_a2);
94 type = satSYS[sys];
95 MT = messageTypeCo[sys];
96 switch (sys) {
97 case GPS:case GAL:case SBAS:case BDS:
98 break;
99 case GLO:
100 if (prn > 24)
101 continue;
102 break;
103 case QZSS:
104 if (prn > 10)
105 continue;
106 break;
107 }
108 if ((lasttow_co != tow_co)) { // create block
109 int nl = 0, ns = 0, l = 0;
110 struct ClockOrbit coOut;
111 if (lasttow_co >= 0) {
112 if (sys == GLO) {
113 coIn.EpochTime[CLOCKORBIT_SATGLONASS] =
114 (fmod((double)coIn.EpochTime[CLOCKORBIT_SATGLONASS]
115 + (3 * 3600 - GPSUTCdiff), 86400.0));
116 }
117 printClockOrbit(outFilenameDbg, &coIn, "INPUT",
118 CLOCKORBIT_SATGNSS, type, CLOCKORBIT_OFFSETGNSS);
119 l = MakeClockOrbit(&coIn, COTYPE_AUTO, 0, coBuffer,
120 sizeof(coBuffer));
121 if (!l)
122 fprintf(stderr, "BUILD ERROR\n");
123 else {
124 if ((f = fopen(outFilenameRaw, "ab+"))) {
125 fwrite(coBuffer, l, 1, f);
126 fclose(f);
127 } else
128 fprintf(stderr, "SAVE ERROR %s\n",
129 outFilenameRaw);
130 }
131 memset(&coOut, 0, sizeof(coOut));
132 nl = GetSSR(&coOut, 0, 0, 0, coBuffer, l, &ns);
133 if (nl < 0)
134 fprintf(stderr, "CLKORB EXTRACT ERROR %d\n", nl);
135 else if (nl > 0)
136 fprintf(stderr, "CLKORB MULTIBLOCK UNSUPPORTED IN TEST\n");
137 else if (ns != l)
138 fprintf(stderr, "CLKORB SIZE MISMATCH (%d/%d)\n", ns, l);
139 else {
140 printClockOrbit(outFilenameDbg, &coOut, "OUTPUT",
141 CLOCKORBIT_SATGNSS, type, CLOCKORBIT_OFFSETGNSS);
142 printClockOrbitDiff(outFilenameDbg, &coIn, &coOut,
143 "DIFF", CLOCKORBIT_SATGNSS, type, CLOCKORBIT_OFFSETGNSS);
144 }
145 }
146 memset(&coIn, 0, sizeof(coIn));
147 lasttow_co = tow_co;
148 coIn.messageType = MT;
149 coIn.EpochTime[CLOCKORBIT_SATGNSS] = (int) tow_co;
150 coIn.UpdateInterval = (int) ui;
151 coIn.Supplied[COBOFS_COMBINED] = 1;
152 coIn.SatRefDatum = DATUM_ITRF;
153 }
154 struct SatData *sd;
155 sd = coIn.Sat
156 + CLOCKORBIT_OFFSETGNSS
157 + coIn.NumberOfSat[CLOCKORBIT_SATGNSS];
158 sd->ID = prn;
159 sd->IOD = iode;
160 sd->Clock.DeltaA0 = clock_a0;
161 sd->Clock.DeltaA1 = clock_a1;
162 sd->Clock.DeltaA2 = clock_a2;
163 sd->Orbit.DeltaRadial = d_radial;
164 sd->Orbit.DeltaAlongTrack = d_along;
165 sd->Orbit.DeltaCrossTrack = d_outofplane;
166 sd->Orbit.DotDeltaRadial = dd_radial;
167 sd->Orbit.DotDeltaAlongTrack = dd_along;
168 sd->Orbit.DotDeltaCrossTrack = dd_outofplane;
169 ++coIn.NumberOfSat[CLOCKORBIT_SATGNSS];
170 }
171 if (messageType == messageTypeCb[GPS]) {
172 sscanf(buffer, "%d %d %d %lf %c%d %d %d %lf %d %lf %d %lf\n",
173 &messageType, &ui, &week, &tow_cb, &type, &prn, &ncb,
174 &cbType[0], &cbValue[0], &cbType[1], &cbValue[1],
175 &cbType[2], &cbValue[2]);
176 type = satSYS[sys];
177 MT = messageTypeCb[sys];
178 switch (sys) {
179 case GPS:
180 break;
181 case GLO:
182 if (prn > 24)
183 continue;
184 cbType[0] = CODETYPEGLONASS_L1_CA;
185 cbType[1] = CODETYPEGLONASS_L1_P;
186 cbType[2] = CODETYPEGLONASS_L2_CA;
187 break;
188 case GAL:
189 cbType[0] = CODETYPEGALILEO_E1_A;
190 cbType[1] = CODETYPEGALILEO_E5_I;
191 cbType[2] = CODETYPEGALILEO_E6_A;
192 break;
193 case QZSS:
194 if (prn > 10)
195 continue;
196 cbType[0] = CODETYPEQZSS_L1_CA;
197 cbType[1] = CODETYPEQZSS_L2_CM;
198 cbType[2] = CODETYPEQZSS_L5_I;
199 break;
200 case SBAS:
201 cbType[0] = CODETYPE_SBAS_L1_CA;
202 cbType[1] = CODETYPE_SBAS_L5_I;
203 cbType[2] = CODETYPE_SBAS_L5_Q;
204 break;
205 case BDS:
206 cbType[0] = CODETYPE_BDS_B1_I;
207 cbType[1] = CODETYPE_BDS_B3_I;
208 cbType[2] = CODETYPE_BDS_B2_I;
209 break;
210 }
211 if (lasttow_cb != tow_cb) { // create block
212 int nl, ns, l;
213 struct CodeBias cbOut;
214 if (lasttow_cb >= 0) {
215 if (sys == GLO) {
216 cbIn.EpochTime[CLOCKORBIT_SATGLONASS] =
217 (fmod((double)cbIn.EpochTime[CLOCKORBIT_SATGLONASS]
218 + (3 * 3600 - GPSUTCdiff), 86400.0));
219 }
220 printCodeBias(outFilenameDbg, &cbIn, "INPUT",
221 CLOCKORBIT_SATGNSS, type, CLOCKORBIT_OFFSETGNSS);
222 l = MakeCodeBias(&cbIn, BTYPE_AUTO, 0, cbBuffer,
223 sizeof(cbBuffer));
224 if (!l)
225 fprintf(stderr, "BUILD ERROR\n");
226 else {
227 if ((f = fopen(outFilenameRaw, "ab+"))) {
228 fwrite(cbBuffer, l, 1, f);
229 fclose(f);
230 } else
231 fprintf(stderr, "SAVE ERROR %s\n", outFilenameRaw);
232 }
233 memset(&cbOut, 0, sizeof(cbOut));
234 nl = GetSSR(NULL, &cbOut, NULL, 0, cbBuffer, l, &ns);
235 if (nl < 0)
236 fprintf(stderr, "CBIAS EXTRACT ERROR %d\n", nl);
237 else if (nl > 0)
238 fprintf(stderr, "CBIAS MULTIBLOCK UNSUPPORTED IN TEST\n");
239 else if (ns != l)
240 fprintf(stderr, "CBIAS SIZE MISMATCH (%d/%d)\n", ns, l);
241 else {
242 printCodeBias(outFilenameDbg, &cbOut, "OUTPUT",
243 CLOCKORBIT_SATGNSS, type, CLOCKORBIT_OFFSETGNSS);
244 printCodeBiasDiff(outFilenameDbg, &cbIn, &cbOut,
245 "DIFF", CLOCKORBIT_SATGNSS, type, CLOCKORBIT_OFFSETGNSS);
246 }
247 }
248 memset(&cbIn, 0, sizeof(cbIn));
249 lasttow_cb = tow_cb;
250 cbIn.messageType = MT;
251 cbIn.EpochTime[CLOCKORBIT_SATGNSS] = (int) tow_cb;
252 cbIn.UpdateInterval = ui;
253 coIn.Supplied[COBOFS_BIAS] = 1;
254 }
255 struct BiasSat *bs;
256 bs = cbIn.Sat
257 + CLOCKORBIT_OFFSETGNSS
258 + cbIn.NumberOfSat[CLOCKORBIT_SATGNSS];
259 bs->ID = prn;
260 bs->NumberOfCodeBiases = ncb;
261 int k = 0;
262 for (k = 0; k < bs->NumberOfCodeBiases; k++) {
263 bs->Biases[k].Type = cbType[k];
264 bs->Biases[k].Bias = cbValue[k];
265 }
266 ++cbIn.NumberOfSat[CLOCKORBIT_SATGNSS];
267 }
268 }
269 free(buffer);
270 close(asciiSsr);
271 }
272 return 0;
273}
274
275void printClockOrbit(const char* filename, struct ClockOrbit* clockOrb,
276 char* flag, int ind, char satSys, int offsetGnss) {
277 int i = 0;
278 FILE *filestream = fopen(filename, "ab+");
279 if (!clockOrb->NumberOfSat[ind])
280 return;
281 if (filestream == NULL) {
282 fprintf(stderr, "ERROR: open file %s\n", filename);
283 return;
284 }
285 fprintf(filestream, "CLKORB_%s\n", flag);
286 for (i = offsetGnss; i < offsetGnss + clockOrb->NumberOfSat[ind]; ++i) {
287 fprintf(filestream,
288 "%10d %d %c%02d %5d %12.3f %12.3f %12.3f %12.3f %12.3f %12f %12f %12f %12.3f\n",
289 clockOrb->EpochTime[ind], clockOrb->UpdateInterval, satSys,
290 clockOrb->Sat[i].ID,
291 clockOrb->Sat[i].IOD,
292 clockOrb->Sat[i].Clock.DeltaA0,
293 clockOrb->Sat[i].Orbit.DeltaRadial,
294 clockOrb->Sat[i].Orbit.DeltaAlongTrack,
295 clockOrb->Sat[i].Orbit.DeltaCrossTrack,
296 clockOrb->Sat[i].Clock.DeltaA1,
297 clockOrb->Sat[i].Orbit.DotDeltaRadial,
298 clockOrb->Sat[i].Orbit.DotDeltaAlongTrack,
299 clockOrb->Sat[i].Orbit.DotDeltaCrossTrack,
300 clockOrb->Sat[i].Clock.DeltaA2);
301 }
302 fclose(filestream);
303}
304
305void printClockOrbitDiff(const char* filename, struct ClockOrbit* clockOrb1,
306 struct ClockOrbit* clockOrb2, char* flag, int ind, char satSys,
307 int offsetGnss) {
308 int i = 0;
309 FILE *filestream = fopen(filename, "ab+");
310 if (!clockOrb1->NumberOfSat[ind])
311 return;
312 if (filestream == NULL) {
313 fprintf(stderr, "ERROR: open file %s\n", filename);
314 return;
315 }
316 fprintf(filestream, "CLKORB_%s\n", flag);
317 for (i = offsetGnss; i < offsetGnss + clockOrb1->NumberOfSat[ind]; ++i) {
318 fprintf(filestream,
319 "%10d %d %c%02d %5d %12.3f %12.3f %12.3f %12.3f %12.3f %12f %12f %12f %12.3f\n",
320 clockOrb1->EpochTime[ind]
321 - clockOrb2->EpochTime[ind],
322 clockOrb1->UpdateInterval
323 - clockOrb2->UpdateInterval, satSys,
324 clockOrb1->Sat[i].ID
325 - clockOrb2->Sat[i].ID,
326 clockOrb1->Sat[i].IOD - clockOrb2->Sat[i].IOD,
327 clockOrb1->Sat[i].Clock.DeltaA0
328 - clockOrb2->Sat[i].Clock.DeltaA0,
329 clockOrb1->Sat[i].Orbit.DeltaRadial
330 - clockOrb2->Sat[i].Orbit.DeltaRadial,
331 clockOrb1->Sat[i].Orbit.DeltaAlongTrack
332 - clockOrb2->Sat[i].Orbit.DeltaAlongTrack,
333 clockOrb1->Sat[i].Orbit.DeltaCrossTrack
334 - clockOrb2->Sat[i].Orbit.DeltaCrossTrack,
335 clockOrb1->Sat[i].Clock.DeltaA1
336 - clockOrb2->Sat[i].Clock.DeltaA1,
337 clockOrb1->Sat[i].Orbit.DotDeltaRadial
338 - clockOrb2->Sat[i].Orbit.DotDeltaRadial,
339 clockOrb1->Sat[i].Orbit.DotDeltaAlongTrack
340 - clockOrb2->Sat[i].Orbit.DotDeltaAlongTrack,
341 clockOrb1->Sat[i].Orbit.DotDeltaCrossTrack
342 - clockOrb2->Sat[i].Orbit.DotDeltaCrossTrack,
343 clockOrb1->Sat[i].Clock.DeltaA2
344 - clockOrb2->Sat[i].Clock.DeltaA2);
345 }
346 fclose(filestream);
347}
348
349void printCodeBias(const char* filename, struct CodeBias* codeBias, char* flag,
350 int ind, char satSys, int offsetGnss) {
351 int i = 0;
352 FILE *filestream = fopen(filename, "ab+");
353 if (!codeBias->NumberOfSat[ind])
354 return;
355 if (filestream == NULL) {
356 fprintf(stderr, "ERROR: open file %s\n", filename);
357 return;
358 }
359 fprintf(filestream, "CBIAS_%s\n", flag);
360 for (i = offsetGnss; i < offsetGnss + codeBias->NumberOfSat[ind]; ++i) {
361 fprintf(filestream, "%10d %d %c%02d %2d ",
362 codeBias->EpochTime[ind], codeBias->UpdateInterval, satSys,
363 codeBias->Sat[i].ID, codeBias->Sat[i].NumberOfCodeBiases);
364 int j;
365 for (j = 0; j < codeBias->Sat[i].NumberOfCodeBiases; j++) {
366 fprintf(filestream, "%4d %12.3f", codeBias->Sat[i].Biases[j].Type,
367 codeBias->Sat[i].Biases[j].Bias);
368 }
369 fprintf(filestream, "\n");
370 }
371 fclose(filestream);
372}
373
374void printCodeBiasDiff(const char* filename, struct CodeBias* codeBias1,
375 struct CodeBias* codeBias2, char* flag, int ind, char satSys,
376 int offsetGnss) {
377 int i = 0;
378 FILE *filestream = fopen(filename, "ab+");
379 if (!codeBias1->NumberOfSat[ind])
380 return;
381 if (filestream == NULL) {
382 fprintf(stderr, "ERROR: open file %s\n", filename);
383 return;
384 }
385 fprintf(filestream, "CBIAS_%s\n", flag);
386 for (i = offsetGnss; i < offsetGnss + codeBias1->NumberOfSat[ind]; ++i) {
387 fprintf(filestream, "%10d %d %c%02d %2d ",
388 codeBias1->EpochTime[ind]
389 - codeBias2->EpochTime[ind],
390 codeBias1->UpdateInterval
391 - codeBias2->UpdateInterval, satSys,
392 codeBias1->Sat[i].ID
393 - codeBias2->Sat[i].ID,
394 codeBias1->Sat[i].NumberOfCodeBiases
395 - codeBias2->Sat[i].NumberOfCodeBiases);
396 int j;
397 for (j = 0; j < codeBias1->Sat[i].NumberOfCodeBiases; j++) {
398 fprintf(filestream, "%4d %12.3f",
399 codeBias1->Sat[i].Biases[j].Type
400 - codeBias2->Sat[i].Biases[j].Type,
401 codeBias1->Sat[i].Biases[j].Bias
402 - codeBias2->Sat[i].Biases[j].Bias);
403 }
404 fprintf(filestream, "\n");
405 }
406 fclose(filestream);
407}
Note: See TracBrowser for help on using the repository browser.