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
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.LinkedList;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.orekit.files.general.OrbitFile;
29 import org.orekit.files.general.SatelliteInformation;
30 import org.orekit.files.general.SatelliteTimeCoordinate;
31 import org.orekit.time.AbsoluteDate;
32
33 /** Represents a parsed SP3 orbit file.
34 * @author Thomas Neidhart
35 */
36 public class SP3File implements OrbitFile, Serializable {
37
38 /** Serializable UID. */
39 private static final long serialVersionUID = 3333652174843017654L;
40
41 /** File type indicator. */
42 public enum SP3FileType {
43 /** GPS only file. */
44 GPS,
45 /** Mixed file. */
46 MIXED,
47 /** GLONASS only file. */
48 GLONASS,
49 /** LEO only file. */
50 LEO,
51 /** Galileo only file. */
52 GALILEO,
53 /** COMPASS only file. */
54 COMPASS,
55 /** QZSS only file. */
56 QZSS,
57 /** undefined file format. */
58 UNDEFINED
59 }
60
61 /** Orbit type indicator. */
62 public enum SP3OrbitType {
63 /** fitted. */
64 FIT,
65 /** extrapolated or predicted. */
66 EXT,
67 /** broadcast. */
68 BCT,
69 /** fitted after applying a Helmert transformation. */
70 HLM;
71
72 /** Parse a string to get the type.
73 * @param s string to parse
74 * @return the type corresponding to the string
75 * @exception IllegalArgumentException if the string does not correspond to a type
76 */
77 public static SP3OrbitType parseType(final String s) {
78 final String normalizedString = s.trim().toUpperCase();
79 if ("EST".equals(normalizedString)) {
80 return FIT;
81 } else {
82 return valueOf(normalizedString);
83 }
84 }
85
86 }
87
88 /** File type. */
89 private SP3FileType type;
90
91 /** Time system. */
92 private TimeSystem timeSystem;
93
94 /** Epoch of the file. */
95 private AbsoluteDate epoch;
96
97 /** GPS week. */
98 private int gpsWeek;
99
100 /** Seconds of the current GPS week. */
101 private double secondsOfWeek;
102
103 /** Julian day. */
104 private int julianDay;
105
106 /** Day fraction. */
107 private double dayFraction;
108
109 /** Time-interval between epochs. */
110 private double epochInterval;
111
112 /** Number of epochs. */
113 private int numberOfEpochs;
114
115 /** Coordinate system. */
116 private String coordinateSystem;
117
118 /** Data used indicator. */
119 private String dataUsed;
120
121 /** Orbit type. */
122 private SP3OrbitType orbitType;
123
124 /** Agency providing the file. */
125 private String agency;
126
127 /** A list containing additional satellite information. */
128 private List<SatelliteInformation> satellites;
129
130 /** A mapping of satellite id to its corresponding {@link SatelliteInformation} object. */
131 private Map<String, SatelliteInformation> satelliteInfo;
132
133 /** A map containing all satellite coordinates. */
134 private Map<String, List<SatelliteTimeCoordinate>> satelliteCoords;
135
136 /** Create a new SP3 file object. */
137 public SP3File() {
138 satellites = new ArrayList<SatelliteInformation>();
139 satelliteInfo = new HashMap<String, SatelliteInformation>();
140 satelliteCoords = new HashMap<String, List<SatelliteTimeCoordinate>>();
141 }
142
143 /** Returns the {@link SP3FileType} associated with this SP3 file.
144 * @return the file type for this SP3 file
145 */
146 public SP3FileType getType() {
147 return type;
148 }
149
150 /** Set the file type for this SP3 file.
151 * @param fileType the file type to be set
152 */
153 public void setType(final SP3FileType fileType) {
154 this.type = fileType;
155 }
156
157 /** {@inheritDoc} */
158 public TimeSystem getTimeSystem() {
159 return timeSystem;
160 }
161
162 /** Set the time system used in this SP3 file.
163 * @param system the time system to be set
164 */
165 public void setTimeSystem(final TimeSystem system) {
166 this.timeSystem = system;
167 }
168
169 /** Returns the data used indicator from the SP3 file.
170 * @return the data used indicator (unparsed)
171 */
172 public String getDataUsed() {
173 return dataUsed;
174 }
175
176 /** Set the data used indicator for this SP3 file.
177 * @param data the data used indicator to be set
178 */
179 public void setDataUsed(final String data) {
180 this.dataUsed = data;
181 }
182
183 /** {@inheritDoc} */
184 public AbsoluteDate getEpoch() {
185 return epoch;
186 }
187
188 /** Set the epoch of the SP3 file.
189 * @param time the epoch to be set
190 */
191 public void setEpoch(final AbsoluteDate time) {
192 this.epoch = time;
193 }
194
195 /** Returns the GPS week as contained in the SP3 file.
196 * @return the GPS week of the SP3 file
197 */
198 public int getGpsWeek() {
199 return gpsWeek;
200 }
201
202 /** Set the GPS week of the SP3 file.
203 * @param week the GPS week to be set
204 */
205 public void setGpsWeek(final int week) {
206 this.gpsWeek = week;
207 }
208
209 /** Returns the seconds of the GPS week as contained in the SP3 file.
210 * @return the seconds of the GPS week
211 */
212 public double getSecondsOfWeek() {
213 return secondsOfWeek;
214 }
215
216 /** Set the seconds of the GPS week for this SP3 file.
217 * @param seconds the seconds to be set
218 */
219 public void setSecondsOfWeek(final double seconds) {
220 this.secondsOfWeek = seconds;
221 }
222
223 /** Returns the julian day for this SP3 file.
224 * @return the julian day
225 */
226 public int getJulianDay() {
227 return julianDay;
228 }
229
230 /** Set the julian day for this SP3 file.
231 * @param day the julian day to be set
232 */
233 public void setJulianDay(final int day) {
234 this.julianDay = day;
235 }
236
237 /** Returns the day fraction for this SP3 file.
238 * @return the day fraction
239 */
240 public double getDayFraction() {
241 return dayFraction;
242 }
243
244 /** Set the day fraction for this SP3 file.
245 * @param fraction the day fraction to be set
246 */
247 public void setDayFraction(final double fraction) {
248 this.dayFraction = fraction;
249 }
250
251 /** {@inheritDoc} */
252 public double getEpochInterval() {
253 return epochInterval;
254 }
255
256 /** Set the epoch interval for this SP3 file.
257 * @param interval the interval between orbit entries
258 */
259 public void setEpochInterval(final double interval) {
260 this.epochInterval = interval;
261 }
262
263 /** {@inheritDoc} */
264 public int getNumberOfEpochs() {
265 return numberOfEpochs;
266 }
267
268 /** Set the number of epochs as contained in the SP3 file.
269 * @param epochCount the number of epochs to be set
270 */
271 public void setNumberOfEpochs(final int epochCount) {
272 this.numberOfEpochs = epochCount;
273 }
274
275 /** {@inheritDoc} */
276 public String getCoordinateSystem() {
277 return coordinateSystem;
278 }
279
280 /** Set the coordinate system used for the orbit entries.
281 * @param system the coordinate system to be set
282 */
283 public void setCoordinateSystem(final String system) {
284 this.coordinateSystem = system;
285 }
286
287 /** Returns the {@link SP3OrbitType} for this SP3 file.
288 * @return the orbit type
289 */
290 public SP3OrbitType getOrbitType() {
291 return orbitType;
292 }
293
294 /** Set the {@link SP3OrbitType} for this SP3 file.
295 * @param oType the orbit type to be set
296 */
297 public void setOrbitType(final SP3OrbitType oType) {
298 this.orbitType = oType;
299 }
300
301 /** Returns the agency that prepared this SP3 file.
302 * @return the agency
303 */
304 public String getAgency() {
305 return agency;
306 }
307
308 /** Set the agency string for this SP3 file.
309 * @param agencyStr the agency string to be set
310 */
311 public void setAgency(final String agencyStr) {
312 this.agency = agencyStr;
313 }
314
315 /** Add a new satellite with a given identifier to the list of
316 * stored satellites.
317 * @param satId the satellite identifier
318 */
319 public void addSatellite(final String satId) {
320 // only add satellites which have not been added before
321 if (getSatellite(satId) == null) {
322 final SatelliteInformation info = new SatelliteInformation(satId);
323 satellites.add(info);
324 satelliteInfo.put(satId, info);
325 satelliteCoords.put(satId, new LinkedList<SatelliteTimeCoordinate>());
326 }
327 }
328
329 /** {@inheritDoc} */
330 public Collection<SatelliteInformation> getSatellites() {
331 return Collections.unmodifiableCollection(satellites);
332 }
333
334 /** {@inheritDoc} */
335 public int getSatelliteCount() {
336 return satellites.size();
337 }
338
339 /** {@inheritDoc} */
340 public SatelliteInformation getSatellite(final String satId) {
341 if (satId == null) {
342 return null;
343 }
344
345 return satelliteInfo.get(satId);
346 }
347
348 /** Returns the nth satellite as contained in the SP3 file.
349 * @param n the index of the satellite
350 * @return a {@link SatelliteInformation} object for the nth satellite
351 */
352 public SatelliteInformation getSatellite(final int n) {
353 return satellites.get(n);
354 }
355
356 /** {@inheritDoc} */
357 public boolean containsSatellite(final String satId) {
358 return satelliteCoords.containsKey(satId);
359 }
360
361 /** {@inheritDoc} */
362 public List<SatelliteTimeCoordinate> getSatelliteCoordinates(final String satId) {
363 return satelliteCoords.get(satId);
364 }
365
366 /** Adds a new P/V coordinate for a given satellite.
367 * @param satId the satellite identifier
368 * @param coord the P/V coordinate of the satellite
369 */
370 public void addSatelliteCoordinate(final String satId, final SatelliteTimeCoordinate coord) {
371 final List<SatelliteTimeCoordinate> coords = satelliteCoords.get(satId);
372 if (coords != null) {
373 coords.add(coord);
374 }
375 }
376 }