OsculationgKeplerianElementsWriter.java

  1. /* Copyright 2002-2025 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.opm;

  18. import java.io.IOException;

  19. import org.orekit.files.ccsds.definitions.Units;
  20. import org.orekit.files.ccsds.ndm.odm.KeplerianElements;
  21. import org.orekit.files.ccsds.ndm.odm.KeplerianElementsKey;
  22. import org.orekit.files.ccsds.section.AbstractWriter;
  23. import org.orekit.files.ccsds.utils.generation.Generator;
  24. import org.orekit.orbits.PositionAngleType;
  25. import org.orekit.utils.units.Unit;

  26. /** Writer for Keplerian elements data in OPM files.
  27.  * @author Luc Maisonobe
  28.  * @since 11.0
  29.  */
  30. class OsculationgKeplerianElementsWriter extends AbstractWriter {

  31.     /** Keplerian elements block. */
  32.     private final KeplerianElements keplerianElements;

  33.     /** Create a writer.
  34.      * @param xmlTag name of the XML tag surrounding the section
  35.      * @param kvnTag name of the KVN tag surrounding the section (may be null)
  36.      * @param keplerianElements Keplerian elements to write
  37.      */
  38.     OsculationgKeplerianElementsWriter(final String xmlTag, final String kvnTag,
  39.                                        final KeplerianElements keplerianElements) {
  40.         super(xmlTag, kvnTag);
  41.         this.keplerianElements = keplerianElements;
  42.     }

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

  46.         // Keplerian elements block
  47.         generator.writeComments(keplerianElements.getComments());
  48.         generator.writeEntry(KeplerianElementsKey.SEMI_MAJOR_AXIS.name(),   keplerianElements.getA(), Unit.KILOMETRE, true);
  49.         generator.writeEntry(KeplerianElementsKey.ECCENTRICITY.name(),      keplerianElements.getE(), Unit.ONE,       true);
  50.         generator.writeEntry(KeplerianElementsKey.INCLINATION.name(),       keplerianElements.getI(), Unit.DEGREE,    true);
  51.         generator.writeEntry(KeplerianElementsKey.RA_OF_ASC_NODE.name(),    keplerianElements.getRaan(), Unit.DEGREE, true);
  52.         generator.writeEntry(KeplerianElementsKey.ARG_OF_PERICENTER.name(), keplerianElements.getPa(), Unit.DEGREE,   true);
  53.         generator.writeEntry(keplerianElements.getAnomalyType() == PositionAngleType.TRUE ?
  54.                                                                    KeplerianElementsKey.TRUE_ANOMALY.name() : KeplerianElementsKey.MEAN_ANOMALY.name(),
  55.                                                                    keplerianElements.getAnomaly(),
  56.                                                                    Unit.DEGREE,
  57.                                                                    true);
  58.         generator.writeEntry(KeplerianElementsKey.GM.name(), keplerianElements.getMu(), Units.KM3_PER_S2, true);

  59.     }

  60. }