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.tdm;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.orekit.files.ccsds.section.CommentsContainer;
24  import org.orekit.files.ccsds.section.Data;
25  import org.orekit.time.AbsoluteDate;
26  
27  /** The Observations Block class contain metadata and the list of observation data lines.
28   * <p>
29   * Beware that the Orekit getters and setters all rely on SI units. The parsers
30   * and writers take care of converting these SI units into CCSDS mandatory units.
31   * The {@link org.orekit.utils.units.Unit Unit} class provides useful
32   * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
33   * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
34   * already use CCSDS units instead of the API SI units. The general-purpose
35   * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
36   * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
37   * (with an 's') also provide some predefined units. These predefined units and the
38   * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
39   * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
40   * what the parsers and writers use for the conversions.
41   * </p>
42   * <p>
43   * The reason for which the observations have been separated into blocks is that the different
44   * data blocks in a TDM file usually refers to different types of observations.
45   * An observation block is associated with a TDM metadata object and contains a list of observations.
46   * At this level, an observation is not an Orekit object, it is a custom object containing:
47   * </p>
48   * <ul>
49   *  <li>a keyword, the type of the observation;</li>
50   *  <li>a timetag, the date of the observation;</li>
51   *  <li>a measurement, the value of the observation.</li>
52   * </ul>
53   * @author Maxime Journot
54   */
55  public class ObservationsBlock extends CommentsContainer implements Data {
56  
57      /** Current observation epoch. */
58      private AbsoluteDate currentObservationEpoch;
59  
60      /** List of observations data lines. */
61      private List<Observation> observations;
62  
63      /** ObservationsBlock constructor. */
64      public ObservationsBlock() {
65          observations = new ArrayList<>();
66      }
67  
68      /** Add the epoch of current observation.
69       * @param epoch current observation epoch
70       * @return alwaus return {@code true}
71       */
72      boolean addObservationEpoch(final AbsoluteDate epoch) {
73          refuseFurtherComments();
74          currentObservationEpoch = epoch;
75          return true;
76      }
77  
78      /** Get current observation epoch if set.
79       * @return current observation epoch, or null if not set
80       */
81      AbsoluteDate getCurrentObservationEpoch() {
82          return currentObservationEpoch;
83      }
84  
85      /** Add the value of current observation.
86       * @param type type of the observation
87       * @param measurement measurement of the observation
88       */
89      void addObservationValue(final ObservationType type, final double measurement) {
90          addObservation(type, currentObservationEpoch, measurement);
91          currentObservationEpoch = null;
92      }
93  
94      /** Get the list of Observations data lines.
95       * @return a reference to the internal list of Observations data lines
96       */
97      public List<Observation> getObservations() {
98          return this.observations;
99      }
100 
101     /** Set the list of Observations Data Lines.
102      * @param observations the list of Observations Data Lines to set
103      */
104     public void setObservations(final List<Observation> observations) {
105         refuseFurtherComments();
106         this.observations = new ArrayList<>(observations);
107     }
108 
109     /** Adds an observation data line.
110      * @param observation the observation to add to the list
111      */
112     public void addObservation(final Observation observation) {
113         refuseFurtherComments();
114         this.observations.add(observation);
115     }
116 
117     /** Adds an observation data line.
118      * @param type type of the observation
119      * @param epoch the timetag
120      * @param measurement the measurement
121      */
122     public void addObservation(final ObservationType type,
123                                final AbsoluteDate epoch,
124                                final double measurement) {
125         this.addObservation(new Observation(type, epoch, measurement));
126     }
127 
128 }