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.frames;
18  
19  
20  import java.util.SortedSet;
21  import java.util.TreeSet;
22  
23  import org.junit.Assert;
24  import org.junit.Test;
25  import org.orekit.data.AbstractFilesLoaderTest;
26  import org.orekit.time.AbsoluteDate;
27  import org.orekit.time.ChronologicalComparator;
28  import org.orekit.time.TimeScalesFactory;
29  import org.orekit.utils.Constants;
30  import org.orekit.utils.IERSConventions;
31  
32  
33  public class EOPC04FilesLoaderTest extends AbstractFilesLoaderTest {
34  
35      @Test
36      public void testMissingMonths() {
37          setRoot("missing-months");
38          IERSConventions.NutationCorrectionConverter converter =
39                  IERSConventions.IERS_2010.getNutationCorrectionConverter();
40          SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
41          new EOPC04FilesLoader(FramesFactory.EOPC04_2000_FILENAME, manager, () -> utc).fillHistory(converter, history);
42          Assert.assertTrue(getMaxGap(history) > 5);
43      }
44  
45      @Test
46      public void testStartDate() {
47          setRoot("regular-data");
48          IERSConventions.NutationCorrectionConverter converter =
49                  IERSConventions.IERS_2010.getNutationCorrectionConverter();
50          SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
51          new EOPC04FilesLoader(FramesFactory.EOPC04_2000_FILENAME, manager, () -> utc).fillHistory(converter, history);
52          Assert.assertEquals(new AbsoluteDate(2003, 1, 1, TimeScalesFactory.getUTC()),
53                              new EOPHistory(IERSConventions.IERS_2010, history, true).getStartDate());
54      }
55  
56      @Test
57      public void testEndDate() {
58          setRoot("regular-data");
59          IERSConventions.NutationCorrectionConverter converter =
60                  IERSConventions.IERS_2010.getNutationCorrectionConverter();
61          SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
62          new EOPC04FilesLoader(FramesFactory.EOPC04_2000_FILENAME, manager, () -> utc).fillHistory(converter, history);
63          Assert.assertEquals(new AbsoluteDate(2005, 12, 31, TimeScalesFactory.getUTC()),
64                              new EOPHistory(IERSConventions.IERS_2010, history, true).getEndDate());
65      }
66  
67      @Test
68      public void testContent() {
69          setRoot("regular-data");
70          IERSConventions.NutationCorrectionConverter converter =
71                  IERSConventions.IERS_2010.getNutationCorrectionConverter();
72          SortedSet<EOPEntry> data = new TreeSet<EOPEntry>(new ChronologicalComparator());
73          new EOPC04FilesLoader(FramesFactory.EOPC04_2000_FILENAME, manager, () -> utc).fillHistory(converter, data);
74          EOPHistory history = new EOPHistory(IERSConventions.IERS_2010, data, true);
75          AbsoluteDate date = new AbsoluteDate(2003, 1, 7, 12, 0, 0, TimeScalesFactory.getUTC());
76          Assert.assertEquals(        (9 * ( 0.0007777 +  0.0008565) - ( 0.0005883 +  0.0008758)) / 16,  history.getLOD(date), 1.0e-10);
77          Assert.assertEquals(        (9 * (-0.2920264 + -0.2928461) - (-0.2913281 + -0.2937305)) / 16,  history.getUT1MinusUTC(date), 1.0e-10);
78          Assert.assertEquals(asToRad((9 * (-0.105933  + -0.108553)  - (-0.103513  + -0.111054))  / 16), history.getPoleCorrection(date).getXp(), 1.0e-10);
79          Assert.assertEquals(asToRad((9 * ( 0.201451  +  0.203596)  - ( 0.199545  +  0.205660))  / 16), history.getPoleCorrection(date).getYp(), 1.0e-10);
80          Assert.assertEquals(ITRFVersion.ITRF_2008, history.getITRFVersion(date));
81      }
82  
83      private double asToRad(double as) {
84          return as * Constants.ARC_SECONDS_TO_RADIANS;
85      }
86  
87  }