BulletinBFilesLoader.java

  1. /* Copyright 2002-2019 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 to finalized 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 section 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.         final Parser parser = new Parser(converter);
  215.         DataProvidersManager.getInstance().feed(supportedNames, parser);
  216.         history.addAll(parser.history);
  217.     }

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

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

  222.         /** Configuration for ITRF versions. */
  223.         private final ITRFVersionLoader itrfVersionLoader;

  224.         /** ITRF version configuration. */
  225.         private ITRFVersionLoader.ITRFVersionConfiguration configuration;

  226.         /** History entries. */
  227.         private final List<EOPEntry> history;

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

  230.         /** Current line number. */
  231.         private int lineNumber;

  232.         /** Current line. */
  233.         private String line;

  234.         /** Start of final data. */
  235.         private int mjdMin;

  236.         /** End of final data. */
  237.         private int mjdMax;

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

  250.         /** {@inheritDoc} */
  251.         public boolean stillAcceptsData() {
  252.             return true;
  253.         }

  254.         /** {@inheritDoc} */
  255.         public void loadData(final InputStream input, final String name)
  256.             throws IOException {

  257.             configuration = null;

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

  260.             // reset parse info to start new file (do not clear history!)
  261.             fieldsMap.clear();
  262.             lineNumber = 0;
  263.             mjdMin     = Integer.MAX_VALUE;
  264.             mjdMax     = Integer.MIN_VALUE;

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

  268.             if (isOldFormat) {

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

  271.                 final Matcher section2Matcher = seekToLine(SECTION_2_HEADER_OLD, reader, name);
  272.                 final boolean isNonRotatingOrigin = section2Matcher.group(1).startsWith("dX");
  273.                 loadEOPOldFormat(isNonRotatingOrigin, reader, name);

  274.             } else {

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

  277.                 // skip to section 3
  278.                 seekToLine(SECTION_3_HEADER, reader, name);

  279.                 // extract LOD data from section 3
  280.                 loadLODNewFormat(reader, name);

  281.                 // set up the EOP entries
  282.                 for (Map.Entry<Integer, double[]> entry : fieldsMap.entrySet()) {
  283.                     final int mjd = entry.getKey();
  284.                     final double[] array = entry.getValue();
  285.                     if (Double.isNaN(array[0] + array[1] + array[2] + array[3] + array[4] + array[5])) {
  286.                         throw notifyUnexpectedErrorEncountered(name);
  287.                     }
  288.                     final AbsoluteDate mjdDate =
  289.                             new AbsoluteDate(new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, mjd),
  290.                                              TimeScalesFactory.getUTC());
  291.                     final double[] equinox = converter.toEquinox(mjdDate, array[4], array[5]);
  292.                     if (configuration == null || !configuration.isValid(mjd)) {
  293.                         // get a configuration for current name and date range
  294.                         configuration = itrfVersionLoader.getConfiguration(name, mjd);
  295.                     }
  296.                     history.add(new EOPEntry(mjd, array[0], array[1], array[2], array[3],
  297.                                              equinox[0], equinox[1], array[4], array[5],
  298.                                              configuration.getVersion()));
  299.                 }

  300.             }

  301.         }

  302.         /** Read until a line matching a pattern is found.
  303.          * @param pattern pattern to look for
  304.          * @param reader reader from where file content is obtained
  305.          * @param name name of the file (or zip entry)
  306.          * @return the matching matcher for the line
  307.          * @exception IOException if data can't be read
  308.          */
  309.         private Matcher seekToLine(final Pattern pattern, final BufferedReader reader, final String name)
  310.             throws IOException {

  311.             for (line = reader.readLine(); line != null; line = reader.readLine()) {
  312.                 ++lineNumber;
  313.                 final Matcher matcher = pattern.matcher(line);
  314.                 if (matcher.matches()) {
  315.                     return matcher;
  316.                 }
  317.             }

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

  321.         }

  322.         /** Read MJD bounds of the final data part from section 1 in the old bulletin B format.
  323.          * @param reader reader from where file content is obtained
  324.          * @param name name of the file (or zip entry)
  325.          * @exception IOException if data can't be read
  326.          */
  327.         private void loadMJDBoundsOldFormat(final BufferedReader reader, final String name)
  328.             throws IOException {

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

  352.             throw new OrekitException(OrekitMessages.UNEXPECTED_END_OF_FILE_AFTER_LINE,
  353.                                       name, lineNumber);

  354.         }

  355.         /** Read EOP data from section 2 in the old bulletin B format.
  356.          * @param isNonRotatingOrigin if true, the file contain Non-Rotating Origin nutation corrections
  357.          * @param reader reader from where file content is obtained
  358.          * @param name name of the file (or zip entry)
  359.          * @exception IOException if data can't be read
  360.          */
  361.         private void loadEOPOldFormat(final boolean isNonRotatingOrigin,
  362.                                       final BufferedReader reader, final String name)
  363.             throws IOException {

  364.             // read the data lines in the final values part inside section 2
  365.             line = reader.readLine();
  366.             while (line != null) {
  367.                 lineNumber++;
  368.                 final Matcher matcher = SECTION_2_DATA_OLD_FORMAT.matcher(line);
  369.                 if (matcher.matches()) {
  370.                     // this is a data line, build an entry from the extracted fields
  371.                     final int    mjd   = Integer.parseInt(matcher.group(1));
  372.                     final double x     = Double.parseDouble(matcher.group(2)) * Constants.ARC_SECONDS_TO_RADIANS;
  373.                     final double y     = Double.parseDouble(matcher.group(3)) * Constants.ARC_SECONDS_TO_RADIANS;
  374.                     final double dtu1  = Double.parseDouble(matcher.group(4));
  375.                     final double lod   = Double.parseDouble(matcher.group(5)) * MILLI_SECONDS_TO_SECONDS;
  376.                     if (mjd >= mjdMin) {
  377.                         final AbsoluteDate mjdDate =
  378.                                 new AbsoluteDate(new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, mjd),
  379.                                                  TimeScalesFactory.getUTC());
  380.                         final double[] equinox;
  381.                         final double[] nro;
  382.                         if (isNonRotatingOrigin) {
  383.                             nro = new double[] {
  384.                                 Double.parseDouble(matcher.group(6)) * MILLI_ARC_SECONDS_TO_RADIANS,
  385.                                 Double.parseDouble(matcher.group(7)) * MILLI_ARC_SECONDS_TO_RADIANS
  386.                             };
  387.                             equinox = converter.toEquinox(mjdDate, nro[0], nro[1]);
  388.                         } else {
  389.                             equinox = new double[] {
  390.                                 Double.parseDouble(matcher.group(6)) * MILLI_ARC_SECONDS_TO_RADIANS,
  391.                                 Double.parseDouble(matcher.group(7)) * MILLI_ARC_SECONDS_TO_RADIANS
  392.                             };
  393.                             nro = converter.toNonRotating(mjdDate, equinox[0], equinox[1]);
  394.                         }
  395.                         if (configuration == null || !configuration.isValid(mjd)) {
  396.                             // get a configuration for current name and date range
  397.                             configuration = itrfVersionLoader.getConfiguration(name, mjd);
  398.                         }
  399.                         history.add(new EOPEntry(mjd, dtu1, lod, x, y, equinox[0], equinox[1], nro[0], nro[1],
  400.                                                  configuration.getVersion()));
  401.                         line = mjd < mjdMax ? reader.readLine() : null;
  402.                     } else {
  403.                         line = reader.readLine();
  404.                     }
  405.                 } else {
  406.                     line = reader.readLine();
  407.                 }
  408.             }

  409.         }

  410.         /** Read X, Y, UT1-UTC, dx, dy from section 1 in the new bulletin B format.
  411.          * @param reader reader from where file content is obtained
  412.          * @param name name of the file (or zip entry)
  413.          * @exception IOException if data can't be read
  414.          */
  415.         private void loadXYDTDxDyNewFormat(final BufferedReader reader, final String name)
  416.             throws IOException {

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

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

  489.         /** Create an exception to be thrown.
  490.          * @param name name of the file (or zip entry)
  491.          * @return OrekitException always thrown to notify an unexpected error has been
  492.          * encountered by the caller
  493.          */
  494.         private OrekitException notifyUnexpectedErrorEncountered(final String name) {
  495.             String loaderName = BulletinBFilesLoader.class.getName();
  496.             loaderName = loaderName.substring(loaderName.lastIndexOf('.') + 1);
  497.             return new OrekitException(OrekitMessages.UNEXPECTED_FILE_FORMAT_ERROR_FOR_LOADER,
  498.                                        name, loaderName);
  499.         }

  500.     }

  501. }