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  
18  package org.orekit.files.ccsds.ndm.odm.omm;
19  
20  import java.io.IOException;
21  
22  import org.orekit.files.ccsds.definitions.TimeConverter;
23  import org.orekit.files.ccsds.definitions.Units;
24  import org.orekit.files.ccsds.ndm.odm.KeplerianElements;
25  import org.orekit.files.ccsds.ndm.odm.KeplerianElementsKey;
26  import org.orekit.files.ccsds.section.AbstractWriter;
27  import org.orekit.files.ccsds.utils.generation.Generator;
28  import org.orekit.utils.units.Unit;
29  
30  /** Writer for Keplerian elements data in OMM files.
31   * @author Luc Maisonobe
32   * @since 11.0
33   */
34  class MeanKeplerianElementsWriter extends AbstractWriter {
35  
36      /** Keplerian elements block. */
37      private final KeplerianElements keplerianElements;
38  
39      /** Converter for dates. */
40      private final TimeConverter timeConverter;
41  
42      /** Flag for SGP/SDP mean element theory. */
43      private final boolean theoryIsSgpSdp;
44  
45      /** Create a writer.
46       * @param xmlTag name of the XML tag surrounding the section
47       * @param kvnTag name of the KVN tag surrounding the section (may be null)
48       * @param keplerianElements Keplerian elements to write
49       * @param timeConverter converter for dates
50       * @param theoryIsSgpSdp if true, mean element theory in SGP or SDP
51       */
52      MeanKeplerianElementsWriter(final String xmlTag, final String kvnTag,
53                                  final KeplerianElements keplerianElements,
54                                  final TimeConverter timeConverter,
55                                  final boolean theoryIsSgpSdp) {
56          super(xmlTag, kvnTag);
57          this.keplerianElements = keplerianElements;
58          this.timeConverter     = timeConverter;
59          this.theoryIsSgpSdp    = theoryIsSgpSdp;
60      }
61  
62      /** {@inheritDoc} */
63      @Override
64      protected void writeContent(final Generator generator) throws IOException {
65  
66          // Keplerian elements block
67          generator.writeComments(keplerianElements.getComments());
68          generator.writeEntry(KeplerianElementsKey.EPOCH.name(), timeConverter, keplerianElements.getEpoch(), true, true);
69          if (theoryIsSgpSdp) {
70              generator.writeEntry(KeplerianElementsKey.MEAN_MOTION.name(), keplerianElements.getMeanMotion(), Units.REV_PER_DAY, true);
71          } else {
72              generator.writeEntry(KeplerianElementsKey.SEMI_MAJOR_AXIS.name(), keplerianElements.getA(), Unit.KILOMETRE, true);
73          }
74          generator.writeEntry(KeplerianElementsKey.ECCENTRICITY.name(),      keplerianElements.getE(), Unit.ONE,          true);
75          generator.writeEntry(KeplerianElementsKey.INCLINATION.name(),       keplerianElements.getI(), Unit.DEGREE,       true);
76          generator.writeEntry(KeplerianElementsKey.RA_OF_ASC_NODE.name(),    keplerianElements.getRaan(), Unit.DEGREE,    true);
77          generator.writeEntry(KeplerianElementsKey.ARG_OF_PERICENTER.name(), keplerianElements.getPa(), Unit.DEGREE,      true);
78          generator.writeEntry(KeplerianElementsKey.MEAN_ANOMALY.name(),      keplerianElements.getAnomaly(), Unit.DEGREE, true);
79          generator.writeEntry(KeplerianElementsKey.GM.name(),                keplerianElements.getMu(), Units.KM3_PER_S2, false);
80  
81      }
82  
83  }