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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const REF: &[u8] = b"J2000";
const BASELT: f64 = 1.0;
const IDA: i32 = 1000;
const IDB: i32 = 2000;
const IDG: i32 = 1001;
const IDC: i32 = 10;
const N1: i32 = 600;
const N2: i32 = 4;
const N3: i32 = 8;
const N4: i32 = 86400;
const SIDLEN: i32 = 40;
struct SaveVars {
XVEC: StackArray<f64, 3>,
YVEC: StackArray<f64, 3>,
ZVEC: StackArray<f64, 3>,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut XVEC = StackArray::<f64, 3>::new(1..=3);
let mut YVEC = StackArray::<f64, 3>::new(1..=3);
let mut ZVEC = StackArray::<f64, 3>::new(1..=3);
{
use f2rust_std::data::Val;
let mut clist = [Val::D(1.0), Val::D(0.0), Val::D(0.0)].into_iter();
XVEC.iter_mut()
.for_each(|n| *n = clist.next().unwrap().into_f64());
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::D(0.0), Val::D(1.0), Val::D(0.0)].into_iter();
YVEC.iter_mut()
.for_each(|n| *n = clist.next().unwrap().into_f64());
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::D(0.0), Val::D(0.0), Val::D(1.0)].into_iter();
ZVEC.iter_mut()
.for_each(|n| *n = clist.next().unwrap().into_f64());
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
Self { XVEC, YVEC, ZVEC }
}
}
//$Procedure ZZNATSPK ( Create an SPK file for Nat's solar system )
pub fn ZZNATSPK(FILE: &[u8], ctx: &mut Context) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut SEGID = [b' '; SIDLEN as usize];
let mut APROG: f64 = 0.0;
let mut ARADA: f64 = 0.0;
let mut ARADB: f64 = 0.0;
let mut DELTAO: f64 = 0.0;
let mut FIRST: f64 = 0.0;
let mut LAST: f64 = 0.0;
let mut MU: f64 = 0.0;
let mut N323: f64 = 0.0;
let mut OMEGAA: f64 = 0.0;
let mut OMEGAB: f64 = 0.0;
let mut OMEGAG: f64 = 0.0;
let mut RALPHA: f64 = 0.0;
let mut SUNST = StackArray2D::<f64, 12>::new(1..=6, 1..=2);
let mut RBETA: f64 = 0.0;
let mut RGAMMA: f64 = 0.0;
let mut SPEEDA: f64 = 0.0;
let mut SPEEDB: f64 = 0.0;
let mut SPEEDG: f64 = 0.0;
let mut STATEA = StackArray::<f64, 6>::new(1..=6);
let mut STATEB = StackArray::<f64, 6>::new(1..=6);
let mut STATEG = StackArray::<f64, 6>::new(1..=6);
let mut TAU: f64 = 0.0;
let mut TSTATE = StackArray::<f64, 6>::new(1..=6);
let mut MYHAND: i32 = 0;
//
// SPICELIB functions
//
//
// Local parameters
//
//
// The current (2004/09/29) values of the parameters imply
//
// Radius of ALPHA = 0.36624698766937712D+05 km
// Radius of BETA = 0.22891526271046937D+04 km
//
//
// Local variables
//
//
// Declarations for RADA and RADB are needed if the lines of code
// computing these items are un-commented.
//
// DOUBLE PRECISION RADA
// DOUBLE PRECISION RADB
//
//
// Saved variables
//
//
// Initial values
//
spicelib::CHKIN(b"ZZNATSPK", ctx)?;
//
// Wipe out any existing file with the target name. Then open
// a new SPC file for writing.
//
KILFIL(FILE, ctx)?;
spicelib::SPCOPN(FILE, b"TestUtilitySPK", &mut MYHAND, ctx)?;
//
// Now just construct the state information needed to create
// segments for objects ALPHA and BETA.
//
// Define the distances RBETA and RALPHA. RBETA is the distance
// light travels in
//
//
// BASELT * ( 1 - N3 ) / ( N3**(2/3) - N3 )
//
// seconds.
//
// RALPHA is
//
// (2/3)
// N * RBETA
// 3
//
//
// This power of
//
// N
// 3
//
// comes up a lot, so we allocate a variable for it.
//
//
N323 = f64::powf((N3 as f64), (2.0 / 3.0));
RBETA = (((spicelib::CLIGHT() * BASELT) * (1 - N3) as f64) / (N323 - N3 as f64));
RALPHA = (N323 * RBETA);
//
// Set the angular rates of bodies alpha and beta.
//
OMEGAA = (spicelib::TWOPI(ctx) / (((N3 as f64) - 1.0) * N4 as f64));
OMEGAB = ((N3 as f64) * OMEGAA);
//
// Get the differential angular velocity.
//
DELTAO = (OMEGAB - OMEGAA);
//
// Set the central GM value.
//
MU = (f64::powf(OMEGAA, 2.0) * f64::powf(RALPHA, 3.0));
//
// Set the angular radii of bodies ALPHA and BETA. We want
// the occultation to last N1 seconds. If the angular
// size of ALPHA is N2 times the angular size of BETA, then
// BETA must make angular progress of (N2+1) * the angular
// size of beta, relative to ALPHA, in N1 seconds.
//
APROG = ((N1 as f64) * DELTAO);
ARADB = ((APROG / (N2 + 1) as f64) / 2 as f64);
ARADA = ((N2 as f64) * ARADB);
//
// Set the radii of ALPHA and BETA. These lines of code can be
// used to reconstitute the radius values; however they're not
// needed in this routine.
//
// RADA = RALPHA * SIN(ARADA)
// RADB = RBETA * SIN(ARADB)
//
// Set the initial positions. We start by making both objects
// line up on the +X axis at J2000 TDB. Later, we'll rotate
// body BETA to make an occultation start at this epoch.
//
spicelib::VSCL(RALPHA, save.XVEC.as_slice(), STATEA.as_slice_mut());
spicelib::VSCL(RBETA, save.XVEC.as_slice(), STATEB.as_slice_mut());
//
// Set the initial velocities. Both objects are traveling in the
// +y direction at J2000 TDB.
//
SPEEDA = (RALPHA * OMEGAA);
SPEEDB = (RBETA * OMEGAB);
spicelib::VSCL(SPEEDA, save.YVEC.as_slice(), STATEA.subarray_mut(4));
spicelib::VSCL(SPEEDB, save.YVEC.as_slice(), STATEB.subarray_mut(4));
//
// Now rotate the state of BETA by -(ARADA+ARADB) about +Z to make
// objects ALPHA and BETA appear to be tangent at the current
// epoch, as seen from the origin.
//
spicelib::VROTV(
STATEB.as_slice(),
save.ZVEC.as_slice(),
-(ARADA + ARADB),
TSTATE.as_slice_mut(),
);
spicelib::VROTV(
STATEB.subarray(4),
save.ZVEC.as_slice(),
-(ARADA + ARADB),
TSTATE.subarray_mut(4),
);
spicelib::MOVED(TSTATE.as_slice(), 6, STATEB.as_slice_mut());
FIRST = -(100.0 * spicelib::JYEAR());
LAST = (100.0 * spicelib::JYEAR());
fstr::assign(&mut SEGID, b"Outer object alpha");
spicelib::SPKW05(
MYHAND,
IDA,
IDC,
REF,
FIRST,
LAST,
&SEGID,
MU,
1,
STATEA.as_slice(),
&[0.0],
ctx,
)?;
fstr::assign(&mut SEGID, b"Inner object beta");
spicelib::SPKW05(
MYHAND,
IDB,
IDC,
REF,
FIRST,
LAST,
&SEGID,
MU,
1,
STATEB.as_slice(),
&[0.0],
ctx,
)?;
//
// Create a segment for GAMMA. This object orbits
// ALPHA with a 24 hour period. The orbit is circular
// and lies in the J2000 X-Y plane. The orbital radius
// is 1.E5 km.
//
RGAMMA = 100000.0;
TAU = spicelib::SPD();
OMEGAG = (spicelib::TWOPI(ctx) / TAU);
MU = (f64::powi(OMEGAG, 2) * f64::powi(RGAMMA, 3));
SPEEDG = (RGAMMA * OMEGAG);
spicelib::VSCL(-RGAMMA, save.YVEC.as_slice(), STATEG.as_slice_mut());
spicelib::VSCL(SPEEDG, save.ZVEC.as_slice(), STATEG.subarray_mut(4));
fstr::assign(&mut SEGID, b"Alpha\'s moon Gamma");
spicelib::SPKW05(
MYHAND,
IDG,
IDA,
REF,
FIRST,
LAST,
&SEGID,
MU,
1,
STATEG.as_slice(),
&[0.0],
ctx,
)?;
//
// Create a type 8 segment for the Sun.
//
fstr::assign(&mut SEGID, b"Motionless Sun at SSB");
spicelib::CLEARD(12, SUNST.as_slice_mut());
spicelib::SPKW08(
MYHAND,
10,
0,
b"J2000",
FIRST,
LAST,
&SEGID,
1,
2,
SUNST.as_slice(),
FIRST,
(LAST - FIRST),
ctx,
)?;
//
// Close the SPK file.
//
spicelib::DAFCLS(MYHAND, ctx)?;
spicelib::CHKOUT(b"ZZNATSPK", ctx)?;
Ok(())
}