GMSTScale.java

  1. /* Copyright 2002-2013 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.apache.commons.math3.util.FastMath;
  19. import org.orekit.utils.Constants;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  61.         // julian centuries since reference date
  62.         final double tc = ts / Constants.JULIAN_CENTURY;

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

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

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

  69.     }

  70.     /** {@inheritDoc} */
  71.     public double offsetToTAI(final DateComponents date, final TimeComponents time) {
  72.         final AbsoluteDate reference = new AbsoluteDate(date, time, TimeScalesFactory.getTAI());
  73.         double offset = 0;
  74.         for (int i = 0; i < 8; i++) {
  75.             offset = -offsetFromTAI(reference.shiftedBy(offset));
  76.         }
  77.         return offset;
  78.     }

  79.     /** {@inheritDoc} */
  80.     public String getName() {
  81.         return "GMST";
  82.     }

  83.     /** {@inheritDoc} */
  84.     public String toString() {
  85.         return getName();
  86.     }

  87. }