-
Notifications
You must be signed in to change notification settings - Fork 15
/
Gopt.m
274 lines (273 loc) · 11.5 KB
/
Gopt.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
classdef Gopt < handle
% Gopt: RTKLIB process option class
% ---------------------------------------------------------------------
% Gopt Declaration:
% gopt = gt.Gopt(); Create gt.Gopt object using default option struct
%
% gopt = gt.Gopt(file); Create gt.Gopt object from configration file
% file : 1x1, RTKLIB configration file (???.conf)
%
% gopt = gt.Gopt(optstr); Create gt.Gopt object from option struct
% optstr : 1x1, RTKLIB option struct
% ---------------------------------------------------------------------
% Gopt Properties:
% pos1 : 1x1, Positioning setting 1 struct
% .posmode : 1x1, Positioning mode (PMODE_???)
% .navsys : 1x1, Navigation systems (NAVSYS_G, ... , NAVSYS_GREQC)
% .frequency : 1x1, Number of frequencies (FREQOPT_L1, ..., FREQOPT_L12345)
% .elmask : 1x1, Elevation mask (deg)
% .snrmask_r : 1x1, SNR mask for rover (ON/OFF)
% .snrmask_b : 1x1, SNR mask for base (ON/OFF)
% .snrmask_L1: 1x9, Elevation vs mask L1 SNR (dB-Hz)
% .snrmask_L2: 1x1, Elevation vs mask L2 SNR (dB-Hz)
% .snrmask_L5: 1x1, Elevation vs mask L5 SNR (dB-Hz)
% .tidecorr : 1x1, Earth tide correction (0:off,1:solid,2:solid+otl+pole)
% .ionoopt : 1x1, Ionosphere option (IONOOPT_???)
% .tropopt : 1x1, Troposphere option (TROPOPT_???)
% .ephopt : 1x1, Satellite ephemeris/clock (EPHOPT_???)
% .raim_fde : 1x1, RAIM FDE (ON/OFF)
% .exclsats : cell array, Excluded satellites e.g. {'G01','C02'}
% pos2 : 1x1, Positioning setting 2 struct
% .armode : 1x1, AR mode (0:off,1:continuous,2:instantaneous,3:fix and hold,4:ppp-ar)
% .gloarmode : 1x1, GLONASS AR mode (0:off,1:on,2:auto cal,3:ext cal)
% .bdsarmode : 1x1, BeiDou AR mode (0:off,1:on)
% .arthres : 1x1, AR validation threshold
% .arlockcnt : 1x1, Min lock count to fix ambiguity
% .aroutcnt : 1x1, Outage count to reset bias
% .armaxiter : 1x1, Max iteration to resolve ambiguity
% .filteriter: 1x1, Number of filter iteration
% .maxinno : 1x1, Reject threshold of innovation (m)
% out : 1x1, Output setting struct
% .solformat : 1x1, Solution format (SOLF_???)
% .timeformat : 1x1, Time format (0:sssss.s,1:yyyy/mm/dd hh:mm:ss.s)
% .trace : 1x1, Debug trace level (0:off,1-5:debug)
% stats : 1x1, Statistics setting struct
% .eratio1 : 1x1, L1 code/phase error ratio
% .eratio2 : 1x1, L2 code/phase error ratio
% .errphase : 1x1, Phase error factor (m)
% .errphaseel : 1x1, Phase error factor (m)
% ant : 1x1, Antenna setting struct
% .rovtype : 1x1, Position type (0:llh,1:xyz,2:single,3:posfile,4:rinexhead,5:rtcm,6:raw)
% .rovpos : 1x3, Rover position for fixed mode
% .rovant : char, Rover antenna name
% .rovdenu : 1x3, Rovere antenna delta position (m)
% .reftype : 1x1, Position type (0:llh,1:xyz,2:single,3:posfile,4:rinexhead,5:rtcm,6:raw)
% .refpos : 1x3, Base position
% .refant : char, Base antenna name
% .refdenu : 1x3, Base antenna delta position (m)
% misc : 1x1, Misc setting struct
% .timeinterp : 1x1, Interpolate reference observation (ON/OFF)
% ---------------------------------------------------------------------
% Gopt Methods;
% setOptFile(file); Set option data from config file
% setOptStruct(optstr); Set option data from option struct
% saveOpt(file); Save option file
% gopt = copy(); Copy object
% optstr = struct(); Convert from gt.Gopt object to struct
% show(); Show current options
% help(); Show help
% ---------------------------------------------------------------------
% Author: Taro Suzuki
%
properties
pos1 % Positioning setting 1 struct
pos2 % Positioning setting 2 struct
out % Output setting struct
stats % Statistics setting struct
ant % Antenna setting struct
misc % Misc setting struct
end
methods
%% constructor
function obj = Gopt(varargin)
if nargin == 0
obj.setOptFile()
elseif nargin==1 && (ischar(varargin{1}) || isStringScalar(varargin{1}))
obj.setOptFile(char(varargin{1})); % file
elseif nargin==1 && isstruct(varargin{1})
obj.setOptStruct(varargin{1}); % opt struct
else
error('Wrong input arguments');
end
end
%% setOptFile
function setOptFile(obj, file)
% setOptFile: Set option data from config file
% -------------------------------------------------------------
% Read the config file of RTKLIB.
%
% Usage: ------------------------------------------------------
% obj.setOptFile(file)
%
% Input: ------------------------------------------------------
% file : RTKLIB config file (???.conf)
%
arguments
obj gt.Gopt
file (1,:) char = ''
end
if isempty(file)
optstr = rtklib.loadopts();
else
optstr = rtklib.loadopts(obj.absPath(file));
end
obj.setOptStruct(optstr);
end
%% setOptStruct
function setOptStruct(obj, optstr)
% setOptStruct: Set option data from option struct
% -------------------------------------------------------------
% Set objects from RTKLIB's option structure.
%
% Usage: ------------------------------------------------------
% obj.setOptStruct(optstr)
%
% Input: ------------------------------------------------------
% optstr : RTKLIB option struct
%
arguments
obj gt.Gopt
optstr (1,1) struct
end
% pos1
obj.pos1 = optstr.pos1;
obj.pos1.posmode = gt.C.PMODE(optstr.pos1.posmode);
obj.pos1.navsys = gt.C.NAVSYS(optstr.pos1.navsys);
obj.pos1.frequency = gt.C.FREQOPT(optstr.pos1.frequency);
obj.pos1.snrmask_r = gt.C.SWITCH(optstr.pos1.snrmask_r);
obj.pos1.snrmask_b = gt.C.SWITCH(optstr.pos1.snrmask_b);
obj.pos1.tidecorr = gt.C.TIDE(optstr.pos1.tidecorr);
obj.pos1.ionoopt = gt.C.IONOOPT(optstr.pos1.ionoopt);
obj.pos1.tropopt = gt.C.TROPOPT(optstr.pos1.tropopt);
obj.pos1.ephopt = gt.C.EPHOPT(optstr.pos1.ephopt);
obj.pos1.raim_fde = gt.C.SWITCH(optstr.pos1.raim_fde);
% pos2
obj.pos2 = optstr.pos2;
obj.pos2.armode = gt.C.ARMODE(optstr.pos2.armode);
obj.pos2.gloarmode = gt.C.SWITCH(optstr.pos2.gloarmode);
obj.pos2.bdsarmode = gt.C.SWITCH(optstr.pos2.bdsarmode);
% out
obj.out = optstr.out;
obj.out.solformat = gt.C.SOLF(optstr.out.solformat);
obj.out.timeformat = gt.C.TIMEF(optstr.out.timeformat);
obj.out.trace = gt.C.TRACE(optstr.out.trace);
% stats
obj.stats = optstr.stats;
% ant
obj.ant = optstr.ant;
obj.ant.rovtype = gt.C.POSOPT(optstr.ant.rovtype);
obj.ant.reftype = gt.C.POSOPT(optstr.ant.reftype);
% misc
obj.misc = optstr.misc;
obj.misc.timeinterp = gt.C.SWITCH(optstr.misc.timeinterp);
end
%% saveOpt
function saveOpt(obj, file)
% saveOpt: Output option file
% -------------------------------------------------------------
% Output RTKLIB option file (???.conf).
%
% Usage: ------------------------------------------------------
% obj.saveOpt(file)
%
% Input: ------------------------------------------------------
% file : Output option file name (???.conf)
%
arguments
obj gt.Gopt
file (1,:) char
end
optstr = obj.struct();
rtklib.saveopts(obj.absPath(file), optstr);
end
%% copy
function gopt = 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: ------------------------------------------------------
% gopt = obj.copy()
%
% Output: -----------------------------------------------------
% gopt : 1x1, Copied gt.Gopt object
%
arguments
obj gt.Gopt
end
gopt = gt.Gopt(obj.struct());
end
%% struct
function optstr = struct(obj)
% struct: Convert from gt.Gopt object to struct
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.struct()
%
% Output: -----------------------------------------------------
% solstr : RTKLIB solution struct
%
arguments
obj gt.Gopt
end
% pos1
pos1_ = obj.pos1;
pos1_ = rmfield(pos1_,'exclsats');
optstr.pos1 = structfun(@double,pos1_,'UniformOutput',false);
optstr.pos1.exclsats = obj.pos1.exclsats;
% pos2
optstr.pos2 = structfun(@double,obj.pos2,'UniformOutput',false);
% out
optstr.out = structfun(@double,obj.out,'UniformOutput',false);
% stats
optstr.stats = structfun(@double,obj.stats,'UniformOutput',false);
% ant
ant_ = obj.ant;
ant_ = rmfield(ant_,'rovant');
ant_ = rmfield(ant_,'refant');
optstr.ant = structfun(@double,ant_,'UniformOutput',false);
optstr.ant.rovant = obj.ant.rovant;
optstr.ant.refant = obj.ant.refant;
% misc
optstr.misc = structfun(@double,obj.misc,'UniformOutput',false);
end
%% show
function show(obj)
% show: Show current options
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.show()
%
disp(obj.pos1)
disp(obj.pos2)
disp(obj.out)
disp(obj.stats)
disp(obj.ant)
disp(obj.misc)
end
%% help
function help(~)
% help: Show help
doc gt.Gopt
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
end
end