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