1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.files.sp3;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.orekit.errors.OrekitException;
24 import org.orekit.errors.OrekitMessages;
25 import org.orekit.gnss.TimeSystem;
26 import org.orekit.time.AbsoluteDate;
27 import org.orekit.utils.CartesianDerivativesFilter;
28
29
30
31
32
33 public class SP3Header {
34
35
36 public static final String SP3_FRAME_CENTER_STRING = "EARTH";
37
38
39 private static final String POS_VEL_ACCURACY_BASE = "pos/vel accuracy base";
40
41
42 private static final String CLOCK_ACCURACY_BASE = "clock accuracy base";
43
44
45 private static final String COMMENTS = "comments";
46
47
48 private char version;
49
50
51 private SP3FileType type;
52
53
54 private TimeSystem timeSystem;
55
56
57 private AbsoluteDate epoch;
58
59
60 private int gpsWeek;
61
62
63 private double secondsOfWeek;
64
65
66 private int modifiedJulianDay;
67
68
69 private double dayFraction;
70
71
72 private double epochInterval;
73
74
75 private int numberOfEpochs;
76
77
78 private String coordinateSystem;
79
80
81 private List<DataUsed> dataUsed;
82
83
84 private SP3OrbitType orbitType;
85
86
87 private String orbitTypeKey;
88
89
90 private String agency;
91
92
93 private CartesianDerivativesFilter filter;
94
95
96 private double posVelBase;
97
98
99 private double clockBase;
100
101
102 private List<String> satIds;
103
104
105 private double[] accuracies;
106
107
108 private final List<String> comments;
109
110
111
112 public SP3Header() {
113 this.version = '?';
114 this.satIds = new ArrayList<>();
115 this.accuracies = null;
116 this.comments = new ArrayList<>();
117 }
118
119
120
121
122
123
124
125
126
127 void validate(final boolean parsing, final boolean hasAccuracy, final String fileName) throws OrekitException {
128
129
130 if ("abcd".indexOf(getVersion()) < 0) {
131 throw new OrekitException(OrekitMessages.SP3_UNSUPPORTED_VERSION, getVersion());
132 }
133
134 if (getVersion() == 'a') {
135
136 if (getPosVelBase() != 0.0) {
137 throw new OrekitException(OrekitMessages.SP3_INVALID_HEADER_ENTRY,
138 POS_VEL_ACCURACY_BASE, getPosVelBase(), fileName, getVersion());
139 }
140 if (getClockBase() != 0.0) {
141 throw new OrekitException(OrekitMessages.SP3_INVALID_HEADER_ENTRY,
142 CLOCK_ACCURACY_BASE, getClockBase(), fileName, getVersion());
143 }
144 } else if (hasAccuracy) {
145
146 if (getPosVelBase() <= 0.0) {
147 throw new OrekitException(OrekitMessages.SP3_INVALID_HEADER_ENTRY,
148 POS_VEL_ACCURACY_BASE, getPosVelBase(), fileName, getVersion());
149 }
150 if (getClockBase() <= 0.0) {
151 throw new OrekitException(OrekitMessages.SP3_INVALID_HEADER_ENTRY,
152 CLOCK_ACCURACY_BASE, getClockBase(), fileName, getVersion());
153 }
154 }
155 if (getVersion() < 'd') {
156
157
158 if (comments.size() != 4 ||
159 comments.get(0).length() > 57 ||
160 comments.get(1).length() > 57 ||
161 comments.get(2).length() > 57 ||
162 comments.get(3).length() > 57) {
163 throw new OrekitException(OrekitMessages.SP3_INVALID_HEADER_ENTRY,
164 COMMENTS, "/* …", fileName, getVersion());
165 }
166 } else {
167
168
169 for (final String c : comments) {
170 if (c.length() > 77) {
171 throw new OrekitException(OrekitMessages.SP3_INVALID_HEADER_ENTRY,
172 COMMENTS, c, fileName, getVersion());
173 }
174 }
175 }
176
177 }
178
179
180
181
182 public void setVersion(final char version) {
183 this.version = version;
184 }
185
186
187
188
189 public char getVersion() {
190 return version;
191 }
192
193
194
195
196 public void setFilter(final CartesianDerivativesFilter filter) {
197 this.filter = filter;
198 }
199
200
201
202
203 public CartesianDerivativesFilter getFilter() {
204 return filter;
205 }
206
207
208
209
210 public SP3FileType getType() {
211 return type;
212 }
213
214
215
216
217 public void setType(final SP3FileType fileType) {
218 this.type = fileType;
219 }
220
221
222
223
224 public TimeSystem getTimeSystem() {
225 return timeSystem;
226 }
227
228
229
230
231 public void setTimeSystem(final TimeSystem system) {
232 this.timeSystem = system;
233 }
234
235
236
237
238 public List<DataUsed> getDataUsed() {
239 return dataUsed;
240 }
241
242
243
244
245 public void setDataUsed(final List<DataUsed> dataUsed) {
246 this.dataUsed = dataUsed;
247 }
248
249
250
251
252 public AbsoluteDate getEpoch() {
253 return epoch;
254 }
255
256
257
258
259 public void setEpoch(final AbsoluteDate time) {
260 this.epoch = time;
261 }
262
263
264
265
266 public int getGpsWeek() {
267 return gpsWeek;
268 }
269
270
271
272
273 public void setGpsWeek(final int week) {
274 this.gpsWeek = week;
275 }
276
277
278
279
280 public double getSecondsOfWeek() {
281 return secondsOfWeek;
282 }
283
284
285
286
287 public void setSecondsOfWeek(final double seconds) {
288 this.secondsOfWeek = seconds;
289 }
290
291
292
293
294 public int getModifiedJulianDay() {
295 return modifiedJulianDay;
296 }
297
298
299
300
301 public void setModifiedJulianDay(final int day) {
302 this.modifiedJulianDay = day;
303 }
304
305
306
307
308 public double getDayFraction() {
309 return dayFraction;
310 }
311
312
313
314
315 public void setDayFraction(final double fraction) {
316 this.dayFraction = fraction;
317 }
318
319
320
321
322 public double getEpochInterval() {
323 return epochInterval;
324 }
325
326
327
328
329 public void setEpochInterval(final double interval) {
330 this.epochInterval = interval;
331 }
332
333
334
335
336 public int getNumberOfEpochs() {
337 return numberOfEpochs;
338 }
339
340
341
342
343 public void setNumberOfEpochs(final int epochCount) {
344 this.numberOfEpochs = epochCount;
345 }
346
347
348
349
350 public String getCoordinateSystem() {
351 return coordinateSystem;
352 }
353
354
355
356
357 public void setCoordinateSystem(final String system) {
358 this.coordinateSystem = system;
359 }
360
361
362
363
364 public SP3OrbitType getOrbitType() {
365 return orbitType;
366 }
367
368
369
370
371 public String getOrbitTypeKey() {
372 return orbitTypeKey;
373 }
374
375
376
377
378 public void setOrbitTypeKey(final String oTypeKey) {
379 this.orbitTypeKey = oTypeKey;
380 this.orbitType = SP3OrbitType.parseType(oTypeKey);
381 }
382
383
384
385
386 public String getAgency() {
387 return agency;
388 }
389
390
391
392
393 public void setAgency(final String agencyStr) {
394 this.agency = agencyStr;
395 }
396
397
398
399
400 public void setPosVelBase(final double posVelBase) {
401 this.posVelBase = posVelBase;
402 }
403
404
405
406
407 public double getPosVelBase() {
408 return posVelBase;
409 }
410
411
412
413
414 public void setClockBase(final double clockBase) {
415 this.clockBase = clockBase;
416 }
417
418
419
420
421 public double getClockBase() {
422 return clockBase;
423 }
424
425
426
427
428 public void addSatId(final String satId) {
429 satIds.add(satId);
430 }
431
432
433
434
435 public List<String> getSatIds() {
436 return Collections.unmodifiableList(satIds);
437 }
438
439
440
441
442
443 public void setAccuracy(final int index, final double accuracy) {
444 if (accuracies == null) {
445
446 accuracies = new double[satIds.size()];
447 }
448 accuracies[index] = accuracy;
449 }
450
451
452
453
454
455
456
457
458
459 public double getAccuracy(final String satId) {
460 for (int i = 0; i < satIds.size(); ++i) {
461 if (satIds.get(i).equals(satId)) {
462 return accuracies[i];
463 }
464 }
465 return Double.NaN;
466 }
467
468
469
470
471 public List<String> getComments() {
472 return Collections.unmodifiableList(comments);
473 }
474
475
476
477
478 public void addComment(final String comment) {
479 comments.add(comment);
480 }
481
482 }