1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  package org.orekit.time;
18  
19  import java.util.concurrent.ConcurrentHashMap;
20  import java.util.concurrent.ConcurrentMap;
21  
22  import org.hipparchus.util.MathArrays;
23  import org.hipparchus.util.Pair;
24  import org.orekit.frames.EOPHistory;
25  import org.orekit.utils.Constants;
26  import org.orekit.utils.IERSConventions;
27  
28  
29  
30  
31  
32  
33  
34  
35  public abstract class AbstractTimeScales implements TimeScales {
36  
37      
38      private final ConcurrentMap<Pair<IERSConventions, Boolean>, GMSTScale> gmstMap;
39      
40      private final ConcurrentMap<Pair<IERSConventions, Boolean>, UT1Scale> ut1Map;
41  
42      
43      public AbstractTimeScales() {
44          final int n = IERSConventions.values().length;
45          gmstMap = new ConcurrentHashMap<>(n * 2);
46          ut1Map = new ConcurrentHashMap<>(n * 2);
47      }
48  
49      
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65      protected UT1Scale getUT1(final EOPHistory history) {
66          return new UT1Scale(history, getUTC());
67      }
68  
69      
70  
71  
72  
73  
74  
75  
76      protected abstract EOPHistory getEopHistory(IERSConventions conventions,
77                                                  boolean simpleEOP);
78  
79      @Override
80      public UT1Scale getUT1(final IERSConventions conventions, final boolean simpleEOP) {
81          final Pair<IERSConventions, Boolean> key = new Pair<>(conventions, simpleEOP);
82          synchronized (this) {
83              return ut1Map.computeIfAbsent(key, k -> getUT1(getEopHistory(conventions, simpleEOP)));
84          }
85      }
86  
87      @Override
88      public GMSTScale getGMST(final IERSConventions conventions, final boolean simpleEOP) {
89          final Pair<IERSConventions, Boolean> key = new Pair<>(conventions, simpleEOP);
90          synchronized (this) {
91              return gmstMap.computeIfAbsent(key, k -> new GMSTScale(getUT1(conventions, simpleEOP)));
92          }
93      }
94  
95      @Override
96      public AbsoluteDate getJulianEpoch() {
97          return new AbsoluteDate(DateComponents.JULIAN_EPOCH, TimeComponents.H12, this.getTT());
98      }
99  
100     @Override
101     public AbsoluteDate getModifiedJulianEpoch() {
102         return new AbsoluteDate(DateComponents.MODIFIED_JULIAN_EPOCH, TimeComponents.H00, this.getTT());
103     }
104 
105     @Override
106     public AbsoluteDate getFiftiesEpoch() {
107         return new AbsoluteDate(DateComponents.FIFTIES_EPOCH, TimeComponents.H00, this.getTT());
108     }
109 
110     @Override
111     public AbsoluteDate getCcsdsEpoch() {
112         return new AbsoluteDate(DateComponents.CCSDS_EPOCH, TimeComponents.H00, this.getTAI());
113     }
114 
115     @Override
116     public AbsoluteDate getGalileoEpoch() {
117         return new AbsoluteDate(DateComponents.GALILEO_EPOCH, TimeComponents.H00, this.getGST());
118     }
119 
120     @Override
121     public AbsoluteDate getGpsEpoch() {
122         return new AbsoluteDate(DateComponents.GPS_EPOCH, TimeComponents.H00, this.getGPS());
123     }
124 
125     @Override
126     public AbsoluteDate getQzssEpoch() {
127         return new AbsoluteDate(DateComponents.QZSS_EPOCH, TimeComponents.H00, this.getQZSS());
128     }
129 
130     @Override
131     public AbsoluteDate getNavicEpoch() {
132         return new AbsoluteDate(DateComponents.NAVIC_EPOCH, TimeComponents.H00, this.getNavIC());
133     }
134 
135     @Override
136     public AbsoluteDate getBeidouEpoch() {
137         return new AbsoluteDate(DateComponents.BEIDOU_EPOCH, TimeComponents.H00, this.getBDT());
138     }
139 
140     @Override
141     public AbsoluteDate getGlonassEpoch() {
142         return new AbsoluteDate(DateComponents.GLONASS_EPOCH,
143                                 new TimeComponents(new TimeOffset(29L, 0L)), this.getTAI()).shiftedBy(new TimeOffset(-10800L, 0L));
144     }
145 
146     @Override
147     public AbsoluteDate getJ2000Epoch() {
148         return new AbsoluteDate(DateComponents.J2000_EPOCH, TimeComponents.H12, this.getTT());
149     }
150 
151     @Override
152     public AbsoluteDate getJavaEpoch() {
153         return new AbsoluteDate(DateComponents.JAVA_EPOCH, this.getTAI()).shiftedBy(new TimeOffset(8L, 82000000000000L));
154     }
155 
156     @Override
157     public AbsoluteDate getPastInfinity() {
158         return getJavaEpoch().shiftedBy(Double.NEGATIVE_INFINITY);
159     }
160 
161     @Override
162     public AbsoluteDate getFutureInfinity() {
163         return getJavaEpoch().shiftedBy(Double.POSITIVE_INFINITY);
164     }
165 
166     @Override
167     public AbsoluteDate createJulianEpoch(final double julianEpoch) {
168         return new AbsoluteDate(getJ2000Epoch(),
169                 Constants.JULIAN_YEAR * (julianEpoch - 2000.0));
170     }
171 
172     @Override
173     public AbsoluteDate createBesselianEpoch(final double besselianEpoch) {
174         return new AbsoluteDate(getJ2000Epoch(),
175                 MathArrays.linearCombination(
176                         Constants.BESSELIAN_YEAR, besselianEpoch - 1900,
177                         Constants.JULIAN_DAY, -36525,
178                         Constants.JULIAN_DAY, 0.31352));
179     }
180 
181 }