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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const INERTL: i32 = 1;
const PCK: i32 = (INERTL + 1);
const CK: i32 = (PCK + 1);
const TK: i32 = (CK + 1);
const DYN: i32 = (TK + 1);
const SWTCH: i32 = (DYN + 1);
const ALL: i32 = -1;
const CTRSIZ: i32 = 2;
const RNAME: &[u8] = b"ZZSPKZP0";
const FRNMLN: i32 = 32;
struct SaveVars {
LTCENT: f64,
SOBS: StackArray<f64, 6>,
POSTN: StackArray<f64, 3>,
TEMP: StackArray<f64, 3>,
XFORM: StackArray2D<f64, 9>,
CENTER: i32,
FJ2000: i32,
I: i32,
REQFRM: i32,
TYPE: i32,
TYPEID: i32,
FIRST: bool,
FOUND: bool,
XMIT: bool,
SVCTR1: StackArray<i32, 2>,
SVREF: Vec<u8>,
SVREQF: i32,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut LTCENT: f64 = 0.0;
let mut SOBS = StackArray::<f64, 6>::new(1..=6);
let mut POSTN = StackArray::<f64, 3>::new(1..=3);
let mut TEMP = StackArray::<f64, 3>::new(1..=3);
let mut XFORM = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
let mut CENTER: i32 = 0;
let mut FJ2000: i32 = 0;
let mut I: i32 = 0;
let mut REQFRM: i32 = 0;
let mut TYPE: i32 = 0;
let mut TYPEID: i32 = 0;
let mut FIRST: bool = false;
let mut FOUND: bool = false;
let mut XMIT: bool = false;
let mut SVCTR1 = StackArray::<i32, 2>::new(1..=CTRSIZ);
let mut SVREF = vec![b' '; FRNMLN as usize];
let mut SVREQF: i32 = 0;
FIRST = true;
Self {
LTCENT,
SOBS,
POSTN,
TEMP,
XFORM,
CENTER,
FJ2000,
I,
REQFRM,
TYPE,
TYPEID,
FIRST,
FOUND,
XMIT,
SVCTR1,
SVREF,
SVREQF,
}
}
}
//$Procedure ZZSPKZP0 ( S/P Kernel, easy position )
pub fn ZZSPKZP0(
TARG: i32,
ET: f64,
REF: &[u8],
ABCORR: &[u8],
OBS: i32,
PTARG: &mut [f64],
LT: &mut f64,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut PTARG = DummyArrayMut::new(PTARG, 1..=3);
//
//
// SPICELIB functions
//
//
// Local parameters
//
//
// Saved frame name length.
//
//
// Local variables
//
//
// Saved frame name/ID item declarations.
//
//
// Saved variables
//
//
// Initial values
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(RNAME, ctx)?;
}
//
// Get the frame id for J2000 on the first call to this routine.
//
if save.FIRST {
NAMFRM(b"J2000", &mut save.FJ2000, ctx)?;
//
// Initialize counter.
//
ZZCTRUIN(save.SVCTR1.as_slice_mut(), ctx);
save.FIRST = false;
}
//
// Decide whether the aberration correction is for received or
// transmitted radiation.
//
save.I = LTRIM(ABCORR);
save.XMIT = EQCHR(fstr::substr(ABCORR, save.I..=save.I), b"X", ctx);
//
// If we only want geometric positions, then compute just that.
//
// Otherwise, compute the state of the observer relative to
// the SSB. Then feed that position into SPKAPO to compute the
// apparent position of the target body relative to the observer
// with the requested aberration corrections.
//
if EQSTR(ABCORR, b"NONE") {
ZZSPKGP0(TARG, ET, REF, OBS, PTARG.as_slice_mut(), LT, ctx)?;
} else {
//
// Get the auxiliary information about the requested output
// frame.
//
ZZNAMFRM(
save.SVCTR1.as_slice_mut(),
&mut save.SVREF,
&mut save.SVREQF,
REF,
&mut save.REQFRM,
ctx,
)?;
if (save.REQFRM == 0) {
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);
ERRCH(b"#", REF, ctx);
SIGERR(b"SPICE(UNKNOWNFRAME)", ctx)?;
CHKOUT(RNAME, ctx)?;
return Ok(());
}
FRINFO(
save.REQFRM,
&mut save.CENTER,
&mut save.TYPE,
&mut save.TYPEID,
&mut save.FOUND,
ctx,
)?;
if FAILED(ctx) {
CHKOUT(RNAME, ctx)?;
return Ok(());
}
if !save.FOUND {
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);
ERRCH(b"#", REF, ctx);
SIGERR(b"SPICE(UNKNOWNFRAME2)", ctx)?;
CHKOUT(RNAME, ctx)?;
return Ok(());
}
//
// If we are dealing with an inertial frame, we can simply
// call SPKSSB, SPKAPO and return.
//
if (save.TYPE == INERTL) {
ZZSPKSB0(OBS, ET, REF, save.SOBS.as_slice_mut(), ctx)?;
ZZSPKPA0(
TARG,
ET,
REF,
save.SOBS.as_slice(),
ABCORR,
PTARG.as_slice_mut(),
LT,
ctx,
)?;
CHKOUT(RNAME, ctx)?;
return Ok(());
}
//
// Still here?
//
// We are dealing with a non-inertial frame. But we need to
// do light time and stellar aberration in an inertial frame.
// Get the "apparent" position of TARG in the intermediary
// inertial reference frame J2000.
//
// We also need the light time to the center of the frame.
//
ZZSPKSB0(OBS, ET, b"J2000", save.SOBS.as_slice_mut(), ctx)?;
ZZSPKPA0(
TARG,
ET,
b"J2000",
save.SOBS.as_slice(),
ABCORR,
save.POSTN.as_slice_mut(),
LT,
ctx,
)?;
if FAILED(ctx) {
CHKOUT(RNAME, ctx)?;
return Ok(());
}
if (save.CENTER == OBS) {
save.LTCENT = 0.0;
} else if (save.CENTER == TARG) {
save.LTCENT = *LT;
} else {
ZZSPKPA0(
save.CENTER,
ET,
b"J2000",
save.SOBS.as_slice(),
ABCORR,
save.TEMP.as_slice_mut(),
&mut save.LTCENT,
ctx,
)?;
}
//
// If something went wrong (like we couldn't get the position of
// the center relative to the observer) now it is time to quit.
//
if FAILED(ctx) {
CHKOUT(RNAME, ctx)?;
return Ok(());
}
//
// If the aberration corrections are for transmission, negate
// the light time, 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 save.XMIT {
save.LTCENT = -save.LTCENT;
}
//
// Get the rotation from J2000 to the requested frame
// and convert the position.
//
ZZREFCH0(
save.FJ2000,
save.REQFRM,
(ET - save.LTCENT),
save.XFORM.as_slice_mut(),
ctx,
)?;
if FAILED(ctx) {
CHKOUT(RNAME, ctx)?;
return Ok(());
}
MXV(
save.XFORM.as_slice(),
save.POSTN.as_slice(),
PTARG.as_slice_mut(),
);
}
CHKOUT(RNAME, ctx)?;
Ok(())
}