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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const MAXREC: i32 = 128;
const FRMSIZ: i32 = 16;
const ND: i32 = 2;
const NI: i32 = 6;
const NSTATE: i32 = 6;
/// S/P Kernel, subset, type 14
///
/// Extract a subset of the data in a type 14 SPK segment into a new
/// type 14 segment.
///
/// # Required Reading
///
/// * [SPK](crate::required_reading::spk)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// SRCHAN I Handle of the SPK file with the source segment.
/// SRCDSC I Descriptor for the source segment.
/// DSTHAN I Handle of the SPK file for the destination segment.
/// DSTDSC I Descriptor for the destination segment.
/// DSTSID I Segment identifier for the new segment.
/// ```
///
/// # Detailed Input
///
/// ```text
/// SRCHAN is the handle of the SPK file containing the source
/// segment.
///
/// SRCDSC is the SPK descriptor for the source segment.
///
/// DSTHAN is the handle of the SPK file containing the new segment.
///
/// DSTDSC is the SPK descriptor for the destination segment. It
/// contains the desired start and stop times for the
/// requested subset.
///
/// DSTSID is the segment identifier for the destination segment.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the length of the SPK record that is to be moved is larger
/// than MAXREC, the error SPICE(SPKRECTOOLARGE) is signaled.
/// ```
///
/// # Files
///
/// ```text
/// See arguments SRCHAN, DSTHAN.
/// ```
///
/// # Particulars
///
/// ```text
/// This subroutine copies a subset of the data form one SPK segment
/// to another.
///
/// The exact structure of a segment of SPK type 14 is detailed in
/// the SPK Required Reading. Please see this document for details.
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) We assume that the source descriptor actually describes a
/// segment in the source SPK file containing the time coverage
/// that is desired for the subsetting operation.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// K.R. Gehringer (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.0.1, 03-JUN-2021 (JDR)
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.0.0, 08-MAR-1995 (KRG)
/// ```
pub fn spks14(
ctx: &mut SpiceContext,
srchan: i32,
srcdsc: &[f64],
dsthan: i32,
dstdsc: &[f64],
dstsid: &str,
) -> crate::Result<()> {
SPKS14(
srchan,
srcdsc,
dsthan,
dstdsc,
dstsid.as_bytes(),
ctx.raw_context(),
)?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure SPKS14 ( S/P Kernel, subset, type 14 )
pub fn SPKS14(
SRCHAN: i32,
SRCDSC: &[f64],
DSTHAN: i32,
DSTDSC: &[f64],
DSTSID: &[u8],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let SRCDSC = DummyArray::new(SRCDSC, 1..);
let DSTDSC = DummyArray::new(DSTDSC, 1..);
let mut MYFRAM = [b' '; FRMSIZ as usize];
let mut BEGTIM: f64 = 0.0;
let mut DTEMP = StackArray::<f64, 2>::new(1..=ND);
let mut ENDTIM: f64 = 0.0;
let mut MYREF: f64 = 0.0;
let mut RECORD = StackArray::<f64, 128>::new(1..=MAXREC);
let mut BEGIDX: i32 = 0;
let mut BODY: i32 = 0;
let mut CENTER: i32 = 0;
let mut CHBDEG: i32 = 0;
let mut DUMMY: i32 = 0;
let mut ENDIDX: i32 = 0;
let mut IFRAME: i32 = 0;
let mut ITEMP = StackArray::<i32, 6>::new(1..=NI);
let mut RECSIZ: i32 = 0;
let mut FOUND: bool = false;
//
// SPICELIB functions
//
//
// Local Parameters
//
// This is the maximum size type 14 record that we can move. This
// allows a 20th degree Chebyshev Polynomial, which should be more
// than sufficient. This should be the same as the value in SPKPV.
//
//
// Reference frame name size. See CHGIRF.
//
//
// DAF ND and NI values for SPK files.
//
//
// Length of a state.
//
//
// Local Variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"SPKS14", ctx)?;
}
//
// First, unpack the destination segment descriptor and set some
// local variables.
//
DAFUS(
DSTDSC.as_slice(),
ND,
NI,
DTEMP.as_slice_mut(),
ITEMP.as_slice_mut(),
);
BEGTIM = DTEMP[1];
ENDTIM = DTEMP[2];
BODY = ITEMP[1];
CENTER = ITEMP[2];
IFRAME = ITEMP[3];
IRFNAM(IFRAME, &mut MYFRAM, ctx)?;
//
// If we can't find the code, it can't be an SPK file.
//
if FAILED(ctx) {
CHKOUT(b"SPKS14", ctx)?;
return Ok(());
}
//
// Get the constants for this segment. There is only one.
//
SGFCON(SRCHAN, SRCDSC.as_slice(), 1, 1, DTEMP.as_slice_mut(), ctx)?;
if FAILED(ctx) {
CHKOUT(b"SPKS14", ctx)?;
return Ok(());
}
//
// The first element of DTEMP now contains the number of coefficients
// used for the Chebyshev polynomials. We need the degree of the
// polynomial which is one less than the number of coefficients.
//
CHBDEG = ((DTEMP[1] as i32) - 1);
//
// Compute the size of the SPK record and signal an error if there is
// not enough room in the variable RECORD to hold it.
//
RECSIZ = (((CHBDEG + 1) * NSTATE) + 2);
if (RECSIZ > MAXREC) {
SETMSG(b"Storage for # double precision numbers is needed for an SPK data record and only # locations were available. Update the parameter MAXREC in the subroutine SPKS14 and notify the NAIF group of this problem.", ctx);
ERRINT(b"#", RECSIZ, ctx);
ERRINT(b"#", MAXREC, ctx);
SIGERR(b"SPICE(SPKRECTOOLARGE)", ctx)?;
CHKOUT(b"SPKS14", ctx)?;
return Ok(());
}
//
// Get the beginning and ending indices for the packets we need for
// the destination segment.
//
SGFRVI(
SRCHAN,
SRCDSC.as_slice(),
BEGTIM,
&mut MYREF,
&mut BEGIDX,
&mut FOUND,
ctx,
)?;
SGFRVI(
SRCHAN,
SRCDSC.as_slice(),
ENDTIM,
&mut MYREF,
&mut ENDIDX,
&mut FOUND,
ctx,
)?;
//
// Begin the destination segment.
//
SPK14B(
DSTHAN, DSTSID, BODY, CENTER, &MYFRAM, BEGTIM, ENDTIM, CHBDEG, ctx,
)?;
if FAILED(ctx) {
CHKOUT(b"SPKS14", ctx)?;
return Ok(());
}
//
// Now we get the data one record at a time from the source segment
// and write it out to the destination segment.
//
for I in BEGIDX..=ENDIDX {
SGFPKT(
SRCHAN,
SRCDSC.as_slice(),
I,
I,
RECORD.as_slice_mut(),
std::slice::from_mut(&mut DUMMY),
ctx,
)?;
SGFREF(
SRCHAN,
SRCDSC.as_slice(),
I,
I,
std::slice::from_mut(&mut MYREF),
ctx,
)?;
SPK14A(DSTHAN, 1, RECORD.as_slice(), &[MYREF], ctx)?;
if FAILED(ctx) {
CHKOUT(b"SPKS14", ctx)?;
return Ok(());
}
}
//
// Now all we need to do is end the segment.
//
SPK14E(DSTHAN, ctx)?;
CHKOUT(b"SPKS14", ctx)?;
Ok(())
}