BulletinBFilesLoader.java

  1. /* Copyright 2002-2017 CS Systèmes d'Information
  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.frames;

  18. import java.io.BufferedReader;
  19. import java.io.IOException;
  20. import java.io.InputStream;
  21. import java.io.InputStreamReader;
  22. import java.util.ArrayList;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. import java.util.SortedSet;
  27. import java.util.regex.Matcher;
  28. import java.util.regex.Pattern;

  29. import org.hipparchus.util.FastMath;
  30. import org.orekit.data.DataLoader;
  31. import org.orekit.data.DataProvidersManager;
  32. import org.orekit.errors.OrekitException;
  33. import org.orekit.errors.OrekitMessages;
  34. import org.orekit.time.AbsoluteDate;
  35. import org.orekit.time.DateComponents;
  36. import org.orekit.time.Month;
  37. import org.orekit.time.TimeScalesFactory;
  38. import org.orekit.utils.Constants;
  39. import org.orekit.utils.IERSConventions;

  40. /** Loader for bulletin B files.
  41.  * <p>Bulletin B files contain {@link EOPEntry
  42.  * Earth Orientation Parameters} for a few months periods.
  43.  * They correspond fo tinalized data, suitable for long term
  44.  * a posteriori analysis.</p>
  45.  * <p>The bulletin B files are recognized thanks to their base names,
  46.  * which must match one of the patterns <code>bulletinb_IAU2000-###.txt</code>,
  47.  * <code>bulletinb_IAU2000.###</code>, <code>bulletinb-###.txt</code> or
  48.  * <code>bulletinb.###</code> (or the same ending with <code>.gz</code>
  49.  * for gzip-compressed files) where # stands for a digit character.</p>
  50.  * <p>
  51.  * Starting with bulletin B 252 published in February 2009, buletins B are
  52.  * written in a format containing nutation corrections for both the
  53.  * new IAU2000 nutation model as dx, dy entries in its section 1 and nutation
  54.  * corrections for the old IAU1976 nutation model as dPsi, dEpsilon entries in
  55.  * its sections 2. These bulletins are available from IERS <a
  56.  * href="ftp://ftp.iers.org/products/eop/bulletinb/format_2009/">
  57.  *  FTP site</a>. They are also available with exactly the same content
  58.  * (but a different naming convention) from <a
  59.  * href="http://hpiers.obspm.fr/eoppc/bul/bulb_new/">Paris-Meudon
  60.  * observatory site</a>.
  61.  * </p>
  62.  * <p>
  63.  * Ending with bulletin B 263 published in January 2010, bulletins B were
  64.  * written in a format containing only one type of nutation corrections in its
  65.  * section 1, either for new IAU2000 nutation model as dx, dy entries or the old
  66.  * IAU1976 nutation model as dPsi, dEpsilon entries, depending on the file (a pair of
  67.  * files with different name was published each month between March 2003 and January 2010).
  68.  * </p>
  69.  * <p>
  70.  * This class handles both the old and the new format.
  71.  * </p>
  72.  * <p>
  73.  * This class is immutable and hence thread-safe
  74.  * </p>
  75.  * @author Luc Maisonobe
  76.  */
  77. class BulletinBFilesLoader implements EOPHistoryLoader {

  78.     /** Conversion factor. */
  79.     private static final double MILLI_ARC_SECONDS_TO_RADIANS = Constants.ARC_SECONDS_TO_RADIANS / 1000;

  80.     /** Conversion factor. */
  81.     private static final double MILLI_SECONDS_TO_SECONDS = 1.e-3;

  82.     /** Section 1 header pattern. */
  83.     private static final Pattern SECTION_1_HEADER;

  84.     /** Section 2 header pattern for old format. */
  85.     private static final Pattern SECTION_2_HEADER_OLD;

  86.     /** Section 3 header pattern. */
  87.     private static final Pattern SECTION_3_HEADER;

  88.     /** Pattern for line introducing the final bulletin B values. */
  89.     private static final Pattern FINAL_VALUES_START;

  90.     /** Pattern for line introducing the bulletin B preliminary extension. */
  91.     private static final Pattern FINAL_VALUES_END;

  92.     /** Data line pattern in section 1 (old format). */
  93.     private static final Pattern SECTION_1_DATA_OLD_FORMAT;

  94.     /** Data line pattern in section 2. */
  95.     private static final Pattern SECTION_2_DATA_OLD_FORMAT;

  96.     /** Data line pattern in section 1 (new format). */
  97.     private static final Pattern SECTION_1_DATA_NEW_FORMAT;

  98.     /** Data line pattern in section 3 (new format). */
  99.     private static final Pattern SECTION_3_DATA_NEW_FORMAT;

  100.     static {

  101.         // the section headers lines in the old bulletin B monthly data files have
  102.         // the following form (the indentation discrepancy for section 6 is really
  103.         // present in the available files):
  104.         // 1 - EARTH ORIENTATION PARAMETERS (IERS evaluation).
  105.         // either
  106.         // 2 - SMOOTHED VALUES OF x, y, UT1, D, DPSI, DEPSILON (IERS EVALUATION)
  107.         // or
  108.         // 2 - SMOOTHED VALUES OF x, y, UT1, D, dX, dY (IERS EVALUATION)
  109.         // 3 - NORMAL VALUES OF THE EARTH ORIENTATION PARAMETERS AT FIVE-DAY INTERVALS
  110.         // 4 - DURATION OF THE DAY AND ANGULAR VELOCITY OF THE EARTH (IERS evaluation).
  111.         // 5 - INFORMATION ON TIME SCALES
  112.         //       6 - SUMMARY OF CONTRIBUTED EARTH ORIENTATION PARAMETERS SERIES
  113.         //
  114.         // the section headers lines in the new bulletin B monthly data files have
  115.         // the following form:
  116.         // 1 - DAILY FINAL VALUES OF  x, y, UT1-UTC, dX, dY
  117.         // 2 - DAILY FINAL VALUES OF CELESTIAL POLE OFFSETS dPsi1980 & dEps1980
  118.         // 3 - EARTH ANGULAR VELOCITY : DAILY FINAL VALUES OF LOD, OMEGA AT 0hUTC
  119.         // 4 - INFORMATION ON TIME SCALES
  120.         // 5 - SUMMARY OF CONTRIBUTED EARTH ORIENTATION PARAMETERS SERIES
  121.         SECTION_1_HEADER     = Pattern.compile("^ +1 - (\\p{Upper}+) \\p{Upper}+ \\p{Upper}+.*");
  122.         SECTION_2_HEADER_OLD = Pattern.compile("^ +2 - SMOOTHED \\p{Upper}+ \\p{Upper}+.*((?:DPSI, DEPSILON)|(?:dX, dY)).*");
  123.         SECTION_3_HEADER     = Pattern.compile("^ +3 - \\p{Upper}+ \\p{Upper}+ \\p{Upper}+.*");

  124.         // the markers bracketing the final values in section 1 in the old bulletin B
  125.         // monthly data files have the following form:
  126.         //
  127.         //  Final Bulletin B values.
  128.         //   ...
  129.         //  Preliminary extension, to be updated weekly in Bulletin A and monthly
  130.         //  in Bulletin B.
  131.         //
  132.         // the markers bracketing the final values in section 1 in the new bulletin B
  133.         // monthly data files have the following form:
  134.         //
  135.         //  Final values
  136.         //   ...
  137.         //  Preliminary extension
  138.         //
  139.         FINAL_VALUES_START = Pattern.compile("^\\p{Blank}+Final( Bulletin B)? values.*");
  140.         FINAL_VALUES_END   = Pattern.compile("^\\p{Blank}+Preliminary extension.*");

  141.         // the data lines in the old bulletin B monthly data files have the following form:
  142.         // in section 1:
  143.         // AUG   1  55044  0.22176 0.49302  0.231416  -33.768584   -69.1    -8.9
  144.         // AUG   6  55049  0.23202 0.48003  0.230263  -33.769737   -69.5    -8.5
  145.         // in section 2:
  146.         // AUG   1   55044  0.22176  0.49302  0.230581 -0.835  -0.310  -69.1   -8.9
  147.         // AUG   2   55045  0.22395  0.49041  0.230928 -0.296  -0.328  -69.5   -8.9
  148.         //
  149.         // the data lines in the new bulletin B monthly data files have the following form:
  150.         // in section 1:
  151.         // 2009   8   2   55045  223.954  490.410  230.9277    0.214 -0.056    0.008    0.009    0.0641  0.048  0.121
  152.         // 2009   8   3   55046  225.925  487.700  231.2186    0.300 -0.138    0.010    0.012    0.0466  0.099  0.248
  153.         // 2009   8   4   55047  227.931  485.078  231.3929    0.347 -0.231    0.019    0.023    0.0360  0.099  0.249
  154.         // 2009   8   5   55048  230.016  482.445  231.4601    0.321 -0.291    0.025    0.028    0.0441  0.095  0.240
  155.         // 2009   8   6   55049  232.017  480.026  231.3619    0.267 -0.273    0.025    0.029    0.0477  0.038  0.095
  156.         // in section 2:
  157.         // 2009   8   2   55045   -69.474    -8.929     0.199     0.121
  158.         // 2009   8   3   55046   -69.459    -9.016     0.250     0.248
  159.         // 2009   8   4   55047   -69.401    -9.039     0.250     0.249
  160.         // 2009   8   5   55048   -69.425    -8.864     0.247     0.240
  161.         // 2009   8   6   55049   -69.510    -8.539     0.153     0.095
  162.         // in section 3:
  163.         // 2009   8   2   55045 -0.3284  0.0013  15.04106723584    0.00000000023
  164.         // 2009   8   3   55046 -0.2438  0.0013  15.04106722111    0.00000000023
  165.         // 2009   8   4   55047 -0.1233  0.0013  15.04106720014    0.00000000023
  166.         // 2009   8   5   55048  0.0119  0.0013  15.04106717660    0.00000000023
  167.         // 2009   8   6   55049  0.1914  0.0013  15.04106714535    0.00000000023
  168.         final StringBuilder builder = new StringBuilder("^\\p{Blank}+(?:");
  169.         for (final Month month : Month.values()) {
  170.             builder.append(month.getUpperCaseAbbreviation());
  171.             builder.append('|');
  172.         }
  173.         builder.delete(builder.length() - 1, builder.length());
  174.         builder.append(")");
  175.         final String integerPattern      = "[-+]?\\p{Digit}+";
  176.         final String realPattern         = "[-+]?(?:(?:\\p{Digit}+(?:\\.\\p{Digit}*)?)|(?:\\.\\p{Digit}+))(?:[eE][-+]?\\p{Digit}+)?";
  177.         final String monthNameField      = builder.toString();
  178.         final String ignoredIntegerField = "\\p{Blank}*" + integerPattern;
  179.         final String storedIntegerField  = "\\p{Blank}*(" + integerPattern + ")";
  180.         final String mjdField            = "\\p{Blank}+(\\p{Digit}\\p{Digit}\\p{Digit}\\p{Digit}\\p{Digit})";
  181.         final String storedRealField     = "\\p{Blank}+(" + realPattern + ")";
  182.         final String ignoredRealField    = "\\p{Blank}+" + realPattern;
  183.         final String finalBlanks         = "\\p{Blank}*$";
  184.         SECTION_1_DATA_OLD_FORMAT = Pattern.compile(monthNameField + ignoredIntegerField + mjdField +
  185.                                                     ignoredRealField + ignoredRealField + ignoredRealField +
  186.                                                     ignoredRealField + ignoredRealField + ignoredRealField +
  187.                                                     finalBlanks);
  188.         SECTION_2_DATA_OLD_FORMAT = Pattern.compile(monthNameField + ignoredIntegerField + mjdField +
  189.                                                     storedRealField  + storedRealField  + storedRealField +
  190.                                                     ignoredRealField +
  191.                                                     storedRealField + storedRealField + storedRealField +
  192.                                                     finalBlanks);
  193.         SECTION_1_DATA_NEW_FORMAT = Pattern.compile(storedIntegerField + storedIntegerField + storedIntegerField + mjdField +
  194.                                                     storedRealField + storedRealField + storedRealField +
  195.                                                     storedRealField + storedRealField + ignoredRealField + ignoredRealField +
  196.                                                     ignoredRealField + ignoredRealField + ignoredRealField +
  197.                                                     finalBlanks);
  198.         SECTION_3_DATA_NEW_FORMAT = Pattern.compile(ignoredIntegerField + ignoredIntegerField + ignoredIntegerField + mjdField +
  199.                                                     storedRealField +
  200.                                                     ignoredRealField + ignoredRealField + ignoredRealField +
  201.                                                     finalBlanks);

  202.     }

  203.     /** Regular expression for supported files names. */
  204.     private final String supportedNames;

  205.     /** Build a loader for IERS bulletins B files.
  206.     * @param supportedNames regular expression for supported files names
  207.     */
  208.     BulletinBFilesLoader(final String supportedNames) {
  209.         this.supportedNames = supportedNames;
  210.     }

  211.     /** {@inheritDoc} */
  212.     public void fillHistory(final IERSConventions.NutationCorrectionConverter converter,
  213.                             final SortedSet<EOPEntry> history)
  214.         throws OrekitException {
  215.         final Parser parser = new Parser(converter);
  216.         DataProvidersManager.getInstance().feed(supportedNames, parser);
  217.         history.addAll(parser.history);
  218.     }

  219.     /** Internal class performing the parsing. */
  220.     private static class Parser implements DataLoader {

  221.         /** Converter for nutation corrections. */
  222.         private final IERSConventions.NutationCorrectionConverter converter;

  223.         /** History entries. */
  224.         private final List<EOPEntry> history;

  225.         /** Map for fields read in different sections. */
  226.         private final Map<Integer, double[]> fieldsMap;

  227.         /** Current line number. */
  228.         private int lineNumber;

  229.         /** Current line. */
  230.         private String line;

  231.         /** Start of final data. */
  232.         private int mjdMin;

  233.         /** End of final data. */
  234.         private int mjdMax;

  235.         /** Simple constructor.
  236.          * @param converter converter to use
  237.          */
  238.         Parser(final IERSConventions.NutationCorrectionConverter converter) {
  239.             this.converter  = converter;
  240.             this.history    = new ArrayList<EOPEntry>();
  241.             this.fieldsMap  = new HashMap<Integer, double[]>();
  242.             this.lineNumber = 0;
  243.             this.mjdMin     = Integer.MAX_VALUE;
  244.             this.mjdMax     = Integer.MIN_VALUE;
  245.         }

  246.         /** {@inheritDoc} */
  247.         public boolean stillAcceptsData() {
  248.             return true;
  249.         }

  250.         /** {@inheritDoc} */
  251.         public void loadData(final InputStream input, final String name)
  252.             throws OrekitException, IOException {

  253.             // set up a reader for line-oriented bulletin B files
  254.             final BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));

  255.             // reset parse info to start new file (do not clear history!)
  256.             fieldsMap.clear();
  257.             lineNumber = 0;
  258.             mjdMin     = Integer.MAX_VALUE;
  259.             mjdMax     = Integer.MIN_VALUE;

  260.             // skip header up to section 1 and check if we are parsing an old or new format file
  261.             final Matcher section1Matcher = seekToLine(SECTION_1_HEADER, reader, name);
  262.             final boolean isOldFormat = "EARTH".equals(section1Matcher.group(1));

  263.             if (isOldFormat) {

  264.                 // extract MJD bounds for final data from section 1
  265.                 loadMJDBoundsOldFormat(reader, name);

  266.                 final Matcher section2Matcher = seekToLine(SECTION_2_HEADER_OLD, reader, name);
  267.                 final boolean isNonRotatingOrigin = section2Matcher.group(1).startsWith("dX");
  268.                 loadEOPOldFormat(isNonRotatingOrigin, reader, name);

  269.             } else {

  270.                 // extract x, y, UT1-UTC, dx, dy from section 1
  271.                 loadXYDTDxDyNewFormat(reader, name);

  272.                 // skip to section 3
  273.                 seekToLine(SECTION_3_HEADER, reader, name);

  274.                 // extract LOD data from section 3
  275.                 loadLODNewFormat(reader, name);

  276.                 // set up the EOP entries
  277.                 for (Map.Entry<Integer, double[]> entry : fieldsMap.entrySet()) {
  278.                     final int mjd = entry.getKey();
  279.                     final double[] array = entry.getValue();
  280.                     if (Double.isNaN(array[0] + array[1] + array[2] + array[3] + array[4] + array[5])) {
  281.                         throw notifyUnexpectedErrorEncountered(name);
  282.                     }
  283.                     final AbsoluteDate mjdDate =
  284.                             new AbsoluteDate(new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, mjd),
  285.                                              TimeScalesFactory.getUTC());
  286.                     final double[] equinox = converter.toEquinox(mjdDate, array[4], array[5]);
  287.                     history.add(new EOPEntry(mjd, array[0], array[1], array[2], array[3],
  288.                                              equinox[0], equinox[1], array[4], array[5]));
  289.                 }

  290.             }

  291.         }

  292.         /** Read until a line matching a pattern is found.
  293.          * @param pattern pattern to look for
  294.          * @param reader reader from where file content is obtained
  295.          * @param name name of the file (or zip entry)
  296.          * @return the matching matcher for the line
  297.          * @exception IOException if data can't be read
  298.          * @exception OrekitException if end of file is reached before line has been found
  299.          */
  300.         private Matcher seekToLine(final Pattern pattern, final BufferedReader reader, final String name)
  301.             throws IOException, OrekitException {

  302.             for (line = reader.readLine(); line != null; line = reader.readLine()) {
  303.                 ++lineNumber;
  304.                 final Matcher matcher = pattern.matcher(line);
  305.                 if (matcher.matches()) {
  306.                     return matcher;
  307.                 }
  308.             }

  309.             // we have reached end of file and not found a matching line
  310.             throw new OrekitException(OrekitMessages.UNEXPECTED_END_OF_FILE_AFTER_LINE,
  311.                                       name, lineNumber);

  312.         }

  313.         /** Read MJD bounds of the final data part from section 1 in the old bulletin B format.
  314.          * @param reader reader from where file content is obtained
  315.          * @param name name of the file (or zip entry)
  316.          * @exception IOException if data can't be read
  317.          * @exception OrekitException if some data is missing or if some loader specific error occurs
  318.          */
  319.         private void loadMJDBoundsOldFormat(final BufferedReader reader, final String name)
  320.             throws OrekitException, IOException {

  321.             boolean inFinalValuesPart = false;
  322.             for (line = reader.readLine(); line != null; line = reader.readLine()) {
  323.                 lineNumber++;
  324.                 Matcher matcher = FINAL_VALUES_START.matcher(line);
  325.                 if (matcher.matches()) {
  326.                     // we are entering final values part (in section 1)
  327.                     inFinalValuesPart = true;
  328.                 } else if (inFinalValuesPart) {
  329.                     matcher = SECTION_1_DATA_OLD_FORMAT.matcher(line);
  330.                     if (matcher.matches()) {
  331.                         // this is a data line, build an entry from the extracted fields
  332.                         final int mjd = Integer.parseInt(matcher.group(1));
  333.                         mjdMin = FastMath.min(mjdMin, mjd);
  334.                         mjdMax = FastMath.max(mjdMax, mjd);
  335.                     } else {
  336.                         matcher = FINAL_VALUES_END.matcher(line);
  337.                         if (matcher.matches()) {
  338.                             // we leave final values part
  339.                             return;
  340.                         }
  341.                     }
  342.                 }
  343.             }

  344.             throw new OrekitException(OrekitMessages.UNEXPECTED_END_OF_FILE_AFTER_LINE,
  345.                                       name, lineNumber);

  346.         }

  347.         /** Read EOP data from section 2 in the old bulletin B format.
  348.          * @param isNonRotatingOrigin if true, the file contain Non-Rotating Origin nutation corrections
  349.          * @param reader reader from where file content is obtained
  350.          * @param name name of the file (or zip entry)
  351.          * @exception IOException if data can't be read
  352.          * @exception OrekitException if some data is missing or if some loader specific error occurs
  353.          */
  354.         private void loadEOPOldFormat(final boolean isNonRotatingOrigin,
  355.                                       final BufferedReader reader, final String name)
  356.             throws OrekitException, IOException {

  357.             // read the data lines in the final values part inside section 2
  358.             line = reader.readLine();
  359.             while (line != null) {
  360.                 lineNumber++;
  361.                 final Matcher matcher = SECTION_2_DATA_OLD_FORMAT.matcher(line);
  362.                 if (matcher.matches()) {
  363.                     // this is a data line, build an entry from the extracted fields
  364.                     final int    mjd   = Integer.parseInt(matcher.group(1));
  365.                     final double x     = Double.parseDouble(matcher.group(2)) * Constants.ARC_SECONDS_TO_RADIANS;
  366.                     final double y     = Double.parseDouble(matcher.group(3)) * Constants.ARC_SECONDS_TO_RADIANS;
  367.                     final double dtu1  = Double.parseDouble(matcher.group(4));
  368.                     final double lod   = Double.parseDouble(matcher.group(5)) * MILLI_SECONDS_TO_SECONDS;
  369.                     if (mjd >= mjdMin) {
  370.                         final AbsoluteDate mjdDate =
  371.                                 new AbsoluteDate(new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, mjd),
  372.                                                  TimeScalesFactory.getUTC());
  373.                         final double[] equinox;
  374.                         final double[] nro;
  375.                         if (isNonRotatingOrigin) {
  376.                             nro = new double[] {
  377.                                 Double.parseDouble(matcher.group(6)) * MILLI_ARC_SECONDS_TO_RADIANS,
  378.                                 Double.parseDouble(matcher.group(7)) * MILLI_ARC_SECONDS_TO_RADIANS
  379.                             };
  380.                             equinox = converter.toEquinox(mjdDate, nro[0], nro[1]);
  381.                         } else {
  382.                             equinox = new double[] {
  383.                                 Double.parseDouble(matcher.group(6)) * MILLI_ARC_SECONDS_TO_RADIANS,
  384.                                 Double.parseDouble(matcher.group(7)) * MILLI_ARC_SECONDS_TO_RADIANS
  385.                             };
  386.                             nro = converter.toNonRotating(mjdDate, equinox[0], equinox[1]);
  387.                         }
  388.                         history.add(new EOPEntry(mjd, dtu1, lod, x, y, equinox[0], equinox[1], nro[0], nro[1]));
  389.                         line = mjd < mjdMax ? reader.readLine() : null;
  390.                     } else {
  391.                         line = reader.readLine();
  392.                     }
  393.                 } else {
  394.                     line = reader.readLine();
  395.                 }
  396.             }

  397.         }

  398.         /** Read X, Y, UT1-UTC, dx, dy from section 1 in the new bulletin B format.
  399.          * @param reader reader from where file content is obtained
  400.          * @param name name of the file (or zip entry)
  401.          * @exception IOException if data can't be read
  402.          * @exception OrekitException if some data is missing or if some loader specific error occurs
  403.          */
  404.         private void loadXYDTDxDyNewFormat(final BufferedReader reader, final String name)
  405.             throws OrekitException, IOException {

  406.             boolean inFinalValuesPart = false;
  407.             line = reader.readLine();
  408.             while (line != null) {
  409.                 lineNumber++;
  410.                 Matcher matcher = FINAL_VALUES_START.matcher(line);
  411.                 if (matcher.matches()) {
  412.                     // we are entering final values part (in section 1)
  413.                     inFinalValuesPart = true;
  414.                     line = reader.readLine();
  415.                 } else if (inFinalValuesPart) {
  416.                     matcher = SECTION_1_DATA_NEW_FORMAT.matcher(line);
  417.                     if (matcher.matches()) {
  418.                         // this is a data line, build an entry from the extracted fields
  419.                         final int year  = Integer.parseInt(matcher.group(1));
  420.                         final int month = Integer.parseInt(matcher.group(2));
  421.                         final int day   = Integer.parseInt(matcher.group(3));
  422.                         final int mjd   = Integer.parseInt(matcher.group(4));
  423.                         if (new DateComponents(year, month, day).getMJD() != mjd) {
  424.                             throw new OrekitException(OrekitMessages.INCONSISTENT_DATES_IN_IERS_FILE,
  425.                                                       name, year, month, day, mjd);
  426.                         }
  427.                         mjdMin = FastMath.min(mjdMin, mjd);
  428.                         mjdMax = FastMath.max(mjdMax, mjd);
  429.                         final double x    = Double.parseDouble(matcher.group(5)) * MILLI_ARC_SECONDS_TO_RADIANS;
  430.                         final double y    = Double.parseDouble(matcher.group(6)) * MILLI_ARC_SECONDS_TO_RADIANS;
  431.                         final double dtu1 = Double.parseDouble(matcher.group(7)) * MILLI_SECONDS_TO_SECONDS;
  432.                         final double dx   = Double.parseDouble(matcher.group(8)) * MILLI_ARC_SECONDS_TO_RADIANS;
  433.                         final double dy   = Double.parseDouble(matcher.group(9)) * MILLI_ARC_SECONDS_TO_RADIANS;
  434.                         fieldsMap.put(mjd,
  435.                                       new double[] {
  436.                                           dtu1, Double.NaN, x, y, dx, dy
  437.                                       });
  438.                         line = reader.readLine();
  439.                     } else {
  440.                         matcher = FINAL_VALUES_END.matcher(line);
  441.                         line = matcher.matches() ? null : reader.readLine();
  442.                     }
  443.                 } else {
  444.                     line = reader.readLine();
  445.                 }
  446.             }
  447.         }

  448.         /** Read LOD from section 3 in the new bulletin B format.
  449.          * @param reader reader from where file content is obtained
  450.          * @param name name of the file (or zip entry)
  451.          * @exception IOException if data can't be read
  452.          * @exception OrekitException if some data is missing or if some loader specific error occurs
  453.          */
  454.         private void loadLODNewFormat(final BufferedReader reader, final String name)
  455.             throws OrekitException, IOException {
  456.             line = reader.readLine();
  457.             while (line != null) {
  458.                 lineNumber++;
  459.                 final Matcher matcher = SECTION_3_DATA_NEW_FORMAT.matcher(line);
  460.                 if (matcher.matches()) {
  461.                     // this is a data line, build an entry from the extracted fields
  462.                     final int    mjd = Integer.parseInt(matcher.group(1));
  463.                     if (mjd >= mjdMin) {
  464.                         final double lod = Double.parseDouble(matcher.group(2)) * MILLI_SECONDS_TO_SECONDS;
  465.                         final double[] array = fieldsMap.get(mjd);
  466.                         if (array == null) {
  467.                             throw notifyUnexpectedErrorEncountered(name);
  468.                         }
  469.                         array[1] = lod;
  470.                         line = mjd >= mjdMax ? null : reader.readLine();
  471.                     } else {
  472.                         line = reader.readLine();
  473.                     }
  474.                 } else {
  475.                     line = reader.readLine();
  476.                 }
  477.             }
  478.         }

  479.         /** Create an exception to be thrown.
  480.          * @param name name of the file (or zip entry)
  481.          * @return OrekitException always thrown to notify an unexpected error has been
  482.          * encountered by the caller
  483.          */
  484.         private OrekitException notifyUnexpectedErrorEncountered(final String name) {
  485.             String loaderName = BulletinBFilesLoader.class.getName();
  486.             loaderName = loaderName.substring(loaderName.lastIndexOf('.') + 1);
  487.             return new OrekitException(OrekitMessages.UNEXPECTED_FILE_FORMAT_ERROR_FOR_LOADER,
  488.                                        name, loaderName);
  489.         }

  490.     }

  491. }