-
Notifications
You must be signed in to change notification settings - Fork 15
/
Gnav.m
376 lines (373 loc) · 14.7 KB
/
Gnav.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
classdef Gnav < handle
% Gnav: GNSS RINEX navigation data class
% ---------------------------------------------------------------------
% Gnav Declaration:
% gnav = Gnav(file); Create gt.Gnav object from RINEX
% file : 1x1, RINEX navigation file
% (wind-card * can be used to extract all navigation files)
%
% gnav = Gnav(navstr); Create gt.Gnav object from navigation struct
% navstr : 1x1, RTKLIB navigation struct
% ---------------------------------------------------------------------
% Gnav Properties:
% eph : Nx1, GPS/QZS/GAL/BDS/IRN ephemeris struct array:
% geph : NGx1, GLONASS ephemeris struct array
% peph : NEx1, Precise ephemeris struct array (from .sp3 file)
% pclk : NCx1, Precise clock struct array (from .clk file)
% erp : 1x1, Earth rotation parameter struct (from .erp file)
% pcv : (MAXSAT)x1, Satellite antenna PCV struct array (from .erp file)
% dcb : (MAXSAT)x3, satellite DCB (0:P1-P2, 1:P1-C1, 2:P2-C2) (m)
% utc : 1x1, UTC time parameters
% .??? : 1x8 or 1x9 or 1x8, ??? = gps or glo or gal or qzs or cmp irn or sbs
% ion : 1x8 or 1x4, ionosphere model parameter
% .??? : ??? = gps or gal or qzs or cmp or irn
% ---------------------------------------------------------------------
% Gnav Methods:
% setNavFile(file); Set navigation data from RINEX file
% setNavStruct(navstr); Set navigation data from navigation struct
% readSP3(file); Read precise ephemeris
% readCLK(file); Read precise RIENX clock
% readERP(file); Read earth rotation parameter
% readSatPCV(file, gtime); Read satellite antenna PCV
% readDCB(file); Read satellite antenna DCB
% outNav(file); Output RINEX navigation file
% gnav = copy(); Copy object
% navstr = struct(); Convert to navigation struct
% [tgd, vtgd] = getTGD(sat); Get TGD value for specified satellite
% help(); Show help
% ---------------------------------------------------------------------
% Author: Taro Suzuki
%
properties
eph % GPS/QZS/GAL/BDS/IRN ephemeris
geph % GLONASS ephemeris
peph % Precise ephemeris
pclk % Precise clock
erp % Earth rotation parameter
pcv % Satellite antenna PCV
dcb % satellite DCB (0:P1-P2, 1:P1-C1, 2:P2-C2) (m)
utc % UTC time parameters
ion % Ionosphere model parameter
end
methods
%% constructor
function obj = Gnav(varargin)
if nargin==1 && (ischar(varargin{1}) || isStringScalar(varargin{1}))
obj.setNavFile(char(varargin{1})); % file
elseif nargin==1 && isstruct(varargin{1})
obj.setNavStruct(varargin{1}); % nav struct
else
error('Wrong input arguments');
end
end
%% setNavFile
function setNavFile(obj, file)
% setNavFile: Set navigation data from RINEX file
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.setNavFile(file)
%
% Input: ------------------------------------------------------
% file : 1x1, RINEX navigation file
%
arguments
obj gt.Gnav
file (1,:) char
end
paths = rtklib.expath(obj.absPath(file));
for path = paths
try
if ~exist('navstr','var')
navstr = rtklib.readrnxnav(obj.absPath(path{:}));
else
navstr = rtklib.readrnxnav(obj.absPath(path{:}), navstr);
end
catch
end
end
if ~exist('navstr','var')
error('Wrong RINEX navigation file: %s',obj.absPath(file));
end
obj.setNavStruct(navstr);
end
%% setNavStruct
function setNavStruct(obj, navstr)
% setNavStruct: Set navigation data from navigation struct
% -------------------------------------------------------------
% The navigation struct is the output of the RTKLIB wrapper
% function.
%
% Usage: ------------------------------------------------------
% obj.setNavStruct(navstr)
%
% Input: ------------------------------------------------------
% navstr : 1x1, Navigation struct
%
arguments
obj gt.Gnav
navstr (1,1) struct
end
obj.eph = navstr.eph;
obj.geph = navstr.geph;
obj.peph = navstr.peph;
obj.pclk = navstr.pclk;
obj.erp = navstr.erp;
obj.pcv = navstr.pcvs;
obj.utc.gps = navstr.utc_gps;
obj.utc.glo = navstr.utc_glo;
obj.utc.gal = navstr.utc_gal;
obj.utc.qzs = navstr.utc_qzs;
obj.utc.cmp = navstr.utc_cmp;
obj.utc.irn = navstr.utc_irn;
obj.utc.sbs = navstr.utc_sbs;
obj.ion.gps = navstr.ion_gps;
obj.ion.gal = navstr.ion_gal;
obj.ion.qzs = navstr.ion_qzs;
obj.ion.cmp = navstr.ion_cmp;
obj.ion.irn = navstr.ion_irn;
obj.dcb = navstr.cbias;
% eliminateDuplicated ephemeris
obj.eliminateDuplicate();
end
%% readSP3
function readSP3(obj, file)
% readSP3: Read precise ephemeris(.SP3)
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.readSP3(file)
%
% Input: ------------------------------------------------------
% file : 1x1, Precise ephemeris(.SP3) file
%
arguments
obj gt.Gnav
file (1,:) char
end
navstr = rtklib.readsp3(obj.absPath(file), obj.struct());
obj.setNavStruct(navstr);
end
%% readCLK
function readCLK(obj, file)
% readCLK: Read precise RINEX clock
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.readCLK(file)
%
% Input: ------------------------------------------------------
% file : 1x1, precise RINEX clock file
%
arguments
obj gt.Gnav
file (1,:) char
end
navstr = rtklib.readrnxc(obj.absPath(file), obj.struct());
obj.setNavStruct(navstr);
end
%% readERP
function readERP(obj, file)
% readERP: Read ERP (Earth Rotation Parameter)
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.readERP(file)
%
% Input: ------------------------------------------------------
% file : 1x1, ERP file
%
arguments
obj gt.Gnav
file (1,:) char
end
obj.erp = rtklib.readerp(obj.absPath(file));
end
%% readSatPCV
function readSatPCV(obj, file, gtime)
% readSatPCV: Read satellite antenna PCV
% -------------------------------------------------------------
% Read satellite PCV (Phase Center Variation) file.
%
% Usage: ------------------------------------------------------
% obj.readSatPCV(file, gtime)
%
% Input: ------------------------------------------------------
% file : 1x1, Satellite antenna PCV file
% gtime : 1x1, gt.Gtime, Observation time
%
arguments
obj gt.Gnav
file (1,:) char
gtime gt.Gtime
end
navstr = rtklib.readsap(obj.absPath(file), gtime.ep(1,:), obj.struct());
obj.setNavStruct(navstr);
end
%% readDCB
function readDCB(obj, file)
% readDCB: Read satellite antenna DCB
% -------------------------------------------------------------
% Read DCB file and calculate DCB correction value.
%
% Usage: ------------------------------------------------------
% obj.readDCB(file)
%
% Input: ------------------------------------------------------
% file : 1x1, Satellite antenna DCB file name
%
arguments
obj gt.Gnav
file (1,:) char
end
navstr = rtklib.readdcb(obj.absPath(file), obj.struct());
obj.setNavStruct(navstr);
end
%% outNav
function outNav(obj, file)
% outNav: Output RINEX navigation file
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.outNav(file)
%
% Input: ------------------------------------------------------
% file : 1x1, Output RINEX navigation file name
%
arguments
obj gt.Gnav
file (1,:) char
end
navstr = obj.struct();
rtklib.outrnxnav(file, navstr);
end
%% copy
function gnav = copy(obj)
% copy: Copy object
% -------------------------------------------------------------
% MATLAB handle class is used, so if you want to create a
% different instance, you need to use the copy method.
%
% Usage: ------------------------------------------------------
% gnav = obj.copy()
%
% Output: -----------------------------------------------------
% gnav : 1x1, Copied gt.Gnav object
%
arguments
obj gt.Gnav
end
gnav = gt.Gnav(obj.struct());
end
%% struct
function navstr = struct(obj)
% struct: Convert to navigation struct
% -------------------------------------------------------------
% The input to the RTKLIB wrapper function must be a structure.
%
% Usage: ------------------------------------------------------
% obj.struct()
%
% Output: -----------------------------------------------------
% navstr: 1x1, Navigation struct (for interface to RTKLIB)
%
arguments
obj gt.Gnav
end
navstr.eph = obj.eph;
navstr.geph = obj.geph;
navstr.peph = obj.peph;
navstr.pclk = obj.pclk;
navstr.erp = obj.erp;
navstr.pcvs = obj.pcv;
navstr.cbias = obj.dcb;
navstr.utc_gps = obj.utc.gps;
navstr.utc_glo = obj.utc.glo;
navstr.utc_gal = obj.utc.gal;
navstr.utc_qzs = obj.utc.qzs;
navstr.utc_cmp = obj.utc.cmp;
navstr.utc_irn = obj.utc.irn;
navstr.utc_sbs = obj.utc.sbs;
navstr.ion_gps = obj.ion.gps;
navstr.ion_gal = obj.ion.gal;
navstr.ion_qzs = obj.ion.qzs;
navstr.ion_cmp = obj.ion.cmp;
navstr.ion_irn = obj.ion.irn;
end
%% getTGD
function [tgd, vtgd] = getTGD(obj, sat)
% getTGD: Get TGD value for specified satellite
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% [tgd, vtgd] = getTGD(sat)
%
% Input: ------------------------------------------------------
% sat : 1xN, satellite number vector
%
% Output: -----------------------------------------------------
% tgd : 1xN, TGD (Time Group Delay) value (m)
% vtgd: 1xN, TGD variance (constant) (m^2)
%
arguments
obj gt.Gnav
sat (1,:) {mustBeInteger, mustBeVector}
end
nsat = length(sat);
sys = rtklib.satsys(sat);
t = struct2table(obj.eph);
% ToDo: support code type input
tgd = zeros(1, nsat);
for i=1:nsat
if sys(i)==gt.C.SYS_GPS||sys(i)==gt.C.SYS_QZS||sys(i)==gt.C.SYS_GAL||sys(i)==gt.C.SYS_CMP
idx = find(t.sat==sat(i), 1);
if ~isempty(idx); tgd(i) = gt.C.CLIGHT*t.tgd(idx,1); end
end
end
ERR_CBIAS = 0.3; % code bias error std (m)
vtgd = ERR_CBIAS^2*ones(1,nsat);
end
%% help
function help(~)
% help: Show help
doc gt.Gnav
end
end
%% Private functions
methods(Access=private)
%% Convert from relative path to absolute path
function apath = absPath(~, rpath)
if isstring(rpath)
rpath = char(rpath);
end
[dirname, filename, ext] = fileparts(rpath);
[status, pathinfo] = fileattrib(dirname);
if status==1
apath = fullfile(pathinfo.Name, strcat([filename, ext]));
else
error('Directory does not exist: %s',dirname);
end
end
%% Eliminate duplicated ephemeris
function eliminateDuplicate(obj)
% GPS
teph = struct2table(obj.eph);
uniquesat = unique(teph.sat);
idxeliminate = [];
for i=1:length(uniquesat)
sys = rtklib.satsys(uniquesat(i));
% GPS
if sys==gt.C.SYS_GPS
idx = find(teph.sat==uniquesat(i));
tephsat = teph(idx,:);
[~,idxsort] = sortrows(tephsat,"ttr");
toc = gt.Gtime(tephsat.toc(idxsort,:));
idxduplicate = abs(diff(toc.t))<seconds(60);
idxeliminate = [idxeliminate; idx(idxsort(idxduplicate))];
end
% ToDo: check other systems
end
obj.eph(idxeliminate) = [];
end
end
end