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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const ND: i32 = 2;
const NI: i32 = 6;
const CALSIZ: i32 = 40;
/// SPK pack descriptor
///
/// Perform routine error checks and if all check pass, pack the
/// descriptor for an SPK segment
///
/// # Required Reading
///
/// * [SPK](crate::required_reading::spk)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// BODY I The NAIF ID code for the body of the segment.
/// CENTER I The center of motion for BODY.
/// FRAME I The frame for this segment.
/// TYPE I The type of SPK segment to create.
/// FIRST I The first epoch for which the segment is valid.
/// LAST I The last epoch for which the segment is valid.
/// DESCR O An SPK segment descriptor.
/// ```
///
/// # Detailed Input
///
/// ```text
/// BODY is the NAIF ID code for the body of the segment.
///
/// CENTER is the center of motion for BODY.
///
/// FRAME is a string that names the frame to which states for
/// the body shall be referenced.
///
/// TYPE is the type of SPK segment to create.
///
/// FIRST is the first epoch for which the segment will have
/// ephemeris data.
///
/// LAST is the last epoch for which the segment will have
/// ephemeris data.
/// ```
///
/// # Detailed Output
///
/// ```text
/// DESCR is a valid SPK segment descriptor to use
/// when creating a DAF segment for this body.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the value of BODY is 0, the error SPICE(BARYCENTEREPHEM) is
/// signaled.
///
/// 2) If the values of BODY and CENTER are the same, the error
/// SPICE(BODYANDCENTERSAME) is signaled.
///
/// 3) If FRAME is not one of the known SPICE reference frames, the
/// error SPICE(INVALIDREFFRAME) is signaled.
///
/// 4) If FIRST is greater than or equal to LAST, the error
/// SPICE(BADDESCRTIMES) is signaled.
///
/// 5) If the value of TYPE is outside the range 1 to 1000
/// (inclusive), the error SPICE(UNKNOWNSPKTYPE) is signaled. This
/// does not ensure that the TYPE is a legitimate SPK segment
/// type, but it is a simple check that helps avoid problems that
/// arise from uninitialized values or improperly ordered calling
/// arguments.
/// ```
///
/// # Particulars
///
/// ```text
/// This is a utility routine for validating and creating
/// the descriptor for an SPK segment. It is intended for
/// use only by routines that create SPK segments.
/// ```
///
/// # Examples
///
/// ```text
/// Suppose that you wish to create an SPK segment of type X
/// and that you are writing a routine to handle the details
/// of the segment creation. This routine can be used to
/// ensure that the descriptor needed for the segment is
/// properly formed and that the information in that descriptor
/// is reasonable.
///
/// Having collected the needed information you can create the
/// descriptor and then begin a new segment as shown below.
///
/// CALL SPKPDS ( BODY, CENTER, FRAME, TYPE, FIRST, LAST, DESCR )
/// CALL DAFBNA ( HANDLE, DESCR, SEGID )
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// K.R. Gehringer (JPL)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 2.0.1, 05-JUL-2021 (JDR)
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 2.0.0, 19-SEP-1995 (WLT)
///
/// Upgraded the routine to support non-inertial frames.
///
/// - SPICELIB Version 1.0.0, 04-JAN-1994 (WLT) (KRG)
/// ```
pub fn spkpds(
ctx: &mut SpiceContext,
body: i32,
center: i32,
frame: &str,
type_: i32,
first: f64,
last: f64,
descr: &mut [f64],
) -> crate::Result<()> {
SPKPDS(
body,
center,
frame.as_bytes(),
type_,
first,
last,
descr,
ctx.raw_context(),
)?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure SPKPDS ( SPK pack descriptor )
pub fn SPKPDS(
BODY: i32,
CENTER: i32,
FRAME: &[u8],
TYPE: i32,
FIRST: f64,
LAST: f64,
DESCR: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut DESCR = DummyArrayMut::new(DESCR, 1..);
let mut CALFST = [b' '; CALSIZ as usize];
let mut CALLST = [b' '; CALSIZ as usize];
let mut DPPART = StackArray::<f64, 2>::new(1..=2);
let mut IPART = StackArray::<i32, 6>::new(1..=6);
let mut REFCOD: i32 = 0;
//
// Spicelib Functions
//
//
// Local Parameters
//
// ND and NI values for an SPK file.
//
//
// Length of a calender string.
//
//
// Local Variables
//
//
// Standard SPICELIB error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"SPKPDS", ctx)?;
}
//
// We do not support ephemerides for the solar system barycenter
// (at least not yet anyway).
//
if (BODY == 0) {
SETMSG(b"You\'ve attempted to create a segment for the solar system barycenter. This is not supported by the ephemeris system.", ctx);
SIGERR(b"SPICE(BARYCENTEREPHEM)", ctx)?;
CHKOUT(b"SPKPDS", ctx)?;
return Ok(());
}
//
// There is no point in having an ephemeris for a body relative
// to itself.
//
if (BODY == CENTER) {
SETMSG(b"You\'ve attempted to create a segment for a body relative to itself. The body ID code was: #.", ctx);
ERRINT(b"#", BODY, ctx);
SIGERR(b"SPICE(BODYANDCENTERSAME)", ctx)?;
CHKOUT(b"SPKPDS", ctx)?;
return Ok(());
}
//
// Get the NAIF integer code for the reference frame.
//
NAMFRM(FRAME, &mut REFCOD, ctx)?;
if (REFCOD == 0) {
SETMSG(b"The reference frame # is not supported.", ctx);
ERRCH(b"#", FRAME, ctx);
SIGERR(b"SPICE(INVALIDREFFRAME)", ctx)?;
CHKOUT(b"SPKPDS", ctx)?;
return Ok(());
}
//
// The segment stop time should be greater then the begin time.
//
if (FIRST >= LAST) {
//
// We've got an error. Get the calendar string for the first
// and last epochs.
//
ETCAL(FIRST, &mut CALFST, ctx);
ETCAL(LAST, &mut CALLST, ctx);
SETMSG(
b"The segment start time: # (#) is at or after the segment stop time # (#).",
ctx,
);
ERRDP(b"#", FIRST, ctx);
ERRCH(b"#", &CALFST, ctx);
ERRDP(b"#", LAST, ctx);
ERRCH(b"#", &CALLST, ctx);
SIGERR(b"SPICE(BADDESCRTIMES)", ctx)?;
CHKOUT(b"SPKPDS", ctx)?;
return Ok(());
}
//
// The type must be something reasonable. The interval from
// 1 to 1000 is what we are calling reasonable these days.
//
if ((TYPE <= 0) || (TYPE > 1000)) {
SETMSG(
b"The type specified, #, is not supported within the SPK system.",
ctx,
);
ERRINT(b"#", TYPE, ctx);
SIGERR(b"SPICE(UNKNOWNSPKTYPE)", ctx)?;
CHKOUT(b"SPKPDS", ctx)?;
return Ok(());
}
//
// Well, that's it. As far as we can determine these seem to be
// reasonable values to put into a descriptor. Do it.
//
IPART[1] = BODY;
IPART[2] = CENTER;
IPART[3] = REFCOD;
IPART[4] = TYPE;
IPART[5] = 0;
IPART[6] = 0;
DPPART[1] = FIRST;
DPPART[2] = LAST;
DAFPS(
ND,
NI,
DPPART.as_slice(),
IPART.as_slice(),
DESCR.as_slice_mut(),
);
CHKOUT(b"SPKPDS", ctx)?;
Ok(())
}