OdmParser.java

  1. /* Copyright 2002-2024 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 java.util.List;
  19. import java.util.function.Function;

  20. import org.orekit.data.DataContext;
  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.errors.OrekitMessages;
  23. import org.orekit.files.ccsds.ndm.NdmConstituent;
  24. import org.orekit.files.ccsds.ndm.ParsedUnitsBehavior;
  25. import org.orekit.files.ccsds.utils.lexical.ParseToken;
  26. import org.orekit.files.ccsds.utils.parsing.AbstractConstituentParser;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.utils.IERSConventions;

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

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

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

  50.     /** Gravitational coefficient parsed in the ODM File. */
  51.     private double muParsed;

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

  54.     /** Complete constructor.
  55.      * @param root root element for XML files
  56.      * @param formatVersionKey key for format version
  57.      * @param conventions IERS Conventions
  58.      * @param simpleEOP if true, tidal effects are ignored when interpolating EOP
  59.      * @param dataContext used to retrieve frames and time scales
  60.      * @param missionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
  61.      * @param mu gravitational coefficient
  62.      * @param parsedUnitsBehavior behavior to adopt for handling parsed units
  63.      * @param filters filters to apply to parse tokens
  64.      * @since 12.0
  65.      */
  66.     protected OdmParser(final String root, final String formatVersionKey,
  67.                         final IERSConventions conventions, final boolean simpleEOP,
  68.                         final DataContext dataContext, final AbsoluteDate missionReferenceDate,
  69.                         final double mu, final ParsedUnitsBehavior parsedUnitsBehavior,
  70.                         final Function<ParseToken, List<ParseToken>>[] filters) {
  71.         super(root, formatVersionKey, conventions, simpleEOP, dataContext, parsedUnitsBehavior, filters);
  72.         this.missionReferenceDate = missionReferenceDate;
  73.         this.muSet                = mu;
  74.         this.muParsed             = Double.NaN;
  75.         this.muCreated            = Double.NaN;
  76.     }

  77.     /**
  78.      * Get reference date for Mission Elapsed Time and Mission Relative Time time systems.
  79.      * @return the reference date
  80.      */
  81.     public AbsoluteDate getMissionReferenceDate() {
  82.         return missionReferenceDate;
  83.     }

  84.     /** Get the gravitational coefficient set at construction.
  85.      * @return gravitational coefficient set at construction
  86.      */
  87.     protected double getMuSet() {
  88.         return muSet;
  89.     }

  90.     /**
  91.      * Set the gravitational coefficient parsed in the ODM File.
  92.      * @param muParsed the coefficient to be set
  93.      */
  94.     protected void setMuParsed(final double muParsed) {
  95.         this.muParsed = muParsed;
  96.     }

  97.     /**
  98.      * Set the gravitational coefficient created from the knowledge of the central body.
  99.      * @param muCreated the coefficient to be set
  100.      */
  101.     protected void setMuCreated(final double muCreated) {
  102.         this.muCreated = muCreated;
  103.     }

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

  125. }