1 /* Copyright 2002-2024 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.hipparchus.linear.MatrixUtils;
23 import org.hipparchus.linear.RealMatrix;
24 import org.orekit.time.AbsoluteDate;
25 import org.orekit.time.TimeStamped;
26 import org.orekit.utils.units.Unit;
27
28 /** Covariance entry.
29 * @author Luc Maisonobe
30 * @since 11.0
31 */
32 public class OrbitCovariance implements TimeStamped {
33
34 /** Type of the elements. */
35 private final OrbitElementsType type;
36
37 /** Entry date. */
38 private final AbsoluteDate date;
39
40 /** Covariance matrix. */
41 private final RealMatrix matrix;
42
43 /** Simple constructor.
44 * @param type type of the elements
45 * @param ordering ordering to use
46 * @param date entry date
47 * @param fields matrix elements
48 * @param first index of first field to consider
49 */
50 public OrbitCovariance(final OrbitElementsType type, final Ordering ordering, final AbsoluteDate date,
51 final String[] fields, final int first) {
52 final List<Unit> units = type.getUnits();
53 this.type = type;
54 this.date = date;
55 this.matrix = MatrixUtils.createRealMatrix(units.size(), units.size());
56 final CovarianceIndexer indexer = new CovarianceIndexer(units.size());
57 for (int k = 0; first + k < fields.length; ++k) {
58 if (!indexer.isCrossCorrelation()) {
59 final int i = indexer.getRow();
60 final int j = indexer.getColumn();
61 final double raw = Double.parseDouble(fields[first + k]);
62 final double converted = units.get(i).toSI(units.get(j).toSI(raw));
63 matrix.setEntry(i, j, converted);
64 if (i != j) {
65 matrix.setEntry(j, i, converted);
66 }
67 }
68 ordering.update(indexer);
69 }
70 }
71
72 /** {@inheritDoc} */
73 @Override
74 public AbsoluteDate getDate() {
75 return date;
76 }
77
78 /** Get the covariance matrix.
79 * @return covariance matrix
80 */
81 public RealMatrix getMatrix() {
82 return matrix;
83 }
84
85 /** Get the type of the elements.
86 * @return type of the elements
87 */
88 public OrbitElementsType getType() {
89 return type;
90 }
91
92 }