Aem.java

  1. /* Copyright 2002-2022 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.adm.aem;

  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.section.Header;
  28. import org.orekit.files.general.AttitudeEphemerisFile;
  29. import org.orekit.utils.IERSConventions;
  30. import org.orekit.utils.TimeStampedAngularCoordinates;

  31. /**
  32.  * This class stores all the information of the Attitude Ephemeris Message (AEM) File parsed
  33.  * by AEMParser. It contains the header and a list of Attitude Ephemerides Blocks each
  34.  * containing metadata and a list of attitude ephemerides data lines.
  35.  * @author Bryan Cazabonne
  36.  * @since 10.2
  37.  */
  38. public class Aem extends NdmConstituent<Header, AemSegment>
  39.     implements AttitudeEphemerisFile<TimeStampedAngularCoordinates, AemSegment> {

  40.     /** Root element for XML files. */
  41.     public static final String ROOT = "aem";

  42.     /** Key for format version. */
  43.     public static final String FORMAT_VERSION_KEY = "CCSDS_AEM_VERS";

  44.     /** Simple constructor.
  45.      * @param header file header
  46.      * @param segments file segments
  47.      * @param conventions IERS conventions
  48.      * @param dataContext used for creating frames, time scales, etc.
  49.      */
  50.     public Aem(final Header header, final List<AemSegment> segments,
  51.                final IERSConventions conventions, final DataContext dataContext) {
  52.         super(header, segments, conventions, dataContext);
  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public Map<String, AemSatelliteEphemeris> getSatellites() {
  57.         final Map<String, List<AemSegment>> byId = new HashMap<>();
  58.         for (final AemSegment segment : getSegments()) {
  59.             final String id = segment.getMetadata().getObjectID();
  60.             byId.putIfAbsent(id, new ArrayList<>());
  61.             byId.get(id).add(segment);
  62.         }
  63.         final Map<String, AemSatelliteEphemeris> ret = new HashMap<>();
  64.         for (final Map.Entry<String, List<AemSegment>> entry : byId.entrySet()) {
  65.             ret.put(entry.getKey(), new AemSatelliteEphemeris(entry.getKey(), entry.getValue()));
  66.         }
  67.         return ret;
  68.     }

  69.     /**
  70.      * Check that, according to the CCSDS standard, every AEMBlock has the same time system.
  71.      */
  72.     public void checkTimeSystems() {
  73.         TimeSystem referenceTimeSystem = null;
  74.         for (final AemSegment segment : getSegments()) {
  75.             final TimeSystem timeSystem = segment.getMetadata().getTimeSystem();
  76.             if (referenceTimeSystem == null) {
  77.                 referenceTimeSystem = timeSystem;
  78.             } else if (!referenceTimeSystem.equals(timeSystem)) {
  79.                 throw new OrekitException(OrekitMessages.CCSDS_AEM_INCONSISTENT_TIME_SYSTEMS,
  80.                                           referenceTimeSystem.name(), timeSystem.name());
  81.             }
  82.         }
  83.     }

  84. }