1   /* Copyright 2002-2025 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  
18  package org.orekit.files.ccsds.ndm.odm.ocm;
19  
20  import java.util.List;
21  
22  import org.orekit.bodies.OneAxisEllipsoid;
23  import org.orekit.time.AbsoluteDate;
24  import org.orekit.time.TimeStamped;
25  import org.orekit.utils.CartesianDerivativesFilter;
26  import org.orekit.utils.TimeStampedPVCoordinates;
27  import org.orekit.utils.units.Unit;
28  
29  /** Trajectory state entry.
30   * @author Luc Maisonobe
31   * @since 11.0
32   */
33  public class TrajectoryState implements TimeStamped {
34  
35      /** Type of the elements. */
36      private final OrbitElementsType type;
37  
38      /** Entry date. */
39      private final AbsoluteDate date;
40  
41      /** Trajectory elements. */
42      private final double[] elements;
43  
44      /** Simple constructor.
45       * @param type type of the elements
46       * @param date entry date
47       * @param fields trajectory elements
48       * @param first index of first field to consider when parsing
49       * @param units units to use for parsing
50       */
51      public TrajectoryState(final OrbitElementsType type, final AbsoluteDate date,
52                             final String[] fields, final int first, final List<Unit> units) {
53          this.type     = type;
54          this.date     = date;
55          this.elements = new double[units.size()];
56          for (int i = 0; i < elements.length; ++i) {
57              elements[i] = units.get(i).toSI(Double.parseDouble(fields[first + i]));
58          }
59      }
60  
61      /** Simple constructor.
62       * @param type type of the elements
63       * @param date entry date
64       * @param elements trajectory elements in SI units
65       * @since 12.0
66       */
67      public TrajectoryState(final OrbitElementsType type, final AbsoluteDate date,
68                             final double[] elements) {
69          this.type     = type;
70          this.date     = date;
71          this.elements = elements.clone();
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public AbsoluteDate getDate() {
77          return date;
78      }
79  
80      /** Get trajectory elements.
81       * @return trajectory elements
82       */
83      public double[] getElements() {
84          return elements.clone();
85      }
86  
87      /** Get the type of the elements.
88       * @return type of the elements
89       */
90      public OrbitElementsType getType() {
91          return type;
92      }
93  
94      /** Get which derivatives of position are available in this state.
95       * @return a value indicating if the file contains velocity and/or acceleration
96        */
97      public CartesianDerivativesFilter getAvailableDerivatives() {
98          return type ==  OrbitElementsType.CARTP ?
99                          CartesianDerivativesFilter.USE_P :
100                         (type == OrbitElementsType.CARTPVA ?
101                          CartesianDerivativesFilter.USE_PVA :
102                          CartesianDerivativesFilter.USE_PV);
103     }
104 
105     /** Convert to Cartesian coordinates.
106      * @param body central body
107      * (may be null if {@link #getType() type} is <em>not</em> {@link OrbitElementsType#GEODETIC})
108      * @param mu gravitational parameter in m³/s²
109      * @return Cartesian coordinates
110      */
111     public TimeStampedPVCoordinates toCartesian(final OneAxisEllipsoid body, final double mu) {
112         return type.toCartesian(date, elements, body, mu);
113     }
114 
115 }