OGMFile.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.      * @exception OrekitException if mass is unknown
  193.      */
  194.     public double getMass() throws OrekitException {
  195.         if (Double.isNaN(mass)) {
  196.             throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_SPACECRAFT_MASS);
  197.         }
  198.         return mass;
  199.     }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  399. }