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;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.orekit.files.rinex.section.Label;
23  import org.orekit.files.rinex.section.RinexBaseHeader;
24  import org.orekit.files.rinex.utils.RinexFileType;
25  import org.orekit.files.rinex.utils.ParsingUtils;
26  import org.orekit.gnss.SatelliteSystem;
27  import org.orekit.time.TimeScales;
28  
29  /** Header for Rinex Navigation.
30   * @author Luc Maisonobe
31   * @since 12.0
32   */
33  public class RinexNavigationHeader extends RinexBaseHeader {
34  
35      /** Index of label in header lines. */
36      public static final int LABEL_INDEX = 60;
37  
38      /** Ionospheric corrections. */
39      private final List<IonosphericCorrection> ionosphericCorrections;
40  
41      /** List of time system corrections. */
42      private final List<TimeSystemCorrection> timeSystemCorrections;
43  
44      /** Number of merged files. */
45      private int mergedFiles;
46  
47      /** Simple constructor.
48       */
49      public RinexNavigationHeader() {
50          super(RinexFileType.NAVIGATION);
51          this.ionosphericCorrections = new ArrayList<>();
52          this.timeSystemCorrections  = new ArrayList<>();
53          this.mergedFiles            = -1;
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public SatelliteSystem parseSatelliteSystem(final String line, final SatelliteSystem defaultSatelliteSystem) {
59          if (getFormatVersion() < 3.0) {
60              // the satellite system is hidden within the entry, with GPS as default
61  
62              // look if default is overridden somewhere in the entry
63              final String entry = line.substring(0, 80).toUpperCase();
64              for (final SatelliteSystem satelliteSystem : SatelliteSystem.values()) {
65                  if (entry.contains(satelliteSystem.name())) {
66                      // we found a satellite system hidden in the middle of the line
67                      return satelliteSystem;
68                  }
69              }
70  
71              // return default value
72              return defaultSatelliteSystem;
73  
74          } else {
75              // the satellite system is in column 40 for 3.X and later
76              return SatelliteSystem.parseSatelliteSystem(line.substring(40, 41), defaultSatelliteSystem);
77          }
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public void parseProgramRunByDate(final String line, final TimeScales timeScales) {
83          parseProgramRunByDate(ParsingUtils.parseString(line, 0, 20),
84                                ParsingUtils.parseString(line, 20, 20),
85                                ParsingUtils.parseString(line, 40, 20),
86                                timeScales);
87      }
88  
89      /**
90       * Getter for the ionospheric corrections.
91       * @return the ionospheric corrections
92       */
93      public List<IonosphericCorrection> getIonosphericCorrections() {
94          return ionosphericCorrections;
95      }
96  
97      /**
98       * Add a ionospheric correction.
99       * @param ionosphericCorrection the ionospheric correction type to add
100      */
101     public void addIonosphericCorrection(final IonosphericCorrection ionosphericCorrection) {
102         this.ionosphericCorrections.add(ionosphericCorrection);
103     }
104 
105     /**
106      * Getter for the time system corrections contained in the file header.
107      * <p>
108      * Corrections to transform the system time to UTC or oter time system.
109      * </p>
110      * @return the list of time system corrections
111      */
112     public List<TimeSystemCorrection> getTimeSystemCorrections() {
113         return timeSystemCorrections;
114     }
115 
116     /**
117      * Add a time system correction to the list.
118      * @param timeSystemCorrection the element to add
119      */
120     public void addTimeSystemCorrections(final TimeSystemCorrection timeSystemCorrection) {
121         this.timeSystemCorrections.add(timeSystemCorrection);
122     }
123 
124     /**
125      * Getter for the number of merged files.
126      * @return the number of merged files
127      */
128     public int getMergedFiles() {
129         return mergedFiles;
130     }
131 
132     /**
133      * Setter for the number of merged files.
134      * @param mergedFiles the number of merged files
135      */
136     public void setMergedFiles(final int mergedFiles) {
137         this.mergedFiles = mergedFiles;
138     }
139 
140     /** {@inheritDoc} */
141     @Override
142     public void checkType(final String line, final String name) {
143         checkType(line, 20, name);
144     }
145 
146     /** {@inheritDoc} */
147     @Override
148     public int getLabelIndex() {
149         return LABEL_INDEX;
150     }
151 
152     /** {@inheritDoc} */
153     @Override
154     public boolean matchFound(final Label label, final String line) {
155         return label.matches(line.substring(getLabelIndex()).trim());
156     }
157 
158 }