CartesianCovarianceWriter.java

  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. package org.orekit.files.ccsds.ndm.odm;

  18. import java.io.IOException;

  19. import org.hipparchus.linear.RealMatrix;
  20. import org.orekit.files.ccsds.definitions.Units;
  21. import org.orekit.files.ccsds.section.AbstractWriter;
  22. import org.orekit.files.ccsds.utils.generation.Generator;

  23. /** Writer for covariance matrix data.
  24.  * @author Luc Maisonobe
  25.  * @since 11.0
  26.  */
  27. public class CartesianCovarianceWriter extends AbstractWriter {

  28.     /** Covariance matrix block. */
  29.     private final CartesianCovariance covariance;

  30.     /** Create a writer.
  31.      * @param xmlTag name of the XML tag surrounding the section
  32.      * @param kvnTag name of the KVN tag surrounding the section (may be null)
  33.      * @param covariance covariance matrix to write
  34.      */
  35.     public CartesianCovarianceWriter(final String xmlTag, final String kvnTag,
  36.                                       final CartesianCovariance covariance) {
  37.         super(xmlTag, kvnTag);
  38.         this.covariance = covariance;
  39.     }

  40.     /** {@inheritDoc} */
  41.     @Override
  42.     protected void writeContent(final Generator generator) throws IOException {

  43.         final RealMatrix matrix = covariance.getCovarianceMatrix();

  44.         // covariance block
  45.         generator.writeComments(covariance.getComments());
  46.         // note that there are no epochs in the OPM/OMM covariance matrices (but there are epochs in OEM covariance matrices)
  47.         generator.writeEntry(CartesianCovarianceKey.COV_REF_FRAME.name(), covariance.getReferenceFrame().getName(), null,             false);
  48.         generator.writeEntry(CartesianCovarianceKey.CX_X.name(),          matrix.getEntry(0, 0),                    Units.KM2,        true);
  49.         generator.writeEntry(CartesianCovarianceKey.CY_X.name(),          matrix.getEntry(1, 0),                    Units.KM2,        true);
  50.         generator.writeEntry(CartesianCovarianceKey.CY_Y.name(),          matrix.getEntry(1, 1),                    Units.KM2,        true);
  51.         generator.writeEntry(CartesianCovarianceKey.CZ_X.name(),          matrix.getEntry(2, 0),                    Units.KM2,        true);
  52.         generator.writeEntry(CartesianCovarianceKey.CZ_Y.name(),          matrix.getEntry(2, 1),                    Units.KM2,        true);
  53.         generator.writeEntry(CartesianCovarianceKey.CZ_Z.name(),          matrix.getEntry(2, 2),                    Units.KM2,        true);
  54.         generator.writeEntry(CartesianCovarianceKey.CX_DOT_X.name(),      matrix.getEntry(3, 0),                    Units.KM2_PER_S,  true);
  55.         generator.writeEntry(CartesianCovarianceKey.CX_DOT_Y.name(),      matrix.getEntry(3, 1),                    Units.KM2_PER_S,  true);
  56.         generator.writeEntry(CartesianCovarianceKey.CX_DOT_Z.name(),      matrix.getEntry(3, 2),                    Units.KM2_PER_S,  true);
  57.         generator.writeEntry(CartesianCovarianceKey.CX_DOT_X_DOT.name(),  matrix.getEntry(3, 3),                    Units.KM2_PER_S2, true);
  58.         generator.writeEntry(CartesianCovarianceKey.CY_DOT_X.name(),      matrix.getEntry(4, 0),                    Units.KM2_PER_S,  true);
  59.         generator.writeEntry(CartesianCovarianceKey.CY_DOT_Y.name(),      matrix.getEntry(4, 1),                    Units.KM2_PER_S,  true);
  60.         generator.writeEntry(CartesianCovarianceKey.CY_DOT_Z.name(),      matrix.getEntry(4, 2),                    Units.KM2_PER_S,  true);
  61.         generator.writeEntry(CartesianCovarianceKey.CY_DOT_X_DOT.name(),  matrix.getEntry(4, 3),                    Units.KM2_PER_S2, true);
  62.         generator.writeEntry(CartesianCovarianceKey.CY_DOT_Y_DOT.name(),  matrix.getEntry(4, 4),                    Units.KM2_PER_S2, true);
  63.         generator.writeEntry(CartesianCovarianceKey.CZ_DOT_X.name(),      matrix.getEntry(5, 0),                    Units.KM2_PER_S,  true);
  64.         generator.writeEntry(CartesianCovarianceKey.CZ_DOT_Y.name(),      matrix.getEntry(5, 1),                    Units.KM2_PER_S,  true);
  65.         generator.writeEntry(CartesianCovarianceKey.CZ_DOT_Z.name(),      matrix.getEntry(5, 2),                    Units.KM2_PER_S,  true);
  66.         generator.writeEntry(CartesianCovarianceKey.CZ_DOT_X_DOT.name(),  matrix.getEntry(5, 3),                    Units.KM2_PER_S2, true);
  67.         generator.writeEntry(CartesianCovarianceKey.CZ_DOT_Y_DOT.name(),  matrix.getEntry(5, 4),                    Units.KM2_PER_S2, true);
  68.         generator.writeEntry(CartesianCovarianceKey.CZ_DOT_Z_DOT.name(),  matrix.getEntry(5, 5),                    Units.KM2_PER_S2, true);

  69.     }

  70. }