MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_bias_sinex.c
Go to the documentation of this file.
1/*------------------------------------------------------------------------------
2 * mrtk_bias_sinex.c : BIAS-SINEX file reader and bias functions
3 *
4 * Copyright (C) 2026 H.SHIONO (MRTKLIB Project)
5 * Copyright (C) 2023-2025 Cabinet Office, Japan
6 * Copyright (C) 2024-2025 Lighthouse Technology & Consulting Co. Ltd.
7 * Copyright (C) 2023-2025 Japan Aerospace Exploration Agency
8 * Copyright (C) 2023-2025 TOSHIBA ELECTRONIC TECHNOLOGIES CORPORATION
9 * Copyright (C) 2015- Mitsubishi Electric Corp.
10 * Copyright (C) 2014 Geospatial Information Authority of Japan
11 * Copyright (C) 2014 T.SUZUKI
12 * Copyright (C) 2007-2023 T.TAKASU
13 *
14 * SPDX-License-Identifier: BSD-2-Clause
15 *----------------------------------------------------------------------------*/
17
18#include <math.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22
23#include "mrtklib/mrtk_sys.h"
24#include "mrtklib/mrtk_trace.h"
25
26/* local constants -----------------------------------------------------------*/
27static const double CLIGHT = 299792458.0;
28#define NS2M (CLIGHT / 1E9)
29#define M2NS (1E9 / CLIGHT)
30
31/*--- forward declarations for legacy functions resolved at link time -------*/
32extern void satno2id(int sat, char* id);
33extern int satid2no(const char* id);
34extern uint8_t obs2code(const char* obs);
35extern char* code2obs(uint8_t code);
36extern char* time_str(gtime_t t, int n);
37
38static biass_t biass = {0};
39static char syscode[] = "GREJCIS";
40static char typeid[][5] = {"DSB ", "ISB ", "OSB "};
41
42/* get system code number -----------------------------------------------------
43 * get system code number based on satellite number
44 * args : int sat I satellite number
45 * return : int O system code number(0 or positive:valid,-1:error)
46 *-----------------------------------------------------------------------------*/
47int getsysno(int sat) {
48 int i;
49 char satid[8];
50
51 satno2id(sat, satid);
52 for (i = 0; i < MAXBSNXSYS; i++) {
53 if (satid[0] == syscode[i]) {
54 return i;
55 }
56 }
57 return -1;
58}
59
60/* get bias structure pointer -------------------------------------------------
61 * get pointer to the bias structure
62 * args : none
63 * return : biass_t * O pointer to bias structure
64 *-----------------------------------------------------------------------------*/
65biass_t* getbiass(void) { return &biass; }
66
67/* free bia ------------------------------------------------------------------*/
68static void freebia(bia_t** ary, int* n, int* nmax) {
69 if (*ary != NULL) {
70 free(*ary);
71 *ary = NULL;
72 *n = *nmax = 0;
73 }
74}
75
76/* delete code/phase bias ----------------------------------------------------*/
77static void freebiass(void) {
78 int i, j;
79
80 for (i = 0; i < MAXSAT; i++) {
81 if (biass.sat.cb[i] != NULL) {
82 freebia(&biass.sat.cb[i], &biass.sat.ncb[i], &biass.sat.ncbmax[i]);
83 }
84 if (biass.sat.pb[i] != NULL) {
85 freebia(&biass.sat.pb[i], &biass.sat.npb[i], &biass.sat.npbmax[i]);
86 }
87 }
88
89 for (i = 0; i < MAXSTA; i++) {
90 for (j = 0; j < MAXBSNXSYS; j++) {
91 if (biass.sta[i].syscb[j] != NULL) {
92 freebia(&biass.sta[i].syscb[j], &biass.sta[i].nsyscb[j], &biass.sta[i].nsyscbmax[j]);
93 }
94 }
95 for (j = 0; j < MAXSAT; j++) {
96 if (biass.sta[i].satcb[j] != NULL) {
97 freebia(&biass.sta[i].satcb[j], &biass.sta[i].nsatcb[j], &biass.sta[i].nsatcbmax[j]);
98 }
99 }
100 }
101}
102
103/* add bias to array ----------------------------------------------------------
104 * add a bias entry to the bias array, reallocating memory if necessary
105 * args : bia_t *bia I bias entry to add
106 * bia_t **ary IO pointer to bias array
107 * int *n IO current number of entries in array
108 * int *nmax IO current maximum number of entries in array
109 * return : none
110 *-----------------------------------------------------------------------------*/
111void addbia(const bia_t* bia, bia_t** ary, int* n, int* nmax) {
112 bia_t* b;
113
114 if (*nmax <= *n) {
115 *nmax += 256;
116 if (!(b = (bia_t*)realloc(*ary, sizeof(bia_t) * (*nmax)))) {
117 trace(NULL, 1, "addbia: memory allocation error\n");
118 free(*ary);
119 *ary = NULL;
120 *n = *nmax = 0;
121 return;
122 }
123 *ary = b;
124 }
125 (*ary)[*n] = *bia;
126 *n += 1;
127}
128
129/* read BIAS-SINEX file -------------------------------------------------------
130 * read bias information from a SINEX file and store it in the bias structure
131 * args : char *file I SINEX file path
132 * return : int O status (1:ok, 0:error)
133 *-----------------------------------------------------------------------------*/
134int readbsnx(const char* file) {
135 double ep[6] = {0, 1, 1, 0, 0, 0}, doy, tod, unit;
136 char satid[] = " ", sta[] = " ", sig1[] = " ", sig2[] = " ";
137 char buff[256], *p, *dscrpt[4];
138 int i, j, n, sat, state = 0, ret = 0;
139 FILE* fp;
140 bia_t bia;
141
142 trace(NULL, 3, "readbsnx : file=%s\n", file);
143
144 if (!(fp = fopen(file, "r"))) {
145 trace(NULL, 2, "bias sinex file open error: %s\n", file);
146 return 0;
147 }
148 freebiass();
149
150 while (fgets(buff, sizeof(buff), fp)) {
151 if (buff[0] == '*') {
152 continue;
153 }
154 if (strstr(buff, "+BIAS/DESCRIPTION")) {
155 state = 1;
156 continue;
157 }
158 if (strstr(buff, "-BIAS/DESCRIPTION")) {
159 state = 0;
160 continue;
161 }
162 if (strstr(buff, "+BIAS/SOLUTION")) {
163 state = 2;
164 continue;
165 }
166 if (strstr(buff, "-BIAS/SOLUTION")) {
167 state = 0;
168 continue;
169 }
170
171 switch (state) {
172 case 1: /* BIAS/DESCRIPTION */
173 dscrpt[0] = strtok(buff + 1, " \n");
174 for (n = 1; n < 4; n++) {
175 if ((p = strtok(NULL, " \n"))) {
176 dscrpt[n] = p;
177 } else {
178 dscrpt[n] = "";
179 }
180 }
181 trace(NULL, 4, "readbsnx KEYWORD, %-39s, %s, %s, %s\n", dscrpt[0], dscrpt[1], dscrpt[2], dscrpt[3]);
182 break;
183
184 case 2: /* BIAS/SOLUTION */
185 if (strlen(buff) < 92) {
186 continue;
187 }
188 for (i = 0; i < 3; i++) {
189 if (strncmp(buff + 1, typeid[i], 4) == 0) { /* BIAS */
190 bia.type = i;
191 break;
192 }
193 }
194 if (i >= 3) {
195 continue;
196 }
197 strncpy(satid, buff + 11, 3); /* PRN */
198 sat = satid2no(satid);
199 strncpy(sta, buff + 15, 9); /* STATION__ */
200 for (i = strlen(sta) - 1; (i >= 0) && (sta[i] == ' '); i--) {
201 sta[i] = '\0';
202 }
203 strncpy(sig1, buff + 25, 3); /* OBS1 */
204 bia.code[0] = obs2code(&sig1[1]);
205 if (bia.type < 2) {
206 strncpy(sig2, buff + 30, 3); /* OBS2 */
207 bia.code[1] = obs2code(&sig2[1]);
208 } else {
209 memcpy(sig2, " ", 3);
210 bia.code[1] = CODE_NONE;
211 }
212 /* BIAS_START____ */
213 sscanf(buff + 35, "%lf:%lf:%lf", ep, &doy, &tod);
214 bia.t0 = timeadd(epoch2time(ep), (doy - 1) * 86400 + tod);
215 /* BIAS_END______ */
216 sscanf(buff + 50, "%lf:%lf:%lf", ep, &doy, &tod);
217 bia.t1 = timeadd(epoch2time(ep), (doy - 1) * 86400 + tod);
218 /* UNIT */
219 if (strncmp(buff + 65, "ns", 2) == 0) {
220 unit = NS2M;
221 } else {
222 unit = 1.0;
223 }
224 /* __ESTIMATED_VALUE____ */
225 bia.val = str2num(buff, 70, 21) * unit;
226 if (strlen(buff) > 92) {
227 /* _STD_DEV___ */
228 bia.valstd = str2num(buff, 92, 11) * unit;
229 }
230 if (strlen(buff) > 127) {
231 /* __ESTIMATED_SLOPE____ */
232 bia.slp = str2num(buff, 104, 21) * unit;
233 /* _STD_DEV___ */
234 bia.slpstd = str2num(buff, 126, 11) * unit;
235 } else {
236 bia.slp = bia.slpstd = 0.0;
237 }
238 if (strlen(sta) == 0) { /* satellite */
239 if (sat == 0) {
240 continue;
241 }
242 if (sig1[0] == 'C') { /* code bias */
243 addbia(&bia, &biass.sat.cb[sat - 1], &biass.sat.ncb[sat - 1], &biass.sat.ncbmax[sat - 1]);
244 } else { /* phase bias */
245 addbia(&bia, &biass.sat.pb[sat - 1], &biass.sat.npb[sat - 1], &biass.sat.npbmax[sat - 1]);
246 }
247 } else { /* station */
248 for (i = 0; (i < MAXSTA) && (i < biass.nsta); i++) {
249 if (strcmp(sta, biass.sta[i].name) == 0) {
250 break;
251 }
252 }
253 if (i >= MAXSTA) {
254 trace(NULL, 2, "readbsnx %s has exceeded the station limit of %d.\n", sta, MAXSTA);
255 continue;
256 }
257 if (i >= biass.nsta) {
258 strcpy(biass.sta[i].name, sta);
259 biass.nsta++;
260 }
261 if (sat == 0) { /* system code bias */
262 for (j = 0; j < MAXBSNXSYS; j++) {
263 if (satid[0] == syscode[j]) {
264 break;
265 }
266 }
267 if (j >= MAXBSNXSYS) {
268 continue;
269 }
270 addbia(&bia, &biass.sta[i].syscb[j], &biass.sta[i].nsyscb[j], &biass.sta[i].nsyscbmax[j]);
271 } else { /* satellite code bias*/
272 addbia(&bia, &biass.sta[i].satcb[sat - 1], &biass.sta[i].nsatcb[sat - 1],
273 &biass.sta[i].nsatcbmax[sat - 1]);
274 }
275 }
276 trace(NULL, 4, "readbsnx %8d,%4s,%-9s, %3s, %3s, %3d, %3s, %3d, %s, %8d,%10.4f,%10.4f,%10.4f,%10.4f\n",
277 ret, typeid[bia.type], sta, satid, sig1, bia.code[0], sig2, bia.code[1], time_str(bia.t0, 0),
278 (int)timediff(bia.t1, bia.t0), bia.val, bia.valstd, bia.slp, bia.slpstd);
279 ret++;
280 }
281 }
282 fclose(fp);
283 return ret;
284}
285
286/* time to bias time(year & day of year & time of day) -----------------------*/
287static void time2biast(gtime_t time, double* year, double* doy, double* tod) {
288 gtime_t btime;
289 double bep[6] = {0, 1, 1, 0, 0, 0}, ep[6] = {0, 0, 0, 0, 0, 0}, tdiff;
290
291 time2epoch(time, ep);
292 bep[0] = ep[0];
293 btime = epoch2time(bep);
294
295 tdiff = timediff(time, btime);
296 *year = ep[0];
297 *doy = (int)floor(tdiff / 86400) + 1;
298 *tod = (int)floor(tdiff - (*doy - 1) * 86400);
299}
300
301/* code to signal string -----------------------------------------------------*/
302static char* code2sigs(uint8_t code, int cpflag) {
303 static char sigs[8];
304
305 strcpy(sigs, " ");
306
307 if (CODE_NONE < code && code <= MAXCODE) {
308 if (cpflag == 0) {
309 sprintf(sigs, "C%2s", code2obs(code));
310 } else if (cpflag == 1) {
311 sprintf(sigs, "L%2s", code2obs(code));
312 }
313 }
314
315 return sigs;
316}
317
318/* output BIAS-SINEX file header -----------------------------------------------
319 * output BIAS-SINEX file header
320 * args : FILE *fp I output file pointer
321 * gtime_t ts I start time
322 * gtime_t te I end time
323 * char *agency I agency name
324 * return : none
325 *-----------------------------------------------------------------------------*/
326void outbsnxh(FILE* fp, gtime_t ts, gtime_t te, const char* agency) {
327 double year, doy, tod, ep[6];
328 gtime_t nt = timeget();
329
330 if (fp == NULL) {
331 return;
332 }
333 trace(NULL, 3, "outbsnxh: \n");
334
335 time2epoch(nt, ep);
336 time2biast(nt, &year, &doy, &tod);
337 fprintf(fp, "%%=BIA 1.00 %3s %04.0f:%03.0f:%05.0f ", agency, year, doy, tod);
338 time2biast(ts, &year, &doy, &tod);
339 fprintf(fp, "%3s %04.0f:%03.0f:%05.0f", agency, year, doy, tod);
340 time2biast(te, &year, &doy, &tod);
341 fprintf(fp, "%04.0f:%03.0f:%05.0f P %04.0f%02.0f%02.0f%02.0f%02.0f%02.0f\n", year, doy, tod, ep[0], ep[1], ep[2],
342 ep[3], ep[4], ep[5]);
343}
344
345/* output FILE/REFERENCE header ------------------------------------------------
346 * output the header of the FILE/REFERENCE section in a BIAS-SINEX file
347 * args : FILE *fp I output file pointer
348 * return : none
349 *-----------------------------------------------------------------------------*/
350void outbsnxrefh(FILE* fp) {
351 if (fp == NULL) {
352 return;
353 }
354 trace(NULL, 3, "outbsnxrefh: \n");
355
356 fprintf(fp, "*-------------------------------------------------------------------------------\n");
357 fprintf(fp, "+FILE/REFERENCE\n");
358 fprintf(fp, "*INFO_TYPE_________ INFO________________________________________________________\n");
359}
360
361/* output FILE/REFERENCE body --------------------------------------------------
362 * output a line in the FILE/REFERENCE section of a BIAS-SINEX file
363 * args : FILE *fp I output file pointer
364 * int type I type of information (0: DESCRIPTION, 1: OUTPUT, ...)
365 * char *reftext I reference text to output
366 * return : none
367 *-----------------------------------------------------------------------------*/
368void outbsnxrefb(FILE* fp, int type, char* reftext) {
369 char* inft[6] = {"DESCRIPTION", "OUTPUT", "CONTACT", "SOFTWARE", "HARDWARE", "INPUT"};
370 if (fp == NULL) {
371 return;
372 }
373 if (type < 0 || type >= 6) {
374 trace(NULL, 2, "outbsnxrefb error: type=%d is out of range.[0-5]\n", type);
375 return;
376 }
377 if (strlen(reftext) > 60) {
378 trace(NULL, 2, "outbsnxrefb error: comment length over %d[60]\n", strlen(reftext));
379 return;
380 }
381 trace(NULL, 3, "outbsnxrefb: \n");
382 fprintf(fp, " %-18s %-60s\n", inft[type], reftext);
383}
384
385/* output FILE/REFERENCE footer ------------------------------------------------
386 * output the end of the FILE/REFERENCE section in a BIAS-SINEX file
387 * args : FILE *fp I output file pointer
388 * return : none
389 *-----------------------------------------------------------------------------*/
390void outbsnxreff(FILE* fp) {
391 if (fp == NULL) {
392 return;
393 }
394 trace(NULL, 3, "outbsnxreff: \n");
395 fprintf(fp, "-FILE/REFERENCE\n");
396}
397
398/* output FILE/COMMENT header --------------------------------------------------
399 * output the header of the FILE/COMMENT section in a BIAS-SINEX file
400 * args : FILE *fp I output file pointer
401 * return : none
402 *-----------------------------------------------------------------------------*/
403void outbsnxcomh(FILE* fp) {
404 if (fp == NULL) {
405 return;
406 }
407 trace(NULL, 3, "outbsnxcomh: \n");
408 fprintf(fp, "*-------------------------------------------------------------------------------\n");
409 fprintf(fp, "+FILE/COMMENT\n");
410}
411
412/* output FILE/COMMENT body ----------------------------------------------------
413 * output a comment line in the FILE/COMMENT section of a BIAS-SINEX file
414 * args : FILE *fp I output file pointer
415 * char *comtext I comment text to output
416 * return : none
417 *-----------------------------------------------------------------------------*/
418void outbsnxcomb(FILE* fp, char* comtext) {
419 if (fp == NULL) {
420 return;
421 }
422 if (strlen(comtext) > 79) {
423 trace(NULL, 2, "outbsnxcomb error: comment length over %d[79]\n", strlen(comtext));
424 return;
425 }
426 trace(NULL, 3, "outbsnxcomb: %s\n", comtext);
427 fprintf(fp, " %-79s\n", comtext);
428}
429
430/* output FILE/COMMENT footer --------------------------------------------------
431 * output the end of the FILE/COMMENT section in a BIAS-SINEX file
432 * args : FILE *fp I output file pointer
433 * return : none
434 *-----------------------------------------------------------------------------*/
435void outbsnxcomf(FILE* fp) {
436 if (fp == NULL) {
437 return;
438 }
439 trace(NULL, 3, "outbsnxcomf: \n");
440 fprintf(fp, "-FILE/COMMENT\n");
441}
442
443/* output BIAS/SOLUTION data --------------------------------------------------*/
444static void outbsnxsold(FILE* fp, int cpflag, int n, const bia_t* biad, char* sat, char* sta) {
445 int i;
446 char osb1str[8], osb2str[8];
447 double sy, sdoy, stod, ey, edoy, etod;
448
449 for (i = 0; i < n; i++) {
450 strcpy(osb1str, code2sigs(biad[i].code[0], cpflag)); /* OBS1 */
451 strcpy(osb2str, code2sigs(biad[i].code[1], cpflag)); /* OBS2 */
452 time2biast(biad[i].t0, &sy, &sdoy, &stod); /* BIAS_START */
453 time2biast(biad[i].t1, &ey, &edoy, &etod); /* BIAS_END */
454
455 /* output */
456 fprintf(fp, " %.4s %.4s %-3s ", typeid[biad[i].type], " ", sat);
457 fprintf(fp, "%-9s ", sta);
458 fprintf(fp, "%-4s ", osb1str);
459 fprintf(fp, "%-4s ", osb2str);
460 fprintf(fp, "%04.0f:%03.0f:%05.0f %04.0f:%03.0f:%05.0f %-4s %21.14E %11.5E %21.14E %11.5E\n", sy, sdoy, stod,
461 ey, edoy, etod, "ns", biad[i].val * M2NS, biad[i].valstd * M2NS, biad[i].slp * M2NS,
462 biad[i].slpstd * M2NS);
463 }
464}
465
466/* output BIAS-SINEX BIAS/SOLUTION ---------------------------------------------
467 * output the BIAS/SOLUTION section in a BIAS-SINEX file
468 * args : FILE *fp I output file pointer
469 * return : none
470 *-----------------------------------------------------------------------------*/
471void outbsnxsol(FILE* fp) {
472 biass_t* biass;
473 int i, j;
474 char satid[8];
475
476 if (fp == NULL) {
477 return;
478 }
479 trace(NULL, 3, "outbsnxsol: \n");
480
481 biass = getbiass();
482
483 fprintf(fp, "*-------------------------------------------------------------------------------\n");
484 fprintf(fp, "+BIAS/SOLUTION\n");
485 fprintf(fp,
486 "*BIAS SVN_ PRN STATION__ OBS1 OBS2 BIAS_START____ BIAS_END______ UNIT __ESTIMATED_VALUE____ _STD_DEV___ "
487 "__ESTIMATED_SLOPE____ _STD_DEV___\n");
488
489 /* satellite code bias */
490 for (i = 0; i < MAXSAT; i++) {
491 satno2id(i + 1, satid);
492 outbsnxsold(fp, 0, biass->sat.ncb[i], biass->sat.cb[i], satid, "");
493 }
494
495 /* satellite phase bias */
496 for (i = 0; i < MAXSAT; i++) {
497 satno2id(i + 1, satid);
498 outbsnxsold(fp, 1, biass->sat.npb[i], biass->sat.pb[i], satid, "");
499 }
500
501 /* station system code bias*/
502 for (i = 0; i < biass->nsta; i++) {
503 for (j = 0; j < MAXBSNXSYS; j++) {
504 sprintf(satid, "%c", syscode[j]);
505 outbsnxsold(fp, 0, biass->sta[i].nsyscb[j], biass->sta[i].syscb[j], satid, biass->sta[i].name);
506 }
507 }
508
509 /* station satellite code bias*/
510 for (i = 0; i < biass->nsta; i++) {
511 for (j = 0; j < MAXSAT; j++) {
512 satno2id(j + 1, satid);
513 outbsnxsold(fp, 0, biass->sta[i].nsatcb[j], biass->sta[i].satcb[j], satid, biass->sta[i].name);
514 }
515 }
516 fprintf(fp, "-BIAS/SOLUTION\n");
517 fprintf(fp, "%%=ENDBIA\n");
518}
519
520/* update satellite OSB -------------------------------------------------------
521 * update the satellite OSB (Observable Satellite Bias) structure
522 * with current biases
523 * args : osb_t *osb IO OSB structure to update
524 * gtime_t gt I current time
525 * int mode I mode (0: current, 1: all)
526 * return : int O number of updated biases
527 *-----------------------------------------------------------------------------*/
528int udosb_sat(osb_t* osb, gtime_t gt, int mode) {
529 biass_t* biass;
530 bia_t* bias;
531 int i, j, ret = 0;
532
533 biass = getbiass();
534
535 for (j = 0; j < MAXCODE; j++) {
536 for (i = 0; i < MAXSAT; i++) {
537 osb->vscb[i][j] = 0;
538 osb->vspb[i][j] = 0;
539 }
540 }
541 for (i = 0; i < MAXSAT; i++) {
542 for (j = 0; j < biass->sat.ncb[i]; j++) {
543 bias = &biass->sat.cb[i][j];
544 if (bias->code[0] == CODE_NONE) {
545 continue;
546 }
547 if (mode || ((timediff(bias->t0, gt) <= 0.0) && (timediff(bias->t1, gt) >= 0.0))) {
548 osb->vscb[i][bias->code[0] - 1] = 1;
549 osb->scb[i][bias->code[0] - 1] = bias->val;
550 ret++;
551 }
552 }
553 for (j = 0; j < biass->sat.npb[i]; j++) {
554 bias = &biass->sat.pb[i][j];
555 if (bias->code[0] == CODE_NONE) {
556 continue;
557 }
558 if (mode || ((timediff(bias->t0, gt) <= 0.0) && (timediff(bias->t1, gt) >= 0.0))) {
559 osb->vspb[i][bias->code[0] - 1] = 1;
560 osb->spb[i][bias->code[0] - 1] = bias->val;
561 ret++;
562 }
563 }
564 }
565 osb->gt[0] = gt;
566 return ret;
567}
568
569/* update station OSB ---------------------------------------------------------
570 * update the station OSB (Observable Satellite Bias) structure
571 * with current biases
572 * args : osb_t *osb IO OSB structure to update
573 * gtime_t gt I current time
574 * int mode I mode (0: current, 1: all)
575 * char *name I station name
576 * return : int O number of updated biases
577 *-----------------------------------------------------------------------------*/
578int udosb_station(osb_t* osb, gtime_t gt, int mode, char* name) {
579 biass_t* biass;
580 bia_t* bias;
581 int i, j, k, ret = 0;
582
583 biass = getbiass();
584
585 for (k = 0; k < biass->nsta; k++) {
586 if (strcmp(name, biass->sta[k].name) == 0) {
587 break;
588 }
589 }
590 if (k >= biass->nsta) {
591 return 0;
592 }
593
594 for (j = 0; j < MAXCODE; j++) {
595 for (i = 0; i < MAXBSNXSYS; i++) {
596 osb->vrsyscb[i][j] = 0;
597 }
598 for (i = 0; i < MAXSAT; i++) {
599 osb->vrsatcb[i][j] = 0;
600 }
601 }
602 for (i = 0; i < MAXBSNXSYS; i++) {
603 for (j = 0; j < biass->sta[k].nsyscb[i]; j++) {
604 bias = &biass->sta[k].syscb[i][j];
605 if (bias->code[0] == CODE_NONE) {
606 continue;
607 }
608 if (mode || ((timediff(bias->t0, gt) <= 0.0) && (timediff(bias->t1, gt) >= 0.0))) {
609 osb->vrsyscb[i][bias->code[0] - 1] = 1;
610 osb->rsyscb[i][bias->code[0] - 1] = bias->val;
611 ret++;
612 }
613 }
614 }
615 for (i = 0; i < MAXSAT; i++) {
616 for (j = 0; j < biass->sta[k].nsatcb[i]; j++) {
617 bias = &biass->sta[k].satcb[i][j];
618 if (bias->code[0] == CODE_NONE) {
619 continue;
620 }
621 if (mode || ((timediff(bias->t0, gt) <= 0.0) && (timediff(bias->t1, gt) >= 0.0))) {
622 osb->vrsatcb[i][bias->code[0] - 1] = 1;
623 osb->rsatcb[i][bias->code[0] - 1] = bias->val;
624 ret++;
625 }
626 }
627 }
628 strncpy(osb->staname, name, 9);
629 osb->gt[1] = gt;
630 return ret;
631}
void satno2id(int sat, char *id)
Definition mrtk_nav.c:817
void outbsnxrefb(FILE *fp, int type, char *reftext)
Output FILE/REFERENCE body line.
biass_t * getbiass(void)
Get pointer to the bias structure.
static char * code2sigs(uint8_t code, int cpflag)
void outbsnxh(FILE *fp, gtime_t ts, gtime_t te, const char *agency)
Output BIAS-SINEX file header.
static void freebiass(void)
void outbsnxcomb(FILE *fp, char *comtext)
Output FILE/COMMENT body line.
void outbsnxreff(FILE *fp)
Output FILE/REFERENCE footer.
int udosb_station(osb_t *osb, gtime_t gt, int mode, char *name)
Update station OSB structure with current biases.
void outbsnxrefh(FILE *fp)
Output FILE/REFERENCE header.
int getsysno(int sat)
Get system code number based on satellite number.
static void outbsnxsold(FILE *fp, int cpflag, int n, const bia_t *biad, char *sat, char *sta)
void outbsnxcomf(FILE *fp)
Output FILE/COMMENT footer.
static void time2biast(gtime_t time, double *year, double *doy, double *tod)
uint8_t obs2code(const char *obs)
Definition mrtk_obs.c:173
int satid2no(const char *id)
Definition mrtk_nav.c:753
void outbsnxsol(FILE *fp)
Output BIAS/SOLUTION section.
int readbsnx(const char *file)
Read BIAS-SINEX file.
#define M2NS
char * code2obs(uint8_t code)
Definition mrtk_obs.c:190
void outbsnxcomh(FILE *fp)
Output FILE/COMMENT header.
static biass_t biass
char * time_str(gtime_t t, int n)
Definition mrtk_time.c:530
static char syscode[]
int udosb_sat(osb_t *osb, gtime_t gt, int mode)
Update satellite OSB structure with current biases.
static void freebia(bia_t **ary, int *n, int *nmax)
void addbia(const bia_t *bia, bia_t **ary, int *n, int *nmax)
Add a bias entry to the bias array.
#define NS2M
MRTKLIB Bias SINEX Module — BIAS-SINEX data types and I/O functions.
#define CLIGHT
Definition mrtk_coords.c:41
#define MAXSAT
Definition mrtk_coords.c:45
#define MAXCODE
#define CODE_NONE
#define MAXSTA
#define MAXBSNXSYS
double str2num(const char *s, int i, int n)
Convert substring in string to number.
Definition mrtk_sys.c:60
MRTKLIB System Module — OS/filesystem utility functions.
gtime_t epoch2time(const double *ep)
Convert calendar day/time to gtime_t struct.
Definition mrtk_time.c:113
void time2epoch(gtime_t t, double *ep)
Convert gtime_t struct to calendar day/time.
Definition mrtk_time.c:136
double timediff(gtime_t t1, gtime_t t2)
Compute time difference (t1 - t2).
Definition mrtk_time.c:279
gtime_t timeadd(gtime_t t, double sec)
Add seconds to gtime_t.
Definition mrtk_time.c:265
char * time_str(gtime_t t, int n)
Get time string (not reentrant).
Definition mrtk_time.c:530
gtime_t timeget(void)
Get current time in UTC.
Definition mrtk_time.c:289
void trace(mrtk_ctx_t *ctx, int level, const char *format,...)
Output trace message.
Definition mrtk_trace.c:78
MRTKLIB Trace Module — debug trace and logging functions.
double slp
double val
gtime_t t0
int code[2]
double valstd
gtime_t t1
double slpstd
GNSS time representation.
Definition mrtk_time.h:49
gtime_t gt[2]
Definition mrtk_nav.h:199
char staname[10]
Definition mrtk_nav.h:200
double rsyscb[MAXBSNXSYS][MAXCODE]
Definition mrtk_nav.h:203
double scb[MAXSAT][MAXCODE]
Definition mrtk_nav.h:201
int vrsatcb[MAXSAT][MAXCODE]
Definition mrtk_nav.h:208
int vspb[MAXSAT][MAXCODE]
Definition mrtk_nav.h:206
int vscb[MAXSAT][MAXCODE]
Definition mrtk_nav.h:205
int vrsyscb[MAXBSNXSYS][MAXCODE]
Definition mrtk_nav.h:207
double spb[MAXSAT][MAXCODE]
Definition mrtk_nav.h:202
double rsatcb[MAXSAT][MAXCODE]
Definition mrtk_nav.h:204
#define free(x)
Definition toml.c:53