MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_fcb.c
Go to the documentation of this file.
1/*------------------------------------------------------------------------------
2 * mrtk_fcb.c : fractional cycle bias (FCB) 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 *----------------------------------------------------------------------------*/
16#include "mrtklib/mrtk_fcb.h"
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
23#include "mrtklib/mrtk_sys.h"
24#include "mrtklib/mrtk_trace.h"
25
26/* local constants -----------------------------------------------------------*/
27static const double CLIGHT = 299792458.0;
28
29#define SYS_GPS 0x01
30#define SYS_GAL 0x08
31#define SYS_QZS 0x10
32#define SYS_CMP 0x20
33
34/*--- forward declarations for legacy functions resolved at link time -------*/
35extern int satid2no(const char* id);
36extern int satsys(int sat, int* prn);
37extern double code2freq(int sys, uint8_t code, int fcn);
38
39static biass_t fcbs = {0};
40
41/* FCB signal and tracking mode IDs ------------------------------------------*/
42static const uint8_t fcb_sig_gps[3][16] = {
43 {CODE_L1C, CODE_L1P, CODE_L1W, CODE_L1Y, CODE_L1M, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
45 {CODE_L5I, CODE_L5Q, CODE_L5X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
46static const uint8_t fcb_sig_gal[3][16] = {{CODE_L1B, CODE_L1C, CODE_L1X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
47 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
48 {CODE_L5I, CODE_L5Q, CODE_L5X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
49static const uint8_t fcb_sig_qzs[3][16] = {{CODE_L1C, CODE_L1S, CODE_L1L, CODE_L1X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
50 {CODE_L2S, CODE_L2L, CODE_L2X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
51 {CODE_L5I, CODE_L5Q, CODE_L5X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
52static const uint8_t fcb_sig_cmp[3][16] = {
53 {CODE_L2I, CODE_L2Q, CODE_L2X, CODE_L1D, CODE_L1P, CODE_L1X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
54 {CODE_L5D, CODE_L5P, CODE_L5X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
55 {CODE_L6I, CODE_L6Q, CODE_L6X, 0, 0, 0, 0, 0}};
56
57/* get fcbs ------------------------------------------------------------------*/
58static biass_t* getfcbs(void) { return &fcbs; }
59
60/* read satellite fcb file ---------------------------------------------------*/
61static int readfcbf(const char* file) {
62 FILE* fp;
63 double ep1[6], ep2[6], bias[3] = {0}, std[3] = {0}, cyc2m;
64 char buff[1024], str[32], *p;
65 int sat, sys;
66 bia_t bia;
67 biass_t* fcbsp;
68 const uint8_t (*sigs)[16];
69 int i, j;
70
71 fcbsp = getfcbs();
72
73 trace(NULL, 3, "readfcbf: file=%s\n", file);
74
75 if (!(fp = fopen(file, "r"))) {
76 trace(NULL, 2, "fcb parameters file open error: %s\n", file);
77 return 0;
78 }
79 while (fgets(buff, sizeof(buff), fp)) {
80 memset(&bia, 0x00, sizeof(bia_t));
81 bia.type = 2; /* OSB */
82 if ((p = strchr(buff, '#'))) {
83 *p = '\0';
84 }
85 if (sscanf(buff,
86 "%lf/%lf/%lf %lf:%lf:%lf %lf/%lf/%lf %lf:%lf:%lf %s"
87 "%lf %lf %lf %lf %lf %lf",
88 ep1, ep1 + 1, ep1 + 2, ep1 + 3, ep1 + 4, ep1 + 5, ep2, ep2 + 1, ep2 + 2, ep2 + 3, ep2 + 4, ep2 + 5,
89 str, bias, std, bias + 1, std + 1, bias + 2, std + 2) < 17) {
90 continue;
91 }
92 if (!(sat = satid2no(str))) {
93 continue;
94 }
95 sys = satsys(sat, NULL);
96 switch (sys) {
97 case SYS_GPS:
98 sigs = fcb_sig_gps;
99 break;
100 case SYS_GAL:
101 sigs = fcb_sig_gal;
102 break;
103 case SYS_QZS:
104 sigs = fcb_sig_qzs;
105 break;
106 case SYS_CMP:
107 sigs = fcb_sig_cmp;
108 break;
109 default:
110 continue;
111 }
112
113 bia.t0 = epoch2time(ep1);
114 bia.t1 = epoch2time(ep2);
115 for (i = 0; i < 3; i++) { /* L1/L2/L5 */
116 for (j = 0; j < 16; j++) {
117 if (sigs[i][j] > 0) {
118 bia.code[0] = sigs[i][j];
119 cyc2m = CLIGHT / code2freq(sys, bia.code[0], 0);
120 bia.val = bias[i] * cyc2m;
121 bia.valstd = std[i] * cyc2m;
122 addbia(&bia, &fcbsp->sat.pb[sat - 1], &fcbsp->sat.npb[sat - 1], &fcbsp->sat.npbmax[sat - 1]);
123 }
124 }
125 }
126 }
127 fclose(fp);
128 return 1;
129}
130
131/* read FCB file --------------------------------------------------------------
132 * read the FCB (Fractional Cycle Bias) file and update the internal structure
133 * args : char *file I FCB file path (wild-card * expanded)
134 * return : int O status (1: success, 0: failure)
135 *-----------------------------------------------------------------------------*/
136int readfcb(const char* file) {
137 char* efiles[MAXEXFILE] = {0};
138 int i, n;
139
140 trace(NULL, 3, "readfcb : file=%s\n", file);
141
142 for (i = 0; i < MAXEXFILE; i++) {
143 if (!(efiles[i] = (char*)malloc(1024))) {
144 for (i--; i >= 0; i--) {
145 free(efiles[i]);
146 }
147 return 0;
148 }
149 }
150 n = expath(file, efiles, MAXEXFILE);
151
152 for (i = 0; i < n; i++) {
153 readfcbf(efiles[i]);
154 }
155 for (i = 0; i < MAXEXFILE; i++) {
156 free(efiles[i]);
157 }
158
159 return 1;
160}
161
162/* update satellite FCB -------------------------------------------------------
163 * update the satellite FCB (Fractional Cycle Bias) structure with current biases
164 * args : osb_t *osb IO FCB structure to update
165 * gtime_t gt I current time
166 * int mode I mode (0: current, 1: all)
167 * return : int O number of updated biases
168 *-----------------------------------------------------------------------------*/
169int udfcb_sat(osb_t* osb, gtime_t gt, int mode) {
170 biass_t* fcbsp;
171 bia_t* bias;
172 int i, j, ret = 0;
173
174 fcbsp = getfcbs();
175
176 for (j = 0; j < MAXCODE; j++) {
177 for (i = 0; i < MAXSAT; i++) {
178 osb->vspb[i][j] = 0;
179 }
180 }
181 for (i = 0; i < MAXSAT; i++) {
182 for (j = 0; j < fcbsp->sat.npb[i]; j++) {
183 bias = &fcbsp->sat.pb[i][j];
184 if (bias->code[0] == CODE_NONE) {
185 continue;
186 }
187 if (mode || ((timediff(bias->t0, gt) <= 0.0) && (timediff(bias->t1, gt) >= 0.0))) {
188 osb->vspb[i][bias->code[0] - 1] = 1;
189 osb->spb[i][bias->code[0] - 1] = bias->val;
190 ret++;
191 }
192 }
193 }
194 osb->gt[0] = gt;
195 return ret;
196}
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.
#define CLIGHT
Definition mrtk_coords.c:41
#define MAXSAT
Definition mrtk_coords.c:45
#define SYS_GPS
Definition mrtk_eph.c:65
#define SYS_QZS
Definition mrtk_eph.c:69
#define SYS_CMP
Definition mrtk_eph.c:70
#define SYS_GAL
Definition mrtk_eph.c:68
int satsys(int sat, int *prn)
Definition mrtk_nav.c:117
int udfcb_sat(osb_t *osb, gtime_t gt, int mode)
Update satellite FCB structure with current biases.
Definition mrtk_fcb.c:169
static const uint8_t fcb_sig_qzs[3][16]
Definition mrtk_fcb.c:49
static const uint8_t fcb_sig_gal[3][16]
Definition mrtk_fcb.c:46
static biass_t * getfcbs(void)
Definition mrtk_fcb.c:58
double code2freq(int sys, uint8_t code, int fcn)
Definition mrtk_obs.c:236
int readfcb(const char *file)
Read FCB (Fractional Cycle Bias) file.
Definition mrtk_fcb.c:136
static const uint8_t fcb_sig_cmp[3][16]
Definition mrtk_fcb.c:52
int satid2no(const char *id)
Definition mrtk_nav.c:753
static int readfcbf(const char *file)
Definition mrtk_fcb.c:61
static biass_t fcbs
Definition mrtk_fcb.c:39
static const uint8_t fcb_sig_gps[3][16]
Definition mrtk_fcb.c:42
MRTKLIB FCB Module — Fractional Cycle Bias data types and functions.
#define CODE_L5Q
#define CODE_L2Q
#define CODE_L1S
#define CODE_L5I
#define CODE_L2X
#define CODE_L1L
#define CODE_L5X
#define CODE_L2P
#define CODE_L2I
#define MAXCODE
#define CODE_L1C
#define CODE_L6I
#define CODE_L2C
#define CODE_L6X
#define CODE_NONE
#define CODE_L1Y
#define CODE_L5P
#define CODE_L5D
#define CODE_L1B
#define CODE_L2S
#define CODE_L1W
#define CODE_L1M
#define CODE_L2W
#define CODE_L2L
#define CODE_L1D
#define CODE_L2D
#define CODE_L2Y
#define CODE_L1P
#define MAXEXFILE
#define CODE_L2M
#define CODE_L6Q
#define CODE_L1X
int expath(const char *path, char *paths[], int nmax)
Expand file path with wild-card (*) in file.
Definition mrtk_sys.c:96
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
double timediff(gtime_t t1, gtime_t t2)
Compute time difference (t1 - t2).
Definition mrtk_time.c:279
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 val
gtime_t t0
int code[2]
double valstd
gtime_t t1
int npb[MAXSAT]
int npbmax[MAXSAT]
bia_t * pb[MAXSAT]
biasat_t sat
GNSS time representation.
Definition mrtk_time.h:49
gtime_t gt[2]
Definition mrtk_nav.h:199
int vspb[MAXSAT][MAXCODE]
Definition mrtk_nav.h:206
double spb[MAXSAT][MAXCODE]
Definition mrtk_nav.h:202
#define malloc(x)
Definition toml.c:52
#define free(x)
Definition toml.c:53