TLE.java

  1. /* Copyright 2002-2020 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.propagation.analytical.tle;

  18. import java.io.Serializable;
  19. import java.text.DecimalFormat;
  20. import java.text.DecimalFormatSymbols;
  21. import java.util.Locale;
  22. import java.util.Objects;
  23. import java.util.regex.Pattern;

  24. import org.hipparchus.util.ArithmeticUtils;
  25. import org.hipparchus.util.FastMath;
  26. import org.orekit.annotation.DefaultDataContext;
  27. import org.orekit.data.DataContext;
  28. import org.orekit.errors.OrekitException;
  29. import org.orekit.errors.OrekitInternalError;
  30. import org.orekit.errors.OrekitMessages;
  31. import org.orekit.time.AbsoluteDate;
  32. import org.orekit.time.DateComponents;
  33. import org.orekit.time.DateTimeComponents;
  34. import org.orekit.time.TimeComponents;
  35. import org.orekit.time.TimeScale;
  36. import org.orekit.time.TimeStamped;

  37. /** This class is a container for a single set of TLE data.
  38.  *
  39.  * <p>TLE sets can be built either by providing directly the two lines, in
  40.  * which case parsing is performed internally or by providing the already
  41.  * parsed elements.</p>
  42.  * <p>TLE are not transparently convertible to {@link org.orekit.orbits.Orbit Orbit}
  43.  * instances. They are significant only with respect to their dedicated {@link
  44.  * TLEPropagator propagator}, which also computes position and velocity coordinates.
  45.  * Any attempt to directly use orbital parameters like {@link #getE() eccentricity},
  46.  * {@link #getI() inclination}, etc. without any reference to the {@link TLEPropagator
  47.  * TLE propagator} is prone to errors.</p>
  48.  * <p>More information on the TLE format can be found on the
  49.  * <a href="https://www.celestrak.com/">CelesTrak website.</a></p>
  50.  * @author Fabien Maussion
  51.  * @author Luc Maisonobe
  52.  */
  53. public class TLE implements TimeStamped, Serializable {

  54.     /** Identifier for default type of ephemeris (SGP4/SDP4). */
  55.     public static final int DEFAULT = 0;

  56.     /** Identifier for SGP type of ephemeris. */
  57.     public static final int SGP = 1;

  58.     /** Identifier for SGP4 type of ephemeris. */
  59.     public static final int SGP4 = 2;

  60.     /** Identifier for SDP4 type of ephemeris. */
  61.     public static final int SDP4 = 3;

  62.     /** Identifier for SGP8 type of ephemeris. */
  63.     public static final int SGP8 = 4;

  64.     /** Identifier for SDP8 type of ephemeris. */
  65.     public static final int SDP8 = 5;

  66.     /** Pattern for line 1. */
  67.     private static final Pattern LINE_1_PATTERN =
  68.         Pattern.compile("1 [ 0-9]{5}[A-Z] [ 0-9]{5}[ A-Z]{3} [ 0-9]{5}[.][ 0-9]{8} (?:(?:[ 0+-][.][ 0-9]{8})|(?: [ +-][.][ 0-9]{7})) " +
  69.                         "[ +-][ 0-9]{5}[+-][ 0-9] [ +-][ 0-9]{5}[+-][ 0-9] [ 0-9] [ 0-9]{4}[ 0-9]");

  70.     /** Pattern for line 2. */
  71.     private static final Pattern LINE_2_PATTERN =
  72.         Pattern.compile("2 [ 0-9]{5} [ 0-9]{3}[.][ 0-9]{4} [ 0-9]{3}[.][ 0-9]{4} [ 0-9]{7} " +
  73.                         "[ 0-9]{3}[.][ 0-9]{4} [ 0-9]{3}[.][ 0-9]{4} [ 0-9]{2}[.][ 0-9]{13}[ 0-9]");

  74.     /** International symbols for parsing. */
  75.     private static final DecimalFormatSymbols SYMBOLS =
  76.         new DecimalFormatSymbols(Locale.US);

  77.     /** Serializable UID. */
  78.     private static final long serialVersionUID = -1596648022319057689L;

  79.     /** The satellite number. */
  80.     private final int satelliteNumber;

  81.     /** Classification (U for unclassified). */
  82.     private final char classification;

  83.     /** Launch year. */
  84.     private final int launchYear;

  85.     /** Launch number. */
  86.     private final int launchNumber;

  87.     /** Piece of launch (from "A" to "ZZZ"). */
  88.     private final String launchPiece;

  89.     /** Type of ephemeris. */
  90.     private final int ephemerisType;

  91.     /** Element number. */
  92.     private final int elementNumber;

  93.     /** the TLE current date. */
  94.     private final AbsoluteDate epoch;

  95.     /** Mean motion (rad/s). */
  96.     private final double meanMotion;

  97.     /** Mean motion first derivative (rad/s²). */
  98.     private final double meanMotionFirstDerivative;

  99.     /** Mean motion second derivative (rad/s³). */
  100.     private final double meanMotionSecondDerivative;

  101.     /** Eccentricity. */
  102.     private final double eccentricity;

  103.     /** Inclination (rad). */
  104.     private final double inclination;

  105.     /** Argument of perigee (rad). */
  106.     private final double pa;

  107.     /** Right Ascension of the Ascending node (rad). */
  108.     private final double raan;

  109.     /** Mean anomaly (rad). */
  110.     private final double meanAnomaly;

  111.     /** Revolution number at epoch. */
  112.     private final int revolutionNumberAtEpoch;

  113.     /** Ballistic coefficient. */
  114.     private final double bStar;

  115.     /** First line. */
  116.     private String line1;

  117.     /** Second line. */
  118.     private String line2;

  119.     /** The UTC scale. */
  120.     private final TimeScale utc;

  121.     /** Simple constructor from unparsed two lines. This constructor uses the {@link
  122.      * DataContext#getDefault() default data context}.
  123.      *
  124.      * <p>The static method {@link #isFormatOK(String, String)} should be called
  125.      * before trying to build this object.<p>
  126.      * @param line1 the first element (69 char String)
  127.      * @param line2 the second element (69 char String)
  128.      * @see #TLE(String, String, TimeScale)
  129.      */
  130.     @DefaultDataContext
  131.     public TLE(final String line1, final String line2) {
  132.         this(line1, line2, DataContext.getDefault().getTimeScales().getUTC());
  133.     }

  134.     /** Simple constructor from unparsed two lines using the given time scale as UTC.
  135.      *
  136.      * <p>The static method {@link #isFormatOK(String, String)} should be called
  137.      * before trying to build this object.<p>
  138.      * @param line1 the first element (69 char String)
  139.      * @param line2 the second element (69 char String)
  140.      * @param utc the UTC time scale.
  141.      * @since 10.1
  142.      */
  143.     public TLE(final String line1, final String line2, final TimeScale utc) {

  144.         // identification
  145.         satelliteNumber = parseInteger(line1, 2, 5);
  146.         final int satNum2 = parseInteger(line2, 2, 5);
  147.         if (satelliteNumber != satNum2) {
  148.             throw new OrekitException(OrekitMessages.TLE_LINES_DO_NOT_REFER_TO_SAME_OBJECT,
  149.                                       line1, line2);
  150.         }
  151.         classification  = line1.charAt(7);
  152.         launchYear      = parseYear(line1, 9);
  153.         launchNumber    = parseInteger(line1, 11, 3);
  154.         launchPiece     = line1.substring(14, 17).trim();
  155.         ephemerisType   = parseInteger(line1, 62, 1);
  156.         elementNumber   = parseInteger(line1, 64, 4);

  157.         // Date format transform (nota: 27/31250 == 86400/100000000)
  158.         final int    year      = parseYear(line1, 18);
  159.         final int    dayInYear = parseInteger(line1, 20, 3);
  160.         final long   df        = 27l * parseInteger(line1, 24, 8);
  161.         final int    secondsA  = (int) (df / 31250l);
  162.         final double secondsB  = (df % 31250l) / 31250.0;
  163.         epoch = new AbsoluteDate(new DateComponents(year, dayInYear),
  164.                                  new TimeComponents(secondsA, secondsB),
  165.                                  utc);

  166.         // mean motion development
  167.         // converted from rev/day, 2 * rev/day^2 and 6 * rev/day^3 to rad/s, rad/s^2 and rad/s^3
  168.         meanMotion                 = parseDouble(line2, 52, 11) * FastMath.PI / 43200.0;
  169.         meanMotionFirstDerivative  = parseDouble(line1, 33, 10) * FastMath.PI / 1.86624e9;
  170.         meanMotionSecondDerivative = Double.parseDouble((line1.substring(44, 45) + '.' +
  171.                                                          line1.substring(45, 50) + 'e' +
  172.                                                          line1.substring(50, 52)).replace(' ', '0')) *
  173.                                      FastMath.PI / 5.3747712e13;

  174.         eccentricity = Double.parseDouble("." + line2.substring(26, 33).replace(' ', '0'));
  175.         inclination  = FastMath.toRadians(parseDouble(line2, 8, 8));
  176.         pa           = FastMath.toRadians(parseDouble(line2, 34, 8));
  177.         raan         = FastMath.toRadians(Double.parseDouble(line2.substring(17, 25).replace(' ', '0')));
  178.         meanAnomaly  = FastMath.toRadians(parseDouble(line2, 43, 8));

  179.         revolutionNumberAtEpoch = parseInteger(line2, 63, 5);
  180.         bStar = Double.parseDouble((line1.substring(53, 54) + '.' +
  181.                                     line1.substring(54, 59) + 'e' +
  182.                                     line1.substring(59, 61)).replace(' ', '0'));

  183.         // save the lines
  184.         this.line1 = line1;
  185.         this.line2 = line2;
  186.         this.utc = utc;

  187.     }

  188.     /** Simple constructor from already parsed elements. This constructor uses the {@link
  189.      * DataContext#getDefault() default data context}.
  190.      *
  191.      * @param satelliteNumber satellite number
  192.      * @param classification classification (U for unclassified)
  193.      * @param launchYear launch year (all digits)
  194.      * @param launchNumber launch number
  195.      * @param launchPiece launch piece (3 char String)
  196.      * @param ephemerisType type of ephemeris
  197.      * @param elementNumber element number
  198.      * @param epoch elements epoch
  199.      * @param meanMotion mean motion (rad/s)
  200.      * @param meanMotionFirstDerivative mean motion first derivative (rad/s²)
  201.      * @param meanMotionSecondDerivative mean motion second derivative (rad/s³)
  202.      * @param e eccentricity
  203.      * @param i inclination (rad)
  204.      * @param pa argument of perigee (rad)
  205.      * @param raan right ascension of ascending node (rad)
  206.      * @param meanAnomaly mean anomaly (rad)
  207.      * @param revolutionNumberAtEpoch revolution number at epoch
  208.      * @param bStar ballistic coefficient
  209.      * @see #TLE(int, char, int, int, String, int, int, AbsoluteDate, double, double,
  210.      * double, double, double, double, double, double, int, double, TimeScale)
  211.      */
  212.     @DefaultDataContext
  213.     public TLE(final int satelliteNumber, final char classification,
  214.                final int launchYear, final int launchNumber, final String launchPiece,
  215.                final int ephemerisType, final int elementNumber, final AbsoluteDate epoch,
  216.                final double meanMotion, final double meanMotionFirstDerivative,
  217.                final double meanMotionSecondDerivative, final double e, final double i,
  218.                final double pa, final double raan, final double meanAnomaly,
  219.                final int revolutionNumberAtEpoch, final double bStar) {
  220.         this(satelliteNumber, classification, launchYear, launchNumber, launchPiece,
  221.                 ephemerisType, elementNumber, epoch, meanMotion,
  222.                 meanMotionFirstDerivative, meanMotionSecondDerivative, e, i, pa, raan,
  223.                 meanAnomaly, revolutionNumberAtEpoch, bStar,
  224.                 DataContext.getDefault().getTimeScales().getUTC());
  225.     }

  226.     /** Simple constructor from already parsed elements using the given time scale as UTC.
  227.      *
  228.      * @param satelliteNumber satellite number
  229.      * @param classification classification (U for unclassified)
  230.      * @param launchYear launch year (all digits)
  231.      * @param launchNumber launch number
  232.      * @param launchPiece launch piece (3 char String)
  233.      * @param ephemerisType type of ephemeris
  234.      * @param elementNumber element number
  235.      * @param epoch elements epoch
  236.      * @param meanMotion mean motion (rad/s)
  237.      * @param meanMotionFirstDerivative mean motion first derivative (rad/s²)
  238.      * @param meanMotionSecondDerivative mean motion second derivative (rad/s³)
  239.      * @param e eccentricity
  240.      * @param i inclination (rad)
  241.      * @param pa argument of perigee (rad)
  242.      * @param raan right ascension of ascending node (rad)
  243.      * @param meanAnomaly mean anomaly (rad)
  244.      * @param revolutionNumberAtEpoch revolution number at epoch
  245.      * @param bStar ballistic coefficient
  246.      * @param utc the UTC time scale.
  247.      * @since 10.1
  248.      */
  249.     public TLE(final int satelliteNumber, final char classification,
  250.                final int launchYear, final int launchNumber, final String launchPiece,
  251.                final int ephemerisType, final int elementNumber, final AbsoluteDate epoch,
  252.                final double meanMotion, final double meanMotionFirstDerivative,
  253.                final double meanMotionSecondDerivative, final double e, final double i,
  254.                final double pa, final double raan, final double meanAnomaly,
  255.                final int revolutionNumberAtEpoch, final double bStar,
  256.                final TimeScale utc) {

  257.         // identification
  258.         this.satelliteNumber = satelliteNumber;
  259.         this.classification  = classification;
  260.         this.launchYear      = launchYear;
  261.         this.launchNumber    = launchNumber;
  262.         this.launchPiece     = launchPiece;
  263.         this.ephemerisType   = ephemerisType;
  264.         this.elementNumber   = elementNumber;

  265.         // orbital parameters
  266.         this.epoch                      = epoch;
  267.         this.meanMotion                 = meanMotion;
  268.         this.meanMotionFirstDerivative  = meanMotionFirstDerivative;
  269.         this.meanMotionSecondDerivative = meanMotionSecondDerivative;
  270.         this.inclination                = i;
  271.         this.raan                       = raan;
  272.         this.eccentricity               = e;
  273.         this.pa                         = pa;
  274.         this.meanAnomaly                = meanAnomaly;

  275.         this.revolutionNumberAtEpoch = revolutionNumberAtEpoch;
  276.         this.bStar                   = bStar;

  277.         // don't build the line until really needed
  278.         this.line1 = null;
  279.         this.line2 = null;
  280.         this.utc = utc;

  281.     }

  282.     /**
  283.      * Get the UTC time scale used to create this TLE.
  284.      *
  285.      * @return UTC time scale.
  286.      */
  287.     TimeScale getUtc() {
  288.         return utc;
  289.     }

  290.     /** Get the first line.
  291.      * @return first line
  292.      */
  293.     public String getLine1() {
  294.         if (line1 == null) {
  295.             buildLine1();
  296.         }
  297.         return line1;
  298.     }

  299.     /** Get the second line.
  300.      * @return second line
  301.      */
  302.     public String getLine2() {
  303.         if (line2 == null) {
  304.             buildLine2();
  305.         }
  306.         return line2;
  307.     }

  308.     /** Build the line 1 from the parsed elements.
  309.      */
  310.     private void buildLine1() {

  311.         final StringBuffer buffer = new StringBuffer();

  312.         buffer.append('1');

  313.         buffer.append(' ');
  314.         buffer.append(addPadding("satelliteNumber-1", satelliteNumber, '0', 5, true));
  315.         buffer.append(classification);

  316.         buffer.append(' ');
  317.         buffer.append(addPadding("launchYear",   launchYear % 100, '0', 2, true));
  318.         buffer.append(addPadding("launchNumber", launchNumber, '0', 3, true));
  319.         buffer.append(addPadding("launchPiece",  launchPiece, ' ', 3, false));

  320.         buffer.append(' ');
  321.         final DateTimeComponents dtc = epoch.getComponents(utc);
  322.         buffer.append(addPadding("year", dtc.getDate().getYear() % 100, '0', 2, true));
  323.         buffer.append(addPadding("day",  dtc.getDate().getDayOfYear(),  '0', 3, true));
  324.         buffer.append('.');
  325.         // nota: 31250/27 == 100000000/86400
  326.         final int fraction = (int) FastMath.rint(31250 * dtc.getTime().getSecondsInUTCDay() / 27.0);
  327.         buffer.append(addPadding("fraction", fraction,  '0', 8, true));

  328.         buffer.append(' ');
  329.         final double n1 = meanMotionFirstDerivative * 1.86624e9 / FastMath.PI;
  330.         final String sn1 = addPadding("meanMotionFirstDerivative",
  331.                                       new DecimalFormat(".00000000", SYMBOLS).format(n1), ' ', 10, true);
  332.         buffer.append(sn1);

  333.         buffer.append(' ');
  334.         final double n2 = meanMotionSecondDerivative * 5.3747712e13 / FastMath.PI;
  335.         buffer.append(formatExponentMarkerFree("meanMotionSecondDerivative", n2, 5, ' ', 8, true));

  336.         buffer.append(' ');
  337.         buffer.append(formatExponentMarkerFree("B*", bStar, 5, ' ', 8, true));

  338.         buffer.append(' ');
  339.         buffer.append(ephemerisType);

  340.         buffer.append(' ');
  341.         buffer.append(addPadding("elementNumber", elementNumber, ' ', 4, true));

  342.         buffer.append(Integer.toString(checksum(buffer)));

  343.         line1 = buffer.toString();

  344.     }

  345.     /** Format a real number without 'e' exponent marker.
  346.      * @param name parameter name
  347.      * @param d number to format
  348.      * @param mantissaSize size of the mantissa (not counting initial '-' or ' ' for sign)
  349.      * @param c padding character
  350.      * @param size desired size
  351.      * @param rightJustified if true, the resulting string is
  352.      * right justified (i.e. space are added to the left)
  353.      * @return formatted and padded number
  354.      */
  355.     private String formatExponentMarkerFree(final String name, final double d, final int mantissaSize,
  356.                                             final char c, final int size, final boolean rightJustified) {
  357.         final double dAbs = FastMath.abs(d);
  358.         int exponent = (dAbs < 1.0e-9) ? -9 : (int) FastMath.ceil(FastMath.log10(dAbs));
  359.         long mantissa = FastMath.round(dAbs * FastMath.pow(10.0, mantissaSize - exponent));
  360.         if (mantissa == 0) {
  361.             exponent = 0;
  362.         } else if (mantissa > (ArithmeticUtils.pow(10, mantissaSize) - 1)) {
  363.             // rare case: if d has a single digit like d = 1.0e-4 with mantissaSize = 5
  364.             // the above computation finds exponent = -4 and mantissa = 100000 which
  365.             // doesn't fit in a 5 digits string
  366.             exponent++;
  367.             mantissa = FastMath.round(dAbs * FastMath.pow(10.0, mantissaSize - exponent));
  368.         }
  369.         final String sMantissa = addPadding(name, (int) mantissa, '0', mantissaSize, true);
  370.         final String sExponent = Integer.toString(FastMath.abs(exponent));
  371.         final String formatted = (d <  0 ? '-' : ' ') + sMantissa + (exponent <= 0 ? '-' : '+') + sExponent;

  372.         return addPadding(name, formatted, c, size, rightJustified);

  373.     }

  374.     /** Build the line 2 from the parsed elements.
  375.      */
  376.     private void buildLine2() {

  377.         final StringBuffer buffer = new StringBuffer();
  378.         final DecimalFormat f34   = new DecimalFormat("##0.0000", SYMBOLS);
  379.         final DecimalFormat f211  = new DecimalFormat("#0.00000000", SYMBOLS);

  380.         buffer.append('2');

  381.         buffer.append(' ');
  382.         buffer.append(addPadding("satelliteNumber-2", satelliteNumber, '0', 5, true));

  383.         buffer.append(' ');
  384.         buffer.append(addPadding("inclination", f34.format(FastMath.toDegrees(inclination)), ' ', 8, true));
  385.         buffer.append(' ');
  386.         buffer.append(addPadding("raan", f34.format(FastMath.toDegrees(raan)), ' ', 8, true));
  387.         buffer.append(' ');
  388.         buffer.append(addPadding("eccentricity", (int) FastMath.rint(eccentricity * 1.0e7), '0', 7, true));
  389.         buffer.append(' ');
  390.         buffer.append(addPadding("pa", f34.format(FastMath.toDegrees(pa)), ' ', 8, true));
  391.         buffer.append(' ');
  392.         buffer.append(addPadding("meanAnomaly", f34.format(FastMath.toDegrees(meanAnomaly)), ' ', 8, true));

  393.         buffer.append(' ');
  394.         buffer.append(addPadding("meanMotion", f211.format(meanMotion * 43200.0 / FastMath.PI), ' ', 11, true));
  395.         buffer.append(addPadding("revolutionNumberAtEpoch", revolutionNumberAtEpoch, ' ', 5, true));

  396.         buffer.append(Integer.toString(checksum(buffer)));

  397.         line2 = buffer.toString();

  398.     }

  399.     /** Add padding characters before an integer.
  400.      * @param name parameter name
  401.      * @param k integer to pad
  402.      * @param c padding character
  403.      * @param size desired size
  404.      * @param rightJustified if true, the resulting string is
  405.      * right justified (i.e. space are added to the left)
  406.      * @return padded string
  407.      */
  408.     private String addPadding(final String name, final int k, final char c,
  409.                               final int size, final boolean rightJustified) {
  410.         return addPadding(name, Integer.toString(k), c, size, rightJustified);
  411.     }

  412.     /** Add padding characters to a string.
  413.      * @param name parameter name
  414.      * @param string string to pad
  415.      * @param c padding character
  416.      * @param size desired size
  417.      * @param rightJustified if true, the resulting string is
  418.      * right justified (i.e. space are added to the left)
  419.      * @return padded string
  420.      */
  421.     private String addPadding(final String name, final String string, final char c,
  422.                               final int size, final boolean rightJustified) {

  423.         if (string.length() > size) {
  424.             throw new OrekitException(OrekitMessages.TLE_INVALID_PARAMETER,
  425.                                       satelliteNumber, name, string);
  426.         }

  427.         final StringBuffer padding = new StringBuffer();
  428.         for (int i = 0; i < size; ++i) {
  429.             padding.append(c);
  430.         }

  431.         if (rightJustified) {
  432.             final String concatenated = padding + string;
  433.             final int l = concatenated.length();
  434.             return concatenated.substring(l - size, l);
  435.         }

  436.         return (string + padding).substring(0, size);

  437.     }

  438.     /** Parse a double.
  439.      * @param line line to parse
  440.      * @param start start index of the first character
  441.      * @param length length of the string
  442.      * @return value of the double
  443.      */
  444.     private double parseDouble(final String line, final int start, final int length) {
  445.         final String field = line.substring(start, start + length).trim();
  446.         return field.length() > 0 ? Double.parseDouble(field.replace(' ', '0')) : 0;
  447.     }

  448.     /** Parse an integer.
  449.      * @param line line to parse
  450.      * @param start start index of the first character
  451.      * @param length length of the string
  452.      * @return value of the integer
  453.      */
  454.     private int parseInteger(final String line, final int start, final int length) {
  455.         final String field = line.substring(start, start + length).trim();
  456.         return field.length() > 0 ? Integer.parseInt(field.replace(' ', '0')) : 0;
  457.     }

  458.     /** Parse a year written on 2 digits.
  459.      * @param line line to parse
  460.      * @param start start index of the first character
  461.      * @return value of the year
  462.      */
  463.     private int parseYear(final String line, final int start) {
  464.         final int year = 2000 + parseInteger(line, start, 2);
  465.         return (year > 2056) ? (year - 100) : year;
  466.     }

  467.     /** Get the satellite id.
  468.      * @return the satellite number
  469.      */
  470.     public int getSatelliteNumber() {
  471.         return satelliteNumber;
  472.     }

  473.     /** Get the classification.
  474.      * @return classification
  475.      */
  476.     public char getClassification() {
  477.         return classification;
  478.     }

  479.     /** Get the launch year.
  480.      * @return the launch year
  481.      */
  482.     public int getLaunchYear() {
  483.         return launchYear;
  484.     }

  485.     /** Get the launch number.
  486.      * @return the launch number
  487.      */
  488.     public int getLaunchNumber() {
  489.         return launchNumber;
  490.     }

  491.     /** Get the launch piece.
  492.      * @return the launch piece
  493.      */
  494.     public String getLaunchPiece() {
  495.         return launchPiece;
  496.     }

  497.     /** Get the type of ephemeris.
  498.      * @return the ephemeris type (one of {@link #DEFAULT}, {@link #SGP},
  499.      * {@link #SGP4}, {@link #SGP8}, {@link #SDP4}, {@link #SDP8})
  500.      */
  501.     public int getEphemerisType() {
  502.         return ephemerisType;
  503.     }

  504.     /** Get the element number.
  505.      * @return the element number
  506.      */
  507.     public int getElementNumber() {
  508.         return elementNumber;
  509.     }

  510.     /** Get the TLE current date.
  511.      * @return the epoch
  512.      */
  513.     public AbsoluteDate getDate() {
  514.         return epoch;
  515.     }

  516.     /** Get the mean motion.
  517.      * @return the mean motion (rad/s)
  518.      */
  519.     public double getMeanMotion() {
  520.         return meanMotion;
  521.     }

  522.     /** Get the mean motion first derivative.
  523.      * @return the mean motion first derivative (rad/s²)
  524.      */
  525.     public double getMeanMotionFirstDerivative() {
  526.         return meanMotionFirstDerivative;
  527.     }

  528.     /** Get the mean motion second derivative.
  529.      * @return the mean motion second derivative (rad/s³)
  530.      */
  531.     public double getMeanMotionSecondDerivative() {
  532.         return meanMotionSecondDerivative;
  533.     }

  534.     /** Get the eccentricity.
  535.      * @return the eccentricity
  536.      */
  537.     public double getE() {
  538.         return eccentricity;
  539.     }

  540.     /** Get the inclination.
  541.      * @return the inclination (rad)
  542.      */
  543.     public double getI() {
  544.         return inclination;
  545.     }

  546.     /** Get the argument of perigee.
  547.      * @return omega (rad)
  548.      */
  549.     public double getPerigeeArgument() {
  550.         return pa;
  551.     }

  552.     /** Get Right Ascension of the Ascending node.
  553.      * @return the raan (rad)
  554.      */
  555.     public double getRaan() {
  556.         return raan;
  557.     }

  558.     /** Get the mean anomaly.
  559.      * @return the mean anomaly (rad)
  560.      */
  561.     public double getMeanAnomaly() {
  562.         return meanAnomaly;
  563.     }

  564.     /** Get the revolution number.
  565.      * @return the revolutionNumberAtEpoch
  566.      */
  567.     public int getRevolutionNumberAtEpoch() {
  568.         return revolutionNumberAtEpoch;
  569.     }

  570.     /** Get the ballistic coefficient.
  571.      * @return bStar
  572.      */
  573.     public double getBStar() {
  574.         return bStar;
  575.     }

  576.     /** Get a string representation of this TLE set.
  577.      * <p>The representation is simply the two lines separated by the
  578.      * platform line separator.</p>
  579.      * @return string representation of this TLE set
  580.      */
  581.     public String toString() {
  582.         try {
  583.             return getLine1() + System.getProperty("line.separator") + getLine2();
  584.         } catch (OrekitException oe) {
  585.             throw new OrekitInternalError(oe);
  586.         }
  587.     }

  588.     /** Check the lines format validity.
  589.      * @param line1 the first element
  590.      * @param line2 the second element
  591.      * @return true if format is recognized (non null lines, 69 characters length,
  592.      * line content), false if not
  593.      */
  594.     public static boolean isFormatOK(final String line1, final String line2) {

  595.         if (line1 == null || line1.length() != 69 ||
  596.             line2 == null || line2.length() != 69) {
  597.             return false;
  598.         }

  599.         if (!(LINE_1_PATTERN.matcher(line1).matches() &&
  600.               LINE_2_PATTERN.matcher(line2).matches())) {
  601.             return false;
  602.         }

  603.         // check sums
  604.         final int checksum1 = checksum(line1);
  605.         if (Integer.parseInt(line1.substring(68)) != (checksum1 % 10)) {
  606.             throw new OrekitException(OrekitMessages.TLE_CHECKSUM_ERROR,
  607.                                       1, Integer.toString(checksum1 % 10), line1.substring(68), line1);
  608.         }

  609.         final int checksum2 = checksum(line2);
  610.         if (Integer.parseInt(line2.substring(68)) != (checksum2 % 10)) {
  611.             throw new OrekitException(OrekitMessages.TLE_CHECKSUM_ERROR,
  612.                                       2, Integer.toString(checksum2 % 10), line2.substring(68), line2);
  613.         }

  614.         return true;

  615.     }

  616.     /** Compute the checksum of the first 68 characters of a line.
  617.      * @param line line to check
  618.      * @return checksum
  619.      */
  620.     private static int checksum(final CharSequence line) {
  621.         int sum = 0;
  622.         for (int j = 0; j < 68; j++) {
  623.             final char c = line.charAt(j);
  624.             if (Character.isDigit(c)) {
  625.                 sum += Character.digit(c, 10);
  626.             } else if (c == '-') {
  627.                 ++sum;
  628.             }
  629.         }
  630.         return sum % 10;
  631.     }

  632.     /** Check if this tle equals the provided tle.
  633.      * <p>Due to the difference in precision between object and string
  634.      * representations of TLE, it is possible for this method to return false
  635.      * even if string representations returned by {@link #toString()}
  636.      * are equal.</p>
  637.      * @param o other tle
  638.      * @return true if this tle equals the provided tle
  639.      */
  640.     @Override
  641.     public boolean equals(final Object o) {
  642.         if (o == this) {
  643.             return true;
  644.         }
  645.         if (!(o instanceof TLE)) {
  646.             return false;
  647.         }
  648.         final TLE tle = (TLE) o;
  649.         return satelliteNumber == tle.satelliteNumber &&
  650.                 classification == tle.classification &&
  651.                 launchYear == tle.launchYear &&
  652.                 launchNumber == tle.launchNumber &&
  653.                 Objects.equals(launchPiece, tle.launchPiece) &&
  654.                 ephemerisType == tle.ephemerisType &&
  655.                 elementNumber == tle.elementNumber &&
  656.                 Objects.equals(epoch, tle.epoch) &&
  657.                 meanMotion == tle.meanMotion &&
  658.                 meanMotionFirstDerivative == tle.meanMotionFirstDerivative &&
  659.                 meanMotionSecondDerivative == tle.meanMotionSecondDerivative &&
  660.                 eccentricity == tle.eccentricity &&
  661.                 inclination == tle.inclination &&
  662.                 pa == tle.pa &&
  663.                 raan == tle.raan &&
  664.                 meanAnomaly == tle.meanAnomaly &&
  665.                 revolutionNumberAtEpoch == tle.revolutionNumberAtEpoch &&
  666.                 bStar == tle.bStar;
  667.     }

  668.     /** Get a hashcode for this tle.
  669.      * @return hashcode
  670.      */
  671.     @Override
  672.     public int hashCode() {
  673.         return Objects.hash(satelliteNumber,
  674.                 classification,
  675.                 launchYear,
  676.                 launchNumber,
  677.                 launchPiece,
  678.                 ephemerisType,
  679.                 elementNumber,
  680.                 epoch,
  681.                 meanMotion,
  682.                 meanMotionFirstDerivative,
  683.                 meanMotionSecondDerivative,
  684.                 eccentricity,
  685.                 inclination,
  686.                 pa,
  687.                 raan,
  688.                 meanAnomaly,
  689.                 revolutionNumberAtEpoch,
  690.                 bStar);
  691.     }

  692. }