1   /* Copyright 2002-2026 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.sinex;
18  
19  import org.hipparchus.geometry.euclidean.threed.Vector3D;
20  import org.orekit.frames.EopHistoryLoader;
21  import org.orekit.frames.ITRFVersion;
22  import org.orekit.gnss.GnssSignal;
23  import org.orekit.gnss.SatInSystem;
24  import org.orekit.time.AbsoluteDate;
25  import org.orekit.time.ChronologicalComparator;
26  import org.orekit.time.TimeScales;
27  
28  import java.util.ArrayList;
29  import java.util.Collections;
30  import java.util.List;
31  import java.util.Map;
32  
33  /**
34   * Container for Solution INdependent EXchange (SINEX) files.
35   * @author Bryan Cazabonne
36   * @author Luc Maisonobe
37   * @since 13.0
38   */
39  public class Sinex extends AbstractSinex {
40  
41      /** Satellites phase centers. */
42      private final Map<SatInSystem, Map<GnssSignal, Vector3D>> satellitesPhaseCenters;
43  
44      /** Station data. */
45      private final Map<String, Station> stations;
46  
47      /** Earth Orientation Parameters data. */
48      private final Map<AbsoluteDate, SinexEopEntry> eop;
49  
50      /** Simple constructor.
51       * @param version                version number
52       * @param timeScales             time scales
53       * @param creationDate           SINEX file creation date
54       * @param startDate              start time of the data used in the Sinex solution
55       * @param endDate                end time of the data used in the Sinex solution
56       * @param satellitesPhaseCenters satellites phase centers
57       * @param stations               station data
58       * @param eop                    Earth Orientation Parameters data
59       * @since 14.0
60       */
61      public Sinex(final double version, final TimeScales timeScales,
62                   final AbsoluteDate creationDate, final AbsoluteDate startDate, final AbsoluteDate endDate,
63                   final Map<SatInSystem, Map<GnssSignal, Vector3D>> satellitesPhaseCenters,
64                   final Map<String, Station> stations, final Map<AbsoluteDate, SinexEopEntry> eop) {
65          super(version, timeScales, creationDate, startDate, endDate);
66          this.satellitesPhaseCenters = satellitesPhaseCenters;
67          this.stations               = stations;
68          this.eop                    = eop;
69      }
70  
71      /** Get the parsed satellites phase centers.
72       * @return unmodifiable view of parsed satellites phase centers
73       */
74      public Map<SatInSystem, Map<GnssSignal, Vector3D>> getSatellitesPhaseCenters() {
75          return Collections.unmodifiableMap(satellitesPhaseCenters);
76      }
77  
78      /** Get the parsed station data.
79       * @return unmodifiable view of parsed station data
80       */
81      public Map<String, Station> getStations() {
82          return Collections.unmodifiableMap(stations);
83      }
84  
85      /** Get the parsed EOP data.
86       * @param itrfVersion ITRF version corresponding to the entries
87       * @return loader for EOP data
88       */
89      public EopHistoryLoader getEopLoader(final ITRFVersion itrfVersion) {
90          return (converter, history) -> {
91  
92              // first set up all entries explicitly present in the parsed files
93              final List<SinexEopEntry> sorted = new ArrayList<>(eop.values());
94              sorted.sort(new ChronologicalComparator());
95  
96              // copy first and last entries according to files validity
97              sorted.add(sorted.getFirst().toNewEpoch(getFileEpochStartTime()));
98              sorted.add(sorted.getLast().toNewEpoch(getFileEpochEndTime()));
99  
100             if (sorted.size() < 4) {
101                 // insert extra entries after first and before last to allow interpolation
102                 sorted.add(sorted.getFirst().toNewEpoch(getFileEpochStartTime().shiftedBy(1.0)));
103                 sorted.add(sorted.getLast().toNewEpoch(getFileEpochEndTime().shiftedBy(-1.0)));
104             }
105 
106             // convert to regular EOP history
107             sorted.forEach(e -> history.add(e.toEopEntry(converter, itrfVersion, getTimeScales().getUTC())));
108 
109         };
110     }
111 
112 }