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.GPSAlmanac;
31  import org.orekit.time.GNSSDate;
32  
33  
34  public class YUMAParserTest {
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 Yuma files with a pattern
44          YUMAParser reader = new YUMAParser(".*\\.yum$");
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 Yuma 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 Yuma files with a pattern
56          YUMAParser reader = new YUMAParser(".*\\.yum$");
57          // the SEM file to read
58          final String fileName = "/gnss/wrong_yuma.txt";
59          final InputStream in = getClass().getResourceAsStream(fileName);
60          // Reads the YUMA file, should throw an exception
61          try {
62              reader.loadData(in, fileName);
63          } catch (OrekitException oe) {
64              Assert.assertEquals("le fichier /gnss/wrong_yuma.txt n'est pas un fichier d'almanach Yuma supporté",
65                                  oe.getMessage(Locale.FRANCE));
66          }
67      }
68  
69      @Test
70      public void testLoadData() throws IOException, ParseException, OrekitException {
71          // the parser for reading Yuma files with a pattern
72          YUMAParser reader = new YUMAParser(".*\\.yum$");
73          // the YUMA file to read
74          final String fileName = "/gnss/yuma.txt";
75          final InputStream in = getClass().getResourceAsStream(fileName);
76          reader.loadData(in, fileName);
77  
78          Assert.assertEquals(".*\\.yum$", reader.getSupportedNames());
79  
80          // Checks the whole file read
81          Assert.assertEquals(31, reader.getAlmanacs().size());
82          Assert.assertEquals(31, reader.getPRNNumbers().size());
83  
84          // Checks the last almanac read
85          final GPSAlmanac alm = reader.getAlmanacs().get(reader.getAlmanacs().size() - 1);
86          Assert.assertEquals(32, alm.getPRN());
87          Assert.assertEquals(-1, alm.getSVN());
88          Assert.assertEquals(862, alm.getWeek());
89          Assert.assertEquals(319488.0, alm.getTime(), 0.);
90          Assert.assertEquals(5165.591309, FastMath.sqrt(alm.getSma()), FastMath.ulp(5.E+03));
91          Assert.assertEquals(0.7963180542E-004, alm.getE(), FastMath.ulp(8E-05));
92          Assert.assertEquals(0.9598609143,  alm.getI0(), 0.);
93          Assert.assertEquals(0., alm.getIDot(), 0.);
94          Assert.assertEquals(0.1426272192E+001, alm.getOmega0(), 0.);
95          Assert.assertEquals(-0.7737465154E-008, alm.getOmegaDot(), FastMath.ulp(-8E-09));
96          Assert.assertEquals(0.248929953, alm.getPa(), 0.);
97          Assert.assertEquals(0.1209154364E+001, alm.getM0(), 0.);
98          Assert.assertEquals(0.9536743164E-005, alm.getAf0(), 0.);
99          Assert.assertEquals(0.3637978807E-011, alm.getAf1(), 0.);
100         Assert.assertEquals(63, alm.getHealth());
101         Assert.assertEquals(-1, alm.getURA());
102         Assert.assertEquals(-1, alm.getSatConfiguration());
103         Assert.assertEquals("YUMA", alm.getSource());
104         Assert.assertTrue(alm.getDate().durationFrom(new GNSSDate(862, 319488 * 1000., SatelliteSystem.GPS).getDate()) == 0);
105         Assert.assertEquals(0., alm.getCic(), 0.);
106         Assert.assertEquals(0., alm.getCis(), 0.);
107         Assert.assertEquals(0., alm.getCrc(), 0.);
108         Assert.assertEquals(0., alm.getCrs(), 0.);
109         Assert.assertEquals(0., alm.getCuc(), 0.);
110         Assert.assertEquals(0., alm.getCus(), 0.);
111         Assert.assertEquals(1.4484676210186782E-4, alm.getMeanMotion(), 0.);
112     }
113 
114     @Test
115     public void testLoadDefault() throws IOException, ParseException, OrekitException {
116         // the parser for reading Yuma files
117         YUMAParser reader = new YUMAParser(null);
118         reader.loadData();
119 
120         Assert.assertEquals(".*\\.alm$", reader.getSupportedNames());
121 
122         Assert.assertEquals(31, reader.getAlmanacs().size());
123         Assert.assertEquals(31, reader.getPRNNumbers().size());
124 
125         // Checks the first almanac read
126         final GPSAlmanac alm = reader.getAlmanacs().get(0);
127         Assert.assertEquals(1, alm.getPRN());
128         Assert.assertEquals(-1, alm.getSVN());
129         Assert.assertEquals(866, alm.getWeek());
130         Assert.assertEquals(589824.0, alm.getTime(), 0.);
131         Assert.assertEquals(5153.602051, FastMath.sqrt(alm.getSma()), FastMath.ulp(5.E+03));
132         Assert.assertEquals(0.5221366882E-02, alm.getE(), 0.);
133         Assert.assertEquals(0.963785748,  alm.getI0(), 0.);
134         Assert.assertEquals(0., alm.getIDot(), 0.);
135         Assert.assertEquals(-1.159458779E+000, alm.getOmega0(), 1.e-9);
136         Assert.assertEquals(-0.7897471819E-008, alm.getOmegaDot(), FastMath.ulp(-8E-09));
137         Assert.assertEquals(0.451712027, alm.getPa(), 1.e-9);
138         Assert.assertEquals(-0.2105941778E+001, alm.getM0(), 1.e-9);
139         Assert.assertEquals(0.1621246338E-004, alm.getAf0(), 1.e-14);
140         Assert.assertEquals(0.0, alm.getAf1(), 0.);
141         Assert.assertEquals(0, alm.getHealth());
142         Assert.assertEquals(-1, alm.getURA());
143         Assert.assertEquals(-1, alm.getSatConfiguration());
144         Assert.assertEquals("YUMA", alm.getSource());
145         Assert.assertTrue(alm.getDate().durationFrom(new GNSSDate(866, 589824 * 1000., SatelliteSystem.GPS).getDate()) == 0);
146         Assert.assertEquals(0., alm.getCic(), 0.);
147         Assert.assertEquals(0., alm.getCis(), 0.);
148         Assert.assertEquals(0., alm.getCrc(), 0.);
149         Assert.assertEquals(0., alm.getCrs(), 0.);
150         Assert.assertEquals(0., alm.getCuc(), 0.);
151         Assert.assertEquals(0., alm.getCus(), 0.);
152         Assert.assertEquals(1.45860023309E-4, alm.getMeanMotion(), 1.e-15);
153     }
154 
155 }