InertiaWriter.java

  1. /* Copyright 2002-2023 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.adm.apm;

  18. import java.io.IOException;

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

  22. /** Writer for inertia data.
  23.  * @author Luc Maisonobe
  24.  * @since 11.0
  25.  */
  26. class InertiaWriter extends AbstractWriter {

  27.     /** Format version.
  28.      * @since 12.0
  29.      */
  30.     private final double formatVersion;

  31.     /** Inertia block. */
  32.     private final Inertia inertia;

  33.     /** Create a writer.
  34.      * @param formatVersion format version
  35.      * @param xmlTag name of the XML tag surrounding the section
  36.      * @param kvnTag name of the KVN tag surrounding the section (may be null)
  37.      * @param spacecraftParameters spacecraft parameters data to write
  38.      */
  39.     InertiaWriter(final double formatVersion, final String xmlTag, final String kvnTag,
  40.                   final Inertia spacecraftParameters) {
  41.         super(xmlTag, kvnTag);
  42.         this.formatVersion = formatVersion;
  43.         this.inertia = spacecraftParameters;
  44.     }

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     protected void writeContent(final Generator generator) throws IOException {

  48.         generator.writeComments(inertia.getComments());

  49.         // frame
  50.         if (inertia.getFrame() != null) {
  51.             generator.writeEntry(InertiaKey.INERTIA_REF_FRAME.name(),
  52.                                  inertia.getFrame().getName(),
  53.                                  null, false);
  54.         }

  55.         // inertia matrix
  56.         if (formatVersion < 2.0) {
  57.             generator.writeEntry(InertiaKey.I11.name(), inertia.getInertiaMatrix().getEntry(0, 0), Units.KG_M2, true);
  58.             generator.writeEntry(InertiaKey.I22.name(), inertia.getInertiaMatrix().getEntry(1, 1), Units.KG_M2, true);
  59.             generator.writeEntry(InertiaKey.I33.name(), inertia.getInertiaMatrix().getEntry(2, 2), Units.KG_M2, true);
  60.             generator.writeEntry(InertiaKey.I12.name(), inertia.getInertiaMatrix().getEntry(0, 1), Units.KG_M2, true);
  61.             generator.writeEntry(InertiaKey.I13.name(), inertia.getInertiaMatrix().getEntry(0, 2), Units.KG_M2, true);
  62.             generator.writeEntry(InertiaKey.I23.name(), inertia.getInertiaMatrix().getEntry(1, 2), Units.KG_M2, true);
  63.         } else {
  64.             generator.writeEntry(InertiaKey.IXX.name(), inertia.getInertiaMatrix().getEntry(0, 0), Units.KG_M2, true);
  65.             generator.writeEntry(InertiaKey.IYY.name(), inertia.getInertiaMatrix().getEntry(1, 1), Units.KG_M2, true);
  66.             generator.writeEntry(InertiaKey.IZZ.name(), inertia.getInertiaMatrix().getEntry(2, 2), Units.KG_M2, true);
  67.             generator.writeEntry(InertiaKey.IXY.name(), inertia.getInertiaMatrix().getEntry(0, 1), Units.KG_M2, true);
  68.             generator.writeEntry(InertiaKey.IXZ.name(), inertia.getInertiaMatrix().getEntry(0, 2), Units.KG_M2, true);
  69.             generator.writeEntry(InertiaKey.IYZ.name(), inertia.getInertiaMatrix().getEntry(1, 2), Units.KG_M2, true);
  70.         }

  71.     }

  72. }