SinexParser.java

  1. /* Copyright 2022-2025 Luc Maisonobe
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.files.sinex;

  18. import org.orekit.time.TimeScales;

  19. import java.util.ArrayList;
  20. import java.util.Arrays;
  21. import java.util.Collections;
  22. import java.util.List;

  23. /** Parser for Solution INdependent EXchange (SINEX) files.
  24.  * <p>
  25.  * The parser can be used to load several data types contained in Sinex files.
  26.  * The current supported data are: station coordinates, site eccentricities, EOP.
  27.  * </p>
  28.  * <p>
  29.  * The parsing of EOP parameters for multiple data sources in different SinexParser objects might pose
  30.  * a problem in case validity dates are overlapping. As Sinex daily solution files provide a single EOP
  31.  * entry, the Sinex parser will add points at the limits of data dates (startDate, endDate) of the Sinex
  32.  * file, which in case of overlap will lead to inconsistencies in the final EOPHistory object. Multiple
  33.  * data sources can be parsed using a single SinexParser to overcome this issue.
  34.  * </p>
  35.  * @author Luc Maisonobe
  36.  * @since 13.0
  37.  */
  38. public class SinexParser extends AbstractSinexParser<Sinex, SinexParseInfo> {

  39.     /** Top level parsers. */
  40.     private final List<LineParser<SinexParseInfo>> topParsers;

  41.     /** Simple constructor.
  42.      * @param timeScales time scales
  43.      */
  44.     public SinexParser(final TimeScales timeScales) {

  45.         super(timeScales);

  46.         // set up parsers for supported blocks
  47.         final List<BlockParser<SinexParseInfo>> blockParsers = new ArrayList<>();
  48.         blockParsers.add(new BlockParser<>("SITE/ID",
  49.                                            Collections.singletonList(SingleLineBlockPredicate.SITE_ID)));
  50.         blockParsers.add(new BlockParser<>("SITE/ANTENNA",
  51.                                            Collections.singletonList(SingleLineBlockPredicate.SITE_ANTENNA)));
  52.         blockParsers.add(new BlockParser<>("SITE/GPS_PHASE_CENTER",
  53.                                            Collections.singletonList(SingleLineBlockPredicate.SITE_GPS_PHASE_CENTER)));
  54.         blockParsers.add(new BlockParser<>("SITE/GAL_PHASE_CENTER",
  55.                                            Collections.singletonList(SingleLineBlockPredicate.SITE_GAL_PHASE_CENTER)));
  56.         blockParsers.add(new BlockParser<>("SITE/ECCENTRICITY",
  57.                                            Collections.singletonList(SingleLineBlockPredicate.SITE_ECCENTRICITY)));
  58.         blockParsers.add(new BlockParser<>("SATELLITE/PHASE_CENTER",
  59.                                            Collections.singletonList(SingleLineBlockPredicate.SATELLITE_PHASE_CENTER)));
  60.         blockParsers.add(new BlockParser<>("SOLUTION/EPOCHS",
  61.                                            Collections.singletonList(SingleLineBlockPredicate.SOLUTION_EPOCHS)));
  62.         blockParsers.add(new BlockParser<>("SOLUTION/ESTIMATE",
  63.                                            Arrays.asList(StationPredicate.STAX, StationPredicate.STAY, StationPredicate.STAZ,
  64.                                                          StationPredicate.VELX, StationPredicate.VELY, StationPredicate.VELZ,
  65.                                                          PsdPredicate.AEXP_E, PsdPredicate.TEXP_E,
  66.                                                          PsdPredicate.ALOG_E, PsdPredicate.TLOG_E,
  67.                                                          PsdPredicate.AEXP_N, PsdPredicate.TEXP_N,
  68.                                                          PsdPredicate.ALOG_N, PsdPredicate.TLOG_N,
  69.                                                          PsdPredicate.AEXP_U, PsdPredicate.TEXP_U,
  70.                                                          PsdPredicate.ALOG_U, PsdPredicate.TLOG_U,
  71.                                                          EopPredicate.XPO,    EopPredicate.YPO,
  72.                                                          EopPredicate.LOD,    EopPredicate.UT,
  73.                                                          EopPredicate.NUT_LN, EopPredicate.NUT_OB,
  74.                                                          EopPredicate.NUT_X,  EopPredicate.NUT_Y,
  75.                                                          new IgnoredBlockContentPredicate<>())));

  76.         // append at the end of the list one catch-all parser ignoring all remaining not supported blocks
  77.         blockParsers.add(new IgnoredBlockParser<>());

  78.         // add the parser for the footer
  79.         topParsers = new ArrayList<>(blockParsers);
  80.         topParsers.add(new FooterParser<>("%ENDSNX"));

  81.         // set up siblings
  82.         blockParsers.forEach(parser -> parser.setSiblingParsers(topParsers));

  83.     }

  84.     /** {@inheritDoc} */
  85.     @Override
  86.     protected LineParser<SinexParseInfo> firstLineParser() {
  87.         return new VersionParser<SinexParseInfo>("SNX") {
  88.             /** {@inheritDoc} */
  89.             @Override
  90.             public Iterable<LineParser<SinexParseInfo>> allowedNextParsers(final SinexParseInfo parseInfo) {
  91.                 return topParsers;
  92.             }
  93.         };
  94.     }

  95.     /** {@inheritDoc} */
  96.     @Override
  97.     protected SinexParseInfo buildParseInfo() {
  98.         final SinexParseInfo parseInfo = new SinexParseInfo(getTimeScales());
  99.         parseInfo.setTimeScale(getTimeScales().getUTC());
  100.         return parseInfo;
  101.     }

  102. }