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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const CDELEN: i32 = 16;
const NAMLEN: i32 = 32;
/// Return d.p. values from the kernel pool
///
/// Fetch from the kernel pool the double precision values
/// of an item associated with a body, where the body is
/// specified by an integer ID code.
///
/// # Required Reading
///
/// * [KERNEL](crate::required_reading::kernel)
/// * [NAIF_IDS](crate::required_reading::naif_ids)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// BODYID I Body ID code.
/// ITEM I Item for which values are desired. ('RADII',
/// 'NUT_PREC_ANGLES', etc. )
/// MAXN I Maximum number of values that may be returned.
/// DIM O Number of values returned.
/// VALUES O Values.
/// ```
///
/// # Detailed Input
///
/// ```text
/// BODYID is the NAIF integer ID code for a body of interest.
/// For example, if the body is the earth, the code is
/// 399.
///
/// ITEM is the item to be returned. Together, the NAIF ID
/// code of the body and the item name combine to form a
/// kernel variable name, e.g.,
///
/// 'BODY599_RADII'
/// 'BODY401_POLE_RA'
///
/// The values associated with the kernel variable having
/// the name constructed as shown are sought. Below
/// we'll take the shortcut of calling this kernel variable
/// the "requested kernel variable."
///
/// Note that ITEM *is* case-sensitive. This attribute
/// is inherited from the case-sensitivity of kernel
/// variable names.
///
/// MAXN is the maximum number of values that may be returned.
/// The output array VALUES must be declared with size at
/// least MAXN. It's an error to supply an output array
/// that is too small to hold all of the values associated
/// with the requested kernel variable.
/// ```
///
/// # Detailed Output
///
/// ```text
/// DIM is the number of values returned; this is always the
/// number of values associated with the requested kernel
/// variable unless an error has been signaled.
///
/// VALUES is the array of values associated with the requested
/// kernel variable. If VALUES is too small to hold all
/// of the values associated with the kernel variable, the
/// returned values of DIM and VALUES are undefined.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the requested kernel variable is not found in the kernel
/// pool, the error SPICE(KERNELVARNOTFOUND) is signaled.
///
/// 2) If the requested kernel variable is found but the associated
/// values aren't numeric, the error SPICE(TYPEMISMATCH) is
/// signaled.
///
/// 3) If the dimension of VALUES indicated by MAXN is too small to
/// contain the requested values, the error SPICE(ARRAYTOOSMALL)
/// is signaled. The output array VALUES must be declared with
/// sufficient size to contain all of the values associated with
/// the requested kernel variable.
///
/// 4) If the input dimension MAXN indicates there is more room
/// in VALUES than there really is---for example, if MAXN is
/// 10 but values is declared with dimension 5---and the dimension
/// of the requested kernel variable is larger than the actual
/// dimension of VALUES, then this routine may overwrite
/// memory. The results are unpredictable.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine simplifies looking up PCK kernel variables by
/// constructing names of requested kernel variables and by
/// performing error checking.
///
/// This routine is intended for use in cases where the maximum number
/// of values that may be returned is known at compile time. The
/// caller fetches all of the values associated with the specified
/// kernel variable via a single call to this routine. If the number
/// of values to be fetched cannot be known until run time, the
/// lower-level routine GDPOOL should be used instead. GDPOOL
/// supports fetching arbitrary amounts of data in multiple "chunks."
///
/// This routine is intended for use in cases where the requested
/// kernel variable is expected to be present in the kernel pool. If
/// the variable is not found or has the wrong data type, this
/// routine signals an error. In cases where it is appropriate to
/// indicate absence of an expected kernel variable by returning a
/// boolean "found flag" with the value .FALSE., again the routine
/// GDPOOL should be used.
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for this example may differ across
/// platforms. The results depend on the SPICE kernels used as
/// input, the compiler and supporting libraries, and the machine
/// specific arithmetic implementation.
///
/// 1) Retrieve the radii of the Earth from the kernel pool, using
/// both 'RADII' and 'radii' as the item name to return. Since
/// the ITEM variable possesses case sensitivity, the later case
/// should fail. Trap the error and print it to the output.
///
/// Use the PCK kernel below to load the required triaxial
/// ellipsoidal shape model for the Earth.
///
/// pck00008.tpc
///
///
/// Example code begins here.
///
///
/// PROGRAM BODVCD_EX1
/// IMPLICIT NONE
///
/// C
/// C Local parameters.
/// C
/// INTEGER NVALS
/// PARAMETER ( NVALS = 3 )
///
///
/// C
/// C Local variables.
/// C
/// DOUBLE PRECISION VALUES (NVALS)
///
/// INTEGER DIM
///
/// C
/// C Load a PCK.
/// C
/// CALL FURNSH ( 'pck00008.tpc' )
///
/// C
/// C When the kernel variable
/// C
/// C BODY399_RADII
/// C
/// C is present in the kernel pool---normally because a PCK
/// C defining this variable has been loaded (as is the case
/// C here)---the call
/// C
/// CALL BODVCD ( 399, 'RADII', 3, DIM, VALUES )
///
/// C
/// C returns the dimension and values associated with the
/// C variable 'BODY399_RADII'
/// C
/// WRITE(*,'(A,3F10.3)') '399 RADII: ', VALUES
///
/// C
/// C The ITEM variable possesses case sensitivity. This
/// C call should cause an error.
/// C
/// CALL BODVRD ( 'EARTH', 'radii', 3, DIM, VALUES )
/// WRITE(*,'(A,3F10.3)') '399 radii: ', VALUES
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// 399 RADII: 6378.140 6378.140 6356.750
///
/// ============================================================***
///
/// Toolkit version: N0066
///
/// SPICE(KERNELVARNOTFOUND) -- The Variable Was not Found in th***
/// Pool.
///
/// The variable BODY399_radii could not be found in the kernel ***
///
/// A traceback follows. The name of the highest level module i***
/// BODVRD
///
/// Oh, by the way: The SPICELIB error handling actions are USER-
/// TAILORABLE. You can choose whether the Toolkit aborts or co***
/// when errors occur, which error messages to output, and where***
/// the output. Please read the ERROR "Required Reading" file, ***
/// the routines ERRACT, ERRDEV, and ERRPRT.
///
/// ============================================================***
///
///
/// Warning: incomplete output. 8 lines extended past the right
/// margin of the header and have been truncated. These lines are
/// marked by "***" at the end of each line.
///
///
/// Note that, usually, the last call will cause a
/// SPICE(KERNELVARNOTFOUND) error to be signaled, because this
/// call will attempt to look up the values associated with a
/// kernel variable of the name
///
/// 'BODY399_radii'
///
/// Since kernel variable names are case sensitive, this
/// name is not considered to match the name
///
/// 'BODY399_RADII'
///
/// which normally would be present after a text PCK
/// containing data for all planets and satellites has
/// been loaded.
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// B.V. Semenov (JPL)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.0.1, 07-SEP-2021 (JDR)
///
/// Edited the header to comply with NAIF standard.
/// Added complete example code based on the existing fragments.
///
/// Removed note about GDPOOL being entry point of POOL from
/// $Particulars section.
///
/// - SPICELIB Version 1.0.0, 24-OCT-2004 (NJB) (BVS) (WLT) (IMU)
/// ```
pub fn bodvcd(
ctx: &mut SpiceContext,
bodyid: i32,
item: &str,
maxn: i32,
dim: &mut i32,
values: &mut [f64],
) -> crate::Result<()> {
BODVCD(
bodyid,
item.as_bytes(),
maxn,
dim,
values,
ctx.raw_context(),
)?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure BODVCD ( Return d.p. values from the kernel pool )
pub fn BODVCD(
BODYID: i32,
ITEM: &[u8],
MAXN: i32,
DIM: &mut i32,
VALUES: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut VALUES = DummyArrayMut::new(VALUES, 1..);
let mut CODE = [b' '; CDELEN as usize];
let mut TYPE = [b' '; 1];
let mut VARNAM = [b' '; NAMLEN as usize];
let mut FOUND: bool = false;
//
// SPICELIB functions
//
//
// Local parameters
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"BODVCD", ctx)?;
}
//
// Construct the variable name from BODY and ITEM.
//
fstr::assign(&mut VARNAM, b"BODY");
INTSTR(BODYID, &mut CODE, ctx);
SUFFIX(&CODE, 0, &mut VARNAM);
SUFFIX(b"_", 0, &mut VARNAM);
SUFFIX(ITEM, 0, &mut VARNAM);
//
// Make sure the item is present in the kernel pool.
//
DTPOOL(&VARNAM, &mut FOUND, DIM, &mut TYPE, ctx)?;
if !FOUND {
SETMSG(
b"The variable # could not be found in the kernel pool.",
ctx,
);
ERRCH(b"#", &VARNAM, ctx);
SIGERR(b"SPICE(KERNELVARNOTFOUND)", ctx)?;
CHKOUT(b"BODVCD", ctx)?;
return Ok(());
}
//
// Make sure the item's data type is numeric.
//
if fstr::ne(&TYPE, b"N") {
SETMSG(
b"The data associated with variable # are not of numeric type.",
ctx,
);
ERRCH(b"#", &VARNAM, ctx);
SIGERR(b"SPICE(TYPEMISMATCH)", ctx)?;
CHKOUT(b"BODVCD", ctx)?;
return Ok(());
}
//
// Make sure there's enough room in the array VALUES to hold
// the requested data.
//
if (MAXN < *DIM) {
SETMSG(b"The data array associated with variable # has dimension #, which is larger than the available space # in the output array.", ctx);
ERRCH(b"#", &VARNAM, ctx);
ERRINT(b"#", *DIM, ctx);
ERRINT(b"#", MAXN, ctx);
SIGERR(b"SPICE(ARRAYTOOSMALL)", ctx)?;
CHKOUT(b"BODVCD", ctx)?;
return Ok(());
}
//
// Grab the values. We know at this point they're present in
// the kernel pool, so we don't check the FOUND flag.
//
GDPOOL(
&VARNAM,
1,
MAXN,
DIM,
VALUES.as_slice_mut(),
&mut FOUND,
ctx,
)?;
CHKOUT(b"BODVCD", ctx)?;
Ok(())
}