1 /* Copyright 2002-2026 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 package org.orekit.files.ccsds.ndm.cdm;
18
19 import java.util.Arrays;
20
21 import org.orekit.errors.OrekitException;
22 import org.orekit.errors.OrekitMessages;
23 import org.orekit.files.ccsds.section.CommentsContainer;
24
25 /**
26 * Container for Sigma/Eigenvectors Covariance data.
27 * <p>
28 * Beware that the Orekit getters and setters all rely on SI units. The parsers
29 * and writers take care of converting these SI units into CCSDS mandatory units.
30 * The {@link org.orekit.utils.units.Unit Unit} class provides useful
31 * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
32 * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
33 * already use CCSDS units instead of the API SI units. The general-purpose
34 * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
35 * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
36 * (with an 's') also provide some predefined units. These predefined units and the
37 * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
38 * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
39 * what the parsers and writers use for the conversions.
40 * </p>
41 * <p>
42 * The positional covariance one-sigma dispersions corresponding to the major,
43 * intermediate and minor eigenvalues, followed by the associated eigenvectors.
44 * The data is presented on a single line (12 values separated by spaces).
45 * (Condition: Mandatory if {@code ALT_COV_TYPE = CSIG3EIGVEC3})
46 * </p>
47 */
48 public class SigmaEigenvectorsCovariance extends CommentsContainer {
49
50 /** Sigma/Eigenvectors Covariance covariance matrix. */
51 private double[] csig3eigvec3;
52
53 /** Flag indicating whether the alternate covariance type set in the CDM Object metadata section is Sigma/Eigenvectors Covariance. */
54 private final boolean altCovFlag;
55
56 /** Simple constructor.
57 * <p> The Sigma/Eigenvectors Covariance data is only provided if {@link CdmMetadataKey#ALT_COV_TYPE} is {@link AltCovarianceType#CSIG3EIGVEC3}, otherwise
58 * its terms will return NaN. </p>
59 * @param altCovFlag Flag indicating whether the alternate covariance type set in the CDM Object metadata section is Sigma/Eigenvectors Covariance.
60 */
61 public SigmaEigenvectorsCovariance(final boolean altCovFlag) {
62 this.altCovFlag = altCovFlag;
63 csig3eigvec3 = new double[12];
64 Arrays.fill(csig3eigvec3, Double.NaN);
65 }
66
67 /** {@inheritDoc} */
68 @Override
69 public void validate(final double version) {
70 super.validate(version);
71
72 // Conditional on ALT_COV_TYPE = Sigma/Eigenvectors Covariance
73 if (!isAltCovFlagSet()) {
74 throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_PREAMBLE_FIELD, CdmMetadataKey.ALT_COV_TYPE);
75 }
76
77 // We only check values that are mandatory in a cdm file
78 for (int i = 0; i < getCsig3eigvec3().length; i++) {
79 checkNotNaN(getCsig3eigvec3()[i], SigmaEigenvectorsCovarianceKey.CSIG3EIGVEC3.name());
80 }
81 }
82
83
84 /**
85 * Get the Sigma/Eigenvectors Covariance data.
86 * <p> The Sigma/Eigenvectors Covariance data is only provided if {@link CdmMetadataKey#ALT_COV_TYPE} is {@link AltCovarianceType#CSIG3EIGVEC3}, otherwise
87 * its terms will return NaN. </p>
88 * @return covarianceData the covariance data in the Sigma/Eigenvectors format.
89 */
90 public double[] getCsig3eigvec3() {
91 return csig3eigvec3 == null ? null : csig3eigvec3.clone();
92 }
93
94 /**
95 * Set the Sigma/Eigenvectors Covariance data.
96 * @param csig3eigvec3 the covariance data in the Sigma/Eigenvectors format.
97 */
98 public void setCsig3eigvec3(final double[] csig3eigvec3) {
99 refuseFurtherComments();
100
101 // Conditional on ALT_COV_TYPE = Sigma/Eigenvectors Covariance
102 if (!isAltCovFlagSet()) {
103 throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_PREAMBLE_FIELD, CdmMetadataKey.ALT_COV_TYPE);
104 }
105
106 this.csig3eigvec3 = csig3eigvec3 == null ? null : csig3eigvec3.clone();
107 }
108
109 /** Get the flag indicating whether the alternate covariance type set in the CDM Object metadata section is Sigma/Eigenvectors Covariance.
110 * @return the altCovFlag
111 */
112 public boolean isAltCovFlagSet() {
113 return altCovFlag;
114 }
115
116 }