1   /* Copyright 2002-2022 CS GROUP
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.time;
18  
19  
20  import org.junit.Assert;
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.orekit.Utils;
24  import org.orekit.frames.ITRFVersion;
25  import org.orekit.utils.Constants;
26  import org.orekit.utils.IERSConventions;
27  
28  
29  public class TCGScaleTest {
30  
31      @Test
32      public void testRatio() {
33          TimeScale scale = TimeScalesFactory.getTCG();
34          Assert.assertEquals("TCG", scale.toString());
35          final double dtTT = 1e6;
36          final AbsoluteDate t1 = AbsoluteDate.J2000_EPOCH;
37          final AbsoluteDate t2 = t1.shiftedBy(dtTT);
38          final double dtTCG = dtTT + scale.offsetFromTAI(t2) - scale.offsetFromTAI(t1);
39          Assert.assertEquals(1 - 6.969290134e-10, dtTT / dtTCG, 1.0e-15);
40      }
41  
42      @Test
43      public void testSymmetry() {
44          TimeScale scale = TimeScalesFactory.getTCG();
45          for (double dt = -10000; dt < 10000; dt += 123.456789) {
46              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt * Constants.JULIAN_DAY);
47              double dt1 = scale.offsetFromTAI(date);
48              DateTimeComponents components = date.getComponents(scale);
49              double dt2 = scale.offsetToTAI(components.getDate(), components.getTime());
50              Assert.assertEquals( 0.0, dt1 + dt2, 1.0e-10);
51          }
52      }
53  
54      @Test
55      public void testDuringLeap() {
56          final TimeScale utc   = TimeScalesFactory.getUTC();
57          final TimeScale scale = TimeScalesFactory.getTCG();
58          final AbsoluteDate before = new AbsoluteDate(new DateComponents(1983, 06, 30),
59                                                       new TimeComponents(23, 59, 59),
60                                                       utc);
61          final AbsoluteDate during = before.shiftedBy(1.25);
62          Assert.assertEquals(61, utc.minuteDuration(during));
63          Assert.assertEquals(1.0, utc.getLeap(during), 1.0e-10);
64          Assert.assertEquals(60, scale.minuteDuration(during));
65          Assert.assertEquals(0.0, scale.getLeap(during), 1.0e-10);
66      }
67  
68      @Test
69      public void testReference() {
70          DateComponents  referenceDate = new DateComponents(1977, 01, 01);
71          TimeComponents  thirtyTwo     = new TimeComponents(0, 0, 32.184);
72          AbsoluteDate ttRef         = new AbsoluteDate(referenceDate, thirtyTwo, TimeScalesFactory.getTT());
73          AbsoluteDate tcgRef        = new AbsoluteDate(referenceDate, thirtyTwo, TimeScalesFactory.getTCG());
74          AbsoluteDate taiRef        = new AbsoluteDate(referenceDate, TimeComponents.H00, TimeScalesFactory.getTAI());
75          AbsoluteDate utcRef        = new AbsoluteDate(new DateComponents(1976, 12, 31),
76                                                        new TimeComponents(23, 59, 45),
77                                                        TimeScalesFactory.getUTC());
78          Assert.assertEquals(0, ttRef.durationFrom(tcgRef), 1.0e-15);
79          Assert.assertEquals(0, ttRef.durationFrom(taiRef), 1.0e-15);
80          Assert.assertEquals(0, ttRef.durationFrom(utcRef), 1.0e-15);
81      }
82  
83      @Test
84      public void testSofa() {
85          TimeScale tt  = TimeScalesFactory.getTT();
86          AbsoluteDate date = new AbsoluteDate(2006, 1, 15, 21, 25, 10.5000096, tt);
87          double delta = TimeScalesFactory.getTCG().offsetFromTAI(date) - tt.offsetFromTAI(date);
88          Assert.assertEquals(Constants.JULIAN_DAY * (0.8924900312508587113 -  0.892482639), delta, 5.0e-10);
89      }
90  
91      @Test
92      public void testAAS06134() {
93  
94          // this reference test has been extracted from the following paper:
95          // Implementation Issues Surrounding the New IAU Reference Systems for Astrodynamics
96          // David A. Vallado, John H. Seago, P. Kenneth Seidelmann
97          // http://www.centerforspace.com/downloads/files/pubs/AAS-06-134.pdf
98          // Note that the dUT1 here is -0.439962, whereas it is -0.4399619 in the book
99          Utils.setLoaders(IERSConventions.IERS_1996,
100                          Utils.buildEOPList(IERSConventions.IERS_1996, ITRFVersion.ITRF_2008, new double[][] {
101                              { 53098, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
102                              { 53099, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
103                              { 53100, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
104                              { 53101, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
105                              { 53102, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
106                              { 53103, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
107                              { 53104, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
108                              { 53105, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN }
109                          }));
110         AbsoluteDate date =
111                 new AbsoluteDate(2004, 4, 6, 7, 51, 28.386009, TimeScalesFactory.getUTC());
112         DateTimeComponents components = date.getComponents(TimeScalesFactory.getTCG());
113         Assert.assertEquals(2004,            components.getDate().getYear());
114         Assert.assertEquals(   4,            components.getDate().getMonth());
115         Assert.assertEquals(   6,            components.getDate().getDay());
116         Assert.assertEquals(   7,            components.getTime().getHour());
117         Assert.assertEquals(  52,            components.getTime().getMinute());
118         Assert.assertEquals(  33.1695861742, components.getTime().getSecond(), 1.0e-10);
119 
120     }
121 
122     @Before
123     public void setUp() {
124         Utils.setDataRoot("regular-data");
125     }
126 
127 }