1 /* Copyright 2002-2020 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.Arrays;
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.DataLoader;
36 import org.orekit.data.DataProvidersManager;
37 import org.orekit.errors.OrekitException;
38 import org.orekit.errors.OrekitInternalError;
39 import org.orekit.errors.OrekitMessages;
40 import org.orekit.time.AbsoluteDate;
41 import org.orekit.time.DateComponents;
42 import org.orekit.time.TimeScale;
43 import org.orekit.utils.Constants;
44 import org.orekit.utils.IERSConventions;
45
46 /** Loader for bulletin A files.
47 * <p>Bulletin A files contain {@link EOPEntry
48 * Earth Orientation Parameters} for a few days periods, they
49 * correspond to rapid data estimations, suitable for near-real time
50 * and prediction purposes. Prediction series are only available for
51 * pole motion xp, yp and UT1-UTC, they are not available for
52 * pole offsets (Δδψ/Δδε and x/y).</p>
53 * <p>A bulletin A published on Modified Julian Day mjd (nominally a
54 * Thursday) will generally contain:
55 * </p>
56 * <ul>
57 * <li>rapid service xp, yp and UT1-UTC data from mjd-6 to mjd</li>
58 * <li>prediction xp, yp and UT1-UTC data from mjd+1 to mjd+365</li>
59 * <li>if it is first bulletin of month m, final values xp, yp and
60 * UT1-UTC data from day 2 of month m-2 to day 1 of month m-1</li>
61 * <li>rapid service pole offsets Δδψ/Δδε and x/y if available, for some
62 * varying period somewhere from mjd-30 to mjd-10 (see below)</li>
63 * <li>if it is first bulletin of month m, final values pole offsets
64 * Δδψ/Δδε and x/y data from day 2 of month m-2 to day 1 of month
65 * m-1</li>
66 * </ul>
67 * <p>
68 * There are some discrepancies in the rapid service time range above,
69 * mainly when the nominal publication Thursday corresponds to holidays.
70 * In this case a bulletin may be published the day before and have a 6
71 * days span only for rapid data, and a later bulletin will have an 8 days
72 * span to recover the normal schedule. This occurred for bulletin A Vol.
73 * XVIII No. 047, bulletin A Vol. XVIII No. 048, bulletin A Vol. XXI No.
74 * 052 and bulletin A Vol. XXII No. 001.
75 * </p>
76 * <p>Rapid service for pole offsets appears irregular. As extreme examples
77 * bulletin A Vol. XXVI No. 037 from 2013-09-12 contained 15 entries
78 * for pole offsets, from mjd-22 to mjd-8, bulletin A Vol. XXVI No. 039
79 * from 2013-09-26 contained only 3 entries for pole offsets, from mjd-15
80 * to mjd-13, and bulletin A Vol. XXVI No. 040 from 2013-10-03 contained no
81 * rapid service pole offsets at all, it contained only final values. Despite
82 * this irregularity, rapid service data is continuous over consecutive files,
83 * so the mean number of entries is 7 as the files are published on a weekly
84 * basis.
85 * </p>
86 * <p>
87 * There are no prediction data for pole offsets.
88 * </p>
89 * <p>
90 * This loader reads both the rapid service, the prediction and the final
91 * values parts. As successive files have overlaps between all these sections,
92 * values extracted from latest files (with respect to the covered dates)
93 * override values extracted from earlier files, regardless of the files
94 * reading order. If numerous bulletins A covering more than one year are read,
95 * one particular date will typically appear in the prediction section of
96 * 52 or 53 files, then in the rapid data section of one file, then it will
97 * be missing in a few files, and will finally appear a last time in the
98 * final values sections of a last file. In this case, the value retained
99 * will be the one extracted from the final values section in the more
100 * recent file.
101 * </p>
102 * <p>
103 * If only one bulletin A file is read and it correspond to the first bulletin
104 * of a month, it will have a roughly one month wide hole between the
105 * final data and the rapid data. This hole will trigger an error as EOP
106 * continuity is checked by default for at most 5 days holes. In this case,
107 * users should call something like {@link Frames#setEOPContinuityThreshold(double)
108 * FramesFactory.setEOPContinuityThreshold(Constants.JULIAN_YEAR)} to prevent
109 * the error to be triggered.
110 * </p>
111 * <p>The bulletin A files are recognized thanks to their base names,
112 * which must match the pattern <code>bulletina-xxxx-###.txt</code>,
113 * (or the same ending with <code>.gz</code> for gzip-compressed files)
114 * where x stands for a roman numeral character and # stands for a digit
115 * character.</p>
116 * <p>
117 * This class is immutable and hence thread-safe
118 * </p>
119 * @author Luc Maisonobe
120 * @since 7.0
121 */
122 class BulletinAFilesLoader extends AbstractEopLoader implements EOPHistoryLoader {
123
124 /** Conversion factor. */
125 private static final double MILLI_ARC_SECONDS_TO_RADIANS = Constants.ARC_SECONDS_TO_RADIANS / 1000;
126
127 /** Regular expression matching blanks at start of line. */
128 private static final String LINE_START_REGEXP = "^\\p{Blank}+";
129
130 /** Regular expression matching blanks at end of line. */
131 private static final String LINE_END_REGEXP = "\\p{Blank}*$";
132
133 /** Regular expression matching integers. */
134 private static final String INTEGER_REGEXP = "[-+]?\\p{Digit}+";
135
136 /** Regular expression matching real numbers. */
137 private static final String REAL_REGEXP = "[-+]?(?:(?:\\p{Digit}+(?:\\.\\p{Digit}*)?)|(?:\\.\\p{Digit}+))(?:[eE][-+]?\\p{Digit}+)?";
138
139 /** Regular expression matching an integer field to store. */
140 private static final String STORED_INTEGER_FIELD = "\\p{Blank}*(" + INTEGER_REGEXP + ")";
141
142 /** regular expression matching a Modified Julian Day field to store. */
143 private static final String STORED_MJD_FIELD = "\\p{Blank}+(\\p{Digit}\\p{Digit}\\p{Digit}\\p{Digit}\\p{Digit})";
144
145 /** Regular expression matching a real field to store. */
146 private static final String STORED_REAL_FIELD = "\\p{Blank}+(" + REAL_REGEXP + ")";
147
148 /** Regular expression matching a real field to ignore. */
149 private static final String IGNORED_REAL_FIELD = "\\p{Blank}+" + REAL_REGEXP;
150
151 /** Enum for files sections, in expected order.
152 * <p>The bulletin A weekly data files contain several sections,
153 * each introduced with some fixed header text and followed by tabular data.
154 * </p>
155 */
156 private enum Section {
157
158 /** Earth Orientation Parameters rapid service. */
159 // section 2 always contain rapid service data including error fields
160 // COMBINED EARTH ORIENTATION PARAMETERS:
161 //
162 // IERS Rapid Service
163 // MJD x error y error UT1-UTC error
164 // " " " " s s
165 // 13 8 30 56534 0.16762 .00009 0.32705 .00009 0.038697 0.000019
166 // 13 8 31 56535 0.16669 .00010 0.32564 .00010 0.038471 0.000019
167 // 13 9 1 56536 0.16592 .00009 0.32410 .00010 0.038206 0.000024
168 // 13 9 2 56537 0.16557 .00009 0.32270 .00009 0.037834 0.000024
169 // 13 9 3 56538 0.16532 .00009 0.32147 .00010 0.037351 0.000024
170 // 13 9 4 56539 0.16488 .00009 0.32044 .00010 0.036756 0.000023
171 // 13 9 5 56540 0.16435 .00009 0.31948 .00009 0.036036 0.000024
172 EOP_RAPID_SERVICE("^ *COMBINED EARTH ORIENTATION PARAMETERS: *$",
173 LINE_START_REGEXP +
174 STORED_INTEGER_FIELD + STORED_INTEGER_FIELD + STORED_INTEGER_FIELD +
175 STORED_MJD_FIELD +
176 STORED_REAL_FIELD + IGNORED_REAL_FIELD +
177 STORED_REAL_FIELD + IGNORED_REAL_FIELD +
178 STORED_REAL_FIELD + IGNORED_REAL_FIELD +
179 LINE_END_REGEXP),
180
181 /** Earth Orientation Parameters final values. */
182 // the first bulletin A of each month also includes final values for the
183 // period covering from day 2 of month m-2 to day 1 of month m-1.
184 // IERS Final Values
185 // MJD x y UT1-UTC
186 // " " s
187 // 13 7 2 56475 0.1441 0.3901 0.05717
188 // 13 7 3 56476 0.1457 0.3895 0.05716
189 // 13 7 4 56477 0.1467 0.3887 0.05728
190 // 13 7 5 56478 0.1477 0.3875 0.05755
191 // 13 7 6 56479 0.1490 0.3862 0.05793
192 // 13 7 7 56480 0.1504 0.3849 0.05832
193 // 13 7 8 56481 0.1516 0.3835 0.05858
194 // 13 7 9 56482 0.1530 0.3822 0.05877
195 EOP_FINAL_VALUES("^ *IERS Final Values *$",
196 LINE_START_REGEXP +
197 STORED_INTEGER_FIELD + STORED_INTEGER_FIELD + STORED_INTEGER_FIELD +
198 STORED_MJD_FIELD +
199 STORED_REAL_FIELD +
200 STORED_REAL_FIELD +
201 STORED_REAL_FIELD +
202 LINE_END_REGEXP),
203
204 /** Earth Orientation Parameters prediction. */
205 // section 3 always contain prediction data without error fields
206 //
207 // PREDICTIONS:
208 // The following formulas will not reproduce the predictions given below,
209 // but may be used to extend the predictions beyond the end of this table.
210 //
211 // x = 0.0969 + 0.1110 cos A - 0.0103 sin A - 0.0435 cos C - 0.0171 sin C
212 // y = 0.3457 - 0.0061 cos A - 0.1001 sin A - 0.0171 cos C + 0.0435 sin C
213 // UT1-UTC = -0.0052 - 0.00104 (MJD - 56548) - (UT2-UT1)
214 //
215 // where A = 2*pi*(MJD-56540)/365.25 and C = 2*pi*(MJD-56540)/435.
216 //
217 // TAI-UTC(MJD 56541) = 35.0
218 // The accuracy may be estimated from the expressions:
219 // S x,y = 0.00068 (MJD-56540)**0.80 S t = 0.00025 (MJD-56540)**0.75
220 // Estimated accuracies are: Predictions 10 d 20 d 30 d 40 d
221 // Polar coord's 0.004 0.007 0.010 0.013
222 // UT1-UTC 0.0014 0.0024 0.0032 0.0040
223 //
224 // MJD x(arcsec) y(arcsec) UT1-UTC(sec)
225 // 2013 9 6 56541 0.1638 0.3185 0.03517
226 // 2013 9 7 56542 0.1633 0.3175 0.03420
227 // 2013 9 8 56543 0.1628 0.3164 0.03322
228 // 2013 9 9 56544 0.1623 0.3153 0.03229
229 // 2013 9 10 56545 0.1618 0.3142 0.03144
230 // 2013 9 11 56546 0.1612 0.3131 0.03071
231 // 2013 9 12 56547 0.1607 0.3119 0.03008
232 EOP_PREDICTION("^ *PREDICTIONS: *$",
233 LINE_START_REGEXP +
234 STORED_INTEGER_FIELD + STORED_INTEGER_FIELD + STORED_INTEGER_FIELD +
235 STORED_MJD_FIELD +
236 STORED_REAL_FIELD +
237 STORED_REAL_FIELD +
238 STORED_REAL_FIELD +
239 LINE_END_REGEXP),
240
241 /** Pole offsets, IAU-1980. */
242 // section 4 may contain rapid service pole offset series including error fields
243 // CELESTIAL POLE OFFSET SERIES:
244 // NEOS Celestial Pole Offset Series
245 // MJD dpsi error deps error
246 // (msec. of arc)
247 // 56519 -87.47 0.13 -12.96 0.08
248 // 56520 -87.72 0.13 -13.20 0.08
249 // 56521 -87.79 0.19 -13.56 0.11
250 POLE_OFFSETS_IAU_1980_RAPID_SERVICE("^ *NEOS Celestial Pole Offset Series *$",
251 LINE_START_REGEXP +
252 STORED_MJD_FIELD +
253 STORED_REAL_FIELD + IGNORED_REAL_FIELD +
254 STORED_REAL_FIELD + IGNORED_REAL_FIELD +
255 LINE_END_REGEXP),
256
257 /** Pole offsets, IAU-1980 final values. */
258 // the format for the IAU-2000 series is similar, but the meanings of the fields
259 // are different
260 // IAU2000A Celestial Pole Offset Series
261 // MJD dX error dY error
262 // (msec. of arc)
263 // 56519 -0.246 0.052 -0.223 0.080
264 // 56520 -0.239 0.052 -0.248 0.080
265 // 56521 -0.224 0.076 -0.277 0.110
266 POLE_OFFSETS_IAU_1980_FINAL_VALUES("^ *IERS Celestial Pole Offset Final Series *$",
267 LINE_START_REGEXP +
268 STORED_MJD_FIELD +
269 STORED_REAL_FIELD +
270 STORED_REAL_FIELD +
271 LINE_END_REGEXP),
272
273 /** Pole offsets, IAU-2000. */
274 // the first bulletin A of each month also includes final values for the
275 // period covering from day 2 of month m-2 to day 1 of month m-1.
276 // IERS Celestial Pole Offset Final Series
277 // MJD dpsi deps
278 // (msec. of arc)
279 // 56475 -81.0 -13.3
280 // 56476 -81.2 -13.4
281 // 56477 -81.6 -13.4
282 // 56478 -82.2 -13.5
283 // 56479 -82.5 -13.6
284 // 56480 -82.5 -13.7
285 POLE_OFFSETS_IAU_2000_RAPID_SERVICE("^ *IAU2000A Celestial Pole Offset Series *$",
286 LINE_START_REGEXP +
287 STORED_MJD_FIELD +
288 STORED_REAL_FIELD + IGNORED_REAL_FIELD +
289 STORED_REAL_FIELD + IGNORED_REAL_FIELD +
290 LINE_END_REGEXP),
291
292 /** Pole offsets, IAU-2000 final values. */
293 // the format for the IAU-2000 series is similar, but the meanings of the fields
294 // are different
295 // IAU2000A Celestial Pole Offset Final Series
296 // MJD dX dY
297 // (msec. of arc)
298 // 56475 0.00 -0.28
299 // 56476 -0.06 -0.29
300 // 56477 -0.07 -0.27
301 // 56478 -0.12 -0.33
302 // 56479 -0.12 -0.33
303 // 56480 -0.13 -0.36
304 POLE_OFFSETS_IAU_2000_FINAL_VALUES("^ *IAU2000A Celestial Pole Offset Final Series *$",
305 LINE_START_REGEXP +
306 STORED_MJD_FIELD +
307 STORED_REAL_FIELD +
308 STORED_REAL_FIELD +
309 LINE_END_REGEXP);
310
311 /** Header pattern. */
312 private final Pattern header;
313
314 /** Data pattern. */
315 private final Pattern data;
316
317 /** Simple constructor.
318 * @param headerRegExp regular expression for header
319 * @param dataRegExp regular expression for data
320 */
321 Section(final String headerRegExp, final String dataRegExp) {
322 this.header = Pattern.compile(headerRegExp);
323 this.data = Pattern.compile(dataRegExp);
324 }
325
326 /** Check if a line matches the section header.
327 * @param line line to check
328 * @return true if the line matches the header
329 */
330 public boolean matchesHeader(final String line) {
331 return header.matcher(line).matches();
332 }
333
334 /** Get the data fields from a line.
335 * @param line line to parse
336 * @return extracted fields, or null if line does not match data format
337 */
338 public String[] getFields(final String line) {
339 final Matcher matcher = data.matcher(line);
340 if (matcher.matches()) {
341 final String[] fields = new String[matcher.groupCount()];
342 for (int i = 0; i < fields.length; ++i) {
343 fields[i] = matcher.group(i + 1);
344 }
345 return fields;
346 } else {
347 return null;
348 }
349 }
350
351 }
352
353 /** Build a loader for IERS bulletins A files.
354 * @param supportedNames regular expression for supported files names
355 * @param manager provides access to the bulletin A files.
356 * @param utcSupplier UTC time scale.
357 */
358 BulletinAFilesLoader(final String supportedNames,
359 final DataProvidersManager manager,
360 final Supplier<TimeScale> utcSupplier) {
361 super(supportedNames, manager, utcSupplier);
362 }
363
364 /** {@inheritDoc} */
365 public void fillHistory(final IERSConventions.NutationCorrectionConverter converter,
366 final SortedSet<EOPEntry> history) {
367 final Parser parser = new Parser();
368 this.feed(parser);
369 parser.fill(history);
370 }
371
372 /** Internal class performing the parsing. */
373 private class Parser implements DataLoader {
374
375 /** Map for xp, yp, dut1 fields read in different sections. */
376 private final Map<Integer, double[]> eopFieldsMap;
377
378 /** Map for pole offsets fields read in different sections. */
379 private final Map<Integer, double[]> poleOffsetsFieldsMap;
380
381 /** Configuration for ITRF versions. */
382 private final ItrfVersionProvider itrfVersionProvider;
383
384 /** ITRF version configuration. */
385 private ITRFVersionLoader.ITRFVersionConfiguration configuration;
386
387 /** File name. */
388 private String fileName;
389
390 /** Current line number. */
391 private int lineNumber;
392
393 /** Current line. */
394 private String line;
395
396 /** Earliest parsed data. */
397 private int mjdMin;
398
399 /** Latest parsed data. */
400 private int mjdMax;
401
402 /** First MJD parsed in current file. */
403 private int firstMJD;
404
405 /** Simple constructor.
406 */
407 Parser() {
408 this.eopFieldsMap = new HashMap<>();
409 this.poleOffsetsFieldsMap = new HashMap<>();
410 this.itrfVersionProvider = new ITRFVersionLoader(
411 ITRFVersionLoader.SUPPORTED_NAMES,
412 getDataProvidersManager());
413 this.lineNumber = 0;
414 this.mjdMin = Integer.MAX_VALUE;
415 this.mjdMax = Integer.MIN_VALUE;
416 this.firstMJD = -1;
417 }
418
419 /** {@inheritDoc} */
420 public boolean stillAcceptsData() {
421 return true;
422 }
423
424 /** {@inheritDoc} */
425 public void loadData(final InputStream input, final String name)
426 throws IOException {
427
428 this.configuration = null;
429 this.fileName = name;
430
431 // set up a reader for line-oriented bulletin A files
432 try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) {
433 lineNumber = 0;
434 firstMJD = -1;
435
436 // loop over sections
437 final List<Section> remaining = new ArrayList<>(Arrays.asList(Section.values()));
438 for (Section section = nextSection(remaining, reader);
439 section != null;
440 section = nextSection(remaining, reader)) {
441
442 switch (section) {
443 case EOP_RAPID_SERVICE :
444 case EOP_FINAL_VALUES :
445 case EOP_PREDICTION :
446 loadXYDT(section, reader, name);
447 break;
448 case POLE_OFFSETS_IAU_1980_RAPID_SERVICE :
449 case POLE_OFFSETS_IAU_1980_FINAL_VALUES :
450 loadPoleOffsets(section, false, reader, name);
451 break;
452 case POLE_OFFSETS_IAU_2000_RAPID_SERVICE :
453 case POLE_OFFSETS_IAU_2000_FINAL_VALUES :
454 loadPoleOffsets(section, true, reader, name);
455 break;
456 default :
457 // this should never happen
458 throw new OrekitInternalError(null);
459 }
460
461 // remove the already parsed section from the list
462 remaining.remove(section);
463
464 }
465
466 // check that the mandatory sections have been parsed
467 if (remaining.contains(Section.EOP_RAPID_SERVICE) ||
468 remaining.contains(Section.EOP_PREDICTION) ||
469 (remaining.contains(Section.POLE_OFFSETS_IAU_1980_RAPID_SERVICE) ^
470 remaining.contains(Section.POLE_OFFSETS_IAU_2000_RAPID_SERVICE)) ||
471 (remaining.contains(Section.POLE_OFFSETS_IAU_1980_FINAL_VALUES) ^
472 remaining.contains(Section.POLE_OFFSETS_IAU_2000_FINAL_VALUES))) {
473 throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_IERS_DATA_FILE, name);
474 }
475
476 }
477 }
478
479 /** Fill EOP history obtained after reading several files.
480 * @param history history to fill up
481 */
482 public void fill(final SortedSet<EOPEntry> history) {
483
484 double[] currentEOP = null;
485 double[] nextEOP = eopFieldsMap.get(mjdMin);
486 for (int mjd = mjdMin; mjd <= mjdMax; ++mjd) {
487
488 final AbsoluteDate mjdDate = AbsoluteDate.createMJDDate(mjd, 0, getUtc());
489 final double[] currentPole = poleOffsetsFieldsMap.get(mjd);
490
491 final double[] previousEOP = currentEOP;
492 currentEOP = nextEOP;
493 nextEOP = eopFieldsMap.get(mjd + 1);
494
495 if (currentEOP == null) {
496 if (currentPole != null) {
497 // we have only pole offsets for this date
498 if (configuration == null || !configuration.isValid(mjd)) {
499 // get a configuration for current name and date range
500 configuration = itrfVersionProvider.getConfiguration(fileName, mjd);
501 }
502 history.add(new EOPEntry(mjd,
503 0.0, 0.0, 0.0, 0.0,
504 currentPole[1] * MILLI_ARC_SECONDS_TO_RADIANS,
505 currentPole[2] * MILLI_ARC_SECONDS_TO_RADIANS,
506 currentPole[3] * MILLI_ARC_SECONDS_TO_RADIANS,
507 currentPole[4] * MILLI_ARC_SECONDS_TO_RADIANS,
508 configuration.getVersion(),
509 mjdDate));
510 }
511 } else {
512
513 // compute LOD as the opposite of the time derivative of UT1-UTC
514 final double lod;
515 if (previousEOP == null) {
516 if (nextEOP == null) {
517 // isolated point
518 lod = 0;
519 } else {
520 // first entry, we use a forward difference
521 lod = currentEOP[3] - nextEOP[3];
522 }
523 } else {
524 if (nextEOP == null) {
525 // last entry, we use a backward difference
526 lod = previousEOP[3] - currentEOP[3];
527 } else {
528 // regular entry, we use a centered difference
529 lod = 0.5 * (previousEOP[3] - nextEOP[3]);
530 }
531 }
532
533 if (configuration == null || !configuration.isValid(mjd)) {
534 // get a configuration for current name and date range
535 configuration = itrfVersionProvider.getConfiguration(fileName, mjd);
536 }
537 if (currentPole == null) {
538 // we have only EOP for this date
539 history.add(new EOPEntry(mjd,
540 currentEOP[3], lod,
541 currentEOP[1] * Constants.ARC_SECONDS_TO_RADIANS,
542 currentEOP[2] * Constants.ARC_SECONDS_TO_RADIANS,
543 0.0, 0.0, 0.0, 0.0,
544 configuration.getVersion(),
545 mjdDate));
546 } else {
547 // we have complete data
548 history.add(new EOPEntry(mjd,
549 currentEOP[3], lod,
550 currentEOP[1] * Constants.ARC_SECONDS_TO_RADIANS,
551 currentEOP[2] * Constants.ARC_SECONDS_TO_RADIANS,
552 currentPole[1] * MILLI_ARC_SECONDS_TO_RADIANS,
553 currentPole[2] * MILLI_ARC_SECONDS_TO_RADIANS,
554 currentPole[3] * MILLI_ARC_SECONDS_TO_RADIANS,
555 currentPole[4] * MILLI_ARC_SECONDS_TO_RADIANS,
556 configuration.getVersion(),
557 mjdDate));
558 }
559 }
560
561 }
562
563 }
564
565 /** Skip to next section header.
566 * @param sections sections to check for
567 * @param reader reader from where file content is obtained
568 * @return the next section or null if no section is found until end of file
569 * @exception IOException if data can't be read
570 */
571 private Section nextSection(final List<Section> sections,
572 final BufferedReader reader)
573 throws IOException {
574
575 for (line = reader.readLine(); line != null; line = reader.readLine()) {
576 ++lineNumber;
577 for (Section section : sections) {
578 if (section.matchesHeader(line)) {
579 return section;
580 }
581 }
582 }
583
584 // we have reached end of file and not found a matching section header
585 return null;
586
587 }
588
589 /** Read X, Y, UT1-UTC.
590 * @param section section to parse
591 * @param reader reader from where file content is obtained
592 * @param name name of the file (or zip entry)
593 * @exception IOException if data can't be read
594 */
595 private void loadXYDT(final Section section, final BufferedReader reader, final String name)
596 throws IOException {
597
598 boolean inValuesPart = false;
599 for (line = reader.readLine(); line != null; line = reader.readLine()) {
600 lineNumber++;
601 final String[] fields = section.getFields(line);
602 if (fields != null) {
603
604 // we are within the values part
605 inValuesPart = true;
606
607 // this is a data line, build an entry from the extracted fields
608 final int year = Integer.parseInt(fields[0]);
609 final int month = Integer.parseInt(fields[1]);
610 final int day = Integer.parseInt(fields[2]);
611 final int mjd = Integer.parseInt(fields[3]);
612 final DateComponents#DateComponents">DateComponents dc = new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, mjd);
613 if ((dc.getYear() % 100) != (year % 100) ||
614 dc.getMonth() != month ||
615 dc.getDay() != day) {
616 throw new OrekitException(OrekitMessages.INCONSISTENT_DATES_IN_IERS_FILE,
617 name, year, month, day, mjd);
618 }
619 mjdMin = FastMath.min(mjdMin, mjd);
620 mjdMax = FastMath.max(mjdMax, mjd);
621 if (firstMJD < 0) {
622 // store the first mjd parsed
623 firstMJD = mjd;
624 }
625
626 // get the entry at the same date if it was already parsed
627 final double[] eop;
628 if (eopFieldsMap.containsKey(mjd)) {
629 eop = eopFieldsMap.get(mjd);
630 } else {
631 eop = new double[4];
632 eopFieldsMap.put(mjd, eop);
633 }
634
635 if (eop[0] <= firstMJD) {
636 // either it is the first time we parse this date (eop[0] = 0),
637 // or the new parsed data is from a more recent file
638 // in both case, we should update the array
639 eop[0] = firstMJD;
640 eop[1] = Double.parseDouble(fields[4]);
641 eop[2] = Double.parseDouble(fields[5]);
642 eop[3] = Double.parseDouble(fields[6]);
643 }
644
645 } else if (inValuesPart) {
646 // we leave values part
647 return;
648 }
649 }
650
651 throw new OrekitException(OrekitMessages.UNEXPECTED_END_OF_FILE_AFTER_LINE,
652 name, lineNumber);
653
654 }
655
656 /** Read EOP data.
657 * @param section section to parse
658 * @param isNonRotatingOrigin if true, the file contain Non-Rotating Origin nutation corrections
659 * @param reader reader from where file content is obtained
660 * @param name name of the file (or zip entry)
661 * @exception IOException if data can't be read
662 */
663 private void loadPoleOffsets(final Section section, final boolean isNonRotatingOrigin,
664 final BufferedReader reader, final String name)
665 throws IOException {
666
667 boolean inValuesPart = false;
668 for (line = reader.readLine(); line != null; line = reader.readLine()) {
669 lineNumber++;
670 final String[] fields = section.getFields(line);
671 if (fields != null) {
672
673 // we are within the values part
674 inValuesPart = true;
675
676 // this is a data line, build an entry from the extracted fields
677 final int mjd = Integer.parseInt(fields[0]);
678 mjdMin = FastMath.min(mjdMin, mjd);
679 mjdMax = FastMath.max(mjdMax, mjd);
680
681 // get the entry at the same date if it was already parsed
682 final double[] pole;
683 if (poleOffsetsFieldsMap.containsKey(mjd)) {
684 pole = poleOffsetsFieldsMap.get(mjd);
685 } else {
686 pole = new double[5];
687 poleOffsetsFieldsMap.put(mjd, pole);
688 }
689
690 if (pole[0] <= firstMJD) {
691 // either it is the first time we parse this date (pole[0] = 0),
692 // or the new parsed data is from a more recent file
693 // in both case, we should update the array
694 pole[0] = firstMJD;
695 if (isNonRotatingOrigin) {
696 pole[1] = Double.parseDouble(fields[1]);
697 pole[2] = Double.parseDouble(fields[2]);
698 } else {
699 pole[3] = Double.parseDouble(fields[1]);
700 pole[4] = Double.parseDouble(fields[2]);
701 }
702 }
703
704 } else if (inValuesPart) {
705 // we leave values part
706 return;
707 }
708 }
709
710 throw new OrekitException(OrekitMessages.UNEXPECTED_END_OF_FILE_AFTER_LINE,
711 name, lineNumber);
712
713 }
714
715 }
716
717 }