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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const NABCOR: i32 = 15;
const ABATSZ: i32 = 6;
const GEOIDX: i32 = 1;
const LTIDX: i32 = (GEOIDX + 1);
const STLIDX: i32 = (LTIDX + 1);
const CNVIDX: i32 = (STLIDX + 1);
const XMTIDX: i32 = (CNVIDX + 1);
const RELIDX: i32 = (XMTIDX + 1);
const CORLEN: i32 = 5;
const SSB: i32 = 0;
//$Procedure T_GETSA ( Test utility, get stellar aberration )
pub fn T_GETSA(
TARG: i32,
ET: f64,
REF: &[u8],
ABCORR: &[u8],
OBS: i32,
PCORR: &mut [f64],
DPCORR: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut PCORR = DummyArrayMut::new(PCORR, 1..=3);
let mut DPCORR = DummyArrayMut::new(DPCORR, 1..=3);
let mut ACC = StackArray::<f64, 3>::new(1..=3);
let mut DELTA: f64 = 0.0;
let mut DLT: f64 = 0.0;
let mut DLTCTR: f64 = 0.0;
let mut LT: f64 = 0.0;
let mut LTCENT: f64 = 0.0;
let mut LTSIGN: f64 = 0.0;
let mut LTSSB: f64 = 0.0;
let mut SASTAT = StackArray::<f64, 6>::new(1..=6);
let mut SSBOBS = StackArray::<f64, 6>::new(1..=6);
let mut STATE = StackArray::<f64, 6>::new(1..=6);
let mut STCTR = StackArray::<f64, 6>::new(1..=6);
let mut STOBS = StackArray2D::<f64, 12>::new(1..=6, 1..=2);
let mut T: f64 = 0.0;
let mut XFORM = StackArray2D::<f64, 36>::new(1..=6, 1..=6);
let mut XSTATE = StackArray::<f64, 6>::new(1..=6);
let mut CENTER: i32 = 0;
let mut REQFRM: i32 = 0;
let mut TYPE: i32 = 0;
let mut TYPEID: i32 = 0;
let mut ATTBLK = StackArray::<bool, 6>::new(1..=ABATSZ);
let mut FOUND: bool = false;
let mut XMIT: bool = false;
//
// SPICELIB functions
//
//
// Local parameters
//
//
// Local variables
//
spicelib::CHKIN(b"T_GETSA", ctx)?;
//
// Compute the corrections in the J2000 frame. We'll
// transform them later to the requested frame.
//
spicelib::ZZPRSCOR(ABCORR, ATTBLK.as_slice_mut(), ctx)?;
XMIT = ATTBLK[XMTIDX];
DELTA = 1.0;
//
// Determine the acceleration of the observer with
// respect to the solar system barycenter at ET.
// Use a quadratic estimate.
//
for I in 1..=2 {
T = (ET + ((((2 * I) - 3) as f64) * DELTA));
spicelib::SPKGEO(
OBS,
T,
b"J2000",
SSB,
STOBS.subarray_mut([1, I]),
&mut LTSSB,
ctx,
)?;
}
spicelib::QDERIV(
3,
STOBS.subarray([4, 1]),
STOBS.subarray([4, 2]),
DELTA,
ACC.as_slice_mut(),
ctx,
)?;
//
// Get the light-time corrected state of the target with respect
// to the observer. Also get the geometric state of the observer
// with respect to the solar system barycenter at ET.
//
spicelib::SPKSSB(OBS, ET, b"J2000", SSBOBS.as_slice_mut(), ctx)?;
spicelib::SPKLTC(
TARG,
ET,
b"J2000",
ABCORR,
SSBOBS.as_slice(),
STATE.as_slice_mut(),
&mut LT,
&mut DLT,
ctx,
)?;
//
// Get the stellar aberration correction and its time derivative.
// Note that the input observer state relative to the solar system
// barycenter was obtained from SPKLTC.
//
spicelib::ZZSTELAB(
XMIT,
ACC.as_slice(),
SSBOBS.subarray(4),
STATE.as_slice(),
PCORR.as_slice_mut(),
DPCORR.as_slice_mut(),
ctx,
)?;
//
// Get the transformation from J2000 to the request frame. This
// transformation should be evaluated at the light-time corrected
// epoch associated with the center of the request frame.
//
spicelib::NAMFRM(REF, &mut REQFRM, ctx)?;
if (REQFRM == 0) {
spicelib::SETMSG(b"The requested output frame \'#\' is not recognized by the reference frame subsystem. Please check that the appropriate kernels have been loaded and that you have correctly entered the name of the output frame. ", ctx);
spicelib::ERRCH(b"#", REF, ctx);
spicelib::SIGERR(b"SPICE(UNKNOWNFRAME)", ctx)?;
spicelib::CHKOUT(b"T_GETSA", ctx)?;
return Ok(());
}
//
// If we reach this point, FOUND will be .TRUE. after
// the following call to FRINFO:
//
spicelib::FRINFO(REQFRM, &mut CENTER, &mut TYPE, &mut TYPEID, &mut FOUND, ctx)?;
//
// Get light time to the frame's center.
//
if (CENTER == OBS) {
LTCENT = 0.0;
DLTCTR = 0.0;
} else if (CENTER == TARG) {
LTCENT = LT;
DLTCTR = DLT;
} else {
spicelib::SPKLTC(
CENTER,
ET,
b"J2000",
ABCORR,
SSBOBS.as_slice(),
STCTR.as_slice_mut(),
&mut LTCENT,
&mut DLTCTR,
ctx,
)?;
}
//
// If something went wrong (like we couldn't get the state of
// the center relative to the observer) now it is time to quit.
//
if spicelib::FAILED(ctx) {
spicelib::CHKOUT(b"T_GETSA", ctx)?;
return Ok(());
}
//
// If the aberration corrections are for transmission, make the sign
// of the light time positive, since we wish to compute the
// orientation of the non-inertial frame at an epoch later than ET
// by the one-way light time.
//
if XMIT {
LTSIGN = 1 as f64;
} else {
LTSIGN = -1 as f64;
}
//
// Look up the transformation from J2000 to REF at the light time
// corrected epoch.
//
spicelib::SXFORM(
b"J2000",
REF,
(ET + (LTSIGN * LTCENT)),
XFORM.as_slice_mut(),
ctx,
)?;
if spicelib::FAILED(ctx) {
spicelib::CHKOUT(b"T_GETSA", ctx)?;
return Ok(());
}
//
// The frame rotation we wish to apply is of the form
//
// R(t)
//
// where
//
// t = ET + LTSIGN*LTCENT(ET)
//
// since the light time from the frame center to the
// observer LTCENT is a function of ET. So
//
// |
// d(R)/d(ET) = d(R)/d(t)| * (1 + d(t)/d(ET))
// |t=ET+LTSIGN*LTCENT
//
//
// |
// = d(R)/d(t)| * (1 + LTSIGN*DLTCTR)
// |t=ET+LTSIGN*LTCENT
//
// Scale the derivative block of the transformation to account
// for the rate of change of light time.
//
for I in 1..=3 {
spicelib::VSCLIP((1.0 + (LTSIGN * DLTCTR)), XFORM.subarray_mut([4, I]));
}
//
// Now apply the transformation to the stellar aberration
// correction position and velocity. We'll pack these
// components together as a state to simplify the multiplication.
//
spicelib::VEQU(PCORR.as_slice(), SASTAT.as_slice_mut());
spicelib::VEQU(DPCORR.as_slice(), SASTAT.subarray_mut(4));
spicelib::MXVG(
XFORM.as_slice(),
SASTAT.as_slice(),
6,
6,
XSTATE.as_slice_mut(),
);
//
// Now unpack the stellar aberration correction components.
//
spicelib::VEQU(XSTATE.as_slice(), PCORR.as_slice_mut());
spicelib::VEQU(XSTATE.subarray(4), DPCORR.as_slice_mut());
spicelib::CHKOUT(b"T_GETSA", ctx)?;
Ok(())
}