1 /* Copyright 2002-2021 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.files.ccsds.definitions.ElementsType;
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 ElementsType 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
49 * @param units units to use for parsing
50 */
51 public TrajectoryState(final ElementsType 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 /** {@inheritDoc} */
62 @Override
63 public AbsoluteDate getDate() {
64 return date;
65 }
66
67 /** Get trajectory elements.
68 * @return trajectory elements
69 */
70 public double[] getElements() {
71 return elements.clone();
72 }
73
74 /** Get the type of the elements.
75 * @return type of the elements
76 */
77 public ElementsType getType() {
78 return type;
79 }
80
81 /** Get which derivatives of position are available in this state.
82 * @return a value indicating if the file contains velocity and/or acceleration
83 */
84 public CartesianDerivativesFilter getAvailableDerivatives() {
85 return type == ElementsType.CARTP ?
86 CartesianDerivativesFilter.USE_P :
87 (type == ElementsType.CARTPVA ?
88 CartesianDerivativesFilter.USE_PVA :
89 CartesianDerivativesFilter.USE_PV);
90 }
91
92 /** Convert to Cartesian coordinates.
93 * @param mu gravitational parameter in m³/s²
94 * @return Cartesian coordinates
95 */
96 public TimeStampedPVCoordinates toCartesian(final double mu) {
97 return type.toCartesian(date, elements, mu);
98 }
99
100 }