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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
pub const LBCELL: i32 = -5;
const KWINTV: &[u8] = b"INTERVAL";
const KWSEG: &[u8] = b"SEGMENT";
const LNSIZE: i32 = 80;
const ND: i32 = 2;
const NI: i32 = 6;
//$Procedure T_CKCOV ( CK coverage, test version )
pub fn T_CKCOV(
CK: &[u8],
IDCODE: i32,
NEEDAV: bool,
LEVEL: &[u8],
TOL: f64,
TIMSYS: &[u8],
COVER: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut COVER = DummyArrayMut::new(COVER, LBCELL..);
let mut ARCH = [b' '; LNSIZE as usize];
let mut KERTYP = [b' '; LNSIZE as usize];
let mut DC = StackArray::<f64, 2>::new(1..=ND);
let mut DCTOL = StackArray::<f64, 2>::new(1..=ND);
let mut DESCR = StackArray::<f64, 5>::new(1..=(ND + ((NI + 1) / 2)));
let mut ET: f64 = 0.0;
let mut CLKID: i32 = 0;
let mut DTYPE: i32 = 0;
let mut HANDLE: i32 = 0;
let mut IC = StackArray::<i32, 6>::new(1..=NI);
let mut SEGBEG: i32 = 0;
let mut SEGEND: i32 = 0;
let mut AVOK: bool = false;
let mut FOUND: bool = false;
let mut ISTDB: bool = false;
let mut SEGLVL: bool = false;
//
// SPICELIB functions
//
//
// Local parameters
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if spicelib::RETURN(ctx) {
return Ok(());
}
spicelib::CHKIN(b"T_CKCOV", ctx)?;
//
// Check tolerance value.
//
if (TOL < 0.0) {
spicelib::SETMSG(b"Tolerance must be non-negative; actual value was #.", ctx);
spicelib::ERRDP(b"#", TOL, ctx);
spicelib::SIGERR(b"SPICE(VALUEOUTOFRANGE)", ctx)?;
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
return Ok(());
}
//
// Use a logical flag to indicate whether this is a segment-level
// coverage description.
//
SEGLVL = spicelib::EQSTR(LEVEL, KWSEG);
//
// Check coverage level keyword.
//
if !(SEGLVL || spicelib::EQSTR(LEVEL, KWINTV)) {
spicelib::SETMSG(
b"Allowed values of LEVEL are # and #; actual value was #.",
ctx,
);
spicelib::ERRCH(b"#", KWSEG, ctx);
spicelib::ERRCH(b"#", KWINTV, ctx);
spicelib::ERRCH(b"#", LEVEL, ctx);
spicelib::SIGERR(b"SPICE(INVALIDOPTION)", ctx)?;
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
return Ok(());
}
//
// See whether GETFAT thinks we've got a CK file.
//
spicelib::GETFAT(CK, &mut ARCH, &mut KERTYP, ctx)?;
if fstr::eq(&ARCH, b"XFR") {
spicelib::SETMSG(b"Input file # has architecture #. The file must be a binary CK file to be readable by this routine. If the input file is an CK file in transfer format, run TOBIN on the file to convert it to binary format.", ctx);
spicelib::ERRCH(b"#", CK, ctx);
spicelib::ERRCH(b"#", &ARCH, ctx);
spicelib::SIGERR(b"SPICE(INVALIDFORMAT)", ctx)?;
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
return Ok(());
} else if fstr::ne(&ARCH, b"DAF") {
spicelib::SETMSG(b"Input file # has architecture #. The file must be a binary CK file to be readable by this routine. Binary CK files have DAF architecture. If you expected the file to be a binary CK file, the problem may be due to the file being an old non-native file lacking binary file format information. It\'s also possible the file has been corrupted.", ctx);
spicelib::ERRCH(b"#", CK, ctx);
spicelib::ERRCH(b"#", &ARCH, ctx);
spicelib::SIGERR(b"SPICE(INVALIDARCHTYPE)", ctx)?;
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
return Ok(());
} else if fstr::ne(&KERTYP, b"CK") {
spicelib::SETMSG(b"Input file # has file type #. The file must be a binary CK file to be readable by this routine. If you expected the file to be a binary CK file, the problem may be due to the file being an old non-native file lacking binary file format information. It\'s also possible the file has been corrupted.", ctx);
spicelib::ERRCH(b"#", CK, ctx);
spicelib::ERRCH(b"#", &KERTYP, ctx);
spicelib::SIGERR(b"SPICE(INVALIDFILETYPE)", ctx)?;
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
return Ok(());
}
//
// Set a logical flag indicating whether the time system is SCLK.
//
ISTDB = spicelib::EQSTR(TIMSYS, b"TDB");
//
// Check time system.
//
if !ISTDB {
if !spicelib::EQSTR(TIMSYS, b"SCLK") {
spicelib::SETMSG(
b"Time system spec TIMSYS was #; allowed values are SCLK and TDB.",
ctx,
);
spicelib::ERRCH(b"#", TIMSYS, ctx);
spicelib::SIGERR(b"SPICE(NOTSUPPORTED)", ctx)?;
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
return Ok(());
}
}
//
// If the output time system is TDB, find the clock ID associated
// with IDCODE.
//
if ISTDB {
spicelib::CKMETA(IDCODE, b"SCLK", &mut CLKID, ctx)?;
if spicelib::FAILED(ctx) {
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
return Ok(());
}
}
//
// Open the file for reading.
//
spicelib::DAFOPR(CK, &mut HANDLE, ctx)?;
if spicelib::FAILED(ctx) {
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
return Ok(());
}
//
// We will examine each segment descriptor in the file, and
// we'll update our coverage bounds according to the data found
// in these descriptors.
//
// If TOL > 0, we'll apply TOL after we've found the coverage
// for the zero-tolerance case.
//
// If the time system is TDB, we'll convert the times to TDB
// at the end of this routine.
//
// Start a forward search.
//
spicelib::DAFBFS(HANDLE, ctx)?;
//
// Find the next DAF array.
//
spicelib::DAFFNA(&mut FOUND, ctx)?;
while FOUND {
//
// Note: we check FAILED() at the bottom of this loop; this
// routine returns if FAILED() returns .TRUE. at that point.
//
// Fetch and unpack the segment descriptor.
//
spicelib::DAFGS(DESCR.as_slice_mut(), ctx)?;
spicelib::DAFUS(
DESCR.as_slice(),
ND,
NI,
DC.as_slice_mut(),
IC.as_slice_mut(),
);
//
// Let AVOK indicate whether the segment satisfies the
// angular velocity restriction.
//
AVOK = ((IC[4] == 1) || !NEEDAV);
if ((IC[1] == IDCODE) && AVOK) {
//
// This segment is for the body of interest. If angular
// velocity is needed, this segment has it.
//
if SEGLVL {
//
// This is a segment-level summary.
//
// Insert the coverage bounds into the coverage window.
// Adjust the interval using the tolerance.
//
DCTOL[1] = intrinsics::DMAX1(&[(DC[1] - TOL), 0.0]);
DCTOL[2] = (DC[2] + TOL);
//
// Convert the time to TDB if necessary.
//
if ISTDB {
//
// Convert the time bounds to TDB before inserting
// into the window.
//
for I in 1..=2 {
spicelib::SCT2E(CLKID, DCTOL[I], &mut ET, ctx)?;
DCTOL[I] = ET;
}
}
if (DCTOL[1] <= DCTOL[2]) {
spicelib::WNINSD(DCTOL[1], DCTOL[2], COVER.as_slice_mut(), ctx)?;
}
} else {
//
// We're looking for an interval-level coverage window.
// This information must be retrieved in a
// data-type-dependent fashion. The coverage routines
// we'll call will, if necessary, adjust intervals by TOL
// and convert interval times to TDB.
//
DTYPE = IC[3];
SEGBEG = IC[5];
SEGEND = IC[6];
if (DTYPE == 1) {
spicelib::ZZCKCV01(
HANDLE,
SEGBEG,
SEGEND,
CLKID,
TOL,
TIMSYS,
COVER.as_slice_mut(),
ctx,
)?;
} else if (DTYPE == 2) {
spicelib::ZZCKCV02(
HANDLE,
SEGBEG,
SEGEND,
CLKID,
TOL,
TIMSYS,
COVER.as_slice_mut(),
ctx,
)?;
} else if (DTYPE == 3) {
spicelib::ZZCKCV03(
HANDLE,
SEGBEG,
SEGEND,
CLKID,
TOL,
TIMSYS,
COVER.as_slice_mut(),
ctx,
)?;
} else if (DTYPE == 4) {
spicelib::ZZCKCV04(
HANDLE,
SEGBEG,
SEGEND,
CLKID,
TOL,
TIMSYS,
COVER.as_slice_mut(),
ctx,
)?;
} else if (DTYPE == 5) {
spicelib::ZZCKCV05(
HANDLE,
SEGBEG,
SEGEND,
CLKID,
DC.as_slice(),
TOL,
TIMSYS,
COVER.as_slice_mut(),
ctx,
)?;
} else if (DTYPE == 6) {
T_ZZCKCV06(
HANDLE,
DESCR.as_slice(),
CLKID,
TOL,
TIMSYS,
COVER.as_slice_mut(),
ctx,
)?;
} else {
spicelib::SETMSG(b"Supported CK data types are 1, 2, 3, 4, 5. Data type of segment: #. This problem may indicate that you need to update your SPICE Toolkit.", ctx);
spicelib::ERRINT(b"#", DTYPE, ctx);
spicelib::SIGERR(b"SPICE(NOTSUPPORTED)", ctx)?;
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
return Ok(());
}
}
}
spicelib::DAFFNA(&mut FOUND, ctx)?;
if spicelib::FAILED(ctx) {
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
return Ok(());
}
}
//
// COVER now represents the coverage of the entire file at the
// granularity indicated by LEVEL, combined with the coverage
// contained in COVER on input.
//
// Release the file.
//
spicelib::DAFCLS(HANDLE, ctx)?;
spicelib::CHKOUT(b"T_CKCOV", ctx)?;
Ok(())
}