GMSTScale.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.time;

  18. import org.hipparchus.RealFieldElement;
  19. import org.hipparchus.util.FastMath;
  20. import org.orekit.utils.Constants;

  21. /** Greenwich Mean Sidereal Time.
  22.  * <p>The Greenwich Mean Sidereal Time is the hour angle between the meridian of Greenwich
  23.  * and mean equinox of date at 0h UT1.</p>
  24.  * <p>This is intended to be accessed thanks to the {@link TimeScalesFactory} class,
  25.  * so there is no public constructor.</p>
  26.  * @author Luc Maisonobe
  27.  * @see AbsoluteDate
  28.  * @since 5.1
  29.  */
  30. public class GMSTScale implements TimeScale {

  31.     /** Serializable UID. */
  32.     private static final long serialVersionUID = 20131209L;

  33.     /** Duration of one julian day. */
  34.     private static final double FULL_DAY = Constants.JULIAN_DAY;

  35.     /** Duration of an half julian day. */
  36.     private static final double HALF_DAY = Constants.JULIAN_DAY / 2.0;

  37.     /** Coefficient for degree 0. */
  38.     private static final double C0 = 24110.54841;

  39.     /** Coefficient for degree 1. */
  40.     private static final double C1 = 8640184.812866;

  41.     /** Coefficient for degree 2. */
  42.     private static final double C2 = 0.093104;

  43.     /** Coefficient for degree 3. */
  44.     private static final double C3 = -0.0000062;

  45.     /** Universal Time 1 time scale. */
  46.     private final UT1Scale     ut1;

  47.     /** Reference date for GMST. */
  48.     private final AbsoluteDate referenceDate;

  49.     // GST 1982: 24110.54841 + 8640184.812866 t + 0.093104 t2 - 6.2e-6 t3
  50.     // GST 2000: 24110.5493771 + 8639877.3173760 tu + 307.4771600 te + 0.0931118 te2 - 0.0000062 te3 + 0.0000013 te4

  51.     /** Package private constructor for the factory.
  52.      * @param ut1 Universal Time 1 scale
  53.      */
  54.     GMSTScale(final UT1Scale ut1) {
  55.         this.ut1           = ut1;
  56.         this.referenceDate = new AbsoluteDate(2000, 1, 1, 12, 0, 0.0, ut1);
  57.     }

  58.     /** {@inheritDoc} */
  59.     @Override
  60.     public double offsetFromTAI(final AbsoluteDate date) {

  61.         // julian seconds since reference date
  62.         final double ts = date.durationFrom(referenceDate);

  63.         // julian centuries since reference date
  64.         final double tc = ts / Constants.JULIAN_CENTURY;

  65.         // GMST at 0h00 UT1 in seconds = offset with respect to UT1
  66.         final double gmst0h = C0 + tc * (C1 + tc * (C2 + tc * C3));

  67.         // offset with respect to TAI
  68.         final double offset = gmst0h + ut1.offsetFromTAI(date);

  69.         // normalize offset between -43200 and +43200 seconds
  70.         return offset - FULL_DAY * FastMath.floor((offset + HALF_DAY) / FULL_DAY);

  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     public <T extends RealFieldElement<T>> T offsetFromTAI(final FieldAbsoluteDate<T> date) {

  75.         // julian seconds since reference date
  76.         final T ts = date.durationFrom(referenceDate);

  77.         // julian centuries since reference date
  78.         final T tc = ts.divide(Constants.JULIAN_CENTURY);

  79.         // GMST at 0h00 UT1 in seconds = offset with respect to UT1
  80.         final T gmst0h = tc.multiply(C3).add(C2).multiply(tc).add(C1).multiply(tc).add(C0);

  81.         // offset with respect to TAI
  82.         final T offset = gmst0h.add(ut1.offsetFromTAI(date));

  83.         // normalize offset between -43200 and +43200 seconds
  84.         return offset.subtract(FULL_DAY * FastMath.floor((offset.getReal() + HALF_DAY) / FULL_DAY));

  85.     }

  86.     /** {@inheritDoc} */
  87.     public String getName() {
  88.         return "GMST";
  89.     }

  90.     /** {@inheritDoc} */
  91.     public String toString() {
  92.         return getName();
  93.     }

  94. }