FieldTLE.java

  1. /* Copyright 2002-2024 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.Collections;
  22. import java.util.List;
  23. import java.util.Locale;
  24. import java.util.Objects;

  25. import org.hipparchus.CalculusFieldElement;
  26. import org.hipparchus.Field;
  27. import org.hipparchus.util.ArithmeticUtils;
  28. import org.hipparchus.util.FastMath;
  29. import org.hipparchus.util.MathUtils;
  30. import org.orekit.annotation.DefaultDataContext;
  31. import org.orekit.data.DataContext;
  32. import org.orekit.errors.OrekitException;
  33. import org.orekit.errors.OrekitInternalError;
  34. import org.orekit.errors.OrekitMessages;
  35. import org.orekit.propagation.FieldSpacecraftState;
  36. import org.orekit.propagation.analytical.tle.generation.TleGenerationAlgorithm;
  37. import org.orekit.time.DateComponents;
  38. import org.orekit.time.DateTimeComponents;
  39. import org.orekit.time.FieldAbsoluteDate;
  40. import org.orekit.time.FieldTimeStamped;
  41. import org.orekit.time.TimeComponents;
  42. import org.orekit.time.TimeScale;
  43. import org.orekit.utils.Constants;
  44. import org.orekit.utils.ParameterDriver;
  45. import org.orekit.utils.ParameterDriversProvider;

  46. /** This class is a container for a single set of TLE data.
  47.  *
  48.  * <p>TLE sets can be built either by providing directly the two lines, in
  49.  * which case parsing is performed internally or by providing the already
  50.  * parsed elements.</p>
  51.  * <p>TLE are not transparently convertible to {@link org.orekit.orbits.Orbit Orbit}
  52.  * instances. They are significant only with respect to their dedicated {@link
  53.  * TLEPropagator propagator}, which also computes position and velocity coordinates.
  54.  * Any attempt to directly use orbital parameters like {@link #getE() eccentricity},
  55.  * {@link #getI() inclination}, etc. without any reference to the {@link TLEPropagator
  56.  * TLE propagator} is prone to errors.</p>
  57.  * <p>More information on the TLE format can be found on the
  58.  * <a href="https://www.celestrak.com/">CelesTrak website.</a></p>
  59.  * @author Fabien Maussion
  60.  * @author Luc Maisonobe
  61.  * @author Thomas Paulet (field translation)
  62.  * @since 11.0
  63.  * @param <T> type of the field elements
  64.  */
  65. public class FieldTLE<T extends CalculusFieldElement<T>> implements FieldTimeStamped<T>, Serializable, ParameterDriversProvider {

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

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

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

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

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

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

  78.     /** Parameter name for B* coefficient. */
  79.     public static final String B_STAR = "BSTAR";

  80.     /** B* scaling factor.
  81.      * <p>
  82.      * We use a power of 2 to avoid numeric noise introduction
  83.      * in the multiplications/divisions sequences.
  84.      * </p>
  85.      */
  86.     private static final double B_STAR_SCALE = FastMath.scalb(1.0, -20);

  87.     /** Name of the mean motion parameter. */
  88.     private static final String MEAN_MOTION = "meanMotion";

  89.     /** Name of the inclination parameter. */
  90.     private static final String INCLINATION = "inclination";

  91.     /** Name of the eccentricity parameter. */
  92.     private static final String ECCENTRICITY = "eccentricity";

  93.     /** International symbols for parsing. */
  94.     private static final DecimalFormatSymbols SYMBOLS =
  95.         new DecimalFormatSymbols(Locale.US);

  96.     /** Serializable UID. */
  97.     private static final long serialVersionUID = -1596648022319057689L;

  98.     /** The satellite number. */
  99.     private final int satelliteNumber;

  100.     /** Classification (U for unclassified). */
  101.     private final char classification;

  102.     /** Launch year. */
  103.     private final int launchYear;

  104.     /** Launch number. */
  105.     private final int launchNumber;

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

  108.     /** Type of ephemeris. */
  109.     private final int ephemerisType;

  110.     /** Element number. */
  111.     private final int elementNumber;

  112.     /** the TLE current date. */
  113.     private final transient FieldAbsoluteDate<T> epoch;

  114.     /** Mean motion (rad/s). */
  115.     private final T meanMotion;

  116.     /** Mean motion first derivative (rad/s²). */
  117.     private final T meanMotionFirstDerivative;

  118.     /** Mean motion second derivative (rad/s³). */
  119.     private final T meanMotionSecondDerivative;

  120.     /** Eccentricity. */
  121.     private final T eccentricity;

  122.     /** Inclination (rad). */
  123.     private final T inclination;

  124.     /** Argument of perigee (rad). */
  125.     private final T pa;

  126.     /** Right Ascension of the Ascending node (rad). */
  127.     private final T raan;

  128.     /** Mean anomaly (rad). */
  129.     private final T meanAnomaly;

  130.     /** Revolution number at epoch. */
  131.     private final int revolutionNumberAtEpoch;

  132.     /** First line. */
  133.     private String line1;

  134.     /** Second line. */
  135.     private String line2;

  136.     /** The UTC scale. */
  137.     private final TimeScale utc;

  138.     /** Driver for ballistic coefficient parameter. */
  139.     private final transient ParameterDriver bStarParameterDriver;

  140.     /** Simple constructor from unparsed two lines. This constructor uses the {@link
  141.      * DataContext#getDefault() default data context}.
  142.      *
  143.      * <p>The static method {@link #isFormatOK(String, String)} should be called
  144.      * before trying to build this object.</p>
  145.      * @param field field utilized by default
  146.      * @param line1 the first element (69 char String)
  147.      * @param line2 the second element (69 char String)
  148.      * @see #FieldTLE(Field, String, String, TimeScale)
  149.      */
  150.     @DefaultDataContext
  151.     public FieldTLE(final Field<T> field, final String line1, final String line2) {
  152.         this(field, line1, line2, DataContext.getDefault().getTimeScales().getUTC());
  153.     }

  154.     /** Simple constructor from unparsed two lines using the given time scale as UTC.
  155.      *
  156.      *<p>This method uses the {@link DataContext#getDefault() default data context}.
  157.      *
  158.      * <p>The static method {@link #isFormatOK(String, String)} should be called
  159.      * before trying to build this object.</p>
  160.      * @param field field utilized by default
  161.      * @param line1 the first element (69 char String)
  162.      * @param line2 the second element (69 char String)
  163.      * @param utc the UTC time scale.
  164.      */
  165.     public FieldTLE(final Field<T> field, final String line1, final String line2, final TimeScale utc) {

  166.         // zero and pi for fields
  167.         final T zero = field.getZero();
  168.         final T pi   = zero.getPi();

  169.         // identification
  170.         satelliteNumber = ParseUtils.parseSatelliteNumber(line1, 2, 5);
  171.         final int satNum2 = ParseUtils.parseSatelliteNumber(line2, 2, 5);
  172.         if (satelliteNumber != satNum2) {
  173.             throw new OrekitException(OrekitMessages.TLE_LINES_DO_NOT_REFER_TO_SAME_OBJECT,
  174.                                       line1, line2);
  175.         }
  176.         classification  = line1.charAt(7);
  177.         launchYear      = ParseUtils.parseYear(line1, 9);
  178.         launchNumber    = ParseUtils.parseInteger(line1, 11, 3);
  179.         launchPiece     = line1.substring(14, 17).trim();
  180.         ephemerisType   = ParseUtils.parseInteger(line1, 62, 1);
  181.         elementNumber   = ParseUtils.parseInteger(line1, 64, 4);

  182.         // Date format transform (nota: 27/31250 == 86400/100000000)
  183.         final int    year      = ParseUtils.parseYear(line1, 18);
  184.         final int    dayInYear = ParseUtils.parseInteger(line1, 20, 3);
  185.         final long   df        = 27l * ParseUtils.parseInteger(line1, 24, 8);
  186.         final int    secondsA  = (int) (df / 31250l);
  187.         final double secondsB  = (df % 31250l) / 31250.0;
  188.         epoch = new FieldAbsoluteDate<>(field, new DateComponents(year, dayInYear),
  189.                                  new TimeComponents(secondsA, secondsB),
  190.                                  utc);

  191.         // mean motion development
  192.         // converted from rev/day, 2 * rev/day^2 and 6 * rev/day^3 to rad/s, rad/s^2 and rad/s^3
  193.         meanMotion                 = pi.multiply(ParseUtils.parseDouble(line2, 52, 11)).divide(43200.0);
  194.         meanMotionFirstDerivative  = pi.multiply(ParseUtils.parseDouble(line1, 33, 10)).divide(1.86624e9);
  195.         meanMotionSecondDerivative = pi.multiply(Double.parseDouble((line1.substring(44, 45) + '.' +
  196.                                                                      line1.substring(45, 50) + 'e' +
  197.                                                                      line1.substring(50, 52)).replace(' ', '0'))).divide(5.3747712e13);

  198.         eccentricity = zero.newInstance(Double.parseDouble("." + line2.substring(26, 33).replace(' ', '0')));
  199.         inclination  = zero.newInstance(FastMath.toRadians(ParseUtils.parseDouble(line2, 8, 8)));
  200.         pa           = zero.newInstance(FastMath.toRadians(ParseUtils.parseDouble(line2, 34, 8)));
  201.         raan         = zero.newInstance(FastMath.toRadians(Double.parseDouble(line2.substring(17, 25).replace(' ', '0'))));
  202.         meanAnomaly  = zero.newInstance(FastMath.toRadians(ParseUtils.parseDouble(line2, 43, 8)));

  203.         revolutionNumberAtEpoch = ParseUtils.parseInteger(line2, 63, 5);
  204.         final double bStarValue = Double.parseDouble((line1.substring(53, 54) + '.' +
  205.                         line1.substring(54, 59) + 'e' +
  206.                         line1.substring(59, 61)).replace(' ', '0'));

  207.         // save the lines
  208.         this.line1 = line1;
  209.         this.line2 = line2;
  210.         this.utc = utc;

  211.         this.bStarParameterDriver = new ParameterDriver(B_STAR, bStarValue, B_STAR_SCALE,
  212.                                                         Double.NEGATIVE_INFINITY,
  213.                                                         Double.POSITIVE_INFINITY);

  214.     }

  215.     /**
  216.      * <p>
  217.      * Simple constructor from already parsed elements. This constructor uses the
  218.      * {@link DataContext#getDefault() default data context}.
  219.      * </p>
  220.      *
  221.      * <p>
  222.      * The mean anomaly, the right ascension of ascending node Ω and the argument of
  223.      * perigee ω are normalized into the [0, 2π] interval as they can be negative.
  224.      * After that, a range check is performed on some of the orbital elements:
  225.      *
  226.      * <pre>
  227.      *     meanMotion &gt;= 0
  228.      *     0 &lt;= i &lt;= π
  229.      *     0 &lt;= Ω &lt;= 2π
  230.      *     0 &lt;= e &lt;= 1
  231.      *     0 &lt;= ω &lt;= 2π
  232.      *     0 &lt;= meanAnomaly &lt;= 2π
  233.      * </pre>
  234.      *
  235.      *
  236.      * @param satelliteNumber satellite number
  237.      * @param classification classification (U for unclassified)
  238.      * @param launchYear launch year (all digits)
  239.      * @param launchNumber launch number
  240.      * @param launchPiece launch piece (3 char String)
  241.      * @param ephemerisType type of ephemeris
  242.      * @param elementNumber element number
  243.      * @param epoch elements epoch
  244.      * @param meanMotion mean motion (rad/s)
  245.      * @param meanMotionFirstDerivative mean motion first derivative (rad/s²)
  246.      * @param meanMotionSecondDerivative mean motion second derivative (rad/s³)
  247.      * @param e eccentricity
  248.      * @param i inclination (rad)
  249.      * @param pa argument of perigee (rad)
  250.      * @param raan right ascension of ascending node (rad)
  251.      * @param meanAnomaly mean anomaly (rad)
  252.      * @param revolutionNumberAtEpoch revolution number at epoch
  253.      * @param bStar ballistic coefficient
  254.      * @see #FieldTLE(int, char, int, int, String, int, int, FieldAbsoluteDate, CalculusFieldElement, CalculusFieldElement,
  255.      * CalculusFieldElement, CalculusFieldElement, CalculusFieldElement, CalculusFieldElement, CalculusFieldElement, CalculusFieldElement, int, double, TimeScale)
  256.      */
  257.     @DefaultDataContext
  258.     public FieldTLE(final int satelliteNumber, final char classification,
  259.                final int launchYear, final int launchNumber, final String launchPiece,
  260.                final int ephemerisType, final int elementNumber, final FieldAbsoluteDate<T> epoch,
  261.                final T meanMotion, final T meanMotionFirstDerivative,
  262.                final T meanMotionSecondDerivative, final T e, final T i,
  263.                final T pa, final T raan, final T meanAnomaly,
  264.                final int revolutionNumberAtEpoch, final double bStar) {
  265.         this(satelliteNumber, classification, launchYear, launchNumber, launchPiece,
  266.                 ephemerisType, elementNumber, epoch, meanMotion,
  267.                 meanMotionFirstDerivative, meanMotionSecondDerivative, e, i, pa, raan,
  268.                 meanAnomaly, revolutionNumberAtEpoch, bStar,
  269.                 DataContext.getDefault().getTimeScales().getUTC());
  270.     }

  271.     /**
  272.      * <p>
  273.      * Simple constructor from already parsed elements using the given time scale as
  274.      * UTC.
  275.      * </p>
  276.      * <p>
  277.      * The mean anomaly, the right ascension of ascending node Ω and the argument of
  278.      * perigee ω are normalized into the [0, 2π] interval as they can be negative.
  279.      * After that, a range check is performed on some of the orbital elements:
  280.      *
  281.      * <pre>
  282.      *     meanMotion &gt;= 0
  283.      *     0 &lt;= i &lt;= π
  284.      *     0 &lt;= Ω &lt;= 2π
  285.      *     0 &lt;= e &lt;= 1
  286.      *     0 &lt;= ω &lt;= 2π
  287.      *     0 &lt;= meanAnomaly &lt;= 2π
  288.      * </pre>
  289.      *
  290.      *
  291.      * @param satelliteNumber satellite number
  292.      * @param classification classification (U for unclassified)
  293.      * @param launchYear launch year (all digits)
  294.      * @param launchNumber launch number
  295.      * @param launchPiece launch piece (3 char String)
  296.      * @param ephemerisType type of ephemeris
  297.      * @param elementNumber element number
  298.      * @param epoch elements epoch
  299.      * @param meanMotion mean motion (rad/s)
  300.      * @param meanMotionFirstDerivative mean motion first derivative (rad/s²)
  301.      * @param meanMotionSecondDerivative mean motion second derivative (rad/s³)
  302.      * @param e eccentricity
  303.      * @param i inclination (rad)
  304.      * @param pa argument of perigee (rad)
  305.      * @param raan right ascension of ascending node (rad)
  306.      * @param meanAnomaly mean anomaly (rad)
  307.      * @param revolutionNumberAtEpoch revolution number at epoch
  308.      * @param bStar ballistic coefficient
  309.      * @param utc the UTC time scale.
  310.      */
  311.     public FieldTLE(final int satelliteNumber, final char classification,
  312.                final int launchYear, final int launchNumber, final String launchPiece,
  313.                final int ephemerisType, final int elementNumber, final FieldAbsoluteDate<T> epoch,
  314.                final T meanMotion, final T meanMotionFirstDerivative,
  315.                final T meanMotionSecondDerivative, final T e, final T i,
  316.                final T pa, final T raan, final T meanAnomaly,
  317.                final int revolutionNumberAtEpoch, final double bStar,
  318.                final TimeScale utc) {

  319.         // pi for fields
  320.         final T pi = e.getPi();

  321.         // identification
  322.         this.satelliteNumber = satelliteNumber;
  323.         this.classification  = classification;
  324.         this.launchYear      = launchYear;
  325.         this.launchNumber    = launchNumber;
  326.         this.launchPiece     = launchPiece;
  327.         this.ephemerisType   = ephemerisType;
  328.         this.elementNumber   = elementNumber;

  329.         // orbital parameters
  330.         this.epoch = epoch;
  331.         // Checking mean motion range
  332.         this.meanMotion = meanMotion;
  333.         this.meanMotionFirstDerivative = meanMotionFirstDerivative;
  334.         this.meanMotionSecondDerivative = meanMotionSecondDerivative;

  335.         // Checking inclination range
  336.         this.inclination = i;

  337.         // Normalizing RAAN in [0,2pi] interval
  338.         this.raan = MathUtils.normalizeAngle(raan, pi);

  339.         // Checking eccentricity range
  340.         this.eccentricity = e;

  341.         // Normalizing PA in [0,2pi] interval
  342.         this.pa = MathUtils.normalizeAngle(pa, pi);

  343.         // Normalizing mean anomaly in [0,2pi] interval
  344.         this.meanAnomaly = MathUtils.normalizeAngle(meanAnomaly, pi);

  345.         this.revolutionNumberAtEpoch = revolutionNumberAtEpoch;
  346.         this.bStarParameterDriver = new ParameterDriver(B_STAR, bStar, B_STAR_SCALE,
  347.                                                        Double.NEGATIVE_INFINITY,
  348.                                                        Double.POSITIVE_INFINITY);

  349.         // don't build the line until really needed
  350.         this.line1 = null;
  351.         this.line2 = null;
  352.         this.utc = utc;

  353.     }

  354.     /**
  355.      * Get the UTC time scale used to create this TLE.
  356.      *
  357.      * @return UTC time scale.
  358.      */
  359.     TimeScale getUtc() {
  360.         return utc;
  361.     }

  362.     /** Get the first line.
  363.      * @return first line
  364.      */
  365.     public String getLine1() {
  366.         if (line1 == null) {
  367.             buildLine1();
  368.         }
  369.         return line1;
  370.     }

  371.     /** Get the second line.
  372.      * @return second line
  373.      */
  374.     public String getLine2() {
  375.         if (line2 == null) {
  376.             buildLine2();
  377.         }
  378.         return line2;
  379.     }

  380.     /** Build the line 1 from the parsed elements.
  381.      */
  382.     private void buildLine1() {

  383.         final StringBuilder buffer = new StringBuilder();

  384.         buffer.append('1');

  385.         buffer.append(' ');
  386.         buffer.append(ParseUtils.buildSatelliteNumber(satelliteNumber, "satelliteNumber-1"));
  387.         buffer.append(classification);

  388.         buffer.append(' ');
  389.         buffer.append(ParseUtils.addPadding("launchYear",   launchYear % 100, '0', 2, true, satelliteNumber));
  390.         buffer.append(ParseUtils.addPadding("launchNumber", launchNumber, '0', 3, true, satelliteNumber));
  391.         buffer.append(ParseUtils.addPadding("launchPiece",  launchPiece, ' ', 3, false, satelliteNumber));

  392.         buffer.append(' ');
  393.         DateTimeComponents dtc = epoch.getComponents(utc);
  394.         int fraction = (int) FastMath.rint(31250 * dtc.getTime().getSecondsInUTCDay() / 27.0);
  395.         if (fraction >= 100000000) {
  396.             dtc =  epoch.shiftedBy(Constants.JULIAN_DAY).getComponents(utc);
  397.             fraction -= 100000000;
  398.         }
  399.         buffer.append(ParseUtils.addPadding("year", dtc.getDate().getYear() % 100, '0', 2, true, satelliteNumber));
  400.         buffer.append(ParseUtils.addPadding("day",  dtc.getDate().getDayOfYear(),  '0', 3, true, satelliteNumber));
  401.         buffer.append('.');
  402.         // nota: 31250/27 == 100000000/86400

  403.         buffer.append(ParseUtils.addPadding("fraction", fraction,  '0', 8, true, satelliteNumber));

  404.         buffer.append(' ');
  405.         final double n1 = meanMotionFirstDerivative.divide(pa.getPi()).multiply(1.86624e9).getReal();
  406.         final String sn1 = ParseUtils.addPadding("meanMotionFirstDerivative",
  407.                                                  new DecimalFormat(".00000000", SYMBOLS).format(n1),
  408.                                                  ' ', 10, true, satelliteNumber);
  409.         buffer.append(sn1);

  410.         buffer.append(' ');
  411.         final double n2 = meanMotionSecondDerivative.divide(pa.getPi()).multiply(5.3747712e13).getReal();
  412.         buffer.append(formatExponentMarkerFree("meanMotionSecondDerivative", n2, 5, ' ', 8, true));

  413.         buffer.append(' ');
  414.         buffer.append(formatExponentMarkerFree("B*", getBStar(), 5, ' ', 8, true));

  415.         buffer.append(' ');
  416.         buffer.append(ephemerisType);

  417.         buffer.append(' ');
  418.         buffer.append(ParseUtils.addPadding("elementNumber", elementNumber, ' ', 4, true, satelliteNumber));

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

  420.         line1 = buffer.toString();

  421.     }

  422.     /** Format a real number without 'e' exponent marker.
  423.      * @param name parameter name
  424.      * @param d number to format
  425.      * @param mantissaSize size of the mantissa (not counting initial '-' or ' ' for sign)
  426.      * @param c padding character
  427.      * @param size desired size
  428.      * @param rightJustified if true, the resulting string is
  429.      * right justified (i.e. space are added to the left)
  430.      * @return formatted and padded number
  431.      */
  432.     private String formatExponentMarkerFree(final String name, final double d, final int mantissaSize,
  433.                                             final char c, final int size, final boolean rightJustified) {
  434.         final double dAbs = FastMath.abs(d);
  435.         int exponent = (dAbs < 1.0e-9) ? -9 : (int) FastMath.ceil(FastMath.log10(dAbs));
  436.         long mantissa = FastMath.round(dAbs * FastMath.pow(10.0, mantissaSize - exponent));
  437.         if (mantissa == 0) {
  438.             exponent = 0;
  439.         } else if (mantissa > (ArithmeticUtils.pow(10, mantissaSize) - 1)) {
  440.             // rare case: if d has a single digit like d = 1.0e-4 with mantissaSize = 5
  441.             // the above computation finds exponent = -4 and mantissa = 100000 which
  442.             // doesn't fit in a 5 digits string
  443.             exponent++;
  444.             mantissa = FastMath.round(dAbs * FastMath.pow(10.0, mantissaSize - exponent));
  445.         }
  446.         final String sMantissa = ParseUtils.addPadding(name, (int) mantissa,
  447.                                                        '0', mantissaSize, true, satelliteNumber);
  448.         final String sExponent = Integer.toString(FastMath.abs(exponent));
  449.         final String formatted = (d <  0 ? '-' : ' ') + sMantissa + (exponent <= 0 ? '-' : '+') + sExponent;

  450.         return ParseUtils.addPadding(name, formatted, c, size, rightJustified, satelliteNumber);

  451.     }

  452.     /** Build the line 2 from the parsed elements.
  453.      */
  454.     private void buildLine2() {

  455.         final StringBuilder buffer = new StringBuilder();
  456.         final DecimalFormat f34   = new DecimalFormat("##0.0000", SYMBOLS);
  457.         final DecimalFormat f211  = new DecimalFormat("#0.00000000", SYMBOLS);

  458.         buffer.append('2');

  459.         buffer.append(' ');
  460.         buffer.append(ParseUtils.buildSatelliteNumber(satelliteNumber, "satelliteNumber-2"));

  461.         buffer.append(' ');
  462.         buffer.append(ParseUtils.addPadding(INCLINATION, f34.format(FastMath.toDegrees(inclination).getReal()), ' ', 8, true, satelliteNumber));
  463.         buffer.append(' ');
  464.         buffer.append(ParseUtils.addPadding("raan", f34.format(FastMath.toDegrees(raan).getReal()), ' ', 8, true, satelliteNumber));
  465.         buffer.append(' ');
  466.         buffer.append(ParseUtils.addPadding(ECCENTRICITY, (int) FastMath.rint(eccentricity.getReal() * 1.0e7), '0', 7, true, satelliteNumber));
  467.         buffer.append(' ');
  468.         buffer.append(ParseUtils.addPadding("pa", f34.format(FastMath.toDegrees(pa).getReal()), ' ', 8, true, satelliteNumber));
  469.         buffer.append(' ');
  470.         buffer.append(ParseUtils.addPadding("meanAnomaly", f34.format(FastMath.toDegrees(meanAnomaly).getReal()), ' ', 8, true, satelliteNumber));

  471.         buffer.append(' ');
  472.         buffer.append(ParseUtils.addPadding(MEAN_MOTION, f211.format(meanMotion.divide(pa.getPi()).multiply(43200.0).getReal()), ' ', 11, true, satelliteNumber));
  473.         buffer.append(ParseUtils.addPadding("revolutionNumberAtEpoch", revolutionNumberAtEpoch,
  474.                                             ' ', 5, true, satelliteNumber));

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

  476.         line2 = buffer.toString();

  477.     }

  478.     /** {@inheritDoc}.
  479.      * <p>Get the drivers for TLE propagation SGP4 and SDP4.
  480.      * @return drivers for SGP4 and SDP4 model parameters
  481.      */
  482.     @Override
  483.     public List<ParameterDriver> getParametersDrivers() {
  484.         return Collections.singletonList(bStarParameterDriver);
  485.     }

  486.     /** Get the satellite id.
  487.      * @return the satellite number
  488.      */
  489.     public int getSatelliteNumber() {
  490.         return satelliteNumber;
  491.     }

  492.     /** Get the classification.
  493.      * @return classification
  494.      */
  495.     public char getClassification() {
  496.         return classification;
  497.     }

  498.     /** Get the launch year.
  499.      * @return the launch year
  500.      */
  501.     public int getLaunchYear() {
  502.         return launchYear;
  503.     }

  504.     /** Get the launch number.
  505.      * @return the launch number
  506.      */
  507.     public int getLaunchNumber() {
  508.         return launchNumber;
  509.     }

  510.     /** Get the launch piece.
  511.      * @return the launch piece
  512.      */
  513.     public String getLaunchPiece() {
  514.         return launchPiece;
  515.     }

  516.     /** Get the type of ephemeris.
  517.      * @return the ephemeris type (one of {@link #DEFAULT}, {@link #SGP},
  518.      * {@link #SGP4}, {@link #SGP8}, {@link #SDP4}, {@link #SDP8})
  519.      */
  520.     public int getEphemerisType() {
  521.         return ephemerisType;
  522.     }

  523.     /** Get the element number.
  524.      * @return the element number
  525.      */
  526.     public int getElementNumber() {
  527.         return elementNumber;
  528.     }

  529.     /** Get the TLE current date.
  530.      * @return the epoch
  531.      */
  532.     public FieldAbsoluteDate<T> getDate() {
  533.         return epoch;
  534.     }

  535.     /** Get the mean motion.
  536.      * @return the mean motion (rad/s)
  537.      */
  538.     public T getMeanMotion() {
  539.         return meanMotion;
  540.     }

  541.     /** Get the mean motion first derivative.
  542.      * @return the mean motion first derivative (rad/s²)
  543.      */
  544.     public T getMeanMotionFirstDerivative() {
  545.         return meanMotionFirstDerivative;
  546.     }

  547.     /** Get the mean motion second derivative.
  548.      * @return the mean motion second derivative (rad/s³)
  549.      */
  550.     public T getMeanMotionSecondDerivative() {
  551.         return meanMotionSecondDerivative;
  552.     }

  553.     /** Get the eccentricity.
  554.      * @return the eccentricity
  555.      */
  556.     public T getE() {
  557.         return eccentricity;
  558.     }

  559.     /** Get the inclination.
  560.      * @return the inclination (rad)
  561.      */
  562.     public T getI() {
  563.         return inclination;
  564.     }

  565.     /** Get the argument of perigee.
  566.      * @return omega (rad)
  567.      */
  568.     public T getPerigeeArgument() {
  569.         return pa;
  570.     }

  571.     /** Get Right Ascension of the Ascending node.
  572.      * @return the raan (rad)
  573.      */
  574.     public T getRaan() {
  575.         return raan;
  576.     }

  577.     /** Get the mean anomaly.
  578.      * @return the mean anomaly (rad)
  579.      */
  580.     public T getMeanAnomaly() {
  581.         return meanAnomaly;
  582.     }

  583.     /** Get the revolution number.
  584.      * @return the revolutionNumberAtEpoch
  585.      */
  586.     public int getRevolutionNumberAtEpoch() {
  587.         return revolutionNumberAtEpoch;
  588.     }

  589.     /** Get the ballistic coefficient.
  590.      * @return bStar
  591.      */
  592.     public double getBStar() {
  593.         return bStarParameterDriver.getValue(getDate().toAbsoluteDate());
  594.     }

  595.     /** Get a string representation of this TLE set.
  596.      * <p>The representation is simply the two lines separated by the
  597.      * platform line separator.</p>
  598.      * @return string representation of this TLE set
  599.      */
  600.     public String toString() {
  601.         try {
  602.             return getLine1() + System.getProperty("line.separator") + getLine2();
  603.         } catch (OrekitException oe) {
  604.             throw new OrekitInternalError(oe);
  605.         }
  606.     }

  607.     /**
  608.      * Convert Spacecraft State into TLE.
  609.      *
  610.      * @param state Spacecraft State to convert into TLE
  611.      * @param templateTLE first guess used to get identification and estimate new TLE
  612.      * @param generationAlgorithm TLE generation algorithm
  613.      * @param <T> type of the element
  614.      * @return a generated TLE
  615.      * @since 12.0
  616.      */
  617.     public static <T extends CalculusFieldElement<T>> FieldTLE<T> stateToTLE(final FieldSpacecraftState<T> state, final FieldTLE<T> templateTLE,
  618.                                                                              final TleGenerationAlgorithm generationAlgorithm) {
  619.         return generationAlgorithm.generate(state, templateTLE);
  620.     }

  621.     /** Check the lines format validity.
  622.      * @param line1 the first element
  623.      * @param line2 the second element
  624.      * @return true if format is recognized (non null lines, 69 characters length,
  625.      * line content), false if not
  626.      */
  627.     public static boolean isFormatOK(final String line1, final String line2) {
  628.         return TLE.isFormatOK(line1, line2);
  629.     }

  630.     /** Compute the checksum of the first 68 characters of a line.
  631.      * @param line line to check
  632.      * @return checksum
  633.      */
  634.     private static int checksum(final CharSequence line) {
  635.         int sum = 0;
  636.         for (int j = 0; j < 68; j++) {
  637.             final char c = line.charAt(j);
  638.             if (Character.isDigit(c)) {
  639.                 sum += Character.digit(c, 10);
  640.             } else if (c == '-') {
  641.                 ++sum;
  642.             }
  643.         }
  644.         return sum % 10;
  645.     }

  646.     /**
  647.      * Convert FieldTLE into TLE.
  648.      * @return TLE
  649.      */
  650.     public TLE toTLE() {
  651.         final TLE regularTLE = new TLE(getSatelliteNumber(), getClassification(), getLaunchYear(), getLaunchNumber(), getLaunchPiece(), getEphemerisType(),
  652.                                        getElementNumber(), getDate().toAbsoluteDate(), getMeanMotion().getReal(), getMeanMotionFirstDerivative().getReal(),
  653.                                        getMeanMotionSecondDerivative().getReal(), getE().getReal(), getI().getReal(), getPerigeeArgument().getReal(),
  654.                                        getRaan().getReal(), getMeanAnomaly().getReal(), getRevolutionNumberAtEpoch(), getBStar(), getUtc());

  655.         for (int k = 0; k < regularTLE.getParametersDrivers().size(); ++k) {
  656.             regularTLE.getParametersDrivers().get(k).setSelected(getParametersDrivers().get(k).isSelected());
  657.         }

  658.         return regularTLE;

  659.     }

  660.     /** Check if this tle equals the provided tle.
  661.      * <p>Due to the difference in precision between object and string
  662.      * representations of TLE, it is possible for this method to return false
  663.      * even if string representations returned by {@link #toString()}
  664.      * are equal.</p>
  665.      * @param o other tle
  666.      * @return true if this tle equals the provided tle
  667.      */
  668.     @Override
  669.     public boolean equals(final Object o) {
  670.         if (o == this) {
  671.             return true;
  672.         }
  673.         if (!(o instanceof FieldTLE)) {
  674.             return false;
  675.         }
  676.         @SuppressWarnings("unchecked")
  677.         final FieldTLE<T> tle = (FieldTLE<T>) o;
  678.         return satelliteNumber == tle.satelliteNumber &&
  679.                 classification == tle.classification &&
  680.                 launchYear == tle.launchYear &&
  681.                 launchNumber == tle.launchNumber &&
  682.                 Objects.equals(launchPiece, tle.launchPiece) &&
  683.                 ephemerisType == tle.ephemerisType &&
  684.                 elementNumber == tle.elementNumber &&
  685.                 Objects.equals(epoch, tle.epoch) &&
  686.                 meanMotion.getReal() == tle.meanMotion.getReal() &&
  687.                 meanMotionFirstDerivative.getReal() == tle.meanMotionFirstDerivative.getReal() &&
  688.                 meanMotionSecondDerivative.getReal() == tle.meanMotionSecondDerivative.getReal() &&
  689.                 eccentricity.getReal() == tle.eccentricity.getReal() &&
  690.                 inclination.getReal() == tle.inclination.getReal() &&
  691.                 pa.getReal() == tle.pa.getReal() &&
  692.                 raan.getReal() == tle.raan.getReal() &&
  693.                 meanAnomaly.getReal() == tle.meanAnomaly.getReal() &&
  694.                 revolutionNumberAtEpoch == tle.revolutionNumberAtEpoch &&
  695.                 getBStar() == tle.getBStar();
  696.     }

  697.     /** Get a hashcode for this tle.
  698.      * @return hashcode
  699.      */
  700.     @Override
  701.     public int hashCode() {
  702.         return Objects.hash(satelliteNumber,
  703.                 classification,
  704.                 launchYear,
  705.                 launchNumber,
  706.                 launchPiece,
  707.                 ephemerisType,
  708.                 elementNumber,
  709.                 epoch,
  710.                 meanMotion,
  711.                 meanMotionFirstDerivative,
  712.                 meanMotionSecondDerivative,
  713.                 eccentricity,
  714.                 inclination,
  715.                 pa,
  716.                 raan,
  717.                 meanAnomaly,
  718.                 revolutionNumberAtEpoch,
  719.                 getBStar());
  720.     }

  721. }