1 /* Copyright 2002-2025 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
18 package org.orekit.estimation.common;
19
20 import org.hipparchus.exception.LocalizedCoreFormats;
21 import org.orekit.errors.OrekitException;
22 import org.orekit.errors.OrekitMessages;
23 import org.orekit.estimation.measurements.ObservableSatellite;
24 import org.orekit.estimation.measurements.ObservedMeasurement;
25 import org.orekit.estimation.measurements.Range;
26 import org.orekit.estimation.measurements.modifiers.Bias;
27 import org.orekit.time.AbsoluteDate;
28 import org.orekit.time.TimeScalesFactory;
29
30 import java.util.Map;
31
32 /** Measurements types. */
33 abstract class MeasurementsParser<T extends ObservedMeasurement<T>> {
34
35 /** Parse the fields of a measurements line.
36 * @param fields measurements line fields
37 * @param stations name to stations data map
38 * @param pvData PV measurements data
39 * @param satellite satellite reference
40 * @param satRangeBias range bias due to transponder delay
41 * @param weight base weights for measurements
42 * @param line complete line
43 * @param lineNumber line number
44 * @param fileName file name
45 * @return parsed measurement
46 */
47 public abstract T parseFields(String[] fields,
48 Map<String, StationData> stations,
49 PVData pvData, ObservableSatellite satellite,
50 Bias<Range> satRangeBias, Weights weight,
51 String line, int lineNumber, String fileName);
52
53 /** Check the number of fields.
54 * @param expected expected number of fields
55 * @param fields measurements line fields
56 * @param line complete line
57 * @param lineNumber line number
58 * @param fileName file name
59 */
60 protected void checkFields(final int expected, final String[] fields,
61 final String line, final int lineNumber, final String fileName) {
62 if (fields.length != expected) {
63 throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE,
64 lineNumber, fileName, line);
65 }
66 }
67
68 /** Get the date for the line.
69 * @param date date field
70 * @param line complete line
71 * @param lineNumber line number
72 * @param fileName file name
73 * @return parsed measurement
74 */
75 protected AbsoluteDate getDate(final String date,
76 final String line, final int lineNumber, final String fileName) {
77 try {
78 return new AbsoluteDate(date, TimeScalesFactory.getUTC());
79 } catch (OrekitException oe) {
80 throw generateException("wrong date " + date, line, lineNumber, fileName);
81 }
82 }
83
84 /** Get the station data for the line.
85 * @param stationName name of the station
86 * @param stations name to stations data map
87 * @param line complete line
88 * @param lineNumber line number
89 * @param fileName file name
90 * @return parsed measurement
91 */
92 protected StationData getStationData(final String stationName,
93 final Map<String, StationData> stations,
94 final String line, final int lineNumber, final String fileName) {
95 final StationData stationData = stations.get(stationName);
96 if (stationData == null) {
97 throw generateException("unknown station " + stationName, line, lineNumber, fileName);
98 }
99 return stationData;
100 }
101
102 /** Generate an exception.
103 * @param detail message detail
104 * @param line complete line
105 * @param lineNumber line number
106 * @param fileName file name
107 * @return generated exception
108 */
109 private static OrekitException generateException(final String detail, final String line,
110 final int lineNumber, final String fileName) {
111 return new OrekitException(LocalizedCoreFormats.SIMPLE_MESSAGE,
112 detail +
113 " at line " + lineNumber +
114 " in file " + fileName +
115 "\n" + line);
116 }
117
118 }