1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.frames;
18
19 import java.util.regex.Matcher;
20 import java.util.regex.Pattern;
21
22 import org.hipparchus.CalculusFieldElement;
23 import org.orekit.annotation.DefaultDataContext;
24 import org.orekit.data.DataContext;
25 import org.orekit.errors.OrekitException;
26 import org.orekit.errors.OrekitMessages;
27 import org.orekit.time.AbsoluteDate;
28 import org.orekit.time.FieldAbsoluteDate;
29 import org.orekit.time.TimeScale;
30
31
32
33
34
35
36
37 public enum ITRFVersion {
38
39
40 ITRF_2020(2020),
41
42
43 ITRF_2014(2014),
44
45
46 ITRF_2008(2008),
47
48
49 ITRF_2005(2005),
50
51
52 ITRF_2000(2000),
53
54
55 ITRF_1997(1997),
56
57
58 ITRF_1996(1996),
59
60
61 ITRF_1994(1994),
62
63
64 ITRF_1993(1993),
65
66
67 ITRF_1992(1992),
68
69
70 ITRF_1991(1991),
71
72
73 ITRF_1990(1990),
74
75
76 ITRF_1989(1989),
77
78
79 ITRF_1988(1988);
80
81
82 private static final Pattern PATTERN = Pattern.compile("[Ii][Tt][Rr][Ff][-_ ]?([0-9]{2,4})");
83
84
85 private final int year;
86
87
88 private final String name;
89
90
91
92
93 ITRFVersion(final int year) {
94 this.year = year;
95 this.name = "ITRF-" + year;
96 }
97
98
99
100
101 public int getYear() {
102 return year;
103 }
104
105
106
107
108 public String getName() {
109 return name;
110 }
111
112
113
114
115
116 public static ITRFVersion getITRFVersion(final int year) {
117
118 final int fixedYear = (year > 87 && year < 100) ? (year + 1900) : year;
119
120
121 for (final ITRFVersion version : values()) {
122 if (version.getYear() == fixedYear) {
123 return version;
124 }
125 }
126
127
128 throw new OrekitException(OrekitMessages.NO_SUCH_ITRF_FRAME, year);
129
130 }
131
132
133
134
135
136 public static ITRFVersion getITRFVersion(final String name) {
137
138
139 final Matcher matcher = PATTERN.matcher(name);
140 if (matcher.matches()) {
141 try {
142 return getITRFVersion(Integer.parseInt(matcher.group(1)));
143 } catch (OrekitException oe) {
144 throw new OrekitException(OrekitMessages.NO_SUCH_ITRF_FRAME, name);
145 }
146 }
147
148
149 throw new OrekitException(OrekitMessages.NO_SUCH_ITRF_FRAME, name);
150
151 }
152
153
154
155
156
157 public static ITRFVersion getLast() {
158 ITRFVersion last = ITRFVersion.ITRF_1988;
159 for (final ITRFVersion iv : ITRFVersion.values()) {
160 if (iv.getYear() > last.getYear()) {
161 last = iv;
162 }
163 }
164 return last;
165 }
166
167
168
169
170
171
172
173
174
175
176 @DefaultDataContext
177 public static Converter getConverter(final ITRFVersion origin, final ITRFVersion destination) {
178 return getConverter(origin, destination,
179 DataContext.getDefault().getTimeScales().getTT());
180 }
181
182
183
184
185
186
187
188
189 public static Converter getConverter(final ITRFVersion origin,
190 final ITRFVersion destination,
191 final TimeScale tt) {
192
193 TransformProvider provider = null;
194
195
196 if (origin == destination) {
197 provider = TransformProviderUtils.IDENTITY_PROVIDER;
198 }
199
200 if (provider == null) {
201
202 provider = getDirectTransformProvider(origin, destination, tt);
203 }
204
205 if (provider == null) {
206
207 final ITRFVersion last = getLast();
208 provider = TransformProviderUtils.getCombinedProvider(getDirectTransformProvider(origin, last, tt),
209 getDirectTransformProvider(last, destination, tt));
210 }
211
212
213 return new Converter(origin, destination, provider);
214
215 }
216
217
218
219
220
221
222
223 private static TransformProvider getDirectTransformProvider(
224 final ITRFVersion origin,
225 final ITRFVersion destination,
226 final TimeScale tt) {
227
228
229 for (final HelmertTransformation.Predefined predefined : HelmertTransformation.Predefined.values()) {
230 if (predefined.getOrigin() == origin && predefined.getDestination() == destination) {
231
232 return predefined.getTransformation(tt);
233 } else if (predefined.getOrigin() == destination && predefined.getDestination() == origin) {
234
235 return TransformProviderUtils.getReversedProvider(predefined.getTransformation(tt));
236 }
237 }
238
239
240 return null;
241
242 }
243
244
245 public static class Converter implements TransformProvider {
246
247
248 private static final long serialVersionUID = 20180330L;
249
250
251 private final ITRFVersion origin;
252
253
254 private final ITRFVersion destination;
255
256
257 private final TransformProvider provider;
258
259
260
261
262
263
264 Converter(final ITRFVersion origin, final ITRFVersion destination, final TransformProvider provider) {
265 this.origin = origin;
266 this.destination = destination;
267 this.provider = provider;
268 }
269
270
271
272
273 public ITRFVersion getOrigin() {
274 return origin;
275 }
276
277
278
279
280 public ITRFVersion getDestination() {
281 return destination;
282 }
283
284
285 @Override
286 public Transform getTransform(final AbsoluteDate date) {
287 return provider.getTransform(date);
288 }
289
290 @Override
291 public StaticTransform getStaticTransform(final AbsoluteDate date) {
292 return provider.getStaticTransform(date);
293 }
294
295
296 @Override
297 public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
298 return provider.getTransform(date);
299 }
300
301
302 @Override
303 public <T extends CalculusFieldElement<T>> FieldStaticTransform<T> getStaticTransform(final FieldAbsoluteDate<T> date) {
304 return provider.getStaticTransform(date);
305 }
306
307 }
308
309 }