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  
19  import org.orekit.models.earth.displacement.PsdCorrection;
20  import org.orekit.time.AbsoluteDate;
21  import org.orekit.utils.Constants;
22  
23  import java.util.function.Predicate;
24  
25  /** Predicates for Post-Seismic Deformation lines.
26   * @author Luc Maisonobe
27   * @since 13.0
28   */
29  enum PsdPredicate implements Predicate<SinexParseInfo> {
30  
31      /** Predicate for AEXP_E line. */
32      AEXP_E {
33          protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
34                               final AbsoluteDate epoch) {
35              parseInfo.setEvolution(PsdCorrection.TimeEvolution.EXP);
36              parseInfo.setAxis(PsdCorrection.Axis.EAST);
37              parseInfo.setAmplitude(value, station, epoch);
38          }
39      },
40  
41      /** Predicate for TEXP_E line. */
42      TEXP_E {
43          protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
44                               final AbsoluteDate epoch) {
45              parseInfo.setEvolution(PsdCorrection.TimeEvolution.EXP);
46              parseInfo.setAxis(PsdCorrection.Axis.EAST);
47              parseInfo.setRelaxationTime(value * Constants.JULIAN_YEAR, station, epoch);
48          }
49      },
50  
51      /** Predicate for ALOG_E line. */
52      ALOG_E {
53          protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
54                               final AbsoluteDate epoch) {
55              parseInfo.setEvolution(PsdCorrection.TimeEvolution.LOG);
56              parseInfo.setAxis(PsdCorrection.Axis.EAST);
57              parseInfo.setAmplitude(value, station, epoch);
58          }
59      },
60  
61      /** Predicate for TLOG_E line. */
62      TLOG_E {
63          protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
64                               final AbsoluteDate epoch) {
65              parseInfo.setEvolution(PsdCorrection.TimeEvolution.LOG);
66              parseInfo.setAxis(PsdCorrection.Axis.EAST);
67              parseInfo.setRelaxationTime(value * Constants.JULIAN_YEAR, station, epoch);
68          }
69      },
70  
71      /** Predicate for AEXP_N line. */
72      AEXP_N {
73          protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
74                               final AbsoluteDate epoch) {
75              parseInfo.setEvolution(PsdCorrection.TimeEvolution.EXP);
76              parseInfo.setAxis(PsdCorrection.Axis.NORTH);
77              parseInfo.setAmplitude(value, station, epoch);
78          }
79      },
80  
81      /** Predicate for TEXP_N line. */
82      TEXP_N {
83          protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
84                               final AbsoluteDate epoch) {
85              parseInfo.setEvolution(PsdCorrection.TimeEvolution.EXP);
86              parseInfo.setAxis(PsdCorrection.Axis.NORTH);
87              parseInfo.setRelaxationTime(value * Constants.JULIAN_YEAR, station, epoch);
88          }
89      },
90  
91      /** Predicate for ALOG_N line. */
92      ALOG_N {
93          protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
94                               final AbsoluteDate epoch) {
95              parseInfo.setEvolution(PsdCorrection.TimeEvolution.LOG);
96              parseInfo.setAxis(PsdCorrection.Axis.NORTH);
97              parseInfo.setAmplitude(value, station, epoch);
98          }
99      },
100 
101     /** Predicate for TLOG_N line. */
102     TLOG_N {
103         protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
104                              final AbsoluteDate epoch) {
105             parseInfo.setEvolution(PsdCorrection.TimeEvolution.LOG);
106             parseInfo.setAxis(PsdCorrection.Axis.NORTH);
107             parseInfo.setRelaxationTime(value * Constants.JULIAN_YEAR, station, epoch);
108         }
109     },
110 
111     /** Predicate for AEXP_U line. */
112     AEXP_U {
113         protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
114                              final AbsoluteDate epoch) {
115             parseInfo.setEvolution(PsdCorrection.TimeEvolution.EXP);
116             parseInfo.setAxis(PsdCorrection.Axis.UP);
117             parseInfo.setAmplitude(value, station, epoch);
118         }
119     },
120 
121     /** Predicate for TEXP_U line. */
122     TEXP_U {
123         protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
124                              final AbsoluteDate epoch) {
125             parseInfo.setEvolution(PsdCorrection.TimeEvolution.EXP);
126             parseInfo.setAxis(PsdCorrection.Axis.UP);
127             parseInfo.setRelaxationTime(value * Constants.JULIAN_YEAR, station, epoch);
128         }
129     },
130 
131     /** Predicate for ALOG_U line. */
132     ALOG_U {
133         protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
134                              final AbsoluteDate epoch) {
135             parseInfo.setEvolution(PsdCorrection.TimeEvolution.LOG);
136             parseInfo.setAxis(PsdCorrection.Axis.UP);
137             parseInfo.setAmplitude(value, station, epoch);
138         }
139     },
140 
141     /** Predicate for TLOG_U line. */
142     TLOG_U {
143         protected void store(final SinexParseInfo parseInfo, final double value, final Station station,
144                              final AbsoluteDate epoch) {
145             parseInfo.setEvolution(PsdCorrection.TimeEvolution.LOG);
146             parseInfo.setAxis(PsdCorrection.Axis.UP);
147             parseInfo.setRelaxationTime(value * Constants.JULIAN_YEAR, station, epoch);
148         }
149     };
150 
151     /** {@inheritDoc} */
152     @Override
153     public boolean test(final SinexParseInfo parseInfo) {
154         if (name().equals(parseInfo.parseString(7, 6))) {
155             // this is the data type we are concerned with
156             store(parseInfo, parseInfo.parseDouble(47, 22),
157                   parseInfo.getCurrentLineStation(14),
158                   parseInfo.stringEpochToAbsoluteDate(parseInfo.parseString(27, 12), false));
159             return true;
160         } else {
161             // it is a data type for another predicate
162             return false;
163         }
164     }
165 
166     /**
167      * Store parsed fields.
168      *
169      * @param parseInfo container for parse info
170      * @param value     parsed value
171      * @param station   station
172      * @param epoch     current epoch
173      */
174     protected abstract void store(SinexParseInfo parseInfo, double value, Station station, AbsoluteDate epoch);
175 
176 }