1 /* Contributed in the public domain.
2 * Licensed to CS GROUP (CS) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * CS licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.orekit.files.ccsds.definitions;
18
19 import org.orekit.errors.OrekitException;
20 import org.orekit.errors.OrekitMessages;
21 import org.orekit.files.ccsds.utils.ContextBinding;
22 import org.orekit.time.AbsoluteDate;
23 import org.orekit.time.SatelliteClockScale;
24
25 /**
26 * The set of time systems defined in CCSDS standards (ADM, ODM, NDM).
27 *
28 * @author Evan Ward
29 */
30 public enum TimeSystem {
31
32 /** Greenwich Mean Sidereal Time. */
33 GMST {
34 /** {@inheritDoc} */
35 public TimeConverter getConverter(final ContextBinding context) {
36 return new TimeConverter(context.getDataContext().getTimeScales().getGMST(context.getConventions(), false),
37 context.getReferenceDate());
38 }
39 },
40
41 /** Global Positioning System. */
42 GPS {
43 /** {@inheritDoc} */
44 public TimeConverter getConverter(final ContextBinding context) {
45 return new TimeConverter(context.getDataContext().getTimeScales().getGPS(),
46 context.getReferenceDate());
47 }
48 },
49
50 /** Mission Elapsed Time. */
51 MET {
52 /** {@inheritDoc} */
53 public TimeConverter getConverter(final ContextBinding context) {
54 return new TimeConverter(new SatelliteClockScale("MET",
55 context.getReferenceDate(),
56 context.getDataContext().getTimeScales().getUTC(),
57 0.0, 0.0),
58 context.getReferenceDate());
59 }
60 },
61
62 /** Mission Relative Time. */
63 MRT {
64 /** {@inheritDoc} */
65 public TimeConverter getConverter(final ContextBinding context) {
66 return new TimeConverter(new SatelliteClockScale("MRT",
67 context.getReferenceDate(),
68 context.getDataContext().getTimeScales().getUTC(),
69 0.0, 0.0),
70 context.getReferenceDate());
71 }
72 },
73
74 /** Spacecraft Clock. */
75 SCLK {
76 /** {@inheritDoc} */
77 public TimeConverter getConverter(final ContextBinding context) {
78 return new TimeConverter(new SatelliteClockScale("SCLK",
79 context.getReferenceDate(),
80 context.getDataContext().getTimeScales().getUTC(),
81 context.getClockCount(),
82 context.getClockRate() - 1.0),
83 context.getReferenceDate()) {
84 /** {@inheritDoc}
85 * <p>
86 * Special implementation: the offset is a clock count rather than a duration
87 * </p>
88 */
89 @Override
90 public double offset(final AbsoluteDate date) {
91 return ((SatelliteClockScale) getTimeScale()).countAtDate(date);
92 }
93 };
94 }
95 },
96
97 /** International Atomic Time. */
98 TAI {
99 /** {@inheritDoc} */
100 public TimeConverter getConverter(final ContextBinding context) {
101 return new TimeConverter(context.getDataContext().getTimeScales().getTAI(),
102 context.getReferenceDate());
103 }
104 },
105
106 /** Barycentric Coordinate Time. */
107 TCB {
108 /** {@inheritDoc} */
109 public TimeConverter getConverter(final ContextBinding context) {
110 return new TimeConverter(context.getDataContext().getTimeScales().getTCB(),
111 context.getReferenceDate());
112 }
113 },
114
115 /** Barycentric Dynamical Time. */
116 TDB {
117 /** {@inheritDoc} */
118 public TimeConverter getConverter(final ContextBinding context) {
119 return new TimeConverter(context.getDataContext().getTimeScales().getTDB(),
120 context.getReferenceDate());
121 }
122 },
123
124 /** Geocentric Coordinate Time. */
125 TCG {
126 /** {@inheritDoc} */
127 public TimeConverter getConverter(final ContextBinding context) {
128 return new TimeConverter(context.getDataContext().getTimeScales().getTCG(),
129 context.getReferenceDate());
130 }
131 },
132
133 /** Terrestrial Time. */
134 TT {
135 /** {@inheritDoc} */
136 public TimeConverter getConverter(final ContextBinding context) {
137 return new TimeConverter(context.getDataContext().getTimeScales().getTT(),
138 context.getReferenceDate());
139 }
140 },
141
142 /** Universal Time. */
143 UT1 {
144 /** {@inheritDoc} */
145 public TimeConverter getConverter(final ContextBinding context) {
146 return new TimeConverter(context.getDataContext().getTimeScales().getUT1(context.getConventions(), false),
147 context.getReferenceDate());
148 }
149 },
150
151 /** Universal Coordinated Time. */
152 UTC {
153 /** {@inheritDoc} */
154 public TimeConverter getConverter(final ContextBinding context) {
155 return new TimeConverter(context.getDataContext().getTimeScales().getUTC(),
156 context.getReferenceDate());
157 }
158 };
159
160 /** Get associated {@link TimeConverter}.
161 * @param context context binding
162 * @return time system for reading/writing date
163 * @since 11.0
164 */
165 public abstract TimeConverter getConverter(ContextBinding context);
166
167 /** Parse a value from a key=value entry.
168 * @param value value to parse
169 * @return CCSDS time system corresponding to the value
170 */
171 public static TimeSystem parse(final String value) {
172 for (final TimeSystem scale : values()) {
173 if (scale.name().equals(value)) {
174 return scale;
175 }
176 }
177 throw new OrekitException(OrekitMessages.CCSDS_TIME_SYSTEM_NOT_IMPLEMENTED, value);
178 }
179
180 }