1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.files.ccsds.definitions;
18
19 import java.util.regex.Pattern;
20
21 import org.orekit.bodies.CelestialBodyFactory;
22 import org.orekit.data.DataContext;
23 import org.orekit.errors.OrekitException;
24 import org.orekit.errors.OrekitInternalError;
25 import org.orekit.errors.OrekitMessages;
26 import org.orekit.frames.Frame;
27 import org.orekit.frames.ITRFVersion;
28 import org.orekit.frames.VersionedITRF;
29 import org.orekit.utils.IERSConventions;
30
31
32
33
34
35 public enum CelestialBodyFrame {
36
37
38 EME2000 {
39
40
41 @Override
42 public Frame getFrame(final IERSConventions conventions,
43 final boolean simpleEOP,
44 final DataContext dataContext) {
45 return dataContext.getFrames().getEME2000();
46 }
47
48 },
49
50
51 J2000 {
52
53
54 @Override
55 public Frame getFrame(final IERSConventions conventions,
56 final boolean simpleEOP,
57 final DataContext dataContext) {
58 return dataContext.getFrames().getEME2000();
59 }
60
61 },
62
63
64 GCRF {
65
66
67 @Override
68 public Frame getFrame(final IERSConventions conventions,
69 final boolean simpleEOP,
70 final DataContext dataContext) {
71 return dataContext.getFrames().getGCRF();
72 }
73
74 },
75
76
77 GRC {
78
79
80 @Override
81 public Frame getFrame(final IERSConventions conventions,
82 final boolean simpleEOP,
83 final DataContext dataContext) {
84 if (conventions == null) {
85 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
86 }
87 return dataContext.getFrames().getITRFEquinox(conventions, simpleEOP);
88 }
89
90 },
91
92
93
94
95 GTOD {
96
97
98 @Override
99 public Frame getFrame(final IERSConventions conventions,
100 final boolean simpleEOP,
101 final DataContext dataContext) {
102 if (conventions == null) {
103 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
104 }
105 return dataContext.getFrames().getGTOD(conventions, simpleEOP);
106 }
107
108 },
109
110
111 ICRF {
112
113
114 @Override
115 public Frame getFrame(final IERSConventions conventions,
116 final boolean simpleEOP,
117 final DataContext dataContext) {
118 return dataContext.getFrames().getICRF();
119 }
120
121 },
122
123
124 ITRF {
125
126
127 @Override
128 public Frame getFrame(final IERSConventions conventions,
129 final boolean simpleEOP,
130 final DataContext dataContext) {
131 return ITRF2020.getFrame(conventions, simpleEOP, dataContext);
132 }
133
134 },
135
136
137 ITRF2020 {
138
139
140 @Override
141 public Frame getFrame(final IERSConventions conventions,
142 final boolean simpleEOP,
143 final DataContext dataContext) {
144 if (conventions == null) {
145 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
146 }
147 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_2020, conventions, simpleEOP);
148 }
149
150 },
151
152
153 ITRF2014 {
154
155
156 @Override
157 public Frame getFrame(final IERSConventions conventions,
158 final boolean simpleEOP,
159 final DataContext dataContext) {
160 if (conventions == null) {
161 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
162 }
163 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_2014, conventions, simpleEOP);
164 }
165
166 },
167
168
169 ITRF2008 {
170
171
172 @Override
173 public Frame getFrame(final IERSConventions conventions,
174 final boolean simpleEOP,
175 final DataContext dataContext) {
176 if (conventions == null) {
177 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
178 }
179 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_2008, conventions, simpleEOP);
180 }
181
182 },
183
184
185 ITRF2005 {
186
187
188 @Override
189 public Frame getFrame(final IERSConventions conventions,
190 final boolean simpleEOP,
191 final DataContext dataContext) {
192 if (conventions == null) {
193 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
194 }
195 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_2005, conventions, simpleEOP);
196 }
197
198 },
199
200
201 ITRF2000 {
202
203
204 @Override
205 public Frame getFrame(final IERSConventions conventions,
206 final boolean simpleEOP,
207 final DataContext dataContext) {
208 if (conventions == null) {
209 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
210 }
211 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_2000, conventions, simpleEOP);
212 }
213
214 },
215
216
217 ITRF1997 {
218
219
220 @Override
221 public Frame getFrame(final IERSConventions conventions,
222 final boolean simpleEOP,
223 final DataContext dataContext) {
224 if (conventions == null) {
225 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
226 }
227 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1997, conventions, simpleEOP);
228 }
229
230 },
231
232
233 ITRF1996 {
234
235
236 @Override
237 public Frame getFrame(final IERSConventions conventions,
238 final boolean simpleEOP,
239 final DataContext dataContext) {
240 if (conventions == null) {
241 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
242 }
243 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1996, conventions, simpleEOP);
244 }
245
246 },
247
248
249 ITRF1994 {
250
251
252 @Override
253 public Frame getFrame(final IERSConventions conventions,
254 final boolean simpleEOP,
255 final DataContext dataContext) {
256 if (conventions == null) {
257 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
258 }
259 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1994, conventions, simpleEOP);
260 }
261
262 },
263
264
265 ITRF1993 {
266
267
268 @Override
269 public Frame getFrame(final IERSConventions conventions,
270 final boolean simpleEOP,
271 final DataContext dataContext) {
272 if (conventions == null) {
273 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
274 }
275 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1993, conventions, simpleEOP);
276 }
277
278 },
279
280
281 ITRF1992 {
282
283
284 @Override
285 public Frame getFrame(final IERSConventions conventions,
286 final boolean simpleEOP,
287 final DataContext dataContext) {
288 if (conventions == null) {
289 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
290 }
291 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1992, conventions, simpleEOP);
292 }
293
294 },
295
296
297 ITRF1991 {
298
299
300 @Override
301 public Frame getFrame(final IERSConventions conventions,
302 final boolean simpleEOP,
303 final DataContext dataContext) {
304 if (conventions == null) {
305 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
306 }
307 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1991, conventions, simpleEOP);
308 }
309
310 },
311
312
313 ITRF1990 {
314
315
316 @Override
317 public Frame getFrame(final IERSConventions conventions,
318 final boolean simpleEOP,
319 final DataContext dataContext) {
320 if (conventions == null) {
321 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
322 }
323 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1990, conventions, simpleEOP);
324 }
325
326 },
327
328
329 ITRF1989 {
330
331
332 @Override
333 public Frame getFrame(final IERSConventions conventions,
334 final boolean simpleEOP,
335 final DataContext dataContext) {
336 if (conventions == null) {
337 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
338 }
339 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1989, conventions, simpleEOP);
340 }
341
342 },
343
344
345 ITRF1988 {
346
347
348 @Override
349 public Frame getFrame(final IERSConventions conventions,
350 final boolean simpleEOP,
351 final DataContext dataContext) {
352 if (conventions == null) {
353 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
354 }
355 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1988, conventions, simpleEOP);
356 }
357
358 },
359
360
361 MCI {
362
363
364 @Override
365 public Frame getFrame(final IERSConventions conventions,
366 final boolean simpleEOP,
367 final DataContext dataContext) {
368 return dataContext.getCelestialBodies().getMars().getInertiallyOrientedFrame();
369 }
370
371 },
372
373
374 TDR {
375
376
377 @Override
378 public Frame getFrame(final IERSConventions conventions,
379 final boolean simpleEOP,
380 final DataContext dataContext) {
381 if (conventions == null) {
382 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
383 }
384 return dataContext.getFrames().getGTOD(conventions, simpleEOP);
385 }
386
387 },
388
389
390
391
392
393
394 TEME {
395
396
397 @Override
398 public Frame getFrame(final IERSConventions conventions,
399 final boolean simpleEOP,
400 final DataContext dataContext) {
401 return dataContext.getFrames().getTEME();
402 }
403
404 },
405
406
407 TOD {
408
409
410 @Override
411 public Frame getFrame(final IERSConventions conventions,
412 final boolean simpleEOP,
413 final DataContext dataContext) {
414 if (conventions == null) {
415 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
416 }
417 return dataContext.getFrames().getTOD(conventions, simpleEOP);
418 }
419
420 };
421
422
423 private static final Pattern DASH = Pattern.compile("-");
424
425
426 private static final String INERTIAL_FRAME_SUFFIX = "/inertial";
427
428
429 private static final String ITRF_SUBSTRING = "ITRF";
430
431
432
433
434
435
436
437
438
439 public abstract Frame getFrame(IERSConventions conventions, boolean simpleEOP, DataContext dataContext);
440
441
442
443
444
445
446 public String getName() {
447 return name();
448 }
449
450
451
452
453
454 public static CelestialBodyFrame parse(final String frameName) {
455 String canonicalized = DASH.matcher(frameName).replaceAll("");
456 if (canonicalized.startsWith(ITRF_SUBSTRING) && canonicalized.length() > 4) {
457 final int year = Integer.parseInt(canonicalized.substring(4));
458 if (year > 87 && year < 100) {
459
460 canonicalized = ITRF_SUBSTRING + (year + 1900);
461 }
462 }
463 return CelestialBodyFrame.valueOf(canonicalized);
464 }
465
466
467
468
469
470
471
472
473
474
475 public static CelestialBodyFrame map(final Frame frame) {
476
477 final String name = frame.getName();
478 try {
479
480 return CelestialBodyFrame.valueOf(name);
481 } catch (IllegalArgumentException iae) {
482 if (frame instanceof ModifiedFrame) {
483 return ((ModifiedFrame) frame).getRefFrame();
484 } else if ((CelestialBodyFactory.MARS + INERTIAL_FRAME_SUFFIX).equals(name)) {
485 return MCI;
486 } else if ((CelestialBodyFactory.SOLAR_SYSTEM_BARYCENTER + INERTIAL_FRAME_SUFFIX).equals(name)) {
487 return ICRF;
488 } else if (name.contains("GTOD")) {
489 return GTOD;
490 } else if (name.contains("TOD")) {
491 return TOD;
492 } else if (name.contains("Equinox") && name.contains(ITRF_SUBSTRING)) {
493 return GRC;
494 } else if (frame instanceof VersionedITRF) {
495 try {
496 final ITRFVersion itrfVersion = ((VersionedITRF) frame).getITRFVersion();
497 return CelestialBodyFrame.valueOf(itrfVersion.name().replace("_", ""));
498 } catch (IllegalArgumentException iae2) {
499
500 throw new OrekitInternalError(iae2);
501 }
502 } else if (name.contains("CIO") && name.contains(ITRF_SUBSTRING)) {
503 return ITRF2014;
504 }
505 throw new OrekitException(iae, OrekitMessages.CCSDS_INVALID_FRAME, name);
506 }
507 }
508
509
510
511
512
513
514
515
516
517
518 public static String guessFrame(final Frame frame) {
519 try {
520 return map(frame).name();
521 } catch (OrekitException oe) {
522
523 return frame.getName();
524 }
525 }
526
527 }