-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
250 lines (205 loc) · 7.97 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package jpl
import (
"encoding/binary"
"io"
)
// CelestialBody represents various celestial bodies as integer constants.
type CelestialBody int
const (
Mercury CelestialBody = iota
Venus
Earth
Mars
Jupiter
Saturn
Uranus
Neptune
Pluto
Moon
Sun
SolarSystemBarycenter
EarthMoonBarycenter
Nutations
Librations
)
// NotAvailable is used to indicate unavailable or undefined data.
const NotAvailable = -1
// FileReader defines an interface for file operations used in JPL.
type FileReader interface {
io.Reader
io.Seeker
io.Closer
}
// headerValidator defines an interface for validating and reading file headers.
type headerValidator interface {
readAndValidateHeader() error
readJplHeader() (irecsz int32, ncoeffs int32, err error)
checkJplFileIntegrity(irecsz int32) error
}
// constantsReader defines an interface for reading constants and parameters.
type constantsReader interface {
readConstantsAndParameters(au *float64, emrat *float64, lpt []int32, numde *int32, ncon *int32) error
readConstJpl() ([]float64, error)
}
// celestialBodyHandler defines an interface for handling specific celestial body interactions.
type celestialBodyHandler interface {
handleNutation(et float64, pv, pvsun []float64) ([]float64, error)
handleLibration(et float64, pv, pvsun []float64) ([]float64, error)
handleEarthMoonInteraction(list []int32, pv []float64)
}
// interpolationHelper defines an interface for functions related to interpolation calculations.
type interpolationHelper interface {
setupListForState(ntarg, ncent CelestialBody) []int32
adjustPositionsForSunEMBBary(ntarg, ncent CelestialBody, pv, pvsun []float64)
computeSubInterval(t float64, na int32) (tc float64, ni int32)
evaluatePolynomials(pc []float64, tc float64, ncf int32) (twot float64)
interpolatePosition(pv []float64, pc []float64, buf []float64, ncf, ncm, ni int32)
interpolateVelocity(pv []float64, vc, pc [18]float64, buf []float64, ncf, ncm, ni int32, bma float64)
interpolateAcceleration(pv []float64, ac [18]float64, buf []float64, ncf, ncm, ni int32, bma2 float64)
interpolateJerk(pv []float64, jc [18]float64, buf []float64, ncf, ncm, ni int32, bma3 float64)
}
// ephemerisHandler defines a combined interface for handling state calculations,
type ephemerisHandler interface {
state(et float64, list []int32, doBary bool, pv, pvsun, rrd []float64) error
EphemerisLookup(et float64, ntarg, ncent CelestialBody) ([]float64, error)
interpolation(buf []float64, t, intv float64, ncfin, ncmin, nain, ifl int32, pv []float64) error
interpolateBodies(list []int32, doBary bool, aufac, t, intv float64, pv, pvsun []float64)
interpolateSunPosition(t, intv float64, pvsun []float64)
interpolateLibrations(list []int32, t, intv float64, pv []float64)
interpolateNutations(list []int32, t, intv float64, nut []float64)
}
// jplFileManager defines an interface for file management operations.
type jplFileManager interface {
openJplFile() ([]float64, error)
loadJPLRecord(nr int32, irecsz int32, ncoeffs int32) error
fsizer() (int32, error)
}
// JPL is the main struct that implements all the interfaces.
type JPL struct {
JplFile FileReader
Endian binary.ByteOrder
Constants struct {
Cval [400]float64
SS [3]float64
AU float64
Emrat float64
Denum int32
Ncon int32
IPT [39]int32
}
ChCnam [6 * 400]byte
PV [78]float64
PVSun [6]float64
Buf [1500]float64
Chebyshev struct {
PC [18]float64
VC [18]float64
AC [18]float64
JC [18]float64
}
DoKm bool
DebugMode bool
ephemerisHandler ephemerisHandler
headerValidator headerValidator
constantsReader constantsReader
fileManager jplFileManager
celestialBodyHandler celestialBodyHandler
interpolationHelper interpolationHelper
}
// Separate structs for each interface implementation
type jplFileManagerImpl struct {
jpl *JPL
}
func (fm *jplFileManagerImpl) openJplFile() ([]float64, error) {
return fm.jpl.openJplFile()
}
func (fm *jplFileManagerImpl) loadJPLRecord(nr int32, irecsz int32, ncoeffs int32) error {
return fm.jpl.loadJPLRecord(nr, irecsz, ncoeffs)
}
func (fm *jplFileManagerImpl) fsizer() (int32, error) {
return fm.jpl.fsizer()
}
type headerValidatorImpl struct {
jpl *JPL
}
func (hv *headerValidatorImpl) readAndValidateHeader() error {
return hv.jpl.readAndValidateHeader()
}
func (hv *headerValidatorImpl) readJplHeader() (int32, int32, error) {
return hv.jpl.readJplHeader()
}
func (hv *headerValidatorImpl) checkJplFileIntegrity(irecsz int32) error {
return hv.jpl.checkJplFileIntegrity(irecsz)
}
type constantsReaderImpl struct {
jpl *JPL
}
func (cr *constantsReaderImpl) readConstantsAndParameters(au *float64, emrat *float64, lpt []int32, numde *int32, ncon *int32) error {
return cr.jpl.readConstantsAndParameters(au, emrat, lpt, numde, ncon)
}
func (cr *constantsReaderImpl) readConstJpl() ([]float64, error) {
return cr.jpl.readConstJpl()
}
type celestialBodyHandlerImpl struct {
jpl *JPL
}
func (cb *celestialBodyHandlerImpl) handleNutation(et float64, pv, pvsun []float64) ([]float64, error) {
return cb.jpl.handleNutation(et, pv, pvsun)
}
func (cb *celestialBodyHandlerImpl) handleLibration(et float64, pv, pvsun []float64) ([]float64, error) {
return cb.jpl.handleLibration(et, pv, pvsun)
}
func (cb *celestialBodyHandlerImpl) handleEarthMoonInteraction(list []int32, pv []float64) {
cb.jpl.handleEarthMoonInteraction(list, pv)
}
type interpolationHelperImpl struct {
jpl *JPL
}
func (ih *interpolationHelperImpl) setupListForState(ntarg, ncent CelestialBody) []int32 {
return ih.jpl.setupListForState(ntarg, ncent)
}
func (ih *interpolationHelperImpl) adjustPositionsForSunEMBBary(ntarg, ncent CelestialBody, pv, pvsun []float64) {
ih.jpl.adjustPositionsForSunEMBBary(ntarg, ncent, pv, pvsun)
}
func (ih *interpolationHelperImpl) computeSubInterval(t float64, na int32) (tc float64, ni int32) {
return ih.jpl.computeSubInterval(t, na)
}
func (ih *interpolationHelperImpl) evaluatePolynomials(pc []float64, tc float64, ncf int32) (twot float64) {
return ih.jpl.evaluatePolynomials(pc, tc, ncf)
}
func (ih *interpolationHelperImpl) interpolatePosition(pv []float64, pc []float64, buf []float64, ncf, ncm, ni int32) {
ih.jpl.interpolatePosition(pv, pc, buf, ncf, ncm, ni)
}
func (ih *interpolationHelperImpl) interpolateVelocity(pv []float64, vc, pc [18]float64, buf []float64, ncf, ncm, ni int32, bma float64) {
ih.jpl.interpolateVelocity(pv, vc, pc, buf, ncf, ncm, ni, bma)
}
func (ih *interpolationHelperImpl) interpolateAcceleration(pv []float64, ac [18]float64, buf []float64, ncf, ncm, ni int32, bma2 float64) {
ih.jpl.interpolateAcceleration(pv, ac, buf, ncf, ncm, ni, bma2)
}
func (ih *interpolationHelperImpl) interpolateJerk(pv []float64, jc [18]float64, buf []float64, ncf, ncm, ni int32, bma3 float64) {
ih.jpl.interpolateJerk(pv, jc, buf, ncf, ncm, ni, bma3)
}
type ephemerisHandlerImpl struct {
jpl *JPL
}
func (eh *ephemerisHandlerImpl) state(et float64, list []int32, doBary bool, pv, pvsun, rrd []float64) error {
return eh.jpl.state(et, list, doBary, pv, pvsun, rrd)
}
func (eh *ephemerisHandlerImpl) EphemerisLookup(et float64, ntarg, ncent CelestialBody) ([]float64, error) {
return eh.jpl.EphemerisLookup(et, ntarg, ncent)
}
func (eh *ephemerisHandlerImpl) interpolation(buf []float64, t, intv float64, ncfin, ncmin, nain, ifl int32, pv []float64) error {
return eh.jpl.interpolation(buf, t, intv, ncfin, ncmin, nain, ifl, pv)
}
func (eh *ephemerisHandlerImpl) interpolateBodies(list []int32, doBary bool, aufac, t, intv float64, pv, pvsun []float64) {
eh.jpl.interpolateBodies(list, doBary, aufac, t, intv, pv, pvsun)
}
func (eh *ephemerisHandlerImpl) interpolateSunPosition(t, intv float64, pvsun []float64) {
eh.jpl.interpolateSunPosition(t, intv, pvsun)
}
func (eh *ephemerisHandlerImpl) interpolateLibrations(list []int32, t, intv float64, pv []float64) {
eh.jpl.interpolateLibrations(list, t, intv, pv)
}
func (eh *ephemerisHandlerImpl) interpolateNutations(list []int32, t, intv float64, nut []float64) {
eh.jpl.interpolateNutations(list, t, intv, nut)
}