1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.files.rinex.clock;
18
19 import org.orekit.files.rinex.section.CommonLabel;
20 import org.orekit.files.rinex.section.Label;
21 import org.orekit.files.rinex.section.RinexClockObsBaseHeader;
22 import org.orekit.files.rinex.utils.ParsingUtils;
23 import org.orekit.files.rinex.utils.RinexFileType;
24 import org.orekit.frames.Frame;
25 import org.orekit.gnss.ObservationType;
26 import org.orekit.gnss.SatInSystem;
27 import org.orekit.gnss.SatelliteSystem;
28 import org.orekit.gnss.TimeSystem;
29 import org.orekit.time.AbsoluteDate;
30 import org.orekit.time.TimeScale;
31 import org.orekit.time.TimeScales;
32 import org.orekit.utils.TimeSpanMap;
33
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39
40
41
42
43
44 public class RinexClockHeader extends RinexClockObsBaseHeader {
45
46
47 public static final int LABEL_INDEX_300_302 = 60;
48
49
50 public static final int LABEL_INDEX_304_PLUS = 65;
51
52
53 private boolean before304;
54
55
56 private TimeScale timeScale;
57
58
59 private int leapSecondsTAI;
60
61
62 private Frame frame;
63
64
65 private String frameName;
66
67
68 private TimeSystem timeSystem;
69
70
71 private String stationName;
72
73
74 private String stationIdentifier;
75
76
77 private String externalClockReference;
78
79
80 private String analysisCenterID;
81
82
83 private String analysisCenterName;
84
85
86 private final TimeSpanMap<List<ReferenceClock>> referenceClocks;
87
88
89 private final Map<SatelliteSystem, List<ObservationType>> systemObservationTypes;
90
91
92 private final List<ClockDataType> clockDataTypes;
93
94
95 private final List<Receiver> receivers;
96
97
98 private final List<SatInSystem> satellites;
99
100
101 private SatelliteSystem mergedSystems;
102
103
104
105 public RinexClockHeader() {
106 super(RinexFileType.CLOCK);
107 this.frameName = "";
108 this.systemObservationTypes = new HashMap<>();
109 this.clockDataTypes = new ArrayList<>();
110 this.timeSystem = null;
111 this.stationIdentifier = "";
112 this.stationName = "";
113 this.externalClockReference = "";
114 this.analysisCenterID = "";
115 this.analysisCenterName = "";
116 this.referenceClocks = new TimeSpanMap<>(null);
117 this.receivers = new ArrayList<>();
118 this.satellites = new ArrayList<>();
119 }
120
121
122 @Override
123 public void setFormatVersion(final double formatVersion) {
124 super.setFormatVersion(formatVersion);
125 before304 = formatVersion < 3.04;
126 }
127
128
129
130
131 boolean isBefore304() {
132 return before304;
133 }
134
135
136 @Override
137 public SatelliteSystem parseSatelliteSystem(final String line, final SatelliteSystem defaultSatelliteSystem) {
138 final String satSystemString = (getFormatVersion() < 3.04 ? line.substring(40, 41) : line.substring(42, 43)).trim();
139 return SatelliteSystem.parseSatelliteSystem(satSystemString, defaultSatelliteSystem);
140 }
141
142
143 @Override
144 public void parseProgramRunByDate(final String line, final TimeScales timeScales) {
145 if (getFormatVersion() < 3.04) {
146 parseProgramRunByDate(ParsingUtils.parseString(line, 0, 20),
147 ParsingUtils.parseString(line, 20, 20),
148 ParsingUtils.parseString(line, 40, 20),
149 timeScales);
150 } else {
151 parseProgramRunByDate(ParsingUtils.parseString(line, 0, 19),
152 ParsingUtils.parseString(line, 21, 19),
153 ParsingUtils.parseString(line, 42, 21),
154 timeScales);
155 }
156 }
157
158
159
160
161 public TimeSystem getTimeSystem() {
162 return timeSystem;
163 }
164
165
166
167
168 public void setTimeSystem(final TimeSystem timeSystem) {
169 this.timeSystem = timeSystem;
170 }
171
172
173
174
175 public TimeScale getTimeScale() {
176 return timeScale;
177 }
178
179
180
181
182 public void setTimeScale(final TimeScale timeScale) {
183 this.timeScale = timeScale;
184 }
185
186
187
188
189 public String getStationName() {
190 return stationName;
191 }
192
193
194
195
196 public void setStationName(final String stationName) {
197 this.stationName = stationName;
198 }
199
200
201
202
203 public String getStationIdentifier() {
204 return stationIdentifier;
205 }
206
207
208
209
210 public void setStationIdentifier(final String stationIdentifier) {
211 this.stationIdentifier = stationIdentifier;
212 }
213
214
215
216
217 public String getExternalClockReference() {
218 return externalClockReference;
219 }
220
221
222
223
224 public void setExternalClockReference(final String externalClockReference) {
225 this.externalClockReference = externalClockReference;
226 }
227
228
229
230
231 public String getAnalysisCenterID() {
232 return analysisCenterID;
233 }
234
235
236
237
238 public void setAnalysisCenterID(final String analysisCenterID) {
239 this.analysisCenterID = analysisCenterID;
240 }
241
242
243
244
245 public String getAnalysisCenterName() {
246 return analysisCenterName;
247 }
248
249
250
251
252 public void setAnalysisCenterName(final String analysisCenterName) {
253 this.analysisCenterName = analysisCenterName;
254 }
255
256
257
258
259 public TimeSpanMap<List<ReferenceClock>> getReferenceClocks() {
260 return referenceClocks;
261 }
262
263
264
265
266
267
268
269 public void addReferenceClockList(final List<ReferenceClock> referenceClockList,
270 final AbsoluteDate startDate, final AbsoluteDate endDate) {
271 referenceClocks.addValidBetween(referenceClockList, startDate, endDate);
272 }
273
274
275
276
277 public Map<SatelliteSystem, List<ObservationType>> getSystemObservationTypes() {
278 return Collections.unmodifiableMap(systemObservationTypes);
279 }
280
281
282
283
284
285 public void addSystemObservationType(final SatelliteSystem satSystem,
286 final ObservationType observationType) {
287 final List<ObservationType> list;
288 synchronized (systemObservationTypes) {
289 list = systemObservationTypes.computeIfAbsent(satSystem, s -> new ArrayList<>());
290 }
291 list.add(observationType);
292 }
293
294
295
296
297
298 public int numberOfObsTypes(final SatelliteSystem system) {
299 if (systemObservationTypes.containsKey(system)) {
300 return systemObservationTypes.get(system).size();
301 } else {
302 return 0;
303 }
304 }
305
306
307
308
309 public List<ClockDataType> getClockDataTypes() {
310 return Collections.unmodifiableList(clockDataTypes);
311 }
312
313
314
315
316 public void addClockDataType(final ClockDataType clockDataType) {
317 clockDataTypes.add(clockDataType);
318 }
319
320
321
322
323 public int getNumberOfClockDataTypes() {
324 return clockDataTypes.size();
325 }
326
327
328
329
330 public void setLeapSecondsTAI(final int leapSecondsTAI) {
331 this.leapSecondsTAI = leapSecondsTAI;
332 }
333
334
335
336
337 public int getLeapSecondsTAI() {
338 return leapSecondsTAI;
339 }
340
341
342
343
344 public Frame getFrame() {
345 return frame;
346 }
347
348
349
350
351 public void setFrame(final Frame frame) {
352 this.frame = frame;
353 }
354
355
356
357
358 public String getFrameName() {
359 return frameName;
360 }
361
362
363
364
365 public void setFrameName(final String frameName) {
366 this.frameName = frameName;
367 }
368
369
370
371
372 public void addSatellite(final SatInSystem satId) {
373
374
375 if (!satellites.contains(satId)) {
376 satellites.add(satId);
377
378
379 if (mergedSystems == null) {
380 mergedSystems = satId.getSystem();
381 } else if (satId.getSystem() != mergedSystems) {
382 mergedSystems = SatelliteSystem.MIXED;
383 }
384
385 }
386
387 }
388
389
390
391
392
393 SatelliteSystem getMergedSystem() {
394 return mergedSystems;
395 }
396
397
398
399
400 public void addReceiver(final Receiver receiver) {
401
402 boolean notInList = true;
403 for (Receiver rec : receivers) {
404 if (rec.getDesignator().equals(receiver.getDesignator())) {
405 notInList = false;
406 break;
407 }
408 }
409
410 if (notInList) {
411 receivers.add(receiver);
412 }
413 }
414
415
416
417
418 public int getNumberOfReceivers() {
419 return receivers.size();
420 }
421
422
423
424
425 public int getNumberOfSatellites() {
426 return satellites.size();
427 }
428
429
430
431
432 public List<Receiver> getReceivers() {
433 return Collections.unmodifiableList(receivers);
434 }
435
436
437
438
439 public List<SatInSystem> getSatellites() {
440 return Collections.unmodifiableList(satellites);
441 }
442
443
444 @Override
445 public void checkType(final String line, final String name) {
446 checkType(line, getFormatVersion() < 3.04 ? 20 : 21, name);
447 }
448
449
450 @Override
451 public int getLabelIndex() {
452 return getFormatVersion() < 3.04 ? LABEL_INDEX_300_302 : LABEL_INDEX_304_PLUS;
453 }
454
455
456 @Override
457 public boolean matchFound(final Label label, final String line) {
458
459 if (label == CommonLabel.VERSION) {
460
461
462 return label.matches(line.substring(LABEL_INDEX_300_302).trim()) ||
463 label.matches(line.substring(LABEL_INDEX_304_PLUS).trim());
464 } else {
465 return label.matches(line.substring(getLabelIndex()).trim());
466 }
467 }
468
469 }