SP3Ephemeris.java

  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. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.orekit.files.general.EphemerisFile;
  22. import org.orekit.frames.Frame;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.utils.CartesianDerivativesFilter;

  25. /** Single satellite ephemeris from an {@link SP3 SP3} file.
  26.  * @author Luc Maisonobe
  27.  * @since 12.0
  28.  */
  29. public class SP3Ephemeris implements EphemerisFile.SatelliteEphemeris<SP3Coordinate, SP3Segment> {

  30.     /** Satellite ID. */
  31.     private final String id;

  32.     /** Standard gravitational parameter in m³ / s². */
  33.     private final double mu;

  34.     /** Reference frame. */
  35.     private final Frame frame;

  36.     /** Number of points to use for interpolation. */
  37.     private final int interpolationSamples;

  38.     /** Available derivatives. */
  39.     private final CartesianDerivativesFilter filter;

  40.     /** Segments. */
  41.     private final List<SP3Segment> segments;

  42.     /** Create an ephemeris for a single satellite.
  43.      * @param id of the satellite.
  44.      * @param mu standard gravitational parameter to use for creating
  45.      * {@link org.orekit.orbits.Orbit Orbits} from the ephemeris data.
  46.      * @param frame reference frame
  47.      * @param interpolationSamples number of points to use for interpolation
  48.      * @param filter available derivatives
  49.      */
  50.     public SP3Ephemeris(final String id, final double mu, final Frame frame,
  51.                         final int interpolationSamples, final CartesianDerivativesFilter filter) {
  52.         this.id                   = id;
  53.         this.mu                   = mu;
  54.         this.frame                = frame;
  55.         this.interpolationSamples = interpolationSamples;
  56.         this.filter               = filter;
  57.         this.segments             = new ArrayList<>();
  58.     }

  59.     /** {@inheritDoc} */
  60.     @Override
  61.     public String getId() {
  62.         return this.id;
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public double getMu() {
  67.         return mu;
  68.     }

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     public List<SP3Segment> getSegments() {
  72.         return Collections.unmodifiableList(segments);
  73.     }

  74.     /** {@inheritDoc} */
  75.     @Override
  76.     public AbsoluteDate getStart() {
  77.         return segments.isEmpty() ? null : segments.get(0).getStart();
  78.     }

  79.     /** {@inheritDoc} */
  80.     @Override
  81.     public AbsoluteDate getStop() {
  82.         return segments.isEmpty() ? null : segments.get(segments.size() - 1).getStop();
  83.     }

  84.     /** Get the reference frame.
  85.      * @return reference frame
  86.      */
  87.     public Frame getFrame() {
  88.         return frame;
  89.     }

  90.     /** Get the number of points to use for interpolation.
  91.      * @return number of points to use for interpolation
  92.      */
  93.     public int getInterpolationSamples() {
  94.         return interpolationSamples;
  95.     }

  96.     /** Get the available derivatives.
  97.      * @return available derivatives
  98.      */
  99.     public CartesianDerivativesFilter getAvailableDerivatives() {
  100.         return filter;
  101.     }

  102.     /** Adds a new P/V coordinate.
  103.      * @param coord the P/V coordinate of the satellite
  104.      * @param maxGap maximum gap between segments
  105.      */
  106.     public void addCoordinate(final SP3Coordinate coord, final double maxGap) {
  107.         final AbsoluteDate lastDate = getStop();
  108.         final SP3Segment segment;
  109.         if (lastDate == null || coord.getDate().durationFrom(lastDate) > maxGap) {
  110.             // we need to create a new segment
  111.             segment = new SP3Segment(mu, frame,  interpolationSamples, filter);
  112.             segments.add(segment);
  113.         } else {
  114.             segment = segments.get(segments.size() - 1);
  115.         }
  116.         segment.addCoordinate(coord);
  117.     }

  118. }