1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.files.ccsds;
18
19 import org.orekit.annotation.DefaultDataContext;
20 import org.orekit.data.DataContext;
21 import org.orekit.errors.OrekitException;
22 import org.orekit.errors.OrekitMessages;
23 import org.orekit.time.AbsoluteDate;
24 import org.orekit.time.DateTimeComponents;
25 import org.orekit.time.TimeScale;
26 import org.orekit.time.TimeScales;
27 import org.orekit.utils.Constants;
28 import org.orekit.utils.IERSConventions;
29
30
31
32
33
34
35 public enum CcsdsTimeScale {
36
37
38 GMST {
39 @Override
40 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
41 return timeScales.getGMST(conventions, false);
42 }
43 },
44
45 GPS {
46 @Override
47 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
48 return timeScales.getGPS();
49 }
50 },
51
52 MET {
53 @Override
54 public AbsoluteDate parseDate(final String date,
55 final IERSConventions conventions,
56 final AbsoluteDate missionReferenceDate,
57 final TimeScales timeScales) {
58 final DateTimeComponents clock = DateTimeComponents.parseDateTime(date);
59 final double offset = clock.getDate().getYear() * Constants.JULIAN_YEAR +
60 clock.getDate().getDayOfYear() * Constants.JULIAN_DAY +
61 clock.getTime().getSecondsInUTCDay();
62 return missionReferenceDate.shiftedBy(offset);
63 }
64
65 @Override
66 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
67 throw new OrekitException(
68 OrekitMessages.CCSDS_NO_CORRESPONDING_TIME_SCALE,
69 "MET");
70 }
71 },
72
73 MRT {
74 @Override
75 public AbsoluteDate parseDate(final String date,
76 final IERSConventions conventions,
77 final AbsoluteDate missionReferenceDate,
78 final TimeScales timeScales) {
79 final DateTimeComponents clock = DateTimeComponents.parseDateTime(date);
80 final double offset = clock.getDate().getYear() * Constants.JULIAN_YEAR +
81 clock.getDate().getDayOfYear() * Constants.JULIAN_DAY +
82 clock.getTime().getSecondsInUTCDay();
83 return missionReferenceDate.shiftedBy(offset);
84 }
85
86 @Override
87 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
88 throw new OrekitException(
89 OrekitMessages.CCSDS_NO_CORRESPONDING_TIME_SCALE,
90 "MRT");
91 }
92 },
93
94 SCLK {
95 @Override
96 public AbsoluteDate parseDate(final String date,
97 final IERSConventions conventions,
98 final AbsoluteDate missionReferenceDate,
99 final TimeScales timeScales) {
100 throw new OrekitException(
101 OrekitMessages.CCSDS_TIME_SYSTEM_NOT_IMPLEMENTED,
102 this.name());
103 }
104
105 @Override
106 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
107 throw new OrekitException(
108 OrekitMessages.CCSDS_NO_CORRESPONDING_TIME_SCALE,
109 this.name());
110 }
111 },
112
113 TAI {
114 @Override
115 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
116 return timeScales.getTAI();
117 }
118 },
119
120 TCB {
121 @Override
122 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
123 return timeScales.getTCB();
124 }
125 },
126
127 TDB {
128 @Override
129 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
130 return timeScales.getTDB();
131 }
132 },
133
134 TCG {
135 @Override
136 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
137 return timeScales.getTCG();
138 }
139 },
140
141 TT {
142 @Override
143 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
144 return timeScales.getTT();
145 }
146 },
147
148 UT1 {
149 @Override
150 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
151 return timeScales.getUT1(conventions, false);
152 }
153 },
154
155 UTC {
156 @Override
157 public TimeScale getTimeScale(final IERSConventions conventions, final TimeScales timeScales) {
158 return timeScales.getUTC();
159 }
160 };
161
162
163
164
165
166
167
168
169
170
171
172
173 @DefaultDataContext
174 public AbsoluteDate parseDate(final String date,
175 final IERSConventions conventions,
176 final AbsoluteDate missionReferenceDate) {
177 return parseDate(date, conventions, missionReferenceDate,
178 DataContext.getDefault().getTimeScales());
179 }
180
181
182
183
184
185
186
187
188
189
190
191 public AbsoluteDate parseDate(final String date,
192 final IERSConventions conventions,
193 final AbsoluteDate missionReferenceDate,
194 final TimeScales timeScales) {
195 return new AbsoluteDate(date, this.getTimeScale(conventions, timeScales));
196 }
197
198
199
200
201
202
203
204
205
206 @DefaultDataContext
207 public TimeScale getTimeScale(final IERSConventions conventions) {
208 return getTimeScale(conventions, DataContext.getDefault().getTimeScales());
209 }
210
211
212
213
214
215
216
217
218 public abstract TimeScale getTimeScale(IERSConventions conventions,
219 TimeScales timeScales);
220
221
222
223
224
225
226
227
228 public static boolean contains(final String timeScale) {
229 for (final CcsdsTimeScale scale : values()) {
230 if (scale.name().equals(timeScale)) {
231 return true;
232 }
233 }
234 return false;
235 }
236
237 }