1   /* Copyright 2022-2025 Thales Alenia Space
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.gnss;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.BeforeEach;
21  import org.junit.jupiter.api.Test;
22  import org.orekit.Utils;
23  import org.orekit.errors.OrekitException;
24  import org.orekit.errors.OrekitMessages;
25  import org.orekit.frames.EOPBasedTransformProvider;
26  import org.orekit.frames.FactoryManagedFrame;
27  import org.orekit.frames.Frame;
28  import org.orekit.frames.FramesFactory;
29  import org.orekit.frames.ITRFVersion;
30  import org.orekit.frames.Predefined;
31  import org.orekit.frames.VersionedITRF;
32  import org.orekit.utils.IERSConventions;
33  
34  public class IGSUtilsTest {
35  
36      @BeforeEach
37      public void setUp() {
38          Utils.setDataRoot("gnss");
39      }
40  
41      @Test
42      public void testItrfVersion() {
43          Assertions.assertSame(ITRFVersion.ITRF_1996, getItrfVersion("ITRF96"));
44          Assertions.assertSame(ITRFVersion.ITRF_2014, getItrfVersion("IGS14"));
45          Assertions.assertSame(ITRFVersion.ITRF_2020, getItrfVersion("ITR20"));
46          Assertions.assertSame(ITRFVersion.ITRF_2008, getItrfVersion("SLR08"));
47      }
48  
49      @Test public void testUnknown() {
50          Assertions.assertSame(Predefined.ITRF_CIO_CONV_2010_ACCURATE_EOP,
51                                ((FactoryManagedFrame) IGSUtils.guessFrame("UNDEF")).getFactoryKey());
52          Assertions.assertSame(Predefined.ITRF_CIO_CONV_2010_ACCURATE_EOP,
53                                ((FactoryManagedFrame) IGSUtils.guessFrame("WGS84")).getFactoryKey());
54      }
55  
56      @Test
57      public void testIersConvention() {
58          Assertions.assertSame(IERSConventions.IERS_1996, getConvention("ITRF88"));
59          Assertions.assertSame(IERSConventions.IERS_1996, getConvention("ITRF89"));
60          Assertions.assertSame(IERSConventions.IERS_1996, getConvention("ITRF96"));
61          Assertions.assertSame(IERSConventions.IERS_1996, getConvention("ITRF00"));
62          Assertions.assertSame(IERSConventions.IERS_2003, getConvention("ITRF05"));
63          Assertions.assertSame(IERSConventions.IERS_2003, getConvention("ITRF08"));
64          Assertions.assertSame(IERSConventions.IERS_2010, getConvention("ITRF14"));
65          Assertions.assertSame(IERSConventions.IERS_2010, getConvention("ITRF20"));
66      }
67  
68      @Test
69      public void testGcrf() {
70          Assertions.assertNull(IGSUtils.guessFrame("GCRF").getParent());
71          Assertions.assertNull(IGSUtils.guessFrame(" GCRF").getParent());
72          Assertions.assertNull(IGSUtils.guessFrame("GCRF ").getParent());
73      }
74  
75      @Test
76      public void testEME2000() {
77          Assertions.assertSame(FramesFactory.getEME2000(), IGSUtils.guessFrame("EME00"));
78          Assertions.assertSame(FramesFactory.getEME2000(), IGSUtils.guessFrame("EME2K"));
79      }
80  
81      @Test
82      public void testITRFNames() {
83          Assertions.assertEquals("IGS89", IGSUtils.frameName(FramesFactory.getITRF(ITRFVersion.ITRF_1989,
84                                                                                    IERSConventions.IERS_2010,
85                                                                                    false)));
86          Assertions.assertEquals("IGS96", IGSUtils.frameName(FramesFactory.getITRF(ITRFVersion.ITRF_1996,
87                                                                                    IERSConventions.IERS_2010,
88                                                                                    false)));
89          Assertions.assertEquals("IGS00", IGSUtils.frameName(FramesFactory.getITRF(ITRFVersion.ITRF_2000,
90                                                                                    IERSConventions.IERS_2010,
91                                                                                    false)));
92          Assertions.assertEquals("IGS05", IGSUtils.frameName(FramesFactory.getITRF(ITRFVersion.ITRF_2005,
93                                                                                    IERSConventions.IERS_2010,
94                                                                                    false)));
95          Assertions.assertEquals("IGS14", IGSUtils.frameName(FramesFactory.getITRF(ITRFVersion.ITRF_2014,
96                                                                                    IERSConventions.IERS_2010,
97                                                                                    false)));
98          Assertions.assertEquals("IGS20", IGSUtils.frameName(FramesFactory.getITRF(ITRFVersion.ITRF_2020,
99                                                                                    IERSConventions.IERS_2010,
100                                                                                   false)));
101     }
102 
103     @Test
104     public void testInertialNames() {
105         Assertions.assertEquals("GCRF",  IGSUtils.frameName(FramesFactory.getGCRF()));
106         Assertions.assertEquals("EME2K", IGSUtils.frameName(FramesFactory.getEME2000()));
107     }
108 
109     @Test
110     public void testUnsupportedFrame() {
111         try {
112             IGSUtils.frameName(FramesFactory.getMOD(IERSConventions.IERS_2010));
113             Assertions.fail("an exception should have been thrown");
114         } catch (OrekitException oe) {
115             Assertions.assertEquals(OrekitMessages.FRAME_NOT_ALLOWED, oe.getSpecifier());
116             Assertions.assertEquals("MOD/2010", oe.getParts()[0]);
117         }
118     }
119 
120     private ITRFVersion getItrfVersion(String key) {
121         return ((VersionedITRF) IGSUtils.guessFrame(key)).getITRFVersion();
122     }
123 
124    private IERSConventions getConvention(final String key) {
125         final Frame frame = IGSUtils.guessFrame(key);
126         final EOPBasedTransformProvider provider =
127             (EOPBasedTransformProvider) frame.getTransformProvider();
128         return provider.getEOPHistory().getConventions();
129     }
130 
131 }