1   /* Copyright 2002-2025 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.gnss;
18  
19  import org.hipparchus.util.FastMath;
20  import org.junit.jupiter.api.Assertions;
21  import org.junit.jupiter.api.BeforeEach;
22  import org.junit.jupiter.api.Test;
23  import org.orekit.Utils;
24  import org.orekit.errors.OrekitException;
25  import org.orekit.propagation.analytical.gnss.data.GNSSConstants;
26  import org.orekit.propagation.analytical.gnss.data.GPSAlmanac;
27  import org.orekit.time.GNSSDate;
28  
29  import java.io.IOException;
30  import java.io.InputStream;
31  import java.text.ParseException;
32  import java.util.Locale;
33  
34  
35  public class SEMParserTest {
36  
37      @BeforeEach
38      public void setUp() {
39          Utils.setDataRoot("gnss");
40      }
41  
42      @Test
43      public void testNoFile() {
44          // the parser for reading SEM files with *.sem as supported name for SEM files
45          SEMParser reader = new SEMParser(".*\\.sem$");
46          // No such YUMA file, should throw an exception
47          try {
48              reader.loadData();
49          } catch (OrekitException oe) {
50              Assertions.assertEquals("aucun fichier d'almanach SEM n'a été trouvé", oe.getMessage(Locale.FRANCE));
51          }
52      }
53  
54      @Test
55      public void testWrongFile() throws IOException, ParseException {
56          // the parser for reading SEM files with default supported name *.al3 for SEM files
57          SEMParser reader = new SEMParser(null);
58          // the SEM file to read
59          final String fileName = "/gnss/wrong_sem.txt";
60          final InputStream in = getClass().getResourceAsStream(fileName);
61          // Reads the SEM file
62          // No such YUMA file, should throw an exception
63          try {
64              reader.loadData(in, fileName);
65          } catch (OrekitException oe) {
66              Assertions.assertEquals("le fichier /gnss/wrong_sem.txt n'est pas un fichier d'almanach SEM supporté",
67                                  oe.getMessage(Locale.FRANCE));
68          }
69      }
70  
71      @Test
72      public void testLoadData() throws IOException, ParseException, OrekitException {
73          // the parser for reading SEM files with *.sem as supported name for SEM files
74          SEMParser reader = new SEMParser(".*\\.sem$");
75          // the SEM file to read
76          final String fileName = "/gnss/current.al3";
77          final InputStream in = getClass().getResourceAsStream(fileName);
78          // Reads the SEM file
79          reader.loadData(in, fileName);
80  
81          Assertions.assertEquals(".*\\.sem$", reader.getSupportedNames());
82  
83          // Checks the number of almanacs read
84          Assertions.assertEquals(31, reader.getAlmanacs().size());
85          Assertions.assertEquals(31, reader.getPRNNumbers().size());
86  
87          // Checks the first almanac read
88          final GPSAlmanac alm = reader.getAlmanacs().get(0);
89          Assertions.assertEquals(1, alm.getPRN());
90          Assertions.assertEquals(63, alm.getSVN());
91          Assertions.assertEquals(862, alm.getWeek());
92          Assertions.assertEquals(319488.0, alm.getTime(), 0.);
93          Assertions.assertEquals(5.15360253906250E+03, FastMath.sqrt(alm.getSma()), FastMath.ulp(5.E+03));
94          Assertions.assertEquals(5.10072708129883E-03, alm.getE(), FastMath.ulp(8E-05));
95          Assertions.assertEquals(6.84547424316406E-03,  (alm.getI0() / GNSSConstants.GNSS_PI) - 0.30, 1.E-17);
96          Assertions.assertEquals(0., alm.getIDot(), 0.);
97          Assertions.assertEquals(-2.08778738975525E-01, alm.getOmega0() / GNSSConstants.GNSS_PI, FastMath.ulp(-2E-01));
98          Assertions.assertEquals(-2.48837750405073E-09, alm.getOmegaDot() / GNSSConstants.GNSS_PI, FastMath.ulp(-3E-09));
99          Assertions.assertEquals(1.46086812019348E-01, alm.getPa() / GNSSConstants.GNSS_PI, FastMath.ulp(1E-01));
100         Assertions.assertEquals(4.55284833908081E-01, alm.getM0() / GNSSConstants.GNSS_PI, FastMath.ulp(4E-01));
101         Assertions.assertEquals(1.33514404296875E-05, alm.getAf0(), FastMath.ulp(1E-05));
102         Assertions.assertEquals(0., alm.getAf1(), 0.);
103         Assertions.assertEquals(0, alm.getHealth());
104         Assertions.assertEquals(0, alm.getURA());
105         Assertions.assertEquals(11, alm.getSatConfiguration());
106         Assertions.assertEquals("SEM", alm.getSource());
107         Assertions.assertEquals(alm.getDate().durationFrom(new GNSSDate(862, 319488.0, SatelliteSystem.GPS).getDate()), 0, 0);
108         Assertions.assertEquals(0., alm.getCic(), 0.);
109         Assertions.assertEquals(0., alm.getCis(), 0.);
110         Assertions.assertEquals(0., alm.getCrc(), 0.);
111         Assertions.assertEquals(0., alm.getCrs(), 0.);
112         Assertions.assertEquals(0., alm.getCuc(), 0.);
113         Assertions.assertEquals(0., alm.getCus(), 0.);
114         Assertions.assertEquals(1.4585998186870066E-4, alm.getMeanMotion0(), 0.);
115     }
116 
117     @Test
118     public void testLoadDefault() throws OrekitException {
119         // the parser for reading SEM files with default supported name *.al3 for SEM files
120         SEMParser reader = new SEMParser(null);
121         // Reads the SEM file
122         reader.loadData();
123 
124         Assertions.assertEquals(".*\\.al3$", reader.getSupportedNames());
125 
126         // Checks the number of almanacs read
127         Assertions.assertEquals(31, reader.getAlmanacs().size());
128         Assertions.assertEquals(31, reader.getPRNNumbers().size());
129 
130         // Checks the last almanac read
131         final GPSAlmanac alm = reader.getAlmanacs().get(reader.getAlmanacs().size() - 1);
132         Assertions.assertEquals(32, alm.getPRN());
133         Assertions.assertEquals(70, alm.getSVN());
134         Assertions.assertEquals(862, alm.getWeek());
135         Assertions.assertEquals(319488.0, alm.getTime(), 0.);
136         Assertions.assertEquals(5.16559130859375E+03, FastMath.sqrt(alm.getSma()), FastMath.ulp(5.E+03));
137         Assertions.assertEquals(7.96318054199219E-05, alm.getE(), FastMath.ulp(8E-05));
138         Assertions.assertEquals(5.53321838378906E-03,  (alm.getI0() / GNSSConstants.GNSS_PI) - 0.30, 1.E-17);
139         Assertions.assertEquals(0., alm.getIDot(), 0.);
140         Assertions.assertEquals(4.53996539115906E-01, alm.getOmega0() / GNSSConstants.GNSS_PI, FastMath.ulp(5E-01));
141         Assertions.assertEquals(-2.46291165240109E-09, alm.getOmegaDot() / GNSSConstants.GNSS_PI, FastMath.ulp(-3E-09));
142         Assertions.assertEquals(7.92368650436401E-02, alm.getPa() / GNSSConstants.GNSS_PI, FastMath.ulp(8E-02));
143         Assertions.assertEquals(3.84885787963867E-01, alm.getM0() / GNSSConstants.GNSS_PI, FastMath.ulp(4E-01));
144         Assertions.assertEquals(9.5367431640625E-6, alm.getAf0(), 0.);
145         Assertions.assertEquals(3.63797880709171E-12, alm.getAf1(), 0.);
146         Assertions.assertEquals(63, alm.getHealth());
147         Assertions.assertEquals(0, alm.getURA());
148         Assertions.assertEquals(11, alm.getSatConfiguration());
149         Assertions.assertEquals("SEM", alm.getSource());
150         Assertions.assertEquals(0, alm.getDate().durationFrom(new GNSSDate(862, 319488.0, SatelliteSystem.GPS).getDate()), 1.0e-15);
151         Assertions.assertEquals(0., alm.getCic(), 0.);
152         Assertions.assertEquals(0., alm.getCis(), 0.);
153         Assertions.assertEquals(0., alm.getCrc(), 0.);
154         Assertions.assertEquals(0., alm.getCrs(), 0.);
155         Assertions.assertEquals(0., alm.getCuc(), 0.);
156         Assertions.assertEquals(0., alm.getCus(), 0.);
157         Assertions.assertEquals(1.4484676213604242E-4, alm.getMeanMotion0(), 0.);
158     }
159 
160 }