RinexObservation.java

  1. /* Copyright 2002-2024 Thales Alenia Space
  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.rinex.observation;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.hipparchus.util.FastMath;
  22. import org.orekit.errors.OrekitIllegalArgumentException;
  23. import org.orekit.errors.OrekitMessages;
  24. import org.orekit.files.rinex.RinexFile;
  25. import org.orekit.time.AbsoluteDate;

  26. /** Container for Rinex observation file.
  27.  * @author Luc Maisonobe
  28.  * @since 12.0
  29.  */
  30. public class RinexObservation extends RinexFile<RinexObservationHeader> {

  31.     /** Observations. */
  32.     private final List<ObservationDataSet> observations;

  33.     /** Simple constructor.
  34.      */
  35.     public RinexObservation() {
  36.         super(new RinexObservationHeader());
  37.         this.observations = new ArrayList<>();
  38.     }

  39.     /** Get an unmodifiable view of the observations.
  40.      * @return unmodifiable view of the observations
  41.      */
  42.     public List<ObservationDataSet> getObservationDataSets() {
  43.         return Collections.unmodifiableList(observations);
  44.     }

  45.     /** Add an observations data set.
  46.      * <p>
  47.      * Observations must be added chronologically, within header date range, and separated
  48.      * by an integer multiple of the {@link RinexObservationHeader#getInterval() interval}
  49.      * (ideally one interval, but entries at same dates and missing entries are allowed so
  50.      * any non-negative integer is allowed).
  51.      * </p>
  52.      * @param observationsDataSet observations data set
  53.      */
  54.     public void addObservationDataSet(final ObservationDataSet observationsDataSet) {

  55.         final RinexObservationHeader header  = getHeader();
  56.         final AbsoluteDate           current = observationsDataSet.getDate();

  57.         // check interval from previous observation
  58.         if (!observations.isEmpty()) {
  59.             final AbsoluteDate previous   = observations.get(observations.size() - 1).getDate();
  60.             final double       factor     = current.durationFrom(previous) / header.getInterval();
  61.             final double       acceptable = FastMath.max(0.0, FastMath.rint(factor));
  62.             if (FastMath.abs(factor - acceptable) > 0.001) {
  63.                 throw new OrekitIllegalArgumentException(OrekitMessages.INCONSISTENT_SAMPLING_DATE,
  64.                                                          previous.shiftedBy(acceptable * header.getInterval()),
  65.                                                          current);
  66.             }
  67.         }

  68.         // check global range
  69.         final AbsoluteDate first = header.getTFirstObs();
  70.         final AbsoluteDate last  = header.getTLastObs();
  71.         if (!current.isBetweenOrEqualTo(first, last)) {
  72.             throw new OrekitIllegalArgumentException(OrekitMessages.OUT_OF_RANGE_DATE,
  73.                                                      current, first, last);
  74.         }

  75.         observations.add(observationsDataSet);

  76.     }

  77. }