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