OGMFile.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.files.ccsds;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.Map;

  23. import org.hipparchus.linear.MatrixUtils;
  24. import org.hipparchus.linear.RealMatrix;
  25. import org.orekit.errors.OrekitException;
  26. import org.orekit.errors.OrekitMessages;
  27. import org.orekit.frames.Frame;
  28. import org.orekit.frames.LOFType;
  29. import org.orekit.orbits.PositionAngle;
  30. import org.orekit.time.AbsoluteDate;

  31. /** This class gathers the general state data present in both OPM and OMM files.
  32.  * <p>
  33.  * This class does not appear in the CCSDS standard, it is only a design
  34.  * feature of Orekit to reduce code duplication.
  35.  * </p>
  36.  * @author sports
  37.  * @since 6.1
  38.  */
  39. public abstract class OGMFile extends ODMFile {

  40.     /** Epoch of state vector and optional Keplerian elements. */
  41.     private AbsoluteDate epoch;

  42.     /** Orbit semi-major axis (m). */
  43.     private double a;

  44.     /** Orbit eccentricity. */
  45.     private double e;

  46.     /** Orbit inclination (rad). */
  47.     private double i;

  48.     /** Orbit right ascension of ascending node (rad). */
  49.     private double raan;

  50.     /** Orbit argument of pericenter (rad). */
  51.     private double pa;

  52.     /** Orbit anomaly (rad). */
  53.     private double anomaly;

  54.     /** Orbit anomaly type (mean or true). */
  55.     private PositionAngle anomalyType;

  56.     /** Spacecraft mass. */
  57.     private double mass;

  58.     /** Solar radiation pressure area (m^2). */
  59.     private double solarRadArea;

  60.     /** Solar radiation pressure coefficient. */
  61.     private double solarRadCoeff;

  62.     /** Drag area (m^2). */
  63.     private double dragArea;

  64.     /** Drag coefficient. */
  65.     private double dragCoeff;

  66.     /** Coordinate system for covariance matrix, for Local Orbital Frames. */
  67.     private LOFType covRefLofType;

  68.     /** Coordinate system for covariance matrix, for absolute frames.
  69.      * If not given it is set equal to refFrame. */
  70.     private Frame covRefFrame;

  71.     /** Position/Velocity covariance matrix. */
  72.     private RealMatrix covarianceMatrix;

  73.     /** Map of user defined parameter keywords and corresponding values. */
  74.     private Map<String, String> userDefinedParameters;

  75.     /** Tests whether the OPM contains Keplerian elements data. */
  76.     private boolean hasKeplerianElements;

  77.     /** Epoch comments. The list contains a string for each line of comment. */
  78.     private List<String> epochComment;

  79.     /** Keplerian elements comments. The list contains a string for each line of comment. */
  80.     private List<String> keplerianElementsComment;

  81.     /** Spacecraft data comments. The list contains a string for each line of comment. */
  82.     private List<String> spacecraftComment;

  83.     /** Covariance matrix data comments. The list contains a string for each line of comment. */
  84.     private List<String> covarianceComment;

  85.     /** Create a new OPM file object. */
  86.     OGMFile() {
  87.         mass                     = Double.NaN;
  88.         userDefinedParameters    = new HashMap<String, String>();
  89.         epochComment             = Collections.emptyList();
  90.         keplerianElementsComment = Collections.emptyList();
  91.         spacecraftComment        = Collections.emptyList();
  92.         covarianceComment        = Collections.emptyList();
  93.     }

  94.     /** Get epoch of state vector, Keplerian elements and covariance matrix data.
  95.      * @return epoch the epoch
  96.      */
  97.     public AbsoluteDate getEpoch() {
  98.         return epoch;
  99.     }

  100.     /** Set epoch of state vector, Keplerian elements and covariance matrix data.
  101.      * @param epoch the epoch to be set
  102.      */
  103.     void setEpoch(final AbsoluteDate epoch) {
  104.         this.epoch = epoch;
  105.     }

  106.     /** Get the orbit semi-major axis.
  107.      * @return the orbit semi-major axis
  108.      */
  109.     public double getA() {
  110.         return a;
  111.     }

  112.     /** Set the orbit semi-major axis.
  113.      * @param a the semi-major axis to be set
  114.      */
  115.     void setA(final double a) {
  116.         this.a = a;
  117.     }

  118.     /** Get the orbit eccentricity.
  119.      * @return the orbit eccentricity
  120.      */
  121.     public double getE() {
  122.         return e;
  123.     }

  124.     /** Set the orbit eccentricity.
  125.      * @param e the eccentricity to be set
  126.      */
  127.     void setE(final double e) {
  128.         this.e = e;
  129.     }

  130.     /** Get the orbit inclination.
  131.      * @return the orbit inclination
  132.      */
  133.     public double getI() {
  134.         return i;
  135.     }

  136.     /**Set the orbit inclination.
  137.      * @param i the inclination to be set
  138.      */
  139.     void setI(final double i) {
  140.         this.i = i;
  141.     }

  142.     /** Get the orbit right ascension of ascending node.
  143.      * @return the orbit right ascension of ascending node
  144.      */
  145.     public double getRaan() {
  146.         return raan;
  147.     }

  148.     /** Set the orbit right ascension of ascending node.
  149.      * @param raan the right ascension of ascending node to be set
  150.      */
  151.     void setRaan(final double raan) {
  152.         this.raan = raan;
  153.     }

  154.     /** Get the orbit argument of pericenter.
  155.      * @return the orbit argument of pericenter
  156.      */
  157.     public double getPa() {
  158.         return pa;
  159.     }

  160.     /** Set the orbit argument of pericenter.
  161.      * @param pa the argument of pericenter to be set
  162.      */
  163.     void setPa(final double pa) {
  164.         this.pa = pa;
  165.     }

  166.     /** Get the orbit anomaly.
  167.      * @return the orbit anomaly
  168.      */
  169.     public double getAnomaly() {
  170.         return anomaly;
  171.     }

  172.     /** Set the orbit anomaly.
  173.      * @param anomaly the anomaly to be set
  174.      */
  175.     void setAnomaly(final double anomaly) {
  176.         this.anomaly = anomaly;
  177.     }

  178.     /** Get the type of anomaly (true or mean).
  179.      * @return the type of anomaly
  180.      */
  181.     public PositionAngle getAnomalyType() {
  182.         return anomalyType;
  183.     }

  184.     /** Set the type of anomaly (true or mean).
  185.      * @param anomalyType the type of anomaly to be set
  186.      */
  187.     void setAnomalyType(final String anomalyType) {
  188.         this.anomalyType = PositionAngle.valueOf(anomalyType);
  189.     }

  190.     /** Get the spacecraft mass.
  191.      * @return the spacecraft mass
  192.      */
  193.     public double getMass() {
  194.         if (Double.isNaN(mass)) {
  195.             throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_SPACECRAFT_MASS);
  196.         }
  197.         return mass;
  198.     }

  199.     /** Set the spacecraft mass.
  200.      * @param mass the spacecraft mass to be set
  201.      */
  202.     void setMass(final double mass) {
  203.         this.mass = mass;
  204.     }

  205.     /** Get the solar radiation pressure area.
  206.      * @return the solar radiation pressure area
  207.      */
  208.     public double getSolarRadArea() {
  209.         return solarRadArea;
  210.     }

  211.     /** Set the solar radiation pressure area.
  212.      * @param solarRadArea the area to be set
  213.      */
  214.     void setSolarRadArea(final double solarRadArea) {
  215.         this.solarRadArea = solarRadArea;
  216.     }

  217.     /** Get the solar radiation pressure coefficient.
  218.      * @return the solar radiation pressure coefficient
  219.      */
  220.     public double getSolarRadCoeff() {
  221.         return solarRadCoeff;
  222.     }

  223.     /** Get the solar radiation pressure coefficient.
  224.      * @param solarRadCoeff the coefficient to be set
  225.      */
  226.     void setSolarRadCoeff(final double solarRadCoeff) {
  227.         this.solarRadCoeff = solarRadCoeff;
  228.     }

  229.     /** Get the drag area.
  230.      * @return the drag area
  231.      */
  232.     public double getDragArea() {
  233.         return dragArea;
  234.     }

  235.     /** Set the drag area.
  236.      * @param dragArea the area to be set
  237.      */
  238.     void setDragArea(final double dragArea) {
  239.         this.dragArea = dragArea;
  240.     }

  241.     /** Get the drag coefficient.
  242.      * @return the drag coefficient
  243.      */
  244.     public double getDragCoeff() {
  245.         return dragCoeff;
  246.     }

  247.     /** Set the drag coefficient.
  248.      * @param dragCoeff the coefficient to be set
  249.      */
  250.     void setDragCoeff(final double dragCoeff) {
  251.         this.dragCoeff = dragCoeff;
  252.     }

  253.     /** Get coordinate system for covariance matrix, for Local Orbital Frames.
  254.      * <p>
  255.      * The value returned is null if the covariance matrix is given in an
  256.      * absolute frame rather than a Local Orbital Frame. In this case, the
  257.      * method {@link #getCovRefFrame()} must be used instead.
  258.      * </p>
  259.      * @return the coordinate system for covariance matrix, or null if the
  260.      * covariance matrix is given in an absolute frame rather than a Local
  261.      * Orbital Frame
  262.      */
  263.     public LOFType getCovRefLofType() {
  264.         return covRefLofType;
  265.     }

  266.     /** Set coordinate system for covariance matrix, for Local Orbital Frames.
  267.      * @param covRefLofType the coordinate system to be set
  268.      */
  269.     void setCovRefLofType(final LOFType covRefLofType) {
  270.         this.covRefLofType = covRefLofType;
  271.         this.covRefFrame   = null;
  272.     }

  273.     /** Get coordinate system for covariance matrix, for absolute frames.
  274.      * <p>
  275.      * The value returned is null if the covariance matrix is given in a
  276.      * Local Orbital Frame rather than an absolute frame. In this case, the
  277.      * method {@link #getCovRefLofType()} must be used instead.
  278.      * </p>
  279.      * @return the coordinate system for covariance matrix
  280.      */
  281.     public Frame getCovRefFrame() {
  282.         return covRefFrame;
  283.     }

  284.     /** Set coordinate system for covariance matrix.
  285.      * @param covRefFrame the coordinate system to be set
  286.      */
  287.     void setCovRefFrame(final Frame covRefFrame) {
  288.         this.covRefLofType = null;
  289.         this.covRefFrame   = covRefFrame;
  290.     }

  291.     /** Get the Position/Velocity covariance matrix.
  292.      * @return the Position/Velocity covariance matrix
  293.      */
  294.     public RealMatrix getCovarianceMatrix() {
  295.         return covarianceMatrix;
  296.     }

  297.     /** Set an entry in the Position/Velocity covariance matrix.
  298.      * <p>
  299.      * Both m(j, k) and m(k, j) are set.
  300.      * </p>
  301.      * @param j row index (must be between 0 and 5 (inclusive)
  302.      * @param k column index (must be between 0 and 5 (inclusive)
  303.      * @param entry value of the matrix entry
  304.      */
  305.     void setCovarianceMatrixEntry(final int j, final int k, final double entry) {
  306.         covarianceMatrix.setEntry(j, k, entry);
  307.         covarianceMatrix.setEntry(k, j, entry);
  308.     }

  309.     /** Get the map of user defined parameter keywords and their corresponding values.
  310.      * @return the map of user defined parameter keywords and their corresponding values.
  311.      */
  312.     public Map<String, String> getUserDefinedParameters() {
  313.         return userDefinedParameters;
  314.     }

  315.     /** Add a pair keyword-value in the map of user defined parameter keywords and their corresponding values.
  316.      * @param keyword the user defined parameter keyword to be set. Starts with USER_DEFINED_
  317.      * @param value the user defined parameter value to be set
  318.      */
  319.     void setUserDefinedParameters(final String keyword,
  320.                                          final String value) {
  321.         userDefinedParameters.put(keyword, value);
  322.     }

  323.     /** Check whether the OPM contains Keplerian elements data.
  324.      * @return true if OPM contains Keplerian elements data.
  325.      */
  326.     public boolean hasKeplerianElements() {
  327.         return hasKeplerianElements;
  328.     }

  329.     /** Set boolean testing whether the OPM contains Keplerian elements data.
  330.      * @param hasKeplerianElements the boolean to be set.
  331.      */
  332.     void setHasKeplerianElements(final boolean hasKeplerianElements) {
  333.         this.hasKeplerianElements = hasKeplerianElements;
  334.     }

  335.     /** Check whether the OPM contains covariance matrix data.
  336.      * @return true if OPM contains covariance matrix data.
  337.      */
  338.     public boolean hasCovarianceMatrix() {
  339.         return covarianceMatrix != null;
  340.     }

  341.     /** Create a covariance matrix, initialized to zero.
  342.      */
  343.     void createCovarianceMatrix() {
  344.         covarianceMatrix = MatrixUtils.createRealMatrix(6, 6);
  345.     }

  346.     /** Get the comment for epoch.
  347.      * @return comment for epoch
  348.      */
  349.     public List<String> getEpochComment() {
  350.         return Collections.unmodifiableList(epochComment);
  351.     }

  352.     /** Set the comment for epoch.
  353.      * @param comment comment to set
  354.      */
  355.     void setEpochComment(final List<String> comment) {
  356.         epochComment = new ArrayList<String>(comment);
  357.     }

  358.     /** Get the comment for Keplerian elements.
  359.      * @return comment for Keplerian elements
  360.      */
  361.     public List<String> getKeplerianElementsComment() {
  362.         return Collections.unmodifiableList(keplerianElementsComment);
  363.     }

  364.     /** Set the comment for Keplerian elements.
  365.      * @param comment comment to set
  366.      */
  367.     void setKeplerianElementsComment(final List<String> comment) {
  368.         keplerianElementsComment = new ArrayList<String>(comment);
  369.     }

  370.     /** Get the comment for spacecraft.
  371.      * @return comment for spacecraft
  372.      */
  373.     public List<String> getSpacecraftComment() {
  374.         return Collections.unmodifiableList(spacecraftComment);
  375.     }

  376.     /** Set the comment for spacecraft.
  377.      * @param comment comment to set
  378.      */
  379.     void setSpacecraftComment(final List<String> comment) {
  380.         spacecraftComment = new ArrayList<String>(comment);
  381.     }

  382.     /** Get the comment for covariance.
  383.      * @return comment for covariance
  384.      */
  385.     public List<String> getCovarianceComment() {
  386.         return Collections.unmodifiableList(covarianceComment);
  387.     }

  388.     /** Set the comment for covariance.
  389.      * @param comment comment to set
  390.      */
  391.     void setCovarianceComment(final List<String> comment) {
  392.         covarianceComment = new ArrayList<String>(comment);
  393.     }

  394.     /** Get the meta data.
  395.      * @return meta data
  396.      */
  397.     public abstract ODMMetaData getMetaData();

  398. }