1 | #include "clock_orbit_rtcm.h"
|
---|
2 | #include "clock_orbit_rtcm.c"
|
---|
3 |
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <stdlib.h>
|
---|
6 |
|
---|
7 | /* prototype, don't use any of this code in a final application */
|
---|
8 |
|
---|
9 | struct ClockOrbit co;
|
---|
10 | double lasttow = -1.0;
|
---|
11 |
|
---|
12 | int main(void)
|
---|
13 | {
|
---|
14 | char * buffer = 0;
|
---|
15 | size_t len = 0;
|
---|
16 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
---|
17 |
|
---|
18 | while(getline(&buffer, &len, stdin) > 0)
|
---|
19 | {
|
---|
20 | char type;
|
---|
21 | int week, prn, iodc, iode;
|
---|
22 | double tow, clock, radial, along, outofplane;
|
---|
23 | int num = sscanf(buffer, "%d %lf %c%d %d %d %lf %lf %lf %lf\n", &week,
|
---|
24 | &tow, &type, &prn, &iodc, &iode, &clock, &radial, &along, &outofplane);
|
---|
25 | if(num == 10)
|
---|
26 | {
|
---|
27 | struct SatData *sd;
|
---|
28 | if(lasttow != tow) /* create block */
|
---|
29 | {
|
---|
30 | if(lasttow >= 0)
|
---|
31 | {
|
---|
32 | FILE *f;
|
---|
33 | int l = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
---|
34 | if(!l) fprintf(stderr, "BUILD ERROR\n");
|
---|
35 | else
|
---|
36 | {
|
---|
37 | int nl, ns;
|
---|
38 | struct ClockOrbit c;
|
---|
39 |
|
---|
40 | if((f = fopen("outfile.raw", "ab+")))
|
---|
41 | {
|
---|
42 | fwrite(obuffer, l, 1, f);
|
---|
43 | fclose(f);
|
---|
44 | }
|
---|
45 | else fprintf(stderr, "SAVE ERROR\n");
|
---|
46 | //fwrite(obuffer, l, 1, stdout);
|
---|
47 | memset(&c, 0, sizeof(c));
|
---|
48 | nl = GetSSR(&c, 0, 0, 0, obuffer, l, &ns);
|
---|
49 | if(nl < 0) fprintf(stderr, "EXTRACT ERROR %d\n", nl);
|
---|
50 | else if(nl > 0) fprintf(stderr, "MULTIBLOCK UNSUPPORTED IN TEST\n");
|
---|
51 | else if(ns != l) fprintf(stderr, "SIZE MISMATCH (%d/%d)\n", ns,l);
|
---|
52 | else
|
---|
53 | {
|
---|
54 | int i;
|
---|
55 | for(i = 0; i < c.NumberOfSat[CLOCKORBIT_SATGPS]; ++i)
|
---|
56 | {
|
---|
57 | printf("%d G%02d %d %f %f %f %f\n", c.EpochTime[CLOCKORBIT_SATGPS],
|
---|
58 | c.Sat[i].ID, co.Sat[i].IOD, c.Sat[i].Clock.DeltaA0,
|
---|
59 | c.Sat[i].Orbit.DeltaRadial, c.Sat[i].Orbit.DeltaAlongTrack,
|
---|
60 | c.Sat[i].Orbit.DeltaCrossTrack);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 | memset(&co, 0, sizeof(co));
|
---|
66 | lasttow = tow;
|
---|
67 | co.EpochTime[CLOCKORBIT_SATGPS] = (int)tow;
|
---|
68 | /* co.GLONASSEpochTime = 0; */
|
---|
69 | co.Supplied[COBOFS_CLOCK] = 1;
|
---|
70 | co.Supplied[COBOFS_ORBIT] = 1;
|
---|
71 | co.SatRefDatum = DATUM_ITRF;
|
---|
72 | }
|
---|
73 |
|
---|
74 | sd = co.Sat + co.NumberOfSat[CLOCKORBIT_SATGPS];
|
---|
75 | sd->ID = prn;
|
---|
76 | sd->IOD = iode;
|
---|
77 | sd->Clock.DeltaA0 = clock;
|
---|
78 | sd->Orbit.DeltaRadial = radial;
|
---|
79 | sd->Orbit.DeltaAlongTrack = along;
|
---|
80 | sd->Orbit.DeltaCrossTrack = outofplane;
|
---|
81 | printf("%d %d/%f %c%02d %d %d %f %f %f %f\n",num, week, tow, type, prn,
|
---|
82 | iodc, iode, clock, radial, along, outofplane);
|
---|
83 | ++co.NumberOfSat[CLOCKORBIT_SATGPS];
|
---|
84 | }
|
---|
85 | }
|
---|
86 | {
|
---|
87 | struct VTEC v;
|
---|
88 | memset(&v, 0, sizeof(v));
|
---|
89 | v.EpochTime = 218764;
|
---|
90 | v.NumLayers = 1;
|
---|
91 | v.UpdateInterval = 1;
|
---|
92 | v.Layers[0].Height = 450000;
|
---|
93 | v.Layers[0].Degree = 4;
|
---|
94 | v.Layers[0].Order = 4;
|
---|
95 | v.Layers[0].Cosinus[0][0] = 24.435;
|
---|
96 | v.Layers[0].Cosinus[1][0] = 4.495;
|
---|
97 | v.Layers[0].Cosinus[2][0] = -7.805;
|
---|
98 | v.Layers[0].Cosinus[3][0] = -1.900;
|
---|
99 | v.Layers[0].Cosinus[4][0] = 2.045;
|
---|
100 | v.Layers[0].Cosinus[1][1] = -9.960;
|
---|
101 | v.Layers[0].Cosinus[2][1] = 0.845;
|
---|
102 | v.Layers[0].Cosinus[3][1] = 2.260;
|
---|
103 | v.Layers[0].Cosinus[4][1] = -0.315;
|
---|
104 | v.Layers[0].Cosinus[2][2] = 3.730;
|
---|
105 | v.Layers[0].Cosinus[3][2] = -0.780;
|
---|
106 | v.Layers[0].Cosinus[4][2] = -0.055;
|
---|
107 | v.Layers[0].Cosinus[3][3] = -0.020;
|
---|
108 | v.Layers[0].Cosinus[4][3] = 1.150;
|
---|
109 | v.Layers[0].Cosinus[4][4] = 0.990;
|
---|
110 |
|
---|
111 | v.Layers[0].Sinus[1][1] = -6.070;
|
---|
112 | v.Layers[0].Sinus[2][1] = -3.105;
|
---|
113 | v.Layers[0].Sinus[3][1] = 1.310;
|
---|
114 | v.Layers[0].Sinus[4][1] = 1.545;
|
---|
115 | v.Layers[0].Sinus[2][2] = 0.325;
|
---|
116 | v.Layers[0].Sinus[3][2] = -1.050;
|
---|
117 | v.Layers[0].Sinus[4][2] = -0.750;
|
---|
118 | v.Layers[0].Sinus[3][3] = 0.170;
|
---|
119 | v.Layers[0].Sinus[4][3] = -0.690;
|
---|
120 | v.Layers[0].Sinus[4][4] = -0.705;
|
---|
121 | FILE *f;
|
---|
122 | int l = MakeVTEC(&v, 0, obuffer, sizeof(obuffer));
|
---|
123 | if(!l) fprintf(stderr, "BUILD ERROR\n");
|
---|
124 | else
|
---|
125 | {
|
---|
126 | int nl, ns;
|
---|
127 | struct VTEC vv;
|
---|
128 |
|
---|
129 | if((f = fopen("outfile.raw", "ab+")))
|
---|
130 | {
|
---|
131 | fwrite(obuffer, l, 1, f);
|
---|
132 | fclose(f);
|
---|
133 | }
|
---|
134 | else fprintf(stderr, "SAVE ERROR\n");
|
---|
135 | //fwrite(obuffer, l, 1, stdout);
|
---|
136 | memset(&vv, 0, sizeof(vv));
|
---|
137 | nl = GetSSR(0, 0, &vv, 0, obuffer, l, &ns);
|
---|
138 | if(nl < 0) fprintf(stderr, "EXTRACT ERROR %d\n", nl);
|
---|
139 | else if(nl > 0) fprintf(stderr, "MULTIBLOCK UNSUPPORTED IN TEST\n");
|
---|
140 | else if(ns != l) fprintf(stderr, "SIZE MISMATCH (%d/%d)\n", ns,l);
|
---|
141 | else
|
---|
142 | {
|
---|
143 | int i, j, k;
|
---|
144 | for(i = 0; i < vv.NumLayers; ++i)
|
---|
145 | {
|
---|
146 | printf("%d layer %d height %f degree %d order %d\n", vv.EpochTime,
|
---|
147 | i, vv.Layers[i].Height, vv.Layers[i].Degree, vv.Layers[i].Order);
|
---|
148 | for(j = 0; j <= vv.Layers[i].Degree; ++j)
|
---|
149 | {
|
---|
150 | printf("Cn%d ",j);
|
---|
151 | for(k = 0; k <= vv.Layers[i].Order; ++k)
|
---|
152 | {
|
---|
153 | printf(" %7.3f",vv.Layers[i].Cosinus[k][j]);
|
---|
154 | }
|
---|
155 | printf("\n");
|
---|
156 | }
|
---|
157 | for(j = 0; j <= vv.Layers[i].Degree; ++j)
|
---|
158 | {
|
---|
159 | printf("Sn%d ",j);
|
---|
160 | for(k = 0; k <= vv.Layers[i].Order; ++k)
|
---|
161 | {
|
---|
162 | printf(" %7.3f",vv.Layers[i].Sinus[k][j]);
|
---|
163 | }
|
---|
164 | printf("\n");
|
---|
165 | }
|
---|
166 | }
|
---|
167 | }
|
---|
168 | }
|
---|
169 | }
|
---|
170 | free(buffer);
|
---|
171 | return 0;
|
---|
172 | }
|
---|