1   /* Copyright 2024-2025 The Johns Hopkins University Applied Physics Laboratory
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    * ADS 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.iirv;
18  
19  import org.orekit.errors.OrekitInternalError;
20  import org.orekit.files.general.EphemerisFile;
21  import org.orekit.time.AbsoluteDate;
22  import org.orekit.utils.TimeStampedPVCoordinates;
23  
24  import java.util.Collections;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  
29  /**
30   * Class for associating a the {@link IIRVEphemeris} ephemeris state data (obtained from an {@link IIRVMessage})
31   * to a single satellite, identified by its IIRV {@link org.orekit.files.iirv.terms.VehicleIdCodeTerm}.
32   */
33  public class IIRVEphemerisFile implements EphemerisFile<TimeStampedPVCoordinates, IIRVSegment> {
34  
35      /** Unmodifiable mapping with a single key-value pair from satellite id to ephemeris. */
36      private final Map<String, IIRVEphemerisFile.IIRVEphemeris> satellites;
37  
38      /**
39       * Constructs a {@link IIRVEphemerisFile} instance.
40       *
41       * @param ephemeris IIRV ephemeris data.
42       */
43      public IIRVEphemerisFile(final IIRVEphemerisFile.IIRVEphemeris ephemeris) {
44          final Map<String, IIRVEphemerisFile.IIRVEphemeris> tempMap = new HashMap<>();
45          tempMap.put(ephemeris.getId(), ephemeris);
46          this.satellites = Collections.unmodifiableMap(tempMap);
47      }
48  
49      /**
50       * Constructs a {@link IIRVEphemerisFile} instance from a {@link IIRVMessage}.
51       *
52       * @param mu                   gravitational parameter (m^3/s^2)
53       * @param interpolationSamples number of samples to use in interpolation
54       * @param startYear            Year associated with the beginning of the IIRV message
55       * @param iirvMessage          IIRV message
56       */
57      public IIRVEphemerisFile(final double mu,
58                               final int interpolationSamples,
59                               final int startYear,
60                               final IIRVMessage iirvMessage) {
61          this(new IIRVEphemerisFile.IIRVEphemeris(new IIRVSegment(mu, interpolationSamples, startYear, iirvMessage)));
62      }
63  
64      /**
65       * Constructs a {@link IIRVEphemerisFile} instance from a {@link IIRVMessage} with default values.
66       * <p>
67       * See {@link IIRVSegment#IIRVSegment(int, IIRVMessage)} for default value information.
68       *
69       * @param startYear   Year associated with the beginning of the IIRV message
70       * @param iirvMessage IIRV message
71       */
72      public IIRVEphemerisFile(final int startYear, final IIRVMessage iirvMessage) {
73          this(new IIRVEphemerisFile.IIRVEphemeris(new IIRVSegment(startYear, iirvMessage)));
74      }
75  
76  
77      /**
78       * {@inheritDoc}
79       * <p>
80       * STK ephemeris files define ephemeris for a single satellite, so the returned
81       * map will have a single entry.
82       * </p>
83       */
84      @Override
85      public Map<String, IIRVEphemerisFile.IIRVEphemeris> getSatellites() {
86          return satellites;
87      }
88  
89      /**
90       * Gets the {@link IIRVEphemeris} associated with this file.
91       *
92       * @return {@link IIRVEphemeris} associated with this file.
93       */
94      public IIRVEphemeris getIIRVEphemeris() {
95          if (satellites.size() != 1) {
96              // This should never happen
97              throw new OrekitInternalError(null);
98          }
99          return satellites.values().iterator().next();
100     }
101 
102     /**
103      * Gets the IIRV message containing the ephemeris data.
104      *
105      * @return IIRVMessage containing the ephemeris data.
106      */
107     public IIRVMessage getIIRV() {
108         return getIIRVEphemeris().getIIRV();
109     }
110 
111     /**
112      * Gets the start year for this file.
113      *
114      * @return start year for this file.
115      */
116     public int getStartYear() {
117         return getIIRVEphemeris().getStartYear();
118     }
119 
120     /**
121      * Ephemeris from an IIRV file.
122      */
123     public static class IIRVEphemeris implements SatelliteEphemeris<TimeStampedPVCoordinates, IIRVSegment> {
124 
125         /** Ephemeris segment. */
126         private final IIRVSegment segment;
127 
128         /**
129          * Constructs a {@link IIRVSegment} instance.
130          * <p>
131          * An IIRV file contains ephemeris data for a single satellite; thus each {@link IIRVEphemeris} instance
132          * contains only a single {@link IIRVSegment}.
133          *
134          * @param segment ephemeris segments
135          */
136         public IIRVEphemeris(final IIRVSegment segment) {
137             this.segment = segment;
138         }
139 
140         /** {@inheritDoc} */
141         @Override
142         public String getId() {
143             return segment.getIIRVMessage().getSatelliteID();
144         }
145 
146         /** {@inheritDoc} */
147         @Override
148         public double getMu() {
149             return segment.getMu();
150         }
151 
152         /**
153          * Get the {@link IIRVSegment} for this satellite.
154          *
155          * @return {@link IIRVSegment} for this satellite.
156          * @see #getSegment()
157          */
158         public IIRVSegment getSegment() {
159             return segment;
160         }
161 
162         /** {@inheritDoc} */
163         @Override
164         public List<IIRVSegment> getSegments() {
165             return Collections.singletonList(segment);
166         }
167 
168         /** {@inheritDoc} */
169         @Override
170         public AbsoluteDate getStart() {
171             return segment.getStart();
172         }
173 
174         /** {@inheritDoc} */
175         @Override
176         public AbsoluteDate getStop() {
177             return segment.getStop();
178         }
179 
180         /**
181          * Gets the {@link IIRVMessage} containing the ephemeris data for this object's {@link IIRVSegment}.
182          *
183          * @return {@link IIRVMessage} containing the ephemeris data for this object's {@link IIRVSegment}.
184          */
185         public IIRVMessage getIIRV() {
186             return segment.getIIRVMessage();
187         }
188 
189         /**
190          * Gets the start year of the ephemeris data.
191          *
192          * @return start year of the ephemeris data
193          */
194         public int getStartYear() {
195             return segment.getStartYear();
196         }
197 
198     }
199 
200 }