1 /* Copyright 2002-2026 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.section;
19
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
22
23 import org.orekit.errors.OrekitException;
24 import org.orekit.errors.OrekitMessages;
25 import org.orekit.files.ccsds.definitions.CcsdsFrameMapper;
26 import org.orekit.files.ccsds.definitions.TimeSystem;
27 import org.orekit.frames.Frame;
28
29 /** This class gathers the meta-data present in the Navigation Data Message (ADM, ODM and TDM).
30 * <p>
31 * Beware that the Orekit getters and setters all rely on SI units. The parsers
32 * and writers take care of converting these SI units into CCSDS mandatory units.
33 * The {@link org.orekit.utils.units.Unit Unit} class provides useful
34 * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
35 * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
36 * already use CCSDS units instead of the API SI units. The general-purpose
37 * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
38 * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
39 * (with an 's') also provide some predefined units. These predefined units and the
40 * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
41 * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
42 * what the parsers and writers use for the conversions.
43 * </p>
44 * @author Luc Maisonobe
45 * @since 11.0
46 */
47 public class Metadata extends CommentsContainer {
48
49 /** Pattern for international designator. */
50 private static final Pattern INTERNATIONAL_DESIGNATOR = Pattern.compile("(\\p{Digit}{4})-(\\p{Digit}{3})(\\p{Upper}{1,3})");
51
52 /** Time System: used for metadata, orbit state and covariance data. */
53 private TimeSystem timeSystem;
54
55 /** For creating a {@link Frame}. */
56 private final CcsdsFrameMapper frameMapper;
57
58 /**
59 * Simple constructor.
60 *
61 * @param defaultTimeSystem default time system (may be null)
62 * @param frameMapper for creating a {@link Frame}.
63 * @since 13.1.5
64 */
65 protected Metadata(final TimeSystem defaultTimeSystem,
66 final CcsdsFrameMapper frameMapper) {
67 this.timeSystem = defaultTimeSystem;
68 this.frameMapper = frameMapper;
69 }
70
71 /**
72 * Get the mapping between a CCSDS frame and a {@link Frame}.
73 *
74 * @return the frame mapper.
75 * @since 13.1.5
76 */
77 public CcsdsFrameMapper getFrameMapper() {
78 return frameMapper;
79 }
80
81 /** {@inheritDoc} */
82 @Override
83 public void validate(final double version) {
84 super.validate(version);
85 checkNotNull(timeSystem, MetadataKey.TIME_SYSTEM.name());
86 }
87
88 /** Get the Time System that: for OPM, is used for metadata, state vector,
89 * maneuver and covariance data, for OMM, is used for metadata, orbit state
90 * and covariance data, for OEM, is used for metadata, ephemeris and
91 * covariance data.
92 * @return the time system
93 */
94 public TimeSystem getTimeSystem() {
95 return timeSystem;
96 }
97
98 /** Set the Time System that: for OPM, is used for metadata, state vector,
99 * maneuver and covariance data, for OMM, is used for metadata, orbit state
100 * and covariance data, for OEM, is used for metadata, ephemeris and
101 * covariance data.
102 * @param timeSystem the time system to be set
103 */
104 public void setTimeSystem(final TimeSystem timeSystem) {
105 refuseFurtherComments();
106 this.timeSystem = timeSystem;
107 }
108
109 /** Get the launch year.
110 * @param objectID object identifier
111 * @return launch year
112 */
113 protected int getLaunchYear(final String objectID) {
114 final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
115 if (matcher.matches()) {
116 return Integer.parseInt(matcher.group(1));
117 }
118 throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
119 }
120
121 /** Get the launch number.
122 * @param objectID object identifier
123 * @return launch number
124 */
125 protected int getLaunchNumber(final String objectID) {
126 final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
127 if (matcher.matches()) {
128 return Integer.parseInt(matcher.group(2));
129 }
130 throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
131 }
132
133 /** Get the piece of launch.
134 * @param objectID object identifier
135 * @return piece of launch
136 */
137 protected String getLaunchPiece(final String objectID) {
138 final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
139 if (matcher.matches()) {
140 return matcher.group(3);
141 }
142 throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
143 }
144
145 }