1   /* Copyright 2002-2021 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  
19  import org.orekit.data.DataContext;
20  import org.orekit.errors.OrekitException;
21  import org.orekit.errors.OrekitMessages;
22  import org.orekit.files.ccsds.ndm.NdmConstituent;
23  import org.orekit.files.ccsds.ndm.ParsedUnitsBehavior;
24  import org.orekit.files.ccsds.utils.parsing.AbstractConstituentParser;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.utils.IERSConventions;
27  
28  /** Common parser for Orbit Parameter/Ephemeris/Mean/Comprehensive Messages.
29   * <p>
30   * Note than starting with Orekit 11.0, CCSDS message parsers are
31   * mutable objects that gather the data being parsed, until the
32   * message is complete and the {@link #parseMessage(org.orekit.data.DataSource)
33   * parseMessage} method has returned. This implies that parsers
34   * should <em>not</em> be used in a multi-thread context. The recommended
35   * way to use parsers is to either dedicate one parser for each message
36   * and drop it afterwards, or to use a single-thread loop.
37   * </p>
38   * @param <T> type of the ODM file
39   * @param <P> type of the parser
40   * @author Luc Maisonobe
41   * @since 11.0
42   */
43  public abstract class OdmParser<T extends NdmConstituent<?, ?>, P extends OdmParser<T, ?>> extends AbstractConstituentParser<T, P> {
44  
45      /** Reference date for Mission Elapsed Time or Mission Relative Time time systems. */
46      private final AbsoluteDate missionReferenceDate;
47  
48      /** Gravitational coefficient set by the user in the parser. */
49      private final double muSet;
50  
51      /** Gravitational coefficient parsed in the ODM File. */
52      private double muParsed;
53  
54      /** Gravitational coefficient created from the knowledge of the central body. */
55      private double muCreated;
56  
57      /** Complete constructor.
58       * @param root root element for XML files
59       * @param formatVersionKey key for format version
60       * @param conventions IERS Conventions
61       * @param simpleEOP if true, tidal effects are ignored when interpolating EOP
62       * @param dataContext used to retrieve frames and time scales
63       * @param missionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
64       * @param mu gravitational coefficient
65       * @param parsedUnitsBehavior behavior to adopt for handling parsed units
66       */
67      protected OdmParser(final String root, final String formatVersionKey,
68                          final IERSConventions conventions, final boolean simpleEOP,
69                          final DataContext dataContext, final AbsoluteDate missionReferenceDate,
70                          final double mu, final ParsedUnitsBehavior parsedUnitsBehavior) {
71          super(root, formatVersionKey, conventions, simpleEOP, dataContext, parsedUnitsBehavior);
72          this.missionReferenceDate = missionReferenceDate;
73          this.muSet                = mu;
74          this.muParsed             = Double.NaN;
75          this.muCreated            = Double.NaN;
76      }
77  
78      /**
79       * Get reference date for Mission Elapsed Time and Mission Relative Time time systems.
80       * @return the reference date
81       */
82      public AbsoluteDate getMissionReferenceDate() {
83          return missionReferenceDate;
84      }
85  
86      /** Get the gravitational coefficient set at construction.
87       * @return gravitational coefficient set at construction
88       */
89      protected double getMuSet() {
90          return muSet;
91      }
92  
93      /**
94       * Set the gravitational coefficient parsed in the ODM File.
95       * @param muParsed the coefficient to be set
96       */
97      protected void setMuParsed(final double muParsed) {
98          this.muParsed = muParsed;
99      }
100 
101     /**
102      * Set the gravitational coefficient created from the knowledge of the central body.
103      * @param muCreated the coefficient to be set
104      */
105     protected void setMuCreated(final double muCreated) {
106         this.muCreated = muCreated;
107     }
108 
109     /**
110      * Select the gravitational coefficient to use.
111      * In order of decreasing priority, finalMU is set equal to:
112      * <ol>
113      *   <li>the coefficient parsed in the file,</li>
114      *   <li>the coefficient set by the user with the parser's method setMu,</li>
115      *   <li>the coefficient created from the knowledge of the central body.</li>
116      * </ol>
117      * @return selected gravitational coefficient
118      */
119     public double getSelectedMu() {
120         if (!Double.isNaN(muParsed)) {
121             return muParsed;
122         } else if (!Double.isNaN(muSet)) {
123             return muSet;
124         } else if (!Double.isNaN(muCreated)) {
125             return muCreated;
126         } else {
127             throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_GM);
128         }
129     }
130 
131 }