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 ITRF2020 {
125
126
127 @Override
128 public Frame getFrame(final IERSConventions conventions,
129 final boolean simpleEOP,
130 final DataContext dataContext) {
131 if (conventions == null) {
132 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
133 }
134 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_2020, conventions, simpleEOP);
135 }
136
137 },
138
139
140 ITRF2014 {
141
142
143 @Override
144 public Frame getFrame(final IERSConventions conventions,
145 final boolean simpleEOP,
146 final DataContext dataContext) {
147 if (conventions == null) {
148 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
149 }
150 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_2014, conventions, simpleEOP);
151 }
152
153 },
154
155
156 ITRF2008 {
157
158
159 @Override
160 public Frame getFrame(final IERSConventions conventions,
161 final boolean simpleEOP,
162 final DataContext dataContext) {
163 if (conventions == null) {
164 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
165 }
166 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_2008, conventions, simpleEOP);
167 }
168
169 },
170
171
172 ITRF2005 {
173
174
175 @Override
176 public Frame getFrame(final IERSConventions conventions,
177 final boolean simpleEOP,
178 final DataContext dataContext) {
179 if (conventions == null) {
180 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
181 }
182 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_2005, conventions, simpleEOP);
183 }
184
185 },
186
187
188 ITRF2000 {
189
190
191 @Override
192 public Frame getFrame(final IERSConventions conventions,
193 final boolean simpleEOP,
194 final DataContext dataContext) {
195 if (conventions == null) {
196 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
197 }
198 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_2000, conventions, simpleEOP);
199 }
200
201 },
202
203
204 ITRF1997 {
205
206
207 @Override
208 public String getName() {
209 return "ITRF-97";
210 }
211
212
213 @Override
214 public Frame getFrame(final IERSConventions conventions,
215 final boolean simpleEOP,
216 final DataContext dataContext) {
217 if (conventions == null) {
218 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
219 }
220 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1997, conventions, simpleEOP);
221 }
222
223 },
224
225
226 ITRF1996 {
227
228
229 @Override
230 public String getName() {
231 return "ITRF-96";
232 }
233
234
235 @Override
236 public Frame getFrame(final IERSConventions conventions,
237 final boolean simpleEOP,
238 final DataContext dataContext) {
239 if (conventions == null) {
240 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
241 }
242 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1996, conventions, simpleEOP);
243 }
244
245 },
246
247
248 ITRF1994 {
249
250
251 @Override
252 public String getName() {
253 return "ITRF-94";
254 }
255
256
257 @Override
258 public Frame getFrame(final IERSConventions conventions,
259 final boolean simpleEOP,
260 final DataContext dataContext) {
261 if (conventions == null) {
262 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
263 }
264 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1994, conventions, simpleEOP);
265 }
266
267 },
268
269
270 ITRF1993 {
271
272
273 @Override
274 public String getName() {
275 return "ITRF-93";
276 }
277
278
279 @Override
280 public Frame getFrame(final IERSConventions conventions,
281 final boolean simpleEOP,
282 final DataContext dataContext) {
283 if (conventions == null) {
284 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
285 }
286 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1993, conventions, simpleEOP);
287 }
288
289 },
290
291
292 ITRF1992 {
293
294
295 @Override
296 public String getName() {
297 return "ITRF-92";
298 }
299
300
301 @Override
302 public Frame getFrame(final IERSConventions conventions,
303 final boolean simpleEOP,
304 final DataContext dataContext) {
305 if (conventions == null) {
306 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
307 }
308 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1992, conventions, simpleEOP);
309 }
310
311 },
312
313
314 ITRF1991 {
315
316
317 @Override
318 public String getName() {
319 return "ITRF-91";
320 }
321
322
323 @Override
324 public Frame getFrame(final IERSConventions conventions,
325 final boolean simpleEOP,
326 final DataContext dataContext) {
327 if (conventions == null) {
328 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
329 }
330 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1991, conventions, simpleEOP);
331 }
332
333 },
334
335
336 ITRF1990 {
337
338
339 @Override
340 public String getName() {
341 return "ITRF-90";
342 }
343
344
345 @Override
346 public Frame getFrame(final IERSConventions conventions,
347 final boolean simpleEOP,
348 final DataContext dataContext) {
349 if (conventions == null) {
350 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
351 }
352 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1990, conventions, simpleEOP);
353 }
354
355 },
356
357
358 ITRF1989 {
359
360
361 @Override
362 public String getName() {
363 return "ITRF-89";
364 }
365
366
367 @Override
368 public Frame getFrame(final IERSConventions conventions,
369 final boolean simpleEOP,
370 final DataContext dataContext) {
371 if (conventions == null) {
372 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
373 }
374 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1989, conventions, simpleEOP);
375 }
376
377 },
378
379
380 ITRF1988 {
381
382
383 @Override
384 public String getName() {
385 return "ITRF-88";
386 }
387
388
389 @Override
390 public Frame getFrame(final IERSConventions conventions,
391 final boolean simpleEOP,
392 final DataContext dataContext) {
393 if (conventions == null) {
394 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
395 }
396 return dataContext.getFrames().getITRF(ITRFVersion.ITRF_1988, conventions, simpleEOP);
397 }
398
399 },
400
401
402 MCI {
403
404
405 @Override
406 public Frame getFrame(final IERSConventions conventions,
407 final boolean simpleEOP,
408 final DataContext dataContext) {
409 return dataContext.getCelestialBodies().getMars().getInertiallyOrientedFrame();
410 }
411
412 },
413
414
415 TDR {
416
417
418 @Override
419 public Frame getFrame(final IERSConventions conventions,
420 final boolean simpleEOP,
421 final DataContext dataContext) {
422 if (conventions == null) {
423 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
424 }
425 return dataContext.getFrames().getGTOD(conventions, simpleEOP);
426 }
427
428 },
429
430
431
432
433
434
435 TEME {
436
437
438 @Override
439 public Frame getFrame(final IERSConventions conventions,
440 final boolean simpleEOP,
441 final DataContext dataContext) {
442 return dataContext.getFrames().getTEME();
443 }
444
445 },
446
447
448 TOD {
449
450
451 @Override
452 public Frame getFrame(final IERSConventions conventions,
453 final boolean simpleEOP,
454 final DataContext dataContext) {
455 if (conventions == null) {
456 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
457 }
458 return dataContext.getFrames().getTOD(conventions, simpleEOP);
459 }
460
461 };
462
463
464 private static final Pattern DASH = Pattern.compile("-");
465
466
467 private static final String INERTIAL_FRAME_SUFFIX = "/inertial";
468
469
470 private static final String ITRF_SUBSTRING = "ITRF";
471
472
473
474
475
476
477
478
479
480 public abstract Frame getFrame(IERSConventions conventions, boolean simpleEOP, DataContext dataContext);
481
482
483
484
485
486
487 public String getName() {
488 return name();
489 }
490
491
492
493
494
495 public static CelestialBodyFrame parse(final String frameName) {
496 String canonicalized = DASH.matcher(frameName).replaceAll("");
497 if (canonicalized.startsWith(ITRF_SUBSTRING) && canonicalized.length() > 4) {
498 final int year = Integer.parseInt(canonicalized.substring(4));
499 if (year > 87 && year < 100) {
500
501 canonicalized = ITRF_SUBSTRING + (year + 1900);
502 }
503 }
504 return CelestialBodyFrame.valueOf(canonicalized);
505 }
506
507
508
509
510
511
512
513
514
515
516 public static CelestialBodyFrame map(final Frame frame) {
517
518 final String name = frame.getName();
519 try {
520
521 return CelestialBodyFrame.valueOf(name);
522 } catch (IllegalArgumentException iae) {
523 if (frame instanceof ModifiedFrame) {
524 return ((ModifiedFrame) frame).getRefFrame();
525 } else if ((CelestialBodyFactory.MARS + INERTIAL_FRAME_SUFFIX).equals(name)) {
526 return MCI;
527 } else if ((CelestialBodyFactory.SOLAR_SYSTEM_BARYCENTER + INERTIAL_FRAME_SUFFIX).equals(name)) {
528 return ICRF;
529 } else if (name.contains("GTOD")) {
530 return GTOD;
531 } else if (name.contains("TOD")) {
532 return TOD;
533 } else if (name.contains("Equinox") && name.contains(ITRF_SUBSTRING)) {
534 return GRC;
535 } else if (frame instanceof VersionedITRF) {
536 try {
537 final ITRFVersion itrfVersion = ((VersionedITRF) frame).getITRFVersion();
538 return CelestialBodyFrame.valueOf(itrfVersion.name().replace("_", ""));
539 } catch (IllegalArgumentException iae2) {
540
541 throw new OrekitInternalError(iae2);
542 }
543 } else if (name.contains("CIO") && name.contains(ITRF_SUBSTRING)) {
544 return ITRF2014;
545 }
546 throw new OrekitException(iae, OrekitMessages.CCSDS_INVALID_FRAME, name);
547 }
548 }
549
550
551
552
553
554
555
556
557
558
559 public static String guessFrame(final Frame frame) {
560 try {
561 return map(frame).name();
562 } catch (OrekitException oe) {
563
564 return frame.getName();
565 }
566 }
567
568 }