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.gnss;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import java.text.ParseException;
22  import java.util.Locale;
23  
24  import org.hipparchus.util.FastMath;
25  import org.junit.Assert;
26  import org.junit.Before;
27  import org.junit.Test;
28  import org.orekit.Utils;
29  import org.orekit.errors.OrekitException;
30  import org.orekit.propagation.analytical.gnss.data.GNSSConstants;
31  import org.orekit.propagation.analytical.gnss.data.GPSAlmanac;
32  import org.orekit.time.GNSSDate;
33  
34  
35  public class SEMParserTest {
36  
37      @Before
38      public void setUp() {
39          Utils.setDataRoot("gnss");
40      }
41  
42      @Test
43      public void testNoFile() throws IOException, ParseException {
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              Assert.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              Assert.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          Assert.assertEquals(".*\\.sem$", reader.getSupportedNames());
82  
83          // Checks the number of almanacs read
84          Assert.assertEquals(31, reader.getAlmanacs().size());
85          Assert.assertEquals(31, reader.getPRNNumbers().size());
86  
87          // Checks the first almanac read
88          final GPSAlmanac alm = reader.getAlmanacs().get(0);
89          Assert.assertEquals(1, alm.getPRN());
90          Assert.assertEquals(63, alm.getSVN());
91          Assert.assertEquals(862, alm.getWeek());
92          Assert.assertEquals(319488.0, alm.getTime(), 0.);
93          Assert.assertEquals(5.15360253906250E+03, FastMath.sqrt(alm.getSma()), FastMath.ulp(5.E+03));
94          Assert.assertEquals(5.10072708129883E-03, alm.getE(), FastMath.ulp(8E-05));
95          Assert.assertEquals(6.84547424316406E-03,  (alm.getI0() / GNSSConstants.GNSS_PI) - 0.30, 1.E-17);
96          Assert.assertEquals(0., alm.getIDot(), 0.);
97          Assert.assertEquals(-2.08778738975525E-01, alm.getOmega0() / GNSSConstants.GNSS_PI, FastMath.ulp(-2E-01));
98          Assert.assertEquals(-2.48837750405073E-09, alm.getOmegaDot() / GNSSConstants.GNSS_PI, FastMath.ulp(-3E-09));
99          Assert.assertEquals(1.46086812019348E-01, alm.getPa() / GNSSConstants.GNSS_PI, FastMath.ulp(1E-01));
100         Assert.assertEquals(4.55284833908081E-01, alm.getM0() / GNSSConstants.GNSS_PI, FastMath.ulp(4E-01));
101         Assert.assertEquals(1.33514404296875E-05, alm.getAf0(), FastMath.ulp(1E-05));
102         Assert.assertEquals(0., alm.getAf1(), 0.);
103         Assert.assertEquals(0, alm.getHealth());
104         Assert.assertEquals(0, alm.getURA());
105         Assert.assertEquals(11, alm.getSatConfiguration());
106         Assert.assertEquals("SEM", alm.getSource());
107         Assert.assertEquals(alm.getDate().durationFrom(new GNSSDate(862, 319488 * 1000., SatelliteSystem.GPS).getDate()), 0, 0);
108         Assert.assertEquals(0., alm.getCic(), 0.);
109         Assert.assertEquals(0., alm.getCis(), 0.);
110         Assert.assertEquals(0., alm.getCrc(), 0.);
111         Assert.assertEquals(0., alm.getCrs(), 0.);
112         Assert.assertEquals(0., alm.getCuc(), 0.);
113         Assert.assertEquals(0., alm.getCus(), 0.);
114         Assert.assertEquals(1.4585998186870066E-4, alm.getMeanMotion(), 0.);
115     }
116 
117     @Test
118     public void testLoadDefault() throws IOException, ParseException, 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         Assert.assertEquals(".*\\.al3$", reader.getSupportedNames());
125 
126         // Checks the number of almanacs read
127         Assert.assertEquals(31, reader.getAlmanacs().size());
128         Assert.assertEquals(31, reader.getPRNNumbers().size());
129 
130         // Checks the last almanac read
131         final GPSAlmanac alm = reader.getAlmanacs().get(reader.getAlmanacs().size() - 1);
132         Assert.assertEquals(32, alm.getPRN());
133         Assert.assertEquals(70, alm.getSVN());
134         Assert.assertEquals(862, alm.getWeek());
135         Assert.assertEquals(319488.0, alm.getTime(), 0.);
136         Assert.assertEquals(5.16559130859375E+03, FastMath.sqrt(alm.getSma()), FastMath.ulp(5.E+03));
137         Assert.assertEquals(7.96318054199219E-05, alm.getE(), FastMath.ulp(8E-05));
138         Assert.assertEquals(5.53321838378906E-03,  (alm.getI0() / GNSSConstants.GNSS_PI) - 0.30, 1.E-17);
139         Assert.assertEquals(0., alm.getIDot(), 0.);
140         Assert.assertEquals(4.53996539115906E-01, alm.getOmega0() / GNSSConstants.GNSS_PI, FastMath.ulp(5E-01));
141         Assert.assertEquals(-2.46291165240109E-09, alm.getOmegaDot() / GNSSConstants.GNSS_PI, FastMath.ulp(-3E-09));
142         Assert.assertEquals(7.92368650436401E-02, alm.getPa() / GNSSConstants.GNSS_PI, FastMath.ulp(8E-02));
143         Assert.assertEquals(3.84885787963867E-01, alm.getM0() / GNSSConstants.GNSS_PI, FastMath.ulp(4E-01));
144         Assert.assertEquals(9.5367431640625E-6, alm.getAf0(), 0.);
145         Assert.assertEquals(3.63797880709171E-12, alm.getAf1(), 0.);
146         Assert.assertEquals(63, alm.getHealth());
147         Assert.assertEquals(0, alm.getURA());
148         Assert.assertEquals(11, alm.getSatConfiguration());
149         Assert.assertEquals("SEM", alm.getSource());
150         Assert.assertTrue(alm.getDate().durationFrom(new GNSSDate(862, 319488 * 1000., SatelliteSystem.GPS).getDate()) == 0);
151         Assert.assertEquals(0., alm.getCic(), 0.);
152         Assert.assertEquals(0., alm.getCis(), 0.);
153         Assert.assertEquals(0., alm.getCrc(), 0.);
154         Assert.assertEquals(0., alm.getCrs(), 0.);
155         Assert.assertEquals(0., alm.getCuc(), 0.);
156         Assert.assertEquals(0., alm.getCus(), 0.);
157         Assert.assertEquals(1.4484676213604242E-4, alm.getMeanMotion(), 0.);
158     }
159 
160 }