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.adm.aem;
18  
19  import java.util.ArrayList;
20  import java.util.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.orekit.data.DataContext;
25  import org.orekit.errors.OrekitException;
26  import org.orekit.errors.OrekitMessages;
27  import org.orekit.files.ccsds.definitions.TimeSystem;
28  import org.orekit.files.ccsds.ndm.NdmConstituent;
29  import org.orekit.files.ccsds.section.Header;
30  import org.orekit.files.general.AttitudeEphemerisFile;
31  import org.orekit.utils.IERSConventions;
32  import org.orekit.utils.TimeStampedAngularCoordinates;
33  
34  /**
35   * This class stores all the information of the Attitude Ephemeris Message (AEM) File parsed
36   * by AEMParser. It contains the header and a list of Attitude Ephemerides Blocks each
37   * containing metadata and a list of attitude ephemerides data lines.
38   * @author Bryan Cazabonne
39   * @since 10.2
40   */
41  public class Aem extends NdmConstituent<Header, AemSegment>
42      implements AttitudeEphemerisFile<TimeStampedAngularCoordinates, AemSegment> {
43  
44      /** Root element for XML files. */
45      public static final String ROOT = "aem";
46  
47      /** Key for format version. */
48      public static final String FORMAT_VERSION_KEY = "CCSDS_AEM_VERS";
49  
50      /** Simple constructor.
51       * @param header file header
52       * @param segments file segments
53       * @param conventions IERS conventions
54       * @param dataContext used for creating frames, time scales, etc.
55       */
56      public Aem(final Header header, final List<AemSegment> segments,
57                     final IERSConventions conventions, final DataContext dataContext) {
58          super(header, segments, conventions, dataContext);
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public Map<String, AemSatelliteEphemeris> getSatellites() {
64          final Map<String, List<AemSegment>> byId = new HashMap<>();
65          for (final AemSegment segment : getSegments()) {
66              final String id = segment.getMetadata().getObjectID();
67              byId.putIfAbsent(id, new ArrayList<>());
68              byId.get(id).add(segment);
69          }
70          final Map<String, AemSatelliteEphemeris> ret = new HashMap<>();
71          for (final Map.Entry<String, List<AemSegment>> entry : byId.entrySet()) {
72              ret.put(entry.getKey(), new AemSatelliteEphemeris(entry.getKey(), entry.getValue()));
73          }
74          return ret;
75      }
76  
77      /**
78       * Check that, according to the CCSDS standard, every AEMBlock has the same time system.
79       */
80      public void checkTimeSystems() {
81          TimeSystem referenceTimeSystem = null;
82          for (final AemSegment segment : getSegments()) {
83              final TimeSystem timeSystem = segment.getMetadata().getTimeSystem();
84              if (referenceTimeSystem == null) {
85                  referenceTimeSystem = timeSystem;
86              } else if (!referenceTimeSystem.equals(timeSystem)) {
87                  throw new OrekitException(OrekitMessages.CCSDS_AEM_INCONSISTENT_TIME_SYSTEMS,
88                                            referenceTimeSystem.name(), timeSystem.name());
89              }
90          }
91      }
92  
93  }