1   /* Copyright 2002-2024 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.sp3;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.orekit.files.general.EphemerisFile;
24  import org.orekit.frames.Frame;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.utils.CartesianDerivativesFilter;
27  
28  /** Single satellite ephemeris from an {@link SP3 SP3} file.
29   * @author Luc Maisonobe
30   * @since 12.0
31   */
32  public class SP3Ephemeris implements EphemerisFile.SatelliteEphemeris<SP3Coordinate, SP3Segment> {
33  
34      /** Satellite ID. */
35      private final String id;
36  
37      /** Standard gravitational parameter in m³ / s². */
38      private final double mu;
39  
40      /** Reference frame. */
41      private final Frame frame;
42  
43      /** Number of points to use for interpolation. */
44      private final int interpolationSamples;
45  
46      /** Available derivatives. */
47      private final CartesianDerivativesFilter filter;
48  
49      /** Segments. */
50      private final List<SP3Segment> segments;
51  
52      /** Create an ephemeris for a single satellite.
53       * @param id of the satellite.
54       * @param mu standard gravitational parameter to use for creating
55       * {@link org.orekit.orbits.Orbit Orbits} from the ephemeris data.
56       * @param frame reference frame
57       * @param interpolationSamples number of points to use for interpolation
58       * @param filter available derivatives
59       */
60      public SP3Ephemeris(final String id, final double mu, final Frame frame,
61                          final int interpolationSamples, final CartesianDerivativesFilter filter) {
62          this.id                   = id;
63          this.mu                   = mu;
64          this.frame                = frame;
65          this.interpolationSamples = interpolationSamples;
66          this.filter               = filter;
67          this.segments             = new ArrayList<>();
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public String getId() {
73          return this.id;
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public double getMu() {
79          return mu;
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public List<SP3Segment> getSegments() {
85          return Collections.unmodifiableList(segments);
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public AbsoluteDate getStart() {
91          return segments.isEmpty() ? null : segments.get(0).getStart();
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public AbsoluteDate getStop() {
97          return segments.isEmpty() ? null : segments.get(segments.size() - 1).getStop();
98      }
99  
100     /** Get the reference frame.
101      * @return reference frame
102      */
103     public Frame getFrame() {
104         return frame;
105     }
106 
107     /** Get the number of points to use for interpolation.
108      * @return number of points to use for interpolation
109      */
110     public int getInterpolationSamples() {
111         return interpolationSamples;
112     }
113 
114     /** Get the available derivatives.
115      * @return available derivatives
116      */
117     public CartesianDerivativesFilter getAvailableDerivatives() {
118         return filter;
119     }
120 
121     /** Adds a new P/V coordinate.
122      * @param coord the P/V coordinate of the satellite
123      * @param maxGap maximum gap between segments
124      */
125     public void addCoordinate(final SP3Coordinate coord, final double maxGap) {
126         final AbsoluteDate lastDate = getStop();
127         final SP3Segment segment;
128         if (lastDate == null || coord.getDate().durationFrom(lastDate) > maxGap) {
129             // we need to create a new segment
130             segment = new SP3Segment(mu, frame,  interpolationSamples, filter);
131             segments.add(segment);
132         } else {
133             segment = segments.get(segments.size() - 1);
134         }
135         segment.addCoordinate(coord);
136     }
137 
138 }