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   
18  package org.orekit.models.earth.ionosphere;
19  
20  import org.junit.Assert;
21  import org.junit.Test;
22  import org.orekit.Utils;
23  import org.orekit.errors.OrekitException;
24  import org.orekit.errors.OrekitMessages;
25  import org.orekit.time.DateComponents;
26  
27  public class KlobucharIonoCoefficientsLoaderTest {
28  
29      @Test
30      /**
31       * Regular test for 1st of January 2017
32       */
33      public void testRegularFile() {
34  
35          Utils.setDataRoot("klobuchar-ionospheric-coefficients");
36          
37          KlobucharIonoCoefficientsLoader ionoLoader = new KlobucharIonoCoefficientsLoader();
38          DateComponents dateComponents = new DateComponents(2017, 1);
39          ionoLoader.loadKlobucharIonosphericCoefficients(dateComponents);
40          
41          final double alpha[] = ionoLoader.getAlpha();
42          final double beta[]  = ionoLoader.getBeta();
43          
44          Assert.assertEquals(1.2821e-08 , alpha[0], 1e-16);
45          Assert.assertEquals(-9.6222e-09, alpha[1], 1e-16);
46          Assert.assertEquals(-3.5982e-07, alpha[2], 1e-16);
47          Assert.assertEquals(-6.0901e-07, alpha[3], 1e-16);
48          
49          Assert.assertEquals(1.0840e+05 , beta[0], 1e-16);
50          Assert.assertEquals(-1.3197e+05, beta[1], 1e-16);
51          Assert.assertEquals(-2.6331e+05, beta[2], 1e-16);
52          Assert.assertEquals(4.0570e+05 , beta[3], 1e-16);
53      }
54      
55      @Test
56      /**
57       * Test of a corrupted file without keyword ALPHA
58       */
59      public void testCorruptedFileBadKeyword() {
60          
61          Utils.setDataRoot("klobuchar-ionospheric-coefficients");
62          final String fileName = "corrupted-bad-keyword-CGIM0020.17N";
63          KlobucharIonoCoefficientsLoader ionoLoader = 
64                          new KlobucharIonoCoefficientsLoader(fileName);
65                          
66          try {
67              ionoLoader.loadKlobucharIonosphericCoefficients();
68              Assert.fail("An exception should have been thrown");
69              
70          } catch (OrekitException oe) {
71              Assert.assertEquals(OrekitMessages.NO_KLOBUCHAR_ALPHA_BETA_IN_FILE, oe.getSpecifier());
72              Assert.assertTrue(((String) oe.getParts()[0]).endsWith(fileName));
73          }
74      }
75      
76      @Test
77      /**
78       * Test of a corrupted file with improper data
79       */
80      public void testCorruptedFileBadData() {
81          
82          Utils.setDataRoot("klobuchar-ionospheric-coefficients");
83          final String fileName = "corrupted-bad-data-CGIM0020.17N";
84          KlobucharIonoCoefficientsLoader ionoLoader = 
85                          new KlobucharIonoCoefficientsLoader(fileName);
86                          
87          try {
88              ionoLoader.loadKlobucharIonosphericCoefficients();
89              Assert.fail("An exception should have been thrown");
90              
91          } catch (OrekitException oe) {
92              Assert.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
93          }
94      }
95      
96      @Test
97      /**
98       * Test for a file that cannot be found
99       */
100     public void testAbsentFile() {
101         
102         Utils.setDataRoot("klobuchar-ionospheric-coefficients");
103         KlobucharIonoCoefficientsLoader ionoLoader = new KlobucharIonoCoefficientsLoader();
104         DateComponents dateComponents = new DateComponents(2017, 3);
105         
106         try {
107             ionoLoader.loadKlobucharIonosphericCoefficients(dateComponents);
108             Assert.fail("An exception should have been thrown");
109             
110         } catch (OrekitException oe) {
111             Assert.assertEquals(OrekitMessages.KLOBUCHAR_ALPHA_BETA_NOT_AVAILABLE_FOR_DATE,
112                                 oe.getSpecifier());
113             Assert.assertEquals(dateComponents.toString(),
114                                 (String) oe.getParts()[0]);
115         }
116     }
117 }