TimeSystem.java

  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. import org.orekit.errors.OrekitException;
  19. import org.orekit.errors.OrekitMessages;
  20. import org.orekit.files.ccsds.utils.ContextBinding;
  21. import org.orekit.time.AbsoluteDate;
  22. import org.orekit.time.SatelliteClockScale;

  23. /**
  24.  * The set of time systems defined in CCSDS standards (ADM, ODM, NDM).
  25.  *
  26.  * @author Evan Ward
  27.  */
  28. public enum TimeSystem {

  29.     /** Greenwich Mean Sidereal Time. */
  30.     GMST {
  31.         /** {@inheritDoc} */
  32.         public TimeConverter getConverter(final ContextBinding context) {
  33.             return new TimeConverter(context.getDataContext().getTimeScales().getGMST(context.getConventions(), false),
  34.                                      context.getReferenceDate());
  35.         }
  36.     },

  37.     /** Global Positioning System. */
  38.     GPS {
  39.         /** {@inheritDoc} */
  40.         public TimeConverter getConverter(final ContextBinding context) {
  41.             return new TimeConverter(context.getDataContext().getTimeScales().getGPS(),
  42.                                      context.getReferenceDate());
  43.         }
  44.     },

  45.     /** Mission Elapsed Time. */
  46.     MET {
  47.         /** {@inheritDoc} */
  48.         public TimeConverter getConverter(final ContextBinding context) {
  49.             return new TimeConverter(new SatelliteClockScale("MET",
  50.                                                              context.getReferenceDate(),
  51.                                                              context.getDataContext().getTimeScales().getUTC(),
  52.                                                              0.0, 0.0),
  53.                                      context.getReferenceDate());
  54.         }
  55.     },

  56.     /** Mission Relative Time. */
  57.     MRT {
  58.         /** {@inheritDoc} */
  59.         public TimeConverter getConverter(final ContextBinding context) {
  60.             return new TimeConverter(new SatelliteClockScale("MRT",
  61.                                                              context.getReferenceDate(),
  62.                                                              context.getDataContext().getTimeScales().getUTC(),
  63.                                                              0.0, 0.0),
  64.                                      context.getReferenceDate());
  65.         }
  66.     },

  67.     /** Spacecraft Clock. */
  68.     SCLK {
  69.         /** {@inheritDoc} */
  70.         public TimeConverter getConverter(final ContextBinding context) {
  71.             return new TimeConverter(new SatelliteClockScale("SCLK",
  72.                                                              context.getReferenceDate(),
  73.                                                              context.getDataContext().getTimeScales().getUTC(),
  74.                                                              context.getClockCount(),
  75.                                                              context.getClockRate() - 1.0),
  76.                                      context.getReferenceDate()) {
  77.                 /** {@inheritDoc}
  78.                  * <p>
  79.                  * Special implementation: the offset is a clock count rather than a duration
  80.                  * </p>
  81.                  */
  82.                 @Override
  83.                 public double offset(final AbsoluteDate date) {
  84.                     return ((SatelliteClockScale) getTimeScale()).countAtDate(date);
  85.                 }
  86.             };
  87.         }
  88.     },

  89.     /** International Atomic Time. */
  90.     TAI {
  91.         /** {@inheritDoc} */
  92.         public TimeConverter getConverter(final ContextBinding context) {
  93.             return new TimeConverter(context.getDataContext().getTimeScales().getTAI(),
  94.                                      context.getReferenceDate());
  95.         }
  96.     },

  97.     /** Barycentric Coordinate Time. */
  98.     TCB {
  99.         /** {@inheritDoc} */
  100.         public TimeConverter getConverter(final ContextBinding context) {
  101.             return new TimeConverter(context.getDataContext().getTimeScales().getTCB(),
  102.                                      context.getReferenceDate());
  103.         }
  104.     },

  105.     /** Barycentric Dynamical Time. */
  106.     TDB {
  107.         /** {@inheritDoc} */
  108.         public TimeConverter getConverter(final ContextBinding context) {
  109.             return new TimeConverter(context.getDataContext().getTimeScales().getTDB(),
  110.                                      context.getReferenceDate());
  111.         }
  112.     },

  113.     /** Geocentric Coordinate Time. */
  114.     TCG {
  115.         /** {@inheritDoc} */
  116.         public TimeConverter getConverter(final ContextBinding context) {
  117.             return new TimeConverter(context.getDataContext().getTimeScales().getTCG(),
  118.                                      context.getReferenceDate());
  119.         }
  120.     },

  121.     /** Terrestrial Time. */
  122.     TT {
  123.         /** {@inheritDoc} */
  124.         public TimeConverter getConverter(final ContextBinding context) {
  125.             return new TimeConverter(context.getDataContext().getTimeScales().getTT(),
  126.                                      context.getReferenceDate());
  127.         }
  128.     },

  129.     /** Universal Time. */
  130.     UT1 {
  131.         /** {@inheritDoc} */
  132.         public TimeConverter getConverter(final ContextBinding context) {
  133.             return new TimeConverter(context.getDataContext().getTimeScales().getUT1(context.getConventions(), false),
  134.                                      context.getReferenceDate());
  135.         }
  136.     },

  137.     /** Universal Coordinated Time. */
  138.     UTC {
  139.         /** {@inheritDoc} */
  140.         public TimeConverter getConverter(final ContextBinding context) {
  141.             return new TimeConverter(context.getDataContext().getTimeScales().getUTC(),
  142.                                      context.getReferenceDate());
  143.         }
  144.     };

  145.     /** Get associated {@link TimeConverter}.
  146.      * @param context context binding
  147.      * @return time system for reading/writing date
  148.      * @since 11.0
  149.      */
  150.     public abstract TimeConverter getConverter(ContextBinding context);

  151.     /** Parse a value from a key=value entry.
  152.      * @param value value to parse
  153.      * @return CCSDS time system corresponding to the value
  154.      */
  155.     public static TimeSystem parse(final String value) {
  156.         for (final TimeSystem scale : values()) {
  157.             if (scale.name().equals(value)) {
  158.                 return scale;
  159.             }
  160.         }
  161.         throw new OrekitException(OrekitMessages.CCSDS_TIME_SYSTEM_NOT_IMPLEMENTED, value);
  162.     }

  163. }