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 package org.orekit.frames;
18
19 import java.io.BufferedReader;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.InputStreamReader;
23 import java.nio.charset.StandardCharsets;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.SortedSet;
30 import java.util.function.Supplier;
31 import java.util.regex.Matcher;
32 import java.util.regex.Pattern;
33
34 import org.hipparchus.util.FastMath;
35 import org.orekit.data.DataProvidersManager;
36 import org.orekit.errors.OrekitException;
37 import org.orekit.errors.OrekitMessages;
38 import org.orekit.time.AbsoluteDate;
39 import org.orekit.time.DateComponents;
40 import org.orekit.time.Month;
41 import org.orekit.time.TimeScale;
42 import org.orekit.utils.Constants;
43 import org.orekit.utils.IERSConventions;
44 import org.orekit.utils.IERSConventions.NutationCorrectionConverter;
45 import org.orekit.utils.units.UnitsConverter;
46
47 /** Loader for bulletin B files.
48 * <p>Bulletin B files contain {@link EOPEntry
49 * Earth Orientation Parameters} for a few months periods.
50 * They correspond to finalized data, suitable for long term
51 * a posteriori analysis.</p>
52 * <p>The bulletin B files are recognized thanks to their base names,
53 * which must match one of the patterns <code>bulletinb_IAU2000-###.txt</code>,
54 * <code>bulletinb_IAU2000.###</code>, <code>bulletinb-###.txt</code> or
55 * <code>bulletinb.###</code> (or the same ending with <code>.gz</code>
56 * for gzip-compressed files) where # stands for a digit character.</p>
57 * <p>
58 * Starting with bulletin B 252 published in February 2009, buletins B are
59 * written in a format containing nutation corrections for both the
60 * new IAU2000 nutation model as dx, dy entries in its section 1 and nutation
61 * corrections for the old IAU1976 nutation model as dPsi, dEpsilon entries in
62 * its section 2. These bulletins are available from IERS <a
63 * href="ftp://ftp.iers.org/products/eop/bulletinb/format_2009/">
64 * FTP site</a>. They are also available with exactly the same content
65 * (but a different naming convention) from <a
66 * href="https://hpiers.obspm.fr/eoppc/bul/bulb_new/">Paris-Meudon
67 * observatory site</a>.
68 * </p>
69 * <p>
70 * Ending with bulletin B 263 published in January 2010, bulletins B were
71 * written in a format containing only one type of nutation corrections in its
72 * section 1, either for new IAU2000 nutation model as dx, dy entries or the old
73 * IAU1976 nutation model as dPsi, dEpsilon entries, depending on the file (a pair of
74 * files with different name was published each month between March 2003 and January 2010).
75 * </p>
76 * <p>
77 * Bulletin B in csv format must be read using {@link EopCsvFilesLoader} rather
78 * than using this loader. Bulletin B in xml format must be read using {@link EopXmlLoader}
79 * rather than using this loader.
80 * </p>
81 * <p>
82 * This class handles both the old and the new format.
83 * </p>
84 * <p>
85 * This class is immutable and hence thread-safe
86 * </p>
87 * @author Luc Maisonobe
88 * @see EopCsvFilesLoader
89 * @see EopXmlLoader
90 */
91 class BulletinBFilesLoader extends AbstractEopLoader implements EopHistoryLoader {
92
93 /** Section 1 header pattern. */
94 private static final Pattern SECTION_1_HEADER;
95
96 /** Section 2 header pattern for old format. */
97 private static final Pattern SECTION_2_HEADER_OLD;
98
99 /** Section 3 header pattern. */
100 private static final Pattern SECTION_3_HEADER;
101
102 /** Pattern for line introducing the final bulletin B values. */
103 private static final Pattern FINAL_VALUES_START;
104
105 /** Pattern for line introducing the bulletin B preliminary extension. */
106 private static final Pattern FINAL_VALUES_END;
107
108 /** Data line pattern in section 1 (old format). */
109 private static final Pattern SECTION_1_DATA_OLD_FORMAT;
110
111 /** Data line pattern in section 2. */
112 private static final Pattern SECTION_2_DATA_OLD_FORMAT;
113
114 /** Data line pattern in section 1 (new format). */
115 private static final Pattern SECTION_1_DATA_NEW_FORMAT;
116
117 /** Data line pattern in section 3 (new format). */
118 private static final Pattern SECTION_3_DATA_NEW_FORMAT;
119
120 static {
121
122 // the section headers lines in the old bulletin B monthly data files have
123 // the following form (the indentation discrepancy for section 6 is really
124 // present in the available files):
125 // 1 - EARTH ORIENTATION PARAMETERS (IERS evaluation).
126 // either
127 // 2 - SMOOTHED VALUES OF x, y, UT1, D, DPSI, DEPSILON (IERS EVALUATION)
128 // or
129 // 2 - SMOOTHED VALUES OF x, y, UT1, D, dX, dY (IERS EVALUATION)
130 // 3 - NORMAL VALUES OF THE EARTH ORIENTATION PARAMETERS AT FIVE-DAY INTERVALS
131 // 4 - DURATION OF THE DAY AND ANGULAR VELOCITY OF THE EARTH (IERS evaluation).
132 // 5 - INFORMATION ON TIME SCALES
133 // 6 - SUMMARY OF CONTRIBUTED EARTH ORIENTATION PARAMETERS SERIES
134 //
135 // the section headers lines in the new bulletin B monthly data files have
136 // the following form:
137 // 1 - DAILY FINAL VALUES OF x, y, UT1-UTC, dX, dY
138 // 2 - DAILY FINAL VALUES OF CELESTIAL POLE OFFSETS dPsi1980 & dEps1980
139 // 3 - EARTH ANGULAR VELOCITY : DAILY FINAL VALUES OF LOD, OMEGA AT 0hUTC
140 // 4 - INFORMATION ON TIME SCALES
141 // 5 - SUMMARY OF CONTRIBUTED EARTH ORIENTATION PARAMETERS SERIES
142 SECTION_1_HEADER = Pattern.compile("^ +1 - (\\p{Upper}+) \\p{Upper}+ \\p{Upper}+.*");
143 SECTION_2_HEADER_OLD = Pattern.compile("^ +2 - SMOOTHED \\p{Upper}+ \\p{Upper}+.*((?:DPSI, DEPSILON)|(?:dX, dY)).*");
144 SECTION_3_HEADER = Pattern.compile("^ +3 - \\p{Upper}+ \\p{Upper}+ \\p{Upper}+.*");
145
146 // the markers bracketing the final values in section 1 in the old bulletin B
147 // monthly data files have the following form:
148 //
149 // Final Bulletin B values.
150 // ...
151 // Preliminary extension, to be updated weekly in Bulletin A and monthly
152 // in Bulletin B.
153 //
154 // the markers bracketing the final values in section 1 in the new bulletin B
155 // monthly data files have the following form:
156 //
157 // Final values
158 // ...
159 // Preliminary extension
160 //
161 FINAL_VALUES_START = Pattern.compile("^\\p{Blank}+Final( Bulletin B)? values.*");
162 FINAL_VALUES_END = Pattern.compile("^\\p{Blank}+Preliminary extension.*");
163
164 // the data lines in the old bulletin B monthly data files have the following form:
165 // in section 1:
166 // AUG 1 55044 0.22176 0.49302 0.231416 -33.768584 -69.1 -8.9
167 // AUG 6 55049 0.23202 0.48003 0.230263 -33.769737 -69.5 -8.5
168 // in section 2:
169 // AUG 1 55044 0.22176 0.49302 0.230581 -0.835 -0.310 -69.1 -8.9
170 // AUG 2 55045 0.22395 0.49041 0.230928 -0.296 -0.328 -69.5 -8.9
171 //
172 // the data lines in the new bulletin B monthly data files have the following form:
173 // in section 1:
174 // 2009 8 2 55045 223.954 490.410 230.9277 0.214 -0.056 0.008 0.009 0.0641 0.048 0.121
175 // 2009 8 3 55046 225.925 487.700 231.2186 0.300 -0.138 0.010 0.012 0.0466 0.099 0.248
176 // 2009 8 4 55047 227.931 485.078 231.3929 0.347 -0.231 0.019 0.023 0.0360 0.099 0.249
177 // 2009 8 5 55048 230.016 482.445 231.4601 0.321 -0.291 0.025 0.028 0.0441 0.095 0.240
178 // 2009 8 6 55049 232.017 480.026 231.3619 0.267 -0.273 0.025 0.029 0.0477 0.038 0.095
179 // in section 2:
180 // 2009 8 2 55045 -69.474 -8.929 0.199 0.121
181 // 2009 8 3 55046 -69.459 -9.016 0.250 0.248
182 // 2009 8 4 55047 -69.401 -9.039 0.250 0.249
183 // 2009 8 5 55048 -69.425 -8.864 0.247 0.240
184 // 2009 8 6 55049 -69.510 -8.539 0.153 0.095
185 // in section 3:
186 // 2009 8 2 55045 -0.3284 0.0013 15.04106723584 0.00000000023
187 // 2009 8 3 55046 -0.2438 0.0013 15.04106722111 0.00000000023
188 // 2009 8 4 55047 -0.1233 0.0013 15.04106720014 0.00000000023
189 // 2009 8 5 55048 0.0119 0.0013 15.04106717660 0.00000000023
190 // 2009 8 6 55049 0.1914 0.0013 15.04106714535 0.00000000023
191 final StringBuilder builder = new StringBuilder("^\\p{Blank}+(?:");
192 for (final Month month : Month.values()) {
193 builder.append(month.getUpperCaseAbbreviation());
194 builder.append('|');
195 }
196 builder.delete(builder.length() - 1, builder.length());
197 builder.append(")");
198 final String integerPattern = "[-+]?\\p{Digit}+";
199 final String realPattern = "[-+]?(?:(?:\\p{Digit}+(?:\\.\\p{Digit}*)?)|(?:\\.\\p{Digit}+))(?:[eE][-+]?\\p{Digit}+)?";
200 final String monthNameField = builder.toString();
201 final String ignoredIntegerField = "\\p{Blank}*" + integerPattern;
202 final String storedIntegerField = "\\p{Blank}*(" + integerPattern + ")";
203 final String mjdField = "\\p{Blank}+(\\p{Digit}\\p{Digit}\\p{Digit}\\p{Digit}\\p{Digit})";
204 final String storedRealField = "\\p{Blank}+(" + realPattern + ")";
205 final String ignoredRealField = "\\p{Blank}+" + realPattern;
206 final String finalBlanks = "\\p{Blank}*$";
207 SECTION_1_DATA_OLD_FORMAT = Pattern.compile(monthNameField + ignoredIntegerField + mjdField +
208 ignoredRealField + ignoredRealField + ignoredRealField +
209 ignoredRealField + ignoredRealField + ignoredRealField +
210 finalBlanks);
211 SECTION_2_DATA_OLD_FORMAT = Pattern.compile(monthNameField + ignoredIntegerField + mjdField +
212 storedRealField + storedRealField + storedRealField +
213 ignoredRealField +
214 storedRealField + storedRealField + storedRealField +
215 finalBlanks);
216 SECTION_1_DATA_NEW_FORMAT = Pattern.compile(storedIntegerField + storedIntegerField + storedIntegerField + mjdField +
217 storedRealField + storedRealField + storedRealField +
218 storedRealField + storedRealField + ignoredRealField + ignoredRealField +
219 ignoredRealField + ignoredRealField + ignoredRealField +
220 finalBlanks);
221 SECTION_3_DATA_NEW_FORMAT = Pattern.compile(ignoredIntegerField + ignoredIntegerField + ignoredIntegerField + mjdField +
222 storedRealField +
223 ignoredRealField + ignoredRealField + ignoredRealField +
224 finalBlanks);
225
226 }
227
228 /** Build a loader for IERS bulletins B files.
229 * @param supportedNames regular expression for supported files names
230 * @param manager provides access to the bulletin B files.
231 * @param utcSupplier UTC time scale.
232 */
233 BulletinBFilesLoader(final String supportedNames,
234 final DataProvidersManager manager,
235 final Supplier<TimeScale> utcSupplier) {
236 super(supportedNames, manager, utcSupplier);
237 }
238
239 /** {@inheritDoc} */
240 public void fillHistory(final IERSConventions.NutationCorrectionConverter converter,
241 final SortedSet<EOPEntry> history) {
242 final ItrfVersionProvider itrfVersionProvider = new ITRFVersionLoader(
243 ITRFVersionLoader.SUPPORTED_NAMES,
244 getDataProvidersManager());
245 final Parser parser = new Parser(converter, itrfVersionProvider, getUtc());
246 final EopParserLoader loader = new EopParserLoader(parser);
247 this.feed(loader);
248 history.addAll(loader.getEop());
249 }
250
251 /** Internal class performing the parsing. */
252 static class Parser extends AbstractEopParser {
253
254 /** ITRF version configuration. */
255 private ITRFVersionLoader.ITRFVersionConfiguration configuration;
256
257 /** History entries. */
258 private List<EOPEntry> history;
259
260 /** Map for fields read in different sections. */
261 private final Map<Integer, double[]> fieldsMap;
262
263 /** Current line number. */
264 private int lineNumber;
265
266 /** Current line. */
267 private String line;
268
269 /** Start of final data. */
270 private int mjdMin;
271
272 /** End of final data. */
273 private int mjdMax;
274
275 /**
276 * Simple constructor.
277 *
278 * @param converter converter to use
279 * @param itrfVersionProvider to use for determining the ITRF version of the EOP.
280 * @param utc time scale for parsing dates.
281 */
282 Parser(final NutationCorrectionConverter converter,
283 final ItrfVersionProvider itrfVersionProvider,
284 final TimeScale utc) {
285 super(converter, itrfVersionProvider, utc);
286 this.fieldsMap = new HashMap<>();
287 this.lineNumber = 0;
288 this.mjdMin = Integer.MAX_VALUE;
289 this.mjdMax = Integer.MIN_VALUE;
290 }
291
292 /** {@inheritDoc} */
293 @Override
294 public Collection<EOPEntry> parse(final InputStream input, final String name)
295 throws IOException {
296
297 // set up a reader for line-oriented bulletin B files
298 try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) {
299 // reset parse info to start new file
300 fieldsMap.clear();
301 lineNumber = 0;
302 mjdMin = Integer.MAX_VALUE;
303 mjdMax = Integer.MIN_VALUE;
304 history = new ArrayList<>();
305 configuration = null;
306
307 // skip header up to section 1 and check if we are parsing an old or new format file
308 final Matcher section1Matcher = seekToLine(SECTION_1_HEADER, reader, name);
309 final boolean isOldFormat = "EARTH".equals(section1Matcher.group(1));
310
311 if (isOldFormat) {
312
313 // extract MJD bounds for final data from section 1
314 loadMJDBoundsOldFormat(reader, name);
315
316 final Matcher section2Matcher = seekToLine(SECTION_2_HEADER_OLD, reader, name);
317 final boolean isNonRotatingOrigin = section2Matcher.group(1).startsWith("dX");
318 loadEOPOldFormat(isNonRotatingOrigin, reader, name);
319
320 } else {
321
322 // extract x, y, UT1-UTC, dx, dy from section 1
323 loadXYDTDxDyNewFormat(reader, name);
324
325 // skip to section 3
326 seekToLine(SECTION_3_HEADER, reader, name);
327
328 // extract LOD data from section 3
329 loadLODNewFormat(reader, name);
330
331 // set up the EOP entries
332 for (Map.Entry<Integer, double[]> entry : fieldsMap.entrySet()) {
333 final int mjd = entry.getKey();
334 final double[] array = entry.getValue();
335 if (Double.isNaN(array[0] + array[1] + array[2] + array[3] + array[4] + array[5])) {
336 throw notifyUnexpectedErrorEncountered(name);
337 }
338 final AbsoluteDate mjdDate =
339 new AbsoluteDate(new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, mjd),
340 getUtc());
341 final double[] equinox = getConverter().toEquinox(mjdDate, array[4], array[5]);
342 if (configuration == null || !configuration.isValid(mjd)) {
343 // get a configuration for current name and date range
344 configuration = getItrfVersionProvider().getConfiguration(name, mjd);
345 }
346 history.add(new EOPEntry(mjd, array[0], array[1], array[2], array[3],
347 Double.NaN, Double.NaN,
348 equinox[0], equinox[1], array[4], array[5],
349 configuration.getVersion(), mjdDate));
350 }
351
352 }
353 }
354
355 return history;
356
357 }
358
359 /** Read until a line matching a pattern is found.
360 * @param pattern pattern to look for
361 * @param reader reader from where file content is obtained
362 * @param name name of the file (or zip entry)
363 * @return the matching matcher for the line
364 * @exception IOException if data can't be read
365 */
366 private Matcher seekToLine(final Pattern pattern, final BufferedReader reader, final String name)
367 throws IOException {
368
369 for (line = reader.readLine(); line != null; line = reader.readLine()) {
370 ++lineNumber;
371 final Matcher matcher = pattern.matcher(line);
372 if (matcher.matches()) {
373 return matcher;
374 }
375 }
376
377 // we have reached end of file and not found a matching line
378 throw new OrekitException(OrekitMessages.UNEXPECTED_END_OF_FILE_AFTER_LINE,
379 name, lineNumber);
380
381 }
382
383 /** Read MJD bounds of the final data part from section 1 in the old bulletin B format.
384 * @param reader reader from where file content is obtained
385 * @param name name of the file (or zip entry)
386 * @exception IOException if data can't be read
387 */
388 private void loadMJDBoundsOldFormat(final BufferedReader reader, final String name)
389 throws IOException {
390
391 boolean inFinalValuesPart = false;
392 for (line = reader.readLine(); line != null; line = reader.readLine()) {
393 lineNumber++;
394 Matcher matcher = FINAL_VALUES_START.matcher(line);
395 if (matcher.matches()) {
396 // we are entering final values part (in section 1)
397 inFinalValuesPart = true;
398 } else if (inFinalValuesPart) {
399 matcher = SECTION_1_DATA_OLD_FORMAT.matcher(line);
400 if (matcher.matches()) {
401 // this is a data line, build an entry from the extracted fields
402 final int mjd = Integer.parseInt(matcher.group(1));
403 mjdMin = FastMath.min(mjdMin, mjd);
404 mjdMax = FastMath.max(mjdMax, mjd);
405 } else {
406 matcher = FINAL_VALUES_END.matcher(line);
407 if (matcher.matches()) {
408 // we leave final values part
409 return;
410 }
411 }
412 }
413 }
414
415 throw new OrekitException(OrekitMessages.UNEXPECTED_END_OF_FILE_AFTER_LINE,
416 name, lineNumber);
417
418 }
419
420 /** Read EOP data from section 2 in the old bulletin B format.
421 * @param isNonRotatingOrigin if true, the file contain Non-Rotating Origin nutation corrections
422 * @param reader reader from where file content is obtained
423 * @param name name of the file (or zip entry)
424 * @exception IOException if data can't be read
425 */
426 private void loadEOPOldFormat(final boolean isNonRotatingOrigin,
427 final BufferedReader reader, final String name)
428 throws IOException {
429
430 // read the data lines in the final values part inside section 2
431 line = reader.readLine();
432 while (line != null) {
433 lineNumber++;
434 final Matcher matcher = SECTION_2_DATA_OLD_FORMAT.matcher(line);
435 if (matcher.matches()) {
436 // this is a data line, build an entry from the extracted fields
437 final int mjd = Integer.parseInt(matcher.group(1));
438 final double x = Double.parseDouble(matcher.group(2)) * Constants.ARC_SECONDS_TO_RADIANS;
439 final double y = Double.parseDouble(matcher.group(3)) * Constants.ARC_SECONDS_TO_RADIANS;
440 final double dtu1 = Double.parseDouble(matcher.group(4));
441 final double lod = UnitsConverter.MILLI_SECONDS_TO_SECONDS.convert(Double.parseDouble(matcher.group(5)));
442 if (mjd >= mjdMin) {
443 final AbsoluteDate mjdDate =
444 new AbsoluteDate(new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, mjd),
445 getUtc());
446 final double[] equinox;
447 final double[] nro;
448 if (isNonRotatingOrigin) {
449 nro = new double[] {
450 UnitsConverter.MILLI_ARC_SECONDS_TO_RADIANS.convert(Double.parseDouble(matcher.group(6))),
451 UnitsConverter.MILLI_ARC_SECONDS_TO_RADIANS.convert(Double.parseDouble(matcher.group(7)))
452 };
453 equinox = getConverter().toEquinox(mjdDate, nro[0], nro[1]);
454 } else {
455 equinox = new double[] {
456 UnitsConverter.MILLI_ARC_SECONDS_TO_RADIANS.convert(Double.parseDouble(matcher.group(6))),
457 UnitsConverter.MILLI_ARC_SECONDS_TO_RADIANS.convert(Double.parseDouble(matcher.group(7)))
458 };
459 nro = getConverter().toNonRotating(mjdDate, equinox[0], equinox[1]);
460 }
461 if (configuration == null || !configuration.isValid(mjd)) {
462 // get a configuration for current name and date range
463 configuration = getItrfVersionProvider().getConfiguration(name, mjd);
464 }
465 history.add(new EOPEntry(mjd, dtu1, lod, x, y, Double.NaN, Double.NaN,
466 equinox[0], equinox[1], nro[0], nro[1],
467 configuration.getVersion(), mjdDate));
468 line = mjd < mjdMax ? reader.readLine() : null;
469 } else {
470 line = reader.readLine();
471 }
472 } else {
473 line = reader.readLine();
474 }
475 }
476
477 }
478
479 /** Read X, Y, UT1-UTC, dx, dy from section 1 in the new bulletin B format.
480 * @param reader reader from where file content is obtained
481 * @param name name of the file (or zip entry)
482 * @exception IOException if data can't be read
483 */
484 private void loadXYDTDxDyNewFormat(final BufferedReader reader, final String name)
485 throws IOException {
486
487 boolean inFinalValuesPart = false;
488 line = reader.readLine();
489 while (line != null) {
490 lineNumber++;
491 Matcher matcher = FINAL_VALUES_START.matcher(line);
492 if (matcher.matches()) {
493 // we are entering final values part (in section 1)
494 inFinalValuesPart = true;
495 line = reader.readLine();
496 } else if (inFinalValuesPart) {
497 matcher = SECTION_1_DATA_NEW_FORMAT.matcher(line);
498 if (matcher.matches()) {
499 // this is a data line, build an entry from the extracted fields
500 final int year = Integer.parseInt(matcher.group(1));
501 final int month = Integer.parseInt(matcher.group(2));
502 final int day = Integer.parseInt(matcher.group(3));
503 final int mjd = Integer.parseInt(matcher.group(4));
504 if (new DateComponents(year, month, day).getMJD() != mjd) {
505 throw new OrekitException(OrekitMessages.INCONSISTENT_DATES_IN_IERS_FILE,
506 name, year, month, day, mjd);
507 }
508 mjdMin = FastMath.min(mjdMin, mjd);
509 mjdMax = FastMath.max(mjdMax, mjd);
510 final double x = UnitsConverter.MILLI_ARC_SECONDS_TO_RADIANS.convert(Double.parseDouble(matcher.group(5)));
511 final double y = UnitsConverter.MILLI_ARC_SECONDS_TO_RADIANS.convert(Double.parseDouble(matcher.group(6)));
512 final double dtu1 = UnitsConverter.MILLI_SECONDS_TO_SECONDS.convert(Double.parseDouble(matcher.group(7)));
513 final double dx = UnitsConverter.MILLI_ARC_SECONDS_TO_RADIANS.convert(Double.parseDouble(matcher.group(8)));
514 final double dy = UnitsConverter.MILLI_ARC_SECONDS_TO_RADIANS.convert(Double.parseDouble(matcher.group(9)));
515 fieldsMap.put(mjd,
516 new double[] {
517 dtu1, Double.NaN, x, y, dx, dy
518 });
519 line = reader.readLine();
520 } else {
521 matcher = FINAL_VALUES_END.matcher(line);
522 line = matcher.matches() ? null : reader.readLine();
523 }
524 } else {
525 line = reader.readLine();
526 }
527 }
528 }
529
530 /** Read LOD from section 3 in the new bulletin B format.
531 * @param reader reader from where file content is obtained
532 * @param name name of the file (or zip entry)
533 * @exception IOException if data can't be read
534 */
535 private void loadLODNewFormat(final BufferedReader reader, final String name)
536 throws IOException {
537 line = reader.readLine();
538 while (line != null) {
539 lineNumber++;
540 final Matcher matcher = SECTION_3_DATA_NEW_FORMAT.matcher(line);
541 if (matcher.matches()) {
542 // this is a data line, build an entry from the extracted fields
543 final int mjd = Integer.parseInt(matcher.group(1));
544 if (mjd >= mjdMin) {
545 final double lod = UnitsConverter.MILLI_SECONDS_TO_SECONDS.convert(Double.parseDouble(matcher.group(2)));
546 final double[] array = fieldsMap.get(mjd);
547 if (array == null) {
548 throw notifyUnexpectedErrorEncountered(name);
549 }
550 array[1] = lod;
551 line = mjd >= mjdMax ? null : reader.readLine();
552 } else {
553 line = reader.readLine();
554 }
555 } else {
556 line = reader.readLine();
557 }
558 }
559 }
560
561 /** Create an exception to be thrown.
562 * @param name name of the file (or zip entry)
563 * @return OrekitException always thrown to notify an unexpected error has been
564 * encountered by the caller
565 */
566 private OrekitException notifyUnexpectedErrorEncountered(final String name) {
567 String loaderName = BulletinBFilesLoader.class.getName();
568 loaderName = loaderName.substring(loaderName.lastIndexOf('.') + 1);
569 return new OrekitException(OrekitMessages.UNEXPECTED_FILE_FORMAT_ERROR_FOR_LOADER,
570 name, loaderName);
571 }
572
573 }
574
575 }