CoordinateSystemTerm.java

  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. import org.orekit.annotation.DefaultDataContext;
  19. import org.orekit.data.DataContext;
  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.errors.OrekitInternalError;
  22. import org.orekit.errors.OrekitMessages;
  23. import org.orekit.files.iirv.terms.base.LongValuedIIRVTerm;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.utils.IERSConventions;

  26. /**
  27.  * 1-character representing the coordinate system associated with the state variables.
  28.  * <p>
  29.  * Valid values:
  30.  * <ul>
  31.  * <li> 1 = Geocentric True-of-Date Rotating
  32.  * <li> 2 = Geocentric mean of 1950.0 (B1950.0)
  33.  * <li> 3 = Heliocentric B1950.0
  34.  * <li> 4 = Reserved for JPL use (non-GSFC)
  35.  * <li> 5 = Reserved for JPL use (non-GSFC)
  36.  * <li> 6 = Geocentric mean of 2000.0 (J2000.0)
  37.  * <li> 7 = Heliocentric J2000.0
  38.  * </ul>
  39.  *
  40.  * @author Nick LaFarge
  41.  * @since 13.0
  42.  */
  43. public class CoordinateSystemTerm extends LongValuedIIRVTerm {
  44.     /**
  45.      * Geocentric True-of-Date Rotating (GTOD) CoordinateSystemTerm.
  46.      * <p>
  47.      * Also known as True of Date Rotating frame (TDR) or Greenwich Rotating Coordinate frame (GCR).
  48.      */
  49.     public static final CoordinateSystemTerm GEOCENTRIC_TRUE_OF_DATE_ROTATING = new CoordinateSystemTerm("1");

  50.     /** Geocentric mean of 1950.0 (B1950.0) CoordinateSystemTerm. */
  51.     public static final CoordinateSystemTerm GEOCENTRIC_MEAN_B1950 = new CoordinateSystemTerm("2");

  52.     /** Heliocentric B1950.0 CoordinateSystemTerm. */
  53.     public static final CoordinateSystemTerm HELIOCENTRIC_B1950 = new CoordinateSystemTerm("3");

  54.     /** Reserved for JPL use (non-GSFC) CoordinateSystemTerm. */
  55.     public static final CoordinateSystemTerm JPL_RESERVED_1 = new CoordinateSystemTerm("4");

  56.     /** Reserved for JPL use (non-GSFC) CoordinateSystemTerm. */
  57.     public static final CoordinateSystemTerm JPL_RESERVED_2 = new CoordinateSystemTerm("5");

  58.     /** Geocentric mean of 2000.0 (J2000.0) CoordinateSystemTerm. */
  59.     public static final CoordinateSystemTerm GEOCENTRIC_MEAN_OF_J2000 = new CoordinateSystemTerm("6");

  60.     /** Heliocentric J2000.0 CoordinateSystemTerm. */
  61.     public static final CoordinateSystemTerm HELIOCENTRIC_J2000 = new CoordinateSystemTerm("7");

  62.     /** The length of the IIRV term within the message. */
  63.     public static final int COORDINATE_SYSTEM_TERM_LENGTH = 1;

  64.     /** Regular expression that ensures the validity of string values for this term. */
  65.     public static final String COORDINATE_SYSTEM_TERM_PATTERN = "[1-7]";

  66.     /**
  67.      * Constructor.
  68.      * <p>
  69.      * See {@link LongValuedIIRVTerm#LongValuedIIRVTerm(String, String, int, boolean)}
  70.      *
  71.      * @param value value of the coordinate system term
  72.      */
  73.     public CoordinateSystemTerm(final String value) {
  74.         super(COORDINATE_SYSTEM_TERM_PATTERN, value, COORDINATE_SYSTEM_TERM_LENGTH, false);
  75.     }

  76.     /**
  77.      * Constructor.
  78.      * <p>
  79.      * See {@link LongValuedIIRVTerm#LongValuedIIRVTerm(String, long, int, boolean)}
  80.      *
  81.      * @param value value of the coordinate system term
  82.      */
  83.     public CoordinateSystemTerm(final long value) {
  84.         super(COORDINATE_SYSTEM_TERM_PATTERN, value, COORDINATE_SYSTEM_TERM_LENGTH, false);
  85.     }

  86.     /**
  87.      * Returns the {@link Frame} specified within the IIRV.
  88.      *
  89.      * @param context data context used to retrieve frames
  90.      * @return coordinate system
  91.      */
  92.     public Frame getFrame(final DataContext context) {
  93.         final String encodedString = toEncodedString();
  94.         switch (toEncodedString()) {
  95.             case "1":
  96.                 return context.getFrames().getGTOD(IERSConventions.IERS_2010, true);
  97.             case "2":
  98.                 throw new OrekitException(OrekitMessages.IIRV_UNMAPPED_COORDINATE_SYSTEM,
  99.                     encodedString, "Geocentric mean of 1950.0 (B1950.0)");
  100.             case "3":
  101.                 throw new OrekitException(OrekitMessages.IIRV_UNMAPPED_COORDINATE_SYSTEM,
  102.                     encodedString, "B1950.0");
  103.             case "4":
  104.             case "5":
  105.                 throw new OrekitException(OrekitMessages.IIRV_UNMAPPED_COORDINATE_SYSTEM,
  106.                     encodedString, "Reserved for JPL");
  107.             case "6":
  108.                 return context.getFrames().getEME2000();
  109.             case "7":
  110.                 return context.getCelestialBodies().getSun().getInertiallyOrientedFrame();
  111.             default:
  112.                 // this should never happen
  113.                 throw new OrekitInternalError(null);
  114.         }
  115.     }

  116.     /**
  117.      * Returns the {@link Frame} specified within the IIRV using the {@link DataContext#getDefault() default data context}.
  118.      *
  119.      * @return coordinate system
  120.      */
  121.     @DefaultDataContext
  122.     public Frame getFrame() {
  123.         return getFrame(DataContext.getDefault());
  124.     }

  125. }