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.files.rinex.navigation.parsers.ionosphere;
18  
19  import org.orekit.files.rinex.navigation.IonosphereBaseMessage;
20  import org.orekit.files.rinex.navigation.IonosphereKlobucharMessage;
21  import org.orekit.files.rinex.navigation.RegionCode;
22  import org.orekit.files.rinex.navigation.RinexNavigation;
23  import org.orekit.files.rinex.navigation.parsers.ParseInfo;
24  import org.orekit.files.rinex.navigation.parsers.RecordLineParser;
25  
26  /** Parser for Klobuchar ionosphere.
27   * @author Luc Maisonobe
28   * @since 14.0
29   */
30  public class KlobucharParser extends RecordLineParser {
31  
32      /** Container for parsing data. */
33      private final ParseInfo parseInfo;
34  
35      /** Container for Klobuchar message. */
36      private final IonosphereKlobucharMessage message;
37  
38      /** Simple constructor.
39       * @param parseInfo container for parsing data
40       * @param message container for navigation message
41       */
42      public KlobucharParser(final ParseInfo parseInfo, final IonosphereKlobucharMessage message) {
43          this.parseInfo = parseInfo;
44          this.message   = message;
45      }
46  
47      /** {@inheritDoc} */
48      @Override
49      public void parseLine00() {
50          message.setTransmitTime(parseInfo.parseDate(message.getSystem()));
51          message.setAlphaI(0, parseInfo.parseDouble2(IonosphereBaseMessage.S_PER_SC_N0));
52          message.setAlphaI(1, parseInfo.parseDouble3(IonosphereBaseMessage.S_PER_SC_N1));
53          message.setAlphaI(2, parseInfo.parseDouble4(IonosphereBaseMessage.S_PER_SC_N2));
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public void parseLine01() {
59          message.setAlphaI(3, parseInfo.parseDouble1(IonosphereBaseMessage.S_PER_SC_N3));
60          message.setBetaI(0, parseInfo.parseDouble2(IonosphereBaseMessage.S_PER_SC_N0));
61          message.setBetaI(1, parseInfo.parseDouble3(IonosphereBaseMessage.S_PER_SC_N1));
62          message.setBetaI(2, parseInfo.parseDouble4(IonosphereBaseMessage.S_PER_SC_N2));
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public void parseLine02() {
68          message.setBetaI(3, parseInfo.parseDouble1(IonosphereBaseMessage.S_PER_SC_N3));
69          final RegionCode regionCode;
70          if (parseInfo.getHeader().getFormatVersion() <= 4.01) {
71              // up to version 4.01, the region code is encoded as either 0 or 1 in the last line
72              regionCode = RegionCode.parseRegionCode(parseInfo.parseInt2());
73          } else {
74              // starting with 4.02, the region code is the sub-type of the message
75              regionCode = RegionCode.parseRegionCode(message.getNavigationMessageSubType());
76          }
77          message.setRegionCode(regionCode);
78          parseInfo.closePendingRecord();
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public void closeRecord(final RinexNavigation file) {
84          file.addKlobucharMessage(message);
85      }
86  
87  }