27static const double CLIGHT = 299792458.0;
28#define NS2M (CLIGHT / 1E9)
29#define M2NS (1E9 / CLIGHT)
32extern void satno2id(
int sat,
char*
id);
34extern uint8_t
obs2code(
const char* obs);
40static char typeid[][5] = {
"DSB ",
"ISB ",
"OSB "};
80 for (i = 0; i <
MAXSAT; i++) {
81 if (
biass.sat.cb[i] != NULL) {
84 if (
biass.sat.pb[i] != NULL) {
89 for (i = 0; i <
MAXSTA; i++) {
91 if (
biass.sta[i].syscb[j] != NULL) {
95 for (j = 0; j <
MAXSAT; j++) {
96 if (
biass.sta[i].satcb[j] != NULL) {
116 if (!(b = (
bia_t*)realloc(*ary,
sizeof(
bia_t) * (*nmax)))) {
117 trace(NULL, 1,
"addbia: memory allocation error\n");
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;
142 trace(NULL, 3,
"readbsnx : file=%s\n", file);
144 if (!(fp = fopen(file,
"r"))) {
145 trace(NULL, 2,
"bias sinex file open error: %s\n", file);
150 while (fgets(buff,
sizeof(buff), fp)) {
151 if (buff[0] ==
'*') {
154 if (strstr(buff,
"+BIAS/DESCRIPTION")) {
158 if (strstr(buff,
"-BIAS/DESCRIPTION")) {
162 if (strstr(buff,
"+BIAS/SOLUTION")) {
166 if (strstr(buff,
"-BIAS/SOLUTION")) {
173 dscrpt[0] = strtok(buff + 1,
" \n");
174 for (n = 1; n < 4; n++) {
175 if ((p = strtok(NULL,
" \n"))) {
181 trace(NULL, 4,
"readbsnx KEYWORD, %-39s, %s, %s, %s\n", dscrpt[0], dscrpt[1], dscrpt[2], dscrpt[3]);
185 if (strlen(buff) < 92) {
188 for (i = 0; i < 3; i++) {
189 if (strncmp(buff + 1,
typeid[i], 4) == 0) {
197 strncpy(satid, buff + 11, 3);
199 strncpy(sta, buff + 15, 9);
200 for (i = strlen(sta) - 1; (i >= 0) && (sta[i] ==
' '); i--) {
203 strncpy(sig1, buff + 25, 3);
206 strncpy(sig2, buff + 30, 3);
209 memcpy(sig2,
" ", 3);
213 sscanf(buff + 35,
"%lf:%lf:%lf", ep, &doy, &tod);
216 sscanf(buff + 50,
"%lf:%lf:%lf", ep, &doy, &tod);
219 if (strncmp(buff + 65,
"ns", 2) == 0) {
226 if (strlen(buff) > 92) {
230 if (strlen(buff) > 127) {
238 if (strlen(sta) == 0) {
242 if (sig1[0] ==
'C') {
248 for (i = 0; (i <
MAXSTA) && (i <
biass.nsta); i++) {
249 if (strcmp(sta,
biass.sta[i].name) == 0) {
254 trace(NULL, 2,
"readbsnx %s has exceeded the station limit of %d.\n", sta,
MAXSTA);
257 if (i >=
biass.nsta) {
258 strcpy(
biass.sta[i].name, sta);
273 &
biass.sta[i].nsatcbmax[sat - 1]);
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),
289 double bep[6] = {0, 1, 1, 0, 0, 0}, ep[6] = {0, 0, 0, 0, 0, 0}, tdiff;
297 *doy = (int)floor(tdiff / 86400) + 1;
298 *tod = (int)floor(tdiff - (*doy - 1) * 86400);
309 sprintf(sigs,
"C%2s",
code2obs(code));
310 }
else if (cpflag == 1) {
311 sprintf(sigs,
"L%2s",
code2obs(code));
327 double year, doy, tod, ep[6];
333 trace(NULL, 3,
"outbsnxh: \n");
337 fprintf(fp,
"%%=BIA 1.00 %3s %04.0f:%03.0f:%05.0f ", agency, year, doy, tod);
339 fprintf(fp,
"%3s %04.0f:%03.0f:%05.0f", agency, 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]);
354 trace(NULL, 3,
"outbsnxrefh: \n");
356 fprintf(fp,
"*-------------------------------------------------------------------------------\n");
357 fprintf(fp,
"+FILE/REFERENCE\n");
358 fprintf(fp,
"*INFO_TYPE_________ INFO________________________________________________________\n");
369 char* inft[6] = {
"DESCRIPTION",
"OUTPUT",
"CONTACT",
"SOFTWARE",
"HARDWARE",
"INPUT"};
373 if (type < 0 || type >= 6) {
374 trace(NULL, 2,
"outbsnxrefb error: type=%d is out of range.[0-5]\n", type);
377 if (strlen(reftext) > 60) {
378 trace(NULL, 2,
"outbsnxrefb error: comment length over %d[60]\n", strlen(reftext));
381 trace(NULL, 3,
"outbsnxrefb: \n");
382 fprintf(fp,
" %-18s %-60s\n", inft[type], reftext);
394 trace(NULL, 3,
"outbsnxreff: \n");
395 fprintf(fp,
"-FILE/REFERENCE\n");
407 trace(NULL, 3,
"outbsnxcomh: \n");
408 fprintf(fp,
"*-------------------------------------------------------------------------------\n");
409 fprintf(fp,
"+FILE/COMMENT\n");
422 if (strlen(comtext) > 79) {
423 trace(NULL, 2,
"outbsnxcomb error: comment length over %d[79]\n", strlen(comtext));
426 trace(NULL, 3,
"outbsnxcomb: %s\n", comtext);
427 fprintf(fp,
" %-79s\n", comtext);
439 trace(NULL, 3,
"outbsnxcomf: \n");
440 fprintf(fp,
"-FILE/COMMENT\n");
444static void outbsnxsold(FILE* fp,
int cpflag,
int n,
const bia_t* biad,
char* sat,
char* sta) {
446 char osb1str[8], osb2str[8];
447 double sy, sdoy, stod, ey, edoy, etod;
449 for (i = 0; i < n; i++) {
450 strcpy(osb1str,
code2sigs(biad[i].code[0], cpflag));
451 strcpy(osb2str,
code2sigs(biad[i].code[1], cpflag));
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);
479 trace(NULL, 3,
"outbsnxsol: \n");
483 fprintf(fp,
"*-------------------------------------------------------------------------------\n");
484 fprintf(fp,
"+BIAS/SOLUTION\n");
486 "*BIAS SVN_ PRN STATION__ OBS1 OBS2 BIAS_START____ BIAS_END______ UNIT __ESTIMATED_VALUE____ _STD_DEV___ "
487 "__ESTIMATED_SLOPE____ _STD_DEV___\n");
490 for (i = 0; i <
MAXSAT; i++) {
496 for (i = 0; i <
MAXSAT; i++) {
502 for (i = 0; i <
biass->nsta; i++) {
504 sprintf(satid,
"%c",
syscode[j]);
510 for (i = 0; i <
biass->nsta; i++) {
511 for (j = 0; j <
MAXSAT; j++) {
516 fprintf(fp,
"-BIAS/SOLUTION\n");
517 fprintf(fp,
"%%=ENDBIA\n");
535 for (j = 0; j <
MAXCODE; j++) {
536 for (i = 0; i <
MAXSAT; i++) {
541 for (i = 0; i <
MAXSAT; i++) {
542 for (j = 0; j <
biass->sat.ncb[i]; j++) {
543 bias = &
biass->sat.cb[i][j];
548 osb->
vscb[i][bias->
code[0] - 1] = 1;
553 for (j = 0; j <
biass->sat.npb[i]; j++) {
554 bias = &
biass->sat.pb[i][j];
559 osb->
vspb[i][bias->
code[0] - 1] = 1;
581 int i, j, k, ret = 0;
585 for (k = 0; k <
biass->nsta; k++) {
586 if (strcmp(name,
biass->sta[k].name) == 0) {
590 if (k >=
biass->nsta) {
594 for (j = 0; j <
MAXCODE; j++) {
598 for (i = 0; i <
MAXSAT; i++) {
603 for (j = 0; j <
biass->sta[k].nsyscb[i]; j++) {
604 bias = &
biass->sta[k].syscb[i][j];
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];
628 strncpy(osb->
staname, name, 9);
void satno2id(int sat, char *id)
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)
int satid2no(const char *id)
void outbsnxsol(FILE *fp)
Output BIAS/SOLUTION section.
int readbsnx(const char *file)
Read BIAS-SINEX file.
char * code2obs(uint8_t code)
void outbsnxcomh(FILE *fp)
Output FILE/COMMENT header.
char * time_str(gtime_t t, int n)
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.
MRTKLIB Bias SINEX Module — BIAS-SINEX data types and I/O functions.
double str2num(const char *s, int i, int n)
Convert substring in string to number.
MRTKLIB System Module — OS/filesystem utility functions.
gtime_t epoch2time(const double *ep)
Convert calendar day/time to gtime_t struct.
void time2epoch(gtime_t t, double *ep)
Convert gtime_t struct to calendar day/time.
double timediff(gtime_t t1, gtime_t t2)
Compute time difference (t1 - t2).
gtime_t timeadd(gtime_t t, double sec)
Add seconds to gtime_t.
char * time_str(gtime_t t, int n)
Get time string (not reentrant).
gtime_t timeget(void)
Get current time in UTC.
void trace(mrtk_ctx_t *ctx, int level, const char *format,...)
Output trace message.
MRTKLIB Trace Module — debug trace and logging functions.
GNSS time representation.
double rsyscb[MAXBSNXSYS][MAXCODE]
double scb[MAXSAT][MAXCODE]
int vrsatcb[MAXSAT][MAXCODE]
int vspb[MAXSAT][MAXCODE]
int vscb[MAXSAT][MAXCODE]
int vrsyscb[MAXBSNXSYS][MAXCODE]
double spb[MAXSAT][MAXCODE]
double rsatcb[MAXSAT][MAXCODE]