Oem.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.oem;

  18. import java.util.ArrayList;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;

  22. import org.orekit.data.DataContext;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.errors.OrekitMessages;
  25. import org.orekit.files.ccsds.definitions.TimeSystem;
  26. import org.orekit.files.ccsds.ndm.NdmConstituent;
  27. import org.orekit.files.ccsds.ndm.odm.OdmHeader;
  28. import org.orekit.files.general.EphemerisFile;
  29. import org.orekit.utils.IERSConventions;
  30. import org.orekit.utils.TimeStampedPVCoordinates;

  31. /** This class stores all the information of the OEM File parsed by OEMParser.
  32.  * <p>
  33.  * It contains the header and a list of Ephemerides Blocks each containing
  34.  * metadata, a list of ephemerides data lines and optional covariance matrices
  35.  * (and their metadata).
  36.  * </p>
  37.  * @author sports
  38.  * @author Evan Ward
  39.  * @since 6.1
  40.  */
  41. public class Oem extends NdmConstituent<OdmHeader, OemSegment>
  42.     implements EphemerisFile<TimeStampedPVCoordinates, OemSegment> {

  43.     /** Root element for XML files. */
  44.     public static final String ROOT = "oem";

  45.     /** Key for format version. */
  46.     public static final String FORMAT_VERSION_KEY = "CCSDS_OEM_VERS";

  47.     /** Gravitational coefficient to use for building Cartesian/Keplerian orbits. */
  48.     private final double mu;

  49.     /** Simple constructor.
  50.      * @param header file header
  51.      * @param segments file segments
  52.      * @param conventions IERS conventions
  53.      * @param dataContext used for creating frames, time scales, etc.
  54.      * @param mu gravitational coefficient
  55.      */
  56.     public Oem(final OdmHeader header, final List<OemSegment> segments,
  57.                final IERSConventions conventions, final DataContext dataContext,
  58.                final double mu) {
  59.         super(header, segments, conventions, dataContext);
  60.         this.mu = mu;
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public Map<String, OemSatelliteEphemeris> getSatellites() {
  65.         final Map<String, List<OemSegment>> byId = new HashMap<>();
  66.         for (final OemSegment segment : getSegments()) {
  67.             final String id = segment.getMetadata().getObjectID();
  68.             byId.putIfAbsent(id, new ArrayList<>());
  69.             byId.get(id).add(segment);
  70.         }
  71.         final Map<String, OemSatelliteEphemeris> ret = new HashMap<>();
  72.         for (final Map.Entry<String, List<OemSegment>> entry : byId.entrySet()) {
  73.             ret.put(entry.getKey(), new OemSatelliteEphemeris(entry.getKey(), mu, entry.getValue()));
  74.         }
  75.         return ret;
  76.     }

  77.     /** Check that, according to the CCSDS standard, every OEMBlock has the same time system.
  78.      */
  79.     public void checkTimeSystems() {
  80.         TimeSystem referenceTimeSystem = null;
  81.         for (final OemSegment segment : getSegments()) {
  82.             final TimeSystem timeSystem = segment.getMetadata().getTimeSystem();
  83.             if (referenceTimeSystem == null) {
  84.                 referenceTimeSystem = timeSystem;
  85.             } else if (!referenceTimeSystem.equals(timeSystem)) {
  86.                 throw new OrekitException(OrekitMessages.CCSDS_INCONSISTENT_TIME_SYSTEMS,
  87.                                           referenceTimeSystem.name(), timeSystem.name());
  88.             }
  89.         }
  90.     }

  91. }