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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const ND: i32 = 2;
const NI: i32 = 6;
const NS: i32 = 5;
const LNSIZE: i32 = 80;
//$Procedure F_SPKF15 ( Family of tests for SPKW15 and SPKR15 )
pub fn F_SPKF15(OK: &mut bool, ctx: &mut Context) -> f2rust_std::Result<()> {
let mut FRAME = [b' '; 8 as usize];
let mut SEGID = [b' '; LNSIZE as usize];
let mut ET: f64 = 0.0;
let mut FIRST: f64 = 0.0;
let mut LAST: f64 = 0.0;
let mut J2FLG: f64 = 0.0;
let mut EPOCH: f64 = 0.0;
let mut TP = StackArray::<f64, 3>::new(1..=3);
let mut PA = StackArray::<f64, 3>::new(1..=3);
let mut PV = StackArray::<f64, 3>::new(1..=3);
let mut GM: f64 = 0.0;
let mut P: f64 = 0.0;
let mut ECC: f64 = 0.0;
let mut J2: f64 = 0.0;
let mut RADIUS: f64 = 0.0;
let mut RECORD = StackArray::<f64, 20>::new(1..=20);
let mut MYREC = StackArray::<f64, 16>::new(1..=16);
let mut DESCR = StackArray::<f64, 5>::new(1..=NS);
let mut DPS = StackArray::<f64, 2>::new(1..=ND);
let mut NUMS = StackArray::<i32, 6>::new(1..=NI);
let mut HANDLE: i32 = 0;
let mut BODY: i32 = 0;
let mut CENTER: i32 = 0;
let mut TYPE: i32 = 0;
let mut SPKHAN: i32 = 0;
let mut FOUND: bool = false;
//
// Spicelib Functions
//
//
// Local Variables.
//
testutil::TOPEN(b"F_SPKF15", ctx)?;
//
// delete any existing test SPK file.
//
testutil::KILFIL(b"t_spkw15.bsp", ctx)?;
spicelib::SPCOPN(b"t_spkw15.bsp", b"testSPK", &mut HANDLE, ctx)?;
//
// Set up a bunch of initial values.
//
BODY = -1000;
CENTER = 399;
fstr::assign(&mut FRAME, b"J2000");
FIRST = 0.0;
LAST = 100000.0;
fstr::assign(&mut SEGID, b" ");
EPOCH = 1000.0;
J2FLG = 0.0;
J2 = 0.001082616;
P = 10000.0;
ECC = 0.1;
GM = 398600.44770326116;
TP[1] = 0.0;
TP[2] = f64::cos((spicelib::PI(ctx) / 6.0));
TP[3] = f64::sin((spicelib::PI(ctx) / 6.0));
PA[1] = 0.0;
PA[2] = f64::sin((spicelib::PI(ctx) / 6.0));
PA[3] = -f64::cos((spicelib::PI(ctx) / 6.0));
PV[1] = 0.0;
PV[2] = 0.0;
PV[3] = 1.0;
RADIUS = 6378.184;
for I in 1..=20 {
RECORD[I] = 1.0;
}
//
// The semi-latus rectum is supposed to be positive. Start
// out at zero and then set it to something reasonable.
//
testutil::TCASE(b"Semi-latus rectum exception", ctx)?;
P = 0.0;
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(BADLATUSRECTUM)", OK, ctx)?;
P = 10000.0;
//
// Negative eccentricities should produce exceptions. After
// checking that this is so set the eccentricity to something
// yielding a periodic orbit.
//
testutil::TCASE(b"Eccentricity Exception", ctx)?;
ECC = -1.0;
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(BADECCENTRICITY)", OK, ctx)?;
ECC = 0.1;
//
// The central mass must be positive. Zero or less should
// trigger an exception. Try zero and -1. After that we
// use the mass of the earth.
//
testutil::TCASE(b"Central Mass Exception --- mass 0", ctx)?;
GM = 0.0;
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(NONPOSITIVEMASS)", OK, ctx)?;
testutil::TCASE(b"Central Mass Exception --- mass -1", ctx)?;
GM = -1.0;
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(NONPOSITIVEMASS)", OK, ctx)?;
GM = 398600.44770326116;
//
// Only a zero trajectory pole can produce a problem. By
// construction we already have one.
//
testutil::TCASE(b"Trajectory Pole Exception", ctx)?;
TP[1] = 0.0;
TP[2] = 0.0;
TP[3] = 0.0;
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(BADVECTOR)", OK, ctx)?;
//
// Set the trajectory pole to 45 degree inclination
//
TP[1] = 0.0;
TP[2] = f64::cos((spicelib::PI(ctx) / 6.0));
TP[3] = f64::sin((spicelib::PI(ctx) / 6.0));
//
// Only a zero periapsis vector yields an exception. We
// already have this by construction. After testing make
// a periapsis vector that is orthogonal to the trajectory
// pole vector.
//
testutil::TCASE(b"Periapsis Vector Exception", ctx)?;
PA[1] = 0.0;
PA[2] = 0.0;
PA[3] = 0.0;
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(BADVECTOR)", OK, ctx)?;
PA[1] = 0.0;
PA[2] = f64::sin((spicelib::PI(ctx) / 6.0));
PA[3] = -f64::cos((spicelib::PI(ctx) / 6.0));
//
// Only a zero central body pole vector can yield an exception.
// We have such a situation by construction. After checking
// this, align the pole with the Z axis.
//
testutil::TCASE(b"Pole Vector Exception", ctx)?;
PV[1] = 0.0;
PV[2] = 0.0;
PV[3] = 0.0;
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(BADVECTOR)", OK, ctx)?;
PV[3] = 1.0;
//
// Anything less than zero should trigger an exception. After
// checking, set the equatorial radius to that of the earth.
//
testutil::TCASE(b"Equatorial Radius Exception", ctx)?;
RADIUS = -1.0;
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(BADRADIUS)", OK, ctx)?;
RADIUS = 6378.184;
//
// If the periapse is not nearly perpepndicular to the
// trajectory pole, we should get an exception. Create
// a vector that isn't perpendicular to the trajectory pole
// by messing up the sign on the z-component.
//
testutil::TCASE(b"Bad Initial Conditions", ctx)?;
PA[1] = 0.0;
PA[2] = 1.0;
PA[3] = 0.0;
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(BADINITSTATE)", OK, ctx)?;
PA[1] = 0.0;
PA[2] = f64::sin((spicelib::PI(ctx) / 6.0));
PA[3] = -f64::cos((spicelib::PI(ctx) / 6.0));
testutil::TCASE(b"Segment Identifier too long", ctx)?;
fstr::assign(
&mut SEGID,
b"This is a very, very, very long segment identifier ",
);
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(SEGIDTOOLONG)", OK, ctx)?;
testutil::TCASE(b"Non-Printing Characters Exception", ctx)?;
fstr::assign(
&mut SEGID,
&fstr::concat(
&fstr::concat(b"This is a ", &intrinsics::CHAR(9)),
b"test segment",
),
);
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(NONPRINTABLECHARS)", OK, ctx)?;
fstr::assign(&mut SEGID, b"Test segment");
//
// That takes care of all noted excpetions in SPKW15.
// Write a legitimate segment and close the SPK file.
//
MYREC[1] = EPOCH;
MYREC[2] = TP[1];
MYREC[3] = TP[2];
MYREC[4] = TP[3];
MYREC[5] = PA[1];
MYREC[6] = PA[2];
MYREC[7] = PA[3];
MYREC[8] = P;
MYREC[9] = ECC;
MYREC[10] = J2FLG;
MYREC[11] = PV[1];
MYREC[12] = PV[2];
MYREC[13] = PV[3];
MYREC[14] = GM;
MYREC[15] = J2;
MYREC[16] = RADIUS;
testutil::TCASE(b"Writing a segment", ctx)?;
FIRST = 1000.0;
LAST = 100000.0;
spicelib::SPKW15(
HANDLE,
BODY,
CENTER,
&FRAME,
FIRST,
LAST,
&SEGID,
EPOCH,
TP.as_slice(),
PA.as_slice(),
P,
ECC,
J2FLG,
PV.as_slice(),
GM,
J2,
RADIUS,
ctx,
)?;
//
// In addition we write a bogus segment with the wrong amount
// of data in it and call it type 15.
//
FIRST = -100000.0;
LAST = -1000.0;
TYPE = 15;
spicelib::SPKPDS(
BODY,
CENTER,
&FRAME,
TYPE,
FIRST,
LAST,
DESCR.as_slice_mut(),
ctx,
)?;
spicelib::DAFBNA(HANDLE, DESCR.as_slice(), b"Bogus Segment", ctx)?;
spicelib::DAFADA(RECORD.as_slice(), 17, ctx)?;
spicelib::DAFENA(ctx)?;
spicelib::DAFCLS(HANDLE, ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Corrupt the descriptor in the type component of the segment
// and make sure that SPKR15 properly diagnoses the problem.
//
testutil::TCASE(b"SPKR15 bad type exception.", ctx)?;
ET = 2000.0;
spicelib::SPKLEF(b"t_spkw15.bsp", &mut SPKHAN, ctx)?;
spicelib::SPKSFS(
BODY,
ET,
&mut HANDLE,
DESCR.as_slice_mut(),
&mut SEGID,
&mut FOUND,
ctx,
)?;
testutil::CHCKSL(b"FOUND", FOUND, true, OK, ctx)?;
if *OK {
spicelib::DAFUS(
DESCR.as_slice(),
ND,
NI,
DPS.as_slice_mut(),
NUMS.as_slice_mut(),
);
NUMS[4] = 14;
spicelib::DAFPS(
ND,
NI,
DPS.as_slice(),
NUMS.as_slice(),
DESCR.as_slice_mut(),
);
spicelib::SPKR15(HANDLE, DESCR.as_slice(), ET, RECORD.as_slice_mut(), ctx)?;
testutil::CHCKXC(true, b"SPICE(WRONGSPKTYPE)", OK, ctx)?;
}
//
// Recall that the second segment we wrote had too much data.
// and had time bounds from -100000 to -1000. We find that
// segment next and make sure that the badly formed segment
// is handled properly.
//
testutil::TCASE(b"SPKR15 bad segment exception.", ctx)?;
ET = -2000.0;
spicelib::SPKSFS(
BODY,
ET,
&mut HANDLE,
DESCR.as_slice_mut(),
&mut SEGID,
&mut FOUND,
ctx,
)?;
testutil::CHCKSL(b"FOUND", FOUND, true, OK, ctx)?;
if *OK {
spicelib::SPKR15(HANDLE, DESCR.as_slice(), ET, RECORD.as_slice_mut(), ctx)?;
testutil::CHCKXC(true, b"SPICE(MALFORMEDSEGMENT)", OK, ctx)?;
}
testutil::TCASE(b"SPKR15 checking segment values.", ctx)?;
ET = 2000.0;
spicelib::SPKSFS(
BODY,
ET,
&mut HANDLE,
DESCR.as_slice_mut(),
&mut SEGID,
&mut FOUND,
ctx,
)?;
testutil::CHCKSL(b"FOUND", FOUND, true, OK, ctx)?;
if *OK {
spicelib::SPKR15(HANDLE, DESCR.as_slice(), ET, RECORD.as_slice_mut(), ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKAD(
b"RECORD",
RECORD.as_slice(),
b"=",
MYREC.as_slice(),
16,
0.00000000000001,
OK,
ctx,
)?;
}
//
// When we've finished all tests, delete the .bsp file we created.
//
spicelib::SPKUEF(SPKHAN, ctx)?;
testutil::KILFIL(b"t_spkw15.bsp", ctx)?;
testutil::T_SUCCESS(OK, ctx);
Ok(())
}