OdmParser.java

  1. /* Copyright 2002-2022 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 org.orekit.data.DataContext;
  19. import org.orekit.errors.OrekitException;
  20. import org.orekit.errors.OrekitMessages;
  21. import org.orekit.files.ccsds.ndm.NdmConstituent;
  22. import org.orekit.files.ccsds.ndm.ParsedUnitsBehavior;
  23. import org.orekit.files.ccsds.utils.parsing.AbstractConstituentParser;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.utils.IERSConventions;

  26. /** Common parser for Orbit Parameter/Ephemeris/Mean/Comprehensive Messages.
  27.  * <p>
  28.  * Note than starting with Orekit 11.0, CCSDS message parsers are
  29.  * mutable objects that gather the data being parsed, until the
  30.  * message is complete and the {@link #parseMessage(org.orekit.data.DataSource)
  31.  * parseMessage} method has returned. This implies that parsers
  32.  * should <em>not</em> be used in a multi-thread context. The recommended
  33.  * way to use parsers is to either dedicate one parser for each message
  34.  * and drop it afterwards, or to use a single-thread loop.
  35.  * </p>
  36.  * @param <T> type of the ODM file
  37.  * @param <P> type of the parser
  38.  * @author Luc Maisonobe
  39.  * @since 11.0
  40.  */
  41. public abstract class OdmParser<T extends NdmConstituent<?, ?>, P extends OdmParser<T, ?>> extends AbstractConstituentParser<T, P> {

  42.     /** Reference date for Mission Elapsed Time or Mission Relative Time time systems. */
  43.     private final AbsoluteDate missionReferenceDate;

  44.     /** Gravitational coefficient set by the user in the parser. */
  45.     private final double muSet;

  46.     /** Gravitational coefficient parsed in the ODM File. */
  47.     private double muParsed;

  48.     /** Gravitational coefficient created from the knowledge of the central body. */
  49.     private double muCreated;

  50.     /** Complete constructor.
  51.      * @param root root element for XML files
  52.      * @param formatVersionKey key for format version
  53.      * @param conventions IERS Conventions
  54.      * @param simpleEOP if true, tidal effects are ignored when interpolating EOP
  55.      * @param dataContext used to retrieve frames and time scales
  56.      * @param missionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
  57.      * @param mu gravitational coefficient
  58.      * @param parsedUnitsBehavior behavior to adopt for handling parsed units
  59.      */
  60.     protected OdmParser(final String root, final String formatVersionKey,
  61.                         final IERSConventions conventions, final boolean simpleEOP,
  62.                         final DataContext dataContext, final AbsoluteDate missionReferenceDate,
  63.                         final double mu, final ParsedUnitsBehavior parsedUnitsBehavior) {
  64.         super(root, formatVersionKey, conventions, simpleEOP, dataContext, parsedUnitsBehavior);
  65.         this.missionReferenceDate = missionReferenceDate;
  66.         this.muSet                = mu;
  67.         this.muParsed             = Double.NaN;
  68.         this.muCreated            = Double.NaN;
  69.     }

  70.     /**
  71.      * Get reference date for Mission Elapsed Time and Mission Relative Time time systems.
  72.      * @return the reference date
  73.      */
  74.     public AbsoluteDate getMissionReferenceDate() {
  75.         return missionReferenceDate;
  76.     }

  77.     /** Get the gravitational coefficient set at construction.
  78.      * @return gravitational coefficient set at construction
  79.      */
  80.     protected double getMuSet() {
  81.         return muSet;
  82.     }

  83.     /**
  84.      * Set the gravitational coefficient parsed in the ODM File.
  85.      * @param muParsed the coefficient to be set
  86.      */
  87.     protected void setMuParsed(final double muParsed) {
  88.         this.muParsed = muParsed;
  89.     }

  90.     /**
  91.      * Set the gravitational coefficient created from the knowledge of the central body.
  92.      * @param muCreated the coefficient to be set
  93.      */
  94.     protected void setMuCreated(final double muCreated) {
  95.         this.muCreated = muCreated;
  96.     }

  97.     /**
  98.      * Select the gravitational coefficient to use.
  99.      * In order of decreasing priority, finalMU is set equal to:
  100.      * <ol>
  101.      *   <li>the coefficient parsed in the file,</li>
  102.      *   <li>the coefficient set by the user with the parser's method setMu,</li>
  103.      *   <li>the coefficient created from the knowledge of the central body.</li>
  104.      * </ol>
  105.      * @return selected gravitational coefficient
  106.      */
  107.     public double getSelectedMu() {
  108.         if (!Double.isNaN(muParsed)) {
  109.             return muParsed;
  110.         } else if (!Double.isNaN(muSet)) {
  111.             return muSet;
  112.         } else if (!Double.isNaN(muCreated)) {
  113.             return muCreated;
  114.         } else {
  115.             throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_GM);
  116.         }
  117.     }

  118. }