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