1   /* Copyright 2022-2025 Luc Maisonobe
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.sinex;
18  
19  import org.orekit.gnss.ObservationType;
20  import org.orekit.gnss.SatInSystem;
21  import org.orekit.gnss.SatelliteSystem;
22  import org.orekit.gnss.TimeSystem;
23  import org.orekit.time.TimeScales;
24  
25  import java.util.HashMap;
26  import java.util.Map;
27  import java.util.function.BiFunction;
28  
29  /** Parse information for Solution INdependent EXchange (SINEX) bias files.
30   * @author Luc Maisonobe
31   * @since 13.0
32   */
33  public class SinexBiasParseInfo extends ParseInfo<SinexBias> {
34  
35      /** Mapper from satellite system and string to observation type. */
36      private final BiFunction<? super SatelliteSystem, ? super String, ? extends ObservationType> typeBuilder;
37  
38      /** DSB description. */
39      private final BiasDescription description;
40  
41      /** DSB data. */
42      private final Map<String, StationDifferentialSignalBias> stationsDsb;
43  
44      /** DSB data. */
45      private final Map<SatInSystem, SatelliteDifferentialSignalBias> satellitesDsb;
46  
47      /** OSB data. */
48      private final Map<String, StationObservableSpecificSignalBias> stationsOsb;
49  
50      /** OSB data. */
51      private final Map<SatInSystem, SatelliteObservableSpecificSignalBias> satellitesOsb;
52  
53      /** Simple constructor.
54       * @param timeScales time scales
55       * @param typeBuilder mapper from string to observation type
56       */
57      SinexBiasParseInfo(final TimeScales timeScales,
58                         final BiFunction<? super SatelliteSystem, ? super String, ? extends ObservationType> typeBuilder) {
59          super(timeScales);
60          this.description   = new BiasDescription();
61          this.stationsDsb   = new HashMap<>();
62          this.satellitesDsb = new HashMap<>();
63          this.stationsOsb   = new HashMap<>();
64          this.satellitesOsb = new HashMap<>();
65          this.typeBuilder   = typeBuilder;
66      }
67  
68      /** Get description.
69       * @return description
70       */
71      BiasDescription getDescription() {
72          return description;
73      }
74  
75      /** Get satellite DSB.
76       * @param satellite satellite identifier
77       * @return satellite DSB
78       */
79      SatelliteDifferentialSignalBias getSatelliteDsb(final SatInSystem satellite) {
80          return satellitesDsb.computeIfAbsent(satellite, SatelliteDifferentialSignalBias::new);
81      }
82  
83      /** Get station DSB.
84       * @param siteCode station site code
85       * @return station DSB
86       */
87      StationDifferentialSignalBias getStationDsb(final String siteCode) {
88          return stationsDsb.computeIfAbsent(siteCode, StationDifferentialSignalBias::new);
89      }
90  
91      /** Get satellite OSB.
92       * @param satellite satellite identifier
93       * @return satellite OSB
94       */
95      SatelliteObservableSpecificSignalBias getSatelliteOsb(final SatInSystem satellite) {
96          return satellitesOsb.computeIfAbsent(satellite, SatelliteObservableSpecificSignalBias::new);
97      }
98  
99      /** Get station OSB.
100      * @param siteCode station site code
101      * @return station OSB
102      */
103     StationObservableSpecificSignalBias getStationOsb(final String siteCode) {
104         return stationsOsb.computeIfAbsent(siteCode, StationObservableSpecificSignalBias::new);
105     }
106 
107     /** Set time system.
108      * @param timeSystem time system
109      */
110     void setTimeSystem(final TimeSystem timeSystem) {
111         getDescription().setTimeSystem(timeSystem);
112         setTimeScale(timeSystem.getTimeScale(getTimeScales()));
113     }
114 
115     /** Extract an observation type from current line.
116      * @param system satellite system
117      * @param start  start index of the string
118      * @param length length of the string
119      * @return parsed observation type (null if field is empty)
120      */
121     protected ObservationType parseObservationType(final SatelliteSystem system, final int start, final int length) {
122         final String type = parseString(start, length);
123         return type.isEmpty() ? null : typeBuilder.apply(system, type);
124     }
125 
126     /** {@inheritDoc} */
127     @Override
128     protected SinexBias build() {
129         return new SinexBias(getTimeScales(), getCreationDate(), getStartDate(), getEndDate(),
130                              description, stationsDsb, satellitesDsb, stationsOsb, satellitesOsb);
131     }
132 
133 }