BulletinAFilesLoader.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.Arrays;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;
  27. import java.util.SortedSet;
  28. import java.util.regex.Matcher;
  29. import java.util.regex.Pattern;

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

  39. /** Loader for bulletin A files.
  40.  * <p>Bulletin A files contain {@link EOPEntry
  41.  * Earth Orientation Parameters} for a few days periods, they
  42.  * correspond to rapid data estimations, suitable for near-real time
  43.  * and prediction purposes. Prediction series are only available for
  44.  * pole motion xp, yp and UT1-UTC, they are not available for
  45.  * pole offsets (Δδψ/Δδε and x/y).</p>
  46.  * <p>A bulletin A published on Modified Julian Day mjd (nominally a
  47.  * Thursday) will generally contain:
  48.  * </p>
  49.  * <ul>
  50.  *   <li>rapid service xp, yp and UT1-UTC data from mjd-6 to mjd</li>
  51.  *   <li>prediction xp, yp and UT1-UTC data from mjd+1 to mjd+365</li>
  52.  *   <li>if it is first bulletin of month m, final values xp, yp and
  53.  *       UT1-UTC data from day 2 of month m-2 to day 1 of month m-1</li>
  54.  *   <li>rapid service pole offsets Δδψ/Δδε and x/y if available, for some
  55.  *       varying period somewhere from mjd-30 to mjd-10 (see below)</li>
  56.  *   <li>if it is first bulletin of month m, final values pole offsets
  57.  *       Δδψ/Δδε and x/y data from day 2 of month m-2 to day 1 of month
  58.  *       m-1</li>
  59.  * </ul>
  60.  * <p>
  61.  * There are some discrepancies in the rapid service time range above,
  62.  * mainly when the nominal publication Thursday corresponds to holidays.
  63.  * In this case a bulletin may be published the day before and have a 6
  64.  * days span only for rapid data, and a later bulletin will have an 8 days
  65.  * span to recover the normal schedule. This occurred for bulletin A Vol.
  66.  * XVIII No. 047, bulletin A Vol. XVIII No. 048, bulletin A Vol. XXI No.
  67.  * 052 and bulletin A Vol. XXII No. 001.
  68.  * </p>
  69.  * <p>Rapid service for pole offsets appears irregular. As extreme examples
  70.  * bulletin A Vol. XXVI No. 037 from 2013-09-12 contained 15 entries
  71.  * for pole offsets, from mjd-22 to mjd-8, bulletin A Vol. XXVI No. 039
  72.  * from 2013-09-26 contained only 3 entries for pole offsets, from mjd-15
  73.  * to mjd-13, and bulletin A Vol. XXVI No. 040 from 2013-10-03 contained no
  74.  * rapid service pole offsets at all, it contained only final values. Despite
  75.  * this irregularity, rapid service data is continuous over consecutive files,
  76.  * so the mean number of entries is 7 as the files are published on a weekly
  77.  * basis.
  78.  * </p>
  79.  * <p>
  80.  * There are no prediction data for pole offsets.
  81.  * </p>
  82.  * <p>
  83.  * This loader reads both the rapid service, the prediction and the final
  84.  * values parts. As successive files have overlaps between all these sections,
  85.  * values extracted from latest files (with respect to the covered dates)
  86.  * override values extracted from earlier files, regardless of the files
  87.  * reading order. If numerous bulletins A covering more than one year are read,
  88.  * one particular date will typically appear in the prediction section of
  89.  * 52 or 53 files, then in the rapid data section of one file, then it will
  90.  * be missing in a few files, and will finally appear a last time in the
  91.  * final values sections of a last file. In this case, the value retained
  92.  * will be the one extracted from the final values section in the more
  93.  * recent file.
  94.  * </p>
  95.  * <p>
  96.  * If only one bulletin A file is read and it correspond to the first bulletin
  97.  * of a month, it will have a roughly one month wide hole between the
  98.  * final data and the rapid data. This hole will trigger an error as EOP
  99.  * continuity is checked by default for at most 5 days holes. In this case,
  100.  * users should call something like {@link FramesFactory#setEOPContinuityThreshold(double)
  101.  * FramesFactory.setEOPContinuityThreshold(Constants.JULIAN_YEAR)} to prevent
  102.  * the error to be triggered.
  103.  * </p>
  104.  * <p>The bulletin A files are recognized thanks to their base names,
  105.  * which must match the pattern <code>bulletina-xxxx-###.txt</code>,
  106.  * (or the same ending with <code>.gz</code> for gzip-compressed files)
  107.  * where x stands for a roman numeral character and # stands for a digit
  108.  * character.</p>
  109.  * <p>
  110.  * This class is immutable and hence thread-safe
  111.  * </p>
  112.  * @author Luc Maisonobe
  113.  * @since 7.0
  114.  */
  115. class BulletinAFilesLoader implements EOPHistoryLoader {

  116.     /** Conversion factor. */
  117.     private static final double MILLI_ARC_SECONDS_TO_RADIANS = Constants.ARC_SECONDS_TO_RADIANS / 1000;

  118.     /** Regular expression matching blanks at start of line. */
  119.     private static final String LINE_START_REGEXP     = "^\\p{Blank}+";

  120.     /** Regular expression matching blanks at end of line. */
  121.     private static final String LINE_END_REGEXP       = "\\p{Blank}*$";

  122.     /** Regular expression matching integers. */
  123.     private static final String INTEGER_REGEXP        = "[-+]?\\p{Digit}+";

  124.     /** Regular expression matching real numbers. */
  125.     private static final String REAL_REGEXP           = "[-+]?(?:(?:\\p{Digit}+(?:\\.\\p{Digit}*)?)|(?:\\.\\p{Digit}+))(?:[eE][-+]?\\p{Digit}+)?";

  126.     /** Regular expression matching an integer field to store. */
  127.     private static final String STORED_INTEGER_FIELD  = "\\p{Blank}*(" + INTEGER_REGEXP + ")";

  128.     /** regular expression matching a Modified Julian Day field to store. */
  129.     private static final String STORED_MJD_FIELD      = "\\p{Blank}+(\\p{Digit}\\p{Digit}\\p{Digit}\\p{Digit}\\p{Digit})";

  130.     /** Regular expression matching a real field to store. */
  131.     private static final String STORED_REAL_FIELD     = "\\p{Blank}+(" + REAL_REGEXP + ")";

  132.     /** Regular expression matching a real field to ignore. */
  133.     private static final String IGNORED_REAL_FIELD    = "\\p{Blank}+" + REAL_REGEXP;

  134.     /** Enum for files sections, in expected order.
  135.      * <p>The bulletin A weekly data files contain several sections,
  136.      * each introduced with some fixed header text and followed by tabular data.
  137.      * </p>
  138.      */
  139.     private enum Section {

  140.         /** Earth Orientation Parameters rapid service. */
  141.         // section 2 always contain rapid service data including error fields
  142.         //      COMBINED EARTH ORIENTATION PARAMETERS:
  143.         //
  144.         //                              IERS Rapid Service
  145.         //              MJD      x    error     y    error   UT1-UTC   error
  146.         //                       "      "       "      "        s        s
  147.         //   13  8 30  56534 0.16762 .00009 0.32705 .00009  0.038697 0.000019
  148.         //   13  8 31  56535 0.16669 .00010 0.32564 .00010  0.038471 0.000019
  149.         //   13  9  1  56536 0.16592 .00009 0.32410 .00010  0.038206 0.000024
  150.         //   13  9  2  56537 0.16557 .00009 0.32270 .00009  0.037834 0.000024
  151.         //   13  9  3  56538 0.16532 .00009 0.32147 .00010  0.037351 0.000024
  152.         //   13  9  4  56539 0.16488 .00009 0.32044 .00010  0.036756 0.000023
  153.         //   13  9  5  56540 0.16435 .00009 0.31948 .00009  0.036036 0.000024
  154.         EOP_RAPID_SERVICE("^ *COMBINED EARTH ORIENTATION PARAMETERS: *$",
  155.                           LINE_START_REGEXP +
  156.                           STORED_INTEGER_FIELD + STORED_INTEGER_FIELD + STORED_INTEGER_FIELD +
  157.                           STORED_MJD_FIELD +
  158.                           STORED_REAL_FIELD + IGNORED_REAL_FIELD +
  159.                           STORED_REAL_FIELD + IGNORED_REAL_FIELD +
  160.                           STORED_REAL_FIELD + IGNORED_REAL_FIELD +
  161.                           LINE_END_REGEXP),

  162.        /** Earth Orientation Parameters final values. */
  163.        // the first bulletin A of each month also includes final values for the
  164.        // period covering from day 2 of month m-2 to day 1 of month m-1.
  165.        //                                IERS Final Values
  166.        //                                 MJD        x        y      UT1-UTC
  167.        //                                            "        "         s
  168.        //             13  7  2           56475    0.1441   0.3901   0.05717
  169.        //             13  7  3           56476    0.1457   0.3895   0.05716
  170.        //             13  7  4           56477    0.1467   0.3887   0.05728
  171.        //             13  7  5           56478    0.1477   0.3875   0.05755
  172.        //             13  7  6           56479    0.1490   0.3862   0.05793
  173.        //             13  7  7           56480    0.1504   0.3849   0.05832
  174.        //             13  7  8           56481    0.1516   0.3835   0.05858
  175.        //             13  7  9           56482    0.1530   0.3822   0.05877
  176.        EOP_FINAL_VALUES("^ *IERS Final Values *$",
  177.                         LINE_START_REGEXP +
  178.                         STORED_INTEGER_FIELD + STORED_INTEGER_FIELD + STORED_INTEGER_FIELD +
  179.                         STORED_MJD_FIELD +
  180.                         STORED_REAL_FIELD +
  181.                         STORED_REAL_FIELD +
  182.                         STORED_REAL_FIELD +
  183.                         LINE_END_REGEXP),

  184.         /** Earth Orientation Parameters prediction. */
  185.         // section 3 always contain prediction data without error fields
  186.         //
  187.         //         PREDICTIONS:
  188.         //         The following formulas will not reproduce the predictions given below,
  189.         //         but may be used to extend the predictions beyond the end of this table.
  190.         //
  191.         //         x =  0.0969 + 0.1110 cos A - 0.0103 sin A - 0.0435 cos C - 0.0171 sin C
  192.         //         y =  0.3457 - 0.0061 cos A - 0.1001 sin A - 0.0171 cos C + 0.0435 sin C
  193.         //            UT1-UTC = -0.0052 - 0.00104 (MJD - 56548) - (UT2-UT1)
  194.         //
  195.         //         where A = 2*pi*(MJD-56540)/365.25 and C = 2*pi*(MJD-56540)/435.
  196.         //
  197.         //            TAI-UTC(MJD 56541) = 35.0
  198.         //         The accuracy may be estimated from the expressions:
  199.         //         S x,y = 0.00068 (MJD-56540)**0.80   S t = 0.00025 (MJD-56540)**0.75
  200.         //         Estimated accuracies are:  Predictions     10 d   20 d   30 d   40 d
  201.         //                                    Polar coord's  0.004  0.007  0.010  0.013
  202.         //                                    UT1-UTC        0.0014 0.0024 0.0032 0.0040
  203.         //
  204.         //                       MJD      x(arcsec)   y(arcsec)   UT1-UTC(sec)
  205.         //          2013  9  6  56541       0.1638      0.3185      0.03517
  206.         //          2013  9  7  56542       0.1633      0.3175      0.03420
  207.         //          2013  9  8  56543       0.1628      0.3164      0.03322
  208.         //          2013  9  9  56544       0.1623      0.3153      0.03229
  209.         //          2013  9 10  56545       0.1618      0.3142      0.03144
  210.         //          2013  9 11  56546       0.1612      0.3131      0.03071
  211.         //          2013  9 12  56547       0.1607      0.3119      0.03008
  212.         EOP_PREDICTION("^ *PREDICTIONS: *$",
  213.                        LINE_START_REGEXP +
  214.                        STORED_INTEGER_FIELD + STORED_INTEGER_FIELD + STORED_INTEGER_FIELD +
  215.                        STORED_MJD_FIELD +
  216.                        STORED_REAL_FIELD +
  217.                        STORED_REAL_FIELD +
  218.                        STORED_REAL_FIELD +
  219.                        LINE_END_REGEXP),

  220.         /** Pole offsets, IAU-1980. */
  221.         // section 4 may contain rapid service pole offset series including error fields
  222.         //        CELESTIAL POLE OFFSET SERIES:
  223.         //                             NEOS Celestial Pole Offset Series
  224.         //                         MJD      dpsi    error     deps    error
  225.         //                                          (msec. of arc)
  226.         //                        56519   -87.47     0.13   -12.96     0.08
  227.         //                        56520   -87.72     0.13   -13.20     0.08
  228.         //                        56521   -87.79     0.19   -13.56     0.11
  229.         POLE_OFFSETS_IAU_1980_RAPID_SERVICE("^ *NEOS Celestial Pole Offset Series *$",
  230.                                             LINE_START_REGEXP +
  231.                                             STORED_MJD_FIELD +
  232.                                             STORED_REAL_FIELD + IGNORED_REAL_FIELD +
  233.                                             STORED_REAL_FIELD + IGNORED_REAL_FIELD +
  234.                                             LINE_END_REGEXP),

  235.         /** Pole offsets, IAU-1980 final values. */
  236.         // the format for the IAU-2000 series is similar, but the meanings of the fields
  237.         // are different
  238.         //                       IAU2000A Celestial Pole Offset Series
  239.         //                        MJD      dX     error     dY     error
  240.         //                                      (msec. of arc)
  241.         //                       56519   -0.246   0.052   -0.223   0.080
  242.         //                       56520   -0.239   0.052   -0.248   0.080
  243.         //                       56521   -0.224   0.076   -0.277   0.110
  244.         POLE_OFFSETS_IAU_1980_FINAL_VALUES("^ *IERS Celestial Pole Offset Final Series *$",
  245.                                            LINE_START_REGEXP +
  246.                                            STORED_MJD_FIELD +
  247.                                            STORED_REAL_FIELD +
  248.                                            STORED_REAL_FIELD +
  249.                                            LINE_END_REGEXP),

  250.         /** Pole offsets, IAU-2000. */
  251.         // the first bulletin A of each month also includes final values for the
  252.         // period covering from day 2 of month m-2 to day 1 of month m-1.
  253.         //                    IERS Celestial Pole Offset Final Series
  254.         //                          MJD          dpsi      deps
  255.         //                                       (msec. of arc)
  256.         //                         56475       -81.0     -13.3
  257.         //                         56476       -81.2     -13.4
  258.         //                         56477       -81.6     -13.4
  259.         //                         56478       -82.2     -13.5
  260.         //                         56479       -82.5     -13.6
  261.         //                         56480       -82.5     -13.7
  262.         POLE_OFFSETS_IAU_2000_RAPID_SERVICE("^ *IAU2000A Celestial Pole Offset Series *$",
  263.                                             LINE_START_REGEXP +
  264.                                             STORED_MJD_FIELD +
  265.                                             STORED_REAL_FIELD + IGNORED_REAL_FIELD +
  266.                                             STORED_REAL_FIELD + IGNORED_REAL_FIELD +
  267.                                             LINE_END_REGEXP),

  268.         /** Pole offsets, IAU-2000 final values. */
  269.         // the format for the IAU-2000 series is similar, but the meanings of the fields
  270.         // are different
  271.         //                   IAU2000A Celestial Pole Offset Final Series
  272.         //                            MJD     dX         dY
  273.         //                            (msec. of arc)
  274.         //                          56475     0.00      -0.28
  275.         //                          56476    -0.06      -0.29
  276.         //                          56477    -0.07      -0.27
  277.         //                          56478    -0.12      -0.33
  278.         //                          56479    -0.12      -0.33
  279.         //                          56480    -0.13      -0.36
  280.         POLE_OFFSETS_IAU_2000_FINAL_VALUES("^ *IAU2000A Celestial Pole Offset Final Series *$",
  281.                                            LINE_START_REGEXP +
  282.                                            STORED_MJD_FIELD +
  283.                                            STORED_REAL_FIELD +
  284.                                            STORED_REAL_FIELD +
  285.                                            LINE_END_REGEXP);

  286.         /** Header pattern. */
  287.         private final Pattern header;

  288.         /** Data pattern. */
  289.         private final Pattern data;

  290.         /** Simple constructor.
  291.          * @param headerRegExp regular expression for header
  292.          * @param dataRegExp regular expression for data
  293.          */
  294.         Section(final String headerRegExp, final String dataRegExp) {
  295.             this.header = Pattern.compile(headerRegExp);
  296.             this.data   = Pattern.compile(dataRegExp);
  297.         }

  298.         /** Check if a line matches the section header.
  299.          * @param line line to check
  300.          * @return true if the line matches the header
  301.          */
  302.         public boolean matchesHeader(final String line) {
  303.             return header.matcher(line).matches();
  304.         }

  305.         /** Get the data fields from a line.
  306.          * @param line line to parse
  307.          * @return extracted fields, or null if line does not match data format
  308.          */
  309.         public String[] getFields(final String line) {
  310.             final Matcher matcher = data.matcher(line);
  311.             if (matcher.matches()) {
  312.                 final String[] fields = new String[matcher.groupCount()];
  313.                 for (int i = 0; i < fields.length; ++i) {
  314.                     fields[i] = matcher.group(i + 1);
  315.                 }
  316.                 return fields;
  317.             } else {
  318.                 return null;
  319.             }
  320.         }

  321.     }

  322.     /** Regular expression for supported files names. */
  323.     private final String supportedNames;

  324.     /** Build a loader for IERS bulletins A files.
  325.     * @param supportedNames regular expression for supported files names
  326.     */
  327.     BulletinAFilesLoader(final String supportedNames) {
  328.         this.supportedNames = supportedNames;
  329.     }

  330.     /** {@inheritDoc} */
  331.     public void fillHistory(final IERSConventions.NutationCorrectionConverter converter,
  332.                             final SortedSet<EOPEntry> history)
  333.         throws OrekitException {
  334.         final Parser parser = new Parser();
  335.         DataProvidersManager.getInstance().feed(supportedNames, parser);
  336.         parser.fill(history);
  337.     }

  338.     /** Internal class performing the parsing. */
  339.     private static class Parser implements DataLoader {

  340.         /** Map for xp, yp, dut1 fields read in different sections. */
  341.         private final Map<Integer, double[]> eopFieldsMap;

  342.         /** Map for pole offsets fields read in different sections. */
  343.         private final Map<Integer, double[]> poleOffsetsFieldsMap;

  344.         /** Current line number. */
  345.         private int lineNumber;

  346.         /** Current line. */
  347.         private String line;

  348.         /** Earliest parsed data. */
  349.         private int mjdMin;

  350.         /** Latest parsed data. */
  351.         private int mjdMax;

  352.         /** First MJD parsed in current file. */
  353.         private int firstMJD;

  354.         /** Simple constructor.
  355.          */
  356.         Parser() {
  357.             this.eopFieldsMap         = new HashMap<Integer, double[]>();
  358.             this.poleOffsetsFieldsMap = new HashMap<Integer, double[]>();
  359.             this.lineNumber           = 0;
  360.             this.mjdMin               = Integer.MAX_VALUE;
  361.             this.mjdMax               = Integer.MIN_VALUE;
  362.             this.firstMJD             = -1;
  363.         }

  364.         /** {@inheritDoc} */
  365.         public boolean stillAcceptsData() {
  366.             return true;
  367.         }

  368.         /** {@inheritDoc} */
  369.         public void loadData(final InputStream input, final String name)
  370.             throws OrekitException, IOException {

  371.             // set up a reader for line-oriented bulletin A files
  372.             final BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
  373.             lineNumber =  0;
  374.             firstMJD   = -1;

  375.             // loop over sections
  376.             final List<Section> remaining = new ArrayList<Section>();
  377.             remaining.addAll(Arrays.asList(Section.values()));
  378.             for (Section section = nextSection(remaining, reader, name);
  379.                  section != null;
  380.                  section = nextSection(remaining, reader, name)) {

  381.                 switch (section) {
  382.                     case EOP_RAPID_SERVICE :
  383.                     case EOP_FINAL_VALUES  :
  384.                     case EOP_PREDICTION    :
  385.                         loadXYDT(section, reader, name);
  386.                         break;
  387.                     case POLE_OFFSETS_IAU_1980_RAPID_SERVICE :
  388.                     case POLE_OFFSETS_IAU_1980_FINAL_VALUES  :
  389.                         loadPoleOffsets(section, false, reader, name);
  390.                         break;
  391.                     case POLE_OFFSETS_IAU_2000_RAPID_SERVICE :
  392.                     case POLE_OFFSETS_IAU_2000_FINAL_VALUES  :
  393.                         loadPoleOffsets(section, true, reader, name);
  394.                         break;
  395.                     default :
  396.                         // this should never happen
  397.                         throw new OrekitInternalError(null);
  398.                 }

  399.                 // remove the already parsed section from the list
  400.                 remaining.remove(section);

  401.             }

  402.             // check that the mandatory sections have been parsed
  403.             if (remaining.contains(Section.EOP_RAPID_SERVICE) ||
  404.                 remaining.contains(Section.EOP_PREDICTION) ||
  405.                 (remaining.contains(Section.POLE_OFFSETS_IAU_1980_RAPID_SERVICE) ^
  406.                  remaining.contains(Section.POLE_OFFSETS_IAU_2000_RAPID_SERVICE)) ||
  407.                 (remaining.contains(Section.POLE_OFFSETS_IAU_1980_FINAL_VALUES) ^
  408.                  remaining.contains(Section.POLE_OFFSETS_IAU_2000_FINAL_VALUES))) {
  409.                 throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_IERS_DATA_FILE, name);
  410.             }

  411.         }

  412.         /** Fill EOP history obtained after reading several files.
  413.          * @param history history to fill up
  414.          * @exception OrekitException if UTC time scale cannot be retrieved
  415.          */
  416.         public void fill(final SortedSet<EOPEntry> history)
  417.             throws OrekitException {

  418.             double[] currentEOP = null;
  419.             double[] nextEOP    = eopFieldsMap.get(mjdMin);
  420.             for (int mjd = mjdMin; mjd <= mjdMax; ++mjd) {

  421.                 final double[] currentPole = poleOffsetsFieldsMap.get(mjd);

  422.                 final double[] previousEOP = currentEOP;
  423.                 currentEOP = nextEOP;
  424.                 nextEOP    = eopFieldsMap.get(mjd + 1);

  425.                 if (currentEOP == null) {
  426.                     if (currentPole != null) {
  427.                         // we have only pole offsets for this date
  428.                         history.add(new EOPEntry(mjd,
  429.                                                  0.0, 0.0, 0.0, 0.0,
  430.                                                  currentPole[1] * MILLI_ARC_SECONDS_TO_RADIANS,
  431.                                                  currentPole[2] * MILLI_ARC_SECONDS_TO_RADIANS,
  432.                                                  currentPole[3] * MILLI_ARC_SECONDS_TO_RADIANS,
  433.                                                  currentPole[4] * MILLI_ARC_SECONDS_TO_RADIANS));
  434.                     }
  435.                 } else {

  436.                     // compute LOD as the opposite of the time derivative of UT1-UTC
  437.                     final double lod;
  438.                     if (previousEOP == null) {
  439.                         if (nextEOP == null) {
  440.                             // isolated point
  441.                             lod = 0;
  442.                         } else {
  443.                             // first entry, we use a forward difference
  444.                             lod = currentEOP[3] - nextEOP[3];
  445.                         }
  446.                     } else {
  447.                         if (nextEOP == null) {
  448.                             // last entry, we use a backward difference
  449.                             lod = previousEOP[3] - currentEOP[3];
  450.                         } else {
  451.                             // regular entry, we use a centered difference
  452.                             lod = 0.5 * (previousEOP[3] - nextEOP[3]);
  453.                         }
  454.                     }

  455.                     if (currentPole == null) {
  456.                         // we have only EOP for this date
  457.                         history.add(new EOPEntry(mjd,
  458.                                                  currentEOP[3], lod,
  459.                                                  currentEOP[1] * Constants.ARC_SECONDS_TO_RADIANS,
  460.                                                  currentEOP[2] * Constants.ARC_SECONDS_TO_RADIANS,
  461.                                                  0.0, 0.0, 0.0, 0.0));
  462.                     } else {
  463.                         // we have complete data
  464.                         history.add(new EOPEntry(mjd,
  465.                                                  currentEOP[3], lod,
  466.                                                  currentEOP[1]  * Constants.ARC_SECONDS_TO_RADIANS,
  467.                                                  currentEOP[2]  * Constants.ARC_SECONDS_TO_RADIANS,
  468.                                                  currentPole[1] * MILLI_ARC_SECONDS_TO_RADIANS,
  469.                                                  currentPole[2] * MILLI_ARC_SECONDS_TO_RADIANS,
  470.                                                  currentPole[3] * MILLI_ARC_SECONDS_TO_RADIANS,
  471.                                                  currentPole[4] * MILLI_ARC_SECONDS_TO_RADIANS));
  472.                     }
  473.                 }

  474.             }

  475.         }

  476.         /** Skip to next section header.
  477.          * @param sections sections to check for
  478.          * @param reader reader from where file content is obtained
  479.          * @param name name of the file (or zip entry)
  480.          * @return the next section or null if no section is found until end of file
  481.          * @exception IOException if data can't be read
  482.          */
  483.         private Section nextSection(final List<Section> sections,
  484.                                     final BufferedReader reader, final String name)
  485.             throws IOException {

  486.             for (line = reader.readLine(); line != null; line = reader.readLine()) {
  487.                 ++lineNumber;
  488.                 for (Section section : sections) {
  489.                     if (section.matchesHeader(line)) {
  490.                         return section;
  491.                     }
  492.                 }
  493.             }

  494.             // we have reached end of file and not found a matching section header
  495.             return null;

  496.         }

  497.         /** Read X, Y, UT1-UTC.
  498.          * @param section section to parse
  499.          * @param reader reader from where file content is obtained
  500.          * @param name name of the file (or zip entry)
  501.          * @exception IOException if data can't be read
  502.          * @exception OrekitException if some data is missing or if some loader specific error occurs
  503.          */
  504.         private void loadXYDT(final Section section, final BufferedReader reader, final String name)
  505.             throws OrekitException, IOException {

  506.             boolean inValuesPart = false;
  507.             for (line = reader.readLine(); line != null; line = reader.readLine()) {
  508.                 lineNumber++;
  509.                 final String[] fields = section.getFields(line);
  510.                 if (fields != null) {

  511.                     // we are within the values part
  512.                     inValuesPart = true;

  513.                     // this is a data line, build an entry from the extracted fields
  514.                     final int year  = Integer.parseInt(fields[0]);
  515.                     final int month = Integer.parseInt(fields[1]);
  516.                     final int day   = Integer.parseInt(fields[2]);
  517.                     final int mjd   = Integer.parseInt(fields[3]);
  518.                     final DateComponents dc = new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, mjd);
  519.                     if ((dc.getYear() % 100) != (year % 100) ||
  520.                          dc.getMonth() != month ||
  521.                          dc.getDay() != day) {
  522.                         throw new OrekitException(OrekitMessages.INCONSISTENT_DATES_IN_IERS_FILE,
  523.                                                   name, year, month, day, mjd);
  524.                     }
  525.                     mjdMin = FastMath.min(mjdMin, mjd);
  526.                     mjdMax = FastMath.max(mjdMax, mjd);
  527.                     if (firstMJD < 0) {
  528.                         // store the first mjd parsed
  529.                         firstMJD = mjd;
  530.                     }

  531.                     // get the entry at the same date if it was already parsed
  532.                     final double[] eop;
  533.                     if (eopFieldsMap.containsKey(mjd)) {
  534.                         eop = eopFieldsMap.get(mjd);
  535.                     } else {
  536.                         eop = new double[4];
  537.                         eopFieldsMap.put(mjd, eop);
  538.                     }

  539.                     if (eop[0] <= firstMJD) {
  540.                         // either it is the first time we parse this date (eop[0] = 0),
  541.                         // or the new parsed data is from a more recent file
  542.                         // in both case, we should update the array
  543.                         eop[0] = firstMJD;
  544.                         eop[1] = Double.parseDouble(fields[4]);
  545.                         eop[2] = Double.parseDouble(fields[5]);
  546.                         eop[3] = Double.parseDouble(fields[6]);
  547.                     }

  548.                 } else if (inValuesPart) {
  549.                     // we leave values part
  550.                     return;
  551.                 }
  552.             }

  553.             throw new OrekitException(OrekitMessages.UNEXPECTED_END_OF_FILE_AFTER_LINE,
  554.                                       name, lineNumber);

  555.         }

  556.         /** Read EOP data.
  557.          * @param section section to parse
  558.          * @param isNonRotatingOrigin if true, the file contain Non-Rotating Origin nutation corrections
  559.          * @param reader reader from where file content is obtained
  560.          * @param name name of the file (or zip entry)
  561.          * @exception IOException if data can't be read
  562.          * @exception OrekitException if some data is missing or if some loader specific error occurs
  563.          */
  564.         private void loadPoleOffsets(final Section section, final boolean isNonRotatingOrigin,
  565.                                      final BufferedReader reader, final String name)
  566.             throws OrekitException, IOException {

  567.             boolean inValuesPart = false;
  568.             for (line = reader.readLine(); line != null; line = reader.readLine()) {
  569.                 lineNumber++;
  570.                 final String[] fields = section.getFields(line);
  571.                 if (fields != null) {

  572.                     // we are within the values part
  573.                     inValuesPart = true;

  574.                     // this is a data line, build an entry from the extracted fields
  575.                     final int mjd = Integer.parseInt(fields[0]);
  576.                     mjdMin = FastMath.min(mjdMin, mjd);
  577.                     mjdMax = FastMath.max(mjdMax, mjd);

  578.                     // get the entry at the same date if it was already parsed
  579.                     final double[] pole;
  580.                     if (poleOffsetsFieldsMap.containsKey(mjd)) {
  581.                         pole = poleOffsetsFieldsMap.get(mjd);
  582.                     } else {
  583.                         pole = new double[5];
  584.                         poleOffsetsFieldsMap.put(mjd, pole);
  585.                     }

  586.                     if (pole[0] <= firstMJD) {
  587.                         // either it is the first time we parse this date (pole[0] = 0),
  588.                         // or the new parsed data is from a more recent file
  589.                         // in both case, we should update the array
  590.                         pole[0] = firstMJD;
  591.                         if (isNonRotatingOrigin) {
  592.                             pole[1] = Double.parseDouble(fields[1]);
  593.                             pole[2] = Double.parseDouble(fields[2]);
  594.                         } else {
  595.                             pole[3] = Double.parseDouble(fields[1]);
  596.                             pole[4] = Double.parseDouble(fields[2]);
  597.                         }
  598.                     }

  599.                 } else if (inValuesPart) {
  600.                     // we leave values part
  601.                     return;
  602.                 }
  603.             }

  604.             throw new OrekitException(OrekitMessages.UNEXPECTED_END_OF_FILE_AFTER_LINE,
  605.                                       name, lineNumber);

  606.         }

  607.     }

  608. }