MeanKeplerianElementsWriter.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.omm;

  18. import java.io.IOException;

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

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

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

  33.     /** Converter for dates. */
  34.     private final TimeConverter timeConverter;

  35.     /** Flag for SGP/SDP mean element theory. */
  36.     private final boolean theoryIsSgpSdp;

  37.     /** Create a writer.
  38.      * @param xmlTag name of the XML tag surrounding the section
  39.      * @param kvnTag name of the KVN tag surrounding the section (may be null)
  40.      * @param keplerianElements Keplerian elements to write
  41.      * @param timeConverter converter for dates
  42.      * @param theoryIsSgpSdp if true, mean element theory in SGP or SDP
  43.      */
  44.     MeanKeplerianElementsWriter(final String xmlTag, final String kvnTag,
  45.                                 final KeplerianElements keplerianElements,
  46.                                 final TimeConverter timeConverter,
  47.                                 final boolean theoryIsSgpSdp) {
  48.         super(xmlTag, kvnTag);
  49.         this.keplerianElements = keplerianElements;
  50.         this.timeConverter     = timeConverter;
  51.         this.theoryIsSgpSdp    = theoryIsSgpSdp;
  52.     }

  53.     /** {@inheritDoc} */
  54.     @Override
  55.     protected void writeContent(final Generator generator) throws IOException {

  56.         // Keplerian elements block
  57.         generator.writeComments(keplerianElements.getComments());
  58.         generator.writeEntry(KeplerianElementsKey.EPOCH.name(), timeConverter, keplerianElements.getEpoch(), true, true);
  59.         if (theoryIsSgpSdp) {
  60.             generator.writeEntry(KeplerianElementsKey.MEAN_MOTION.name(), keplerianElements.getMeanMotion(), Units.REV_PER_DAY, true);
  61.         } else {
  62.             generator.writeEntry(KeplerianElementsKey.SEMI_MAJOR_AXIS.name(), keplerianElements.getA(), Unit.KILOMETRE, true);
  63.         }
  64.         generator.writeEntry(KeplerianElementsKey.ECCENTRICITY.name(),      keplerianElements.getE(), Unit.ONE,          true);
  65.         generator.writeEntry(KeplerianElementsKey.INCLINATION.name(),       keplerianElements.getI(), Unit.DEGREE,       true);
  66.         generator.writeEntry(KeplerianElementsKey.RA_OF_ASC_NODE.name(),    keplerianElements.getRaan(), Unit.DEGREE,    true);
  67.         generator.writeEntry(KeplerianElementsKey.ARG_OF_PERICENTER.name(), keplerianElements.getPa(), Unit.DEGREE,      true);
  68.         generator.writeEntry(KeplerianElementsKey.MEAN_ANOMALY.name(),      keplerianElements.getAnomaly(), Unit.DEGREE, true);
  69.         generator.writeEntry(KeplerianElementsKey.GM.name(),                keplerianElements.getMu(), Units.KM3_PER_S2, false);

  70.     }

  71. }