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

Last change on this file since 6462 was 5669, checked in by stoecker, 11 years ago

fix overlap, remove tabs

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