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

Last change on this file since 5664 was 5664, checked in by stoecker, 10 years ago

SSR update

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