MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_station.c
Go to the documentation of this file.
1/*------------------------------------------------------------------------------
2 * mrtk_station.c : station position and BLQ 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/**
17 * @file mrtk_station.c
18 * @brief MRTKLIB Station Module — Implementation.
19 *
20 * All functions and static data in this file are cut-and-paste extractions
21 * from the legacy rtkcmn.c with zero algorithmic changes.
22 */
23
25
26#include <ctype.h>
27#include <math.h>
28#include <stdio.h>
29#include <string.h>
30
31#include "mrtklib/mrtk_trace.h"
32
33/*============================================================================
34 * Forward Declarations (resolved at link time)
35 *===========================================================================*/
36
37/*============================================================================
38 * Private Constants
39 *===========================================================================*/
40
41#define PI 3.1415926535897932 /* pi */
42#define D2R (PI / 180.0) /* deg to rad */
43
44/*============================================================================
45 * Private Functions
46 *===========================================================================*/
47
48/* read blq record -----------------------------------------------------------*/
49extern int readblqrecord(FILE* fp, double* odisp) {
50 double v[11];
51 char buff[256];
52 int i, n = 0;
53
54 while (fgets(buff, sizeof(buff), fp)) {
55 if (!strncmp(buff, "$$", 2)) {
56 continue;
57 }
58 if (sscanf(buff, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", v, v + 1, v + 2, v + 3, v + 4, v + 5, v + 6,
59 v + 7, v + 8, v + 9, v + 10) < 11) {
60 continue;
61 }
62 for (i = 0; i < 11; i++) {
63 odisp[n + i * 6] = v[i];
64 }
65 if (++n == 6) {
66 return 1;
67 }
68 }
69 return 0;
70}
71
72/*============================================================================
73 * Public Functions
74 *===========================================================================*/
75
76/* read elevation mask file ----------------------------------------------------
77 * read elevation mask file
78 * args : char *file I elevation mask file
79 * int16_t *elmask O elevation mask vector (360 x 1) (0.1 deg)
80 * elmask[i]: elevation mask at azimuth i (deg)
81 * return : status (1:ok,0:file open error)
82 * notes : text format of the elevation mask file
83 * AZ1 EL1
84 * AZ2 EL2
85 * ...
86 * (1) EL{i} defines the elevation mask (deg) at the azimuth angle az
87 * (AZ{i} <= az (deg) < AZ{i+1}, AZ1 < AZ2 < ... < AZ{n}, n <= 360)
88 * (2) text after % or # is treated as comments
89 *-----------------------------------------------------------------------------*/
90extern int readelmask(const char* file, int16_t* elmask) {
91 FILE* fp;
92 double az[360], el[360], mask = 0.0;
93 char buff[256], *p;
94 int i, j = 0, n = 0;
95
96 trace(NULL, 3, "readelmask: file=%s\n", file);
97
98 for (i = 0; i < 360; i++) {
99 elmask[i] = 0;
100 }
101 if (!(fp = fopen(file, "r"))) {
102 fprintf(stderr, "elevation mask file open error : %s\n", file);
103 return 0;
104 }
105 while (fgets(buff, sizeof(buff), fp) && n < 360) {
106 if ((p = strchr(buff, '%'))) {
107 *p = '\0';
108 }
109 if ((p = strchr(buff, '#'))) {
110 *p = '\0';
111 }
112 if (sscanf(buff, "%lf %lf", az + n, el + n) == 2) {
113 n++;
114 }
115 }
116 fclose(fp);
117
118 for (i = 0; i < 360; i++) {
119 if (j < n && i >= (int)az[j]) {
120 mask = el[j++];
121 }
122 elmask[i] = (int16_t)(mask / 0.1);
123 }
124 return 1;
125}
126/* read station positions ------------------------------------------------------
127 * read positions from station position file
128 * args : char *file I station position file containing
129 * lat(deg) lon(deg) height(m) name in a line
130 * char *rcvs I station name
131 * double *pos O station position {lat,lon,h} (rad/m)
132 * (all 0 if search error)
133 * return : none
134 *-----------------------------------------------------------------------------*/
135extern void readpos(const char* file, const char* rcv, double* pos) {
136 static double poss[2048][3];
137 static char stas[2048][16];
138 FILE* fp;
139 int i, j, len, np = 0;
140 char buff[256], str[256];
141
142 trace(NULL, 3, "readpos: file=%s\n", file);
143
144 if (!(fp = fopen(file, "r"))) {
145 fprintf(stderr, "reference position file open error : %s\n", file);
146 return;
147 }
148 while (np < 2048 && fgets(buff, sizeof(buff), fp)) {
149 if (buff[0] == '%' || buff[0] == '#') {
150 continue;
151 }
152 if (sscanf(buff, "%lf %lf %lf %s", &poss[np][0], &poss[np][1], &poss[np][2], str) < 4) {
153 continue;
154 }
155 sprintf(stas[np++], "%.15s", str);
156 }
157 fclose(fp);
158 len = (int)strlen(rcv);
159 for (i = 0; i < np; i++) {
160 if (strncmp(stas[i], rcv, len)) {
161 continue;
162 }
163 for (j = 0; j < 3; j++) {
164 pos[j] = poss[i][j];
165 }
166 pos[0] *= D2R;
167 pos[1] *= D2R;
168 return;
169 }
170 pos[0] = pos[1] = pos[2] = 0.0;
171}
172/* read blq ocean tide loading parameters --------------------------------------
173 * read blq ocean tide loading parameters
174 * args : char *file I BLQ ocean tide loading parameter file
175 * char *sta I station name
176 * double *odisp O ocean tide loading parameters
177 * return : status (1:ok,0:file open error)
178 *-----------------------------------------------------------------------------*/
179extern int readblq(const char* file, const char* sta, double* odisp) {
180 FILE* fp;
181 char buff[256], staname[32] = "", name[32], *p;
182
183 /* station name to upper case */
184 sscanf(sta, "%16s", staname);
185 for (p = staname; (*p = (char)toupper((int)(*p))); p++) {
186 /* convert in-place via loop header */
187 }
188
189 if (!(fp = fopen(file, "r"))) {
190 trace(NULL, 2, "blq file open error: file=%s\n", file);
191 return 0;
192 }
193 while (fgets(buff, sizeof(buff), fp)) {
194 if (!strncmp(buff, "$$", 2) || strlen(buff) < 2) {
195 continue;
196 }
197
198 if (sscanf(buff + 2, "%16s", name) < 1) {
199 continue;
200 }
201 for (p = name; (*p = (char)toupper((int)(*p))); p++) {
202 /* convert in-place via loop header */
203 }
204 if (strcmp(name, staname)) {
205 continue;
206 }
207
208 /* read blq record */
209 if (readblqrecord(fp, odisp)) {
210 fclose(fp);
211 return 1;
212 }
213 }
214 fclose(fp);
215 trace(NULL, 2, "no otl parameters: sta=%s file=%s\n", sta, file);
216 return 0;
217}
#define D2R
Definition mrtk_coords.c:36
static sta_t stas[MAXRCV]
int readelmask(const char *file, int16_t *elmask)
Read elevation mask file.
void readpos(const char *file, const char *rcv, double *pos)
Read station positions from file.
int readblq(const char *file, const char *sta, double *odisp)
Read BLQ ocean tide loading parameters.
int readblqrecord(FILE *fp, double *odisp)
Read a single BLQ record (6 lines x 11 values).
MRTKLIB Station Module — Site environment parameter I/O.
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.