1   /* Copyright 2024-2025 The Johns Hopkins University Applied Physics Laboratory
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.iirv.terms;
18  
19  import org.orekit.annotation.DefaultDataContext;
20  import org.orekit.data.DataContext;
21  import org.orekit.errors.OrekitException;
22  import org.orekit.errors.OrekitInternalError;
23  import org.orekit.errors.OrekitMessages;
24  import org.orekit.files.iirv.terms.base.LongValuedIIRVTerm;
25  import org.orekit.frames.Frame;
26  import org.orekit.utils.IERSConventions;
27  
28  /**
29   * 1-character representing the coordinate system associated with the state variables.
30   * <p>
31   * Valid values:
32   * <ul>
33   * <li> 1 = Geocentric True-of-Date Rotating
34   * <li> 2 = Geocentric mean of 1950.0 (B1950.0)
35   * <li> 3 = Heliocentric B1950.0
36   * <li> 4 = Reserved for JPL use (non-GSFC)
37   * <li> 5 = Reserved for JPL use (non-GSFC)
38   * <li> 6 = Geocentric mean of 2000.0 (J2000.0)
39   * <li> 7 = Heliocentric J2000.0
40   * </ul>
41   *
42   * @author Nick LaFarge
43   * @since 13.0
44   */
45  public class CoordinateSystemTerm extends LongValuedIIRVTerm {
46      /**
47       * Geocentric True-of-Date Rotating (GTOD) CoordinateSystemTerm.
48       * <p>
49       * Also known as True of Date Rotating frame (TDR) or Greenwich Rotating Coordinate frame (GCR).
50       */
51      public static final CoordinateSystemTerm GEOCENTRIC_TRUE_OF_DATE_ROTATING = new CoordinateSystemTerm("1");
52  
53      /** Geocentric mean of 1950.0 (B1950.0) CoordinateSystemTerm. */
54      public static final CoordinateSystemTerm GEOCENTRIC_MEAN_B1950 = new CoordinateSystemTerm("2");
55  
56      /** Heliocentric B1950.0 CoordinateSystemTerm. */
57      public static final CoordinateSystemTerm HELIOCENTRIC_B1950 = new CoordinateSystemTerm("3");
58  
59      /** Reserved for JPL use (non-GSFC) CoordinateSystemTerm. */
60      public static final CoordinateSystemTerm JPL_RESERVED_1 = new CoordinateSystemTerm("4");
61  
62      /** Reserved for JPL use (non-GSFC) CoordinateSystemTerm. */
63      public static final CoordinateSystemTerm JPL_RESERVED_2 = new CoordinateSystemTerm("5");
64  
65      /** Geocentric mean of 2000.0 (J2000.0) CoordinateSystemTerm. */
66      public static final CoordinateSystemTerm GEOCENTRIC_MEAN_OF_J2000 = new CoordinateSystemTerm("6");
67  
68      /** Heliocentric J2000.0 CoordinateSystemTerm. */
69      public static final CoordinateSystemTerm HELIOCENTRIC_J2000 = new CoordinateSystemTerm("7");
70  
71      /** The length of the IIRV term within the message. */
72      public static final int COORDINATE_SYSTEM_TERM_LENGTH = 1;
73  
74      /** Regular expression that ensures the validity of string values for this term. */
75      public static final String COORDINATE_SYSTEM_TERM_PATTERN = "[1-7]";
76  
77      /**
78       * Constructor.
79       * <p>
80       * See {@link LongValuedIIRVTerm#LongValuedIIRVTerm(String, String, int, boolean)}
81       *
82       * @param value value of the coordinate system term
83       */
84      public CoordinateSystemTerm(final String value) {
85          super(COORDINATE_SYSTEM_TERM_PATTERN, value, COORDINATE_SYSTEM_TERM_LENGTH, false);
86      }
87  
88      /**
89       * Constructor.
90       * <p>
91       * See {@link LongValuedIIRVTerm#LongValuedIIRVTerm(String, long, int, boolean)}
92       *
93       * @param value value of the coordinate system term
94       */
95      public CoordinateSystemTerm(final long value) {
96          super(COORDINATE_SYSTEM_TERM_PATTERN, value, COORDINATE_SYSTEM_TERM_LENGTH, false);
97      }
98  
99      /**
100      * Returns the {@link Frame} specified within the IIRV.
101      *
102      * @param context data context used to retrieve frames
103      * @return coordinate system
104      */
105     public Frame getFrame(final DataContext context) {
106         final String encodedString = toEncodedString();
107         switch (toEncodedString()) {
108             case "1":
109                 return context.getFrames().getGTOD(IERSConventions.IERS_2010, true);
110             case "2":
111                 throw new OrekitException(OrekitMessages.IIRV_UNMAPPED_COORDINATE_SYSTEM,
112                     encodedString, "Geocentric mean of 1950.0 (B1950.0)");
113             case "3":
114                 throw new OrekitException(OrekitMessages.IIRV_UNMAPPED_COORDINATE_SYSTEM,
115                     encodedString, "B1950.0");
116             case "4":
117             case "5":
118                 throw new OrekitException(OrekitMessages.IIRV_UNMAPPED_COORDINATE_SYSTEM,
119                     encodedString, "Reserved for JPL");
120             case "6":
121                 return context.getFrames().getEME2000();
122             case "7":
123                 return context.getCelestialBodies().getSun().getInertiallyOrientedFrame();
124             default:
125                 // this should never happen
126                 throw new OrekitInternalError(null);
127         }
128     }
129 
130     /**
131      * Returns the {@link Frame} specified within the IIRV using the {@link DataContext#getDefault() default data context}.
132      *
133      * @return coordinate system
134      */
135     @DefaultDataContext
136     public Frame getFrame() {
137         return getFrame(DataContext.getDefault());
138     }
139 
140 }