SP3File.java

  1. /* Copyright 2002-2012 Space Applications Services
  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.sp3;

  18. import java.io.Serializable;
  19. import java.util.ArrayList;
  20. import java.util.Collection;
  21. import java.util.Collections;
  22. import java.util.HashMap;
  23. import java.util.LinkedList;
  24. import java.util.List;
  25. import java.util.Map;

  26. import org.orekit.files.general.OrbitFile;
  27. import org.orekit.files.general.SatelliteInformation;
  28. import org.orekit.files.general.SatelliteTimeCoordinate;
  29. import org.orekit.time.AbsoluteDate;

  30. /** Represents a parsed SP3 orbit file.
  31.  * @author Thomas Neidhart
  32.  */
  33. public class SP3File implements OrbitFile, Serializable {

  34.     /** Serializable UID. */
  35.     private static final long serialVersionUID = 3333652174843017654L;

  36.     /** File type indicator. */
  37.     public enum SP3FileType {
  38.         /** GPS only file. */
  39.         GPS,
  40.         /** Mixed file. */
  41.         MIXED,
  42.         /** GLONASS only file. */
  43.         GLONASS,
  44.         /** LEO only file. */
  45.         LEO,
  46.         /** Galileo only file. */
  47.         GALILEO,
  48.         /** COMPASS only file. */
  49.         COMPASS,
  50.         /** QZSS only file. */
  51.         QZSS,
  52.         /** undefined file format. */
  53.         UNDEFINED
  54.     }

  55.     /** Orbit type indicator. */
  56.     public enum SP3OrbitType {
  57.         /** fitted. */
  58.         FIT,
  59.         /** extrapolated or predicted. */
  60.         EXT,
  61.         /** broadcast. */
  62.         BCT,
  63.         /** fitted after applying a Helmert transformation. */
  64.         HLM
  65.     }

  66.     /** File type. */
  67.     private SP3FileType type;

  68.     /** Time system. */
  69.     private TimeSystem timeSystem;

  70.     /** Epoch of the file. */
  71.     private AbsoluteDate epoch;

  72.     /** GPS week. */
  73.     private int gpsWeek;

  74.     /** Seconds of the current GPS week. */
  75.     private double secondsOfWeek;

  76.     /** Julian day. */
  77.     private int julianDay;

  78.     /** Day fraction. */
  79.     private double dayFraction;

  80.     /** Time-interval between epochs. */
  81.     private double epochInterval;

  82.     /** Number of epochs. */
  83.     private int numberOfEpochs;

  84.     /** Coordinate system. */
  85.     private String coordinateSystem;

  86.     /** Data used indicator. */
  87.     private String dataUsed;

  88.     /** Orbit type. */
  89.     private SP3OrbitType orbitType;

  90.     /** Agency providing the file. */
  91.     private String agency;

  92.     /** A list containing additional satellite information. */
  93.     private List<SatelliteInformation> satellites;

  94.     /** A mapping of satellite id to its corresponding {@link SatelliteInformation} object. */
  95.     private Map<String, SatelliteInformation> satelliteInfo;

  96.     /** A map containing all satellite coordinates. */
  97.     private Map<String, List<SatelliteTimeCoordinate>> satelliteCoords;

  98.     /** Create a new SP3 file object. */
  99.     public SP3File() {
  100.         satellites = new ArrayList<SatelliteInformation>();
  101.         satelliteInfo = new HashMap<String, SatelliteInformation>();
  102.         satelliteCoords = new HashMap<String, List<SatelliteTimeCoordinate>>();
  103.     }

  104.     /** Returns the {@link SP3FileType} associated with this SP3 file.
  105.      * @return the file type for this SP3 file
  106.      */
  107.     public SP3FileType getType() {
  108.         return type;
  109.     }

  110.     /** Set the file type for this SP3 file.
  111.      * @param fileType the file type to be set
  112.      */
  113.     public void setType(final SP3FileType fileType) {
  114.         this.type = fileType;
  115.     }

  116.     /** {@inheritDoc} */
  117.     public TimeSystem getTimeSystem() {
  118.         return timeSystem;
  119.     }

  120.     /** Set the time system used in this SP3 file.
  121.      * @param system the time system to be set
  122.      */
  123.     public void setTimeSystem(final TimeSystem system) {
  124.         this.timeSystem = system;
  125.     }

  126.     /** Returns the data used indicator from the SP3 file.
  127.      * @return the data used indicator (unparsed)
  128.      */
  129.     public String getDataUsed() {
  130.         return dataUsed;
  131.     }

  132.     /** Set the data used indicator for this SP3 file.
  133.      * @param data the data used indicator to be set
  134.      */
  135.     public void setDataUsed(final String data) {
  136.         this.dataUsed = data;
  137.     }

  138.     /** {@inheritDoc} */
  139.     public AbsoluteDate getEpoch() {
  140.         return epoch;
  141.     }

  142.     /** Set the epoch of the SP3 file.
  143.      * @param time the epoch to be set
  144.      */
  145.     public void setEpoch(final AbsoluteDate time) {
  146.         this.epoch = time;
  147.     }

  148.     /** Returns the GPS week as contained in the SP3 file.
  149.      * @return the GPS week of the SP3 file
  150.      */
  151.     public int getGpsWeek() {
  152.         return gpsWeek;
  153.     }

  154.     /** Set the GPS week of the SP3 file.
  155.      * @param week the GPS week to be set
  156.      */
  157.     public void setGpsWeek(final int week) {
  158.         this.gpsWeek = week;
  159.     }

  160.     /** Returns the seconds of the GPS week as contained in the SP3 file.
  161.      * @return the seconds of the GPS week
  162.      */
  163.     public double getSecondsOfWeek() {
  164.         return secondsOfWeek;
  165.     }

  166.     /** Set the seconds of the GPS week for this SP3 file.
  167.      * @param seconds the seconds to be set
  168.      */
  169.     public void setSecondsOfWeek(final double seconds) {
  170.         this.secondsOfWeek = seconds;
  171.     }

  172.     /** Returns the julian day for this SP3 file.
  173.      * @return the julian day
  174.      */
  175.     public int getJulianDay() {
  176.         return julianDay;
  177.     }

  178.     /** Set the julian day for this SP3 file.
  179.      * @param day the julian day to be set
  180.      */
  181.     public void setJulianDay(final int day) {
  182.         this.julianDay = day;
  183.     }

  184.     /** Returns the day fraction for this SP3 file.
  185.      * @return the day fraction
  186.      */
  187.     public double getDayFraction() {
  188.         return dayFraction;
  189.     }

  190.     /** Set the day fraction for this SP3 file.
  191.      * @param fraction the day fraction to be set
  192.      */
  193.     public void setDayFraction(final double fraction) {
  194.         this.dayFraction = fraction;
  195.     }

  196.     /** {@inheritDoc} */
  197.     public double getEpochInterval() {
  198.         return epochInterval;
  199.     }

  200.     /** Set the epoch interval for this SP3 file.
  201.      * @param interval the interval between orbit entries
  202.      */
  203.     public void setEpochInterval(final double interval) {
  204.         this.epochInterval = interval;
  205.     }

  206.     /** {@inheritDoc} */
  207.     public int getNumberOfEpochs() {
  208.         return numberOfEpochs;
  209.     }

  210.     /** Set the number of epochs as contained in the SP3 file.
  211.      * @param epochCount the number of epochs to be set
  212.      */
  213.     public void setNumberOfEpochs(final int epochCount) {
  214.         this.numberOfEpochs = epochCount;
  215.     }

  216.     /** {@inheritDoc} */
  217.     public String getCoordinateSystem() {
  218.         return coordinateSystem;
  219.     }

  220.     /** Set the coordinate system used for the orbit entries.
  221.      * @param system the coordinate system to be set
  222.      */
  223.     public void setCoordinateSystem(final String system) {
  224.         this.coordinateSystem = system;
  225.     }

  226.     /** Returns the {@link SP3OrbitType} for this SP3 file.
  227.      * @return the orbit type
  228.      */
  229.     public SP3OrbitType getOrbitType() {
  230.         return orbitType;
  231.     }

  232.     /** Set the {@link SP3OrbitType} for this SP3 file.
  233.      * @param oType the orbit type to be set
  234.      */
  235.     public void setOrbitType(final SP3OrbitType oType) {
  236.         this.orbitType = oType;
  237.     }

  238.     /** Returns the agency that prepared this SP3 file.
  239.      * @return the agency
  240.      */
  241.     public String getAgency() {
  242.         return agency;
  243.     }

  244.     /** Set the agency string for this SP3 file.
  245.      * @param agencyStr the agency string to be set
  246.      */
  247.     public void setAgency(final String agencyStr) {
  248.         this.agency = agencyStr;
  249.     }

  250.     /** Add a new satellite with a given identifier to the list of
  251.      * stored satellites.
  252.      * @param satId the satellite identifier
  253.      */
  254.     public void addSatellite(final String satId) {
  255.         // only add satellites which have not been added before
  256.         if (getSatellite(satId) == null) {
  257.             final SatelliteInformation info = new SatelliteInformation(satId);
  258.             satellites.add(info);
  259.             satelliteInfo.put(satId, info);
  260.             satelliteCoords.put(satId, new LinkedList<SatelliteTimeCoordinate>());
  261.         }
  262.     }

  263.     /** {@inheritDoc} */
  264.     public Collection<SatelliteInformation> getSatellites() {
  265.         return Collections.unmodifiableCollection(satellites);
  266.     }

  267.     /** {@inheritDoc} */
  268.     public int getSatelliteCount() {
  269.         return satellites.size();
  270.     }

  271.     /** {@inheritDoc} */
  272.     public SatelliteInformation getSatellite(final String satId) {
  273.         if (satId == null) {
  274.             return null;
  275.         }

  276.         return satelliteInfo.get(satId);
  277.     }

  278.     /** Returns the nth satellite as contained in the SP3 file.
  279.      * @param n the index of the satellite
  280.      * @return a {@link SatelliteInformation} object for the nth satellite
  281.      */
  282.     public SatelliteInformation getSatellite(final int n) {
  283.         return satellites.get(n);
  284.     }

  285.     /** {@inheritDoc} */
  286.     public boolean containsSatellite(final String satId) {
  287.         return satelliteCoords.containsKey(satId);
  288.     }

  289.     /** {@inheritDoc} */
  290.     public List<SatelliteTimeCoordinate> getSatelliteCoordinates(final String satId) {
  291.         return satelliteCoords.get(satId);
  292.     }

  293.     /** Adds a new P/V coordinate for a given satellite.
  294.      * @param satId the satellite identifier
  295.      * @param coord the P/V coordinate of the satellite
  296.      */
  297.     public void addSatelliteCoordinate(final String satId, final SatelliteTimeCoordinate coord) {
  298.         final List<SatelliteTimeCoordinate> coords = satelliteCoords.get(satId);
  299.         if (coords != null) {
  300.             coords.add(coord);
  301.         }
  302.     }
  303. }