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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const VERIDX: i32 = 1;
const LLBIDX: i32 = (VERIDX + 1);
const LLEIDX: i32 = (LLBIDX + 1);
const NULPTR: i32 = -1;
const BWDIDX: i32 = 1;
const FWDIDX: i32 = (BWDIDX + 1);
const IBSIDX: i32 = (FWDIDX + 1);
const ISZIDX: i32 = (IBSIDX + 1);
const DBSIDX: i32 = (ISZIDX + 1);
const DSZIDX: i32 = (DBSIDX + 1);
const CBSIDX: i32 = (DSZIDX + 1);
const CSZIDX: i32 = (CBSIDX + 1);
const DLADSZ: i32 = CSZIDX;
const FMTVER: i32 = 1000000;
const NCHREC: i32 = 1024;
const SRFIDX: i32 = 1;
const CTRIDX: i32 = (SRFIDX + 1);
const CLSIDX: i32 = (CTRIDX + 1);
const TYPIDX: i32 = (CLSIDX + 1);
const FRMIDX: i32 = (TYPIDX + 1);
const SYSIDX: i32 = (FRMIDX + 1);
const PARIDX: i32 = (SYSIDX + 1);
const NSYPAR: i32 = 10;
const MN1IDX: i32 = (PARIDX + NSYPAR);
const MX1IDX: i32 = (MN1IDX + 1);
const MN2IDX: i32 = (MX1IDX + 1);
const MX2IDX: i32 = (MN2IDX + 1);
const MN3IDX: i32 = (MX2IDX + 1);
const MX3IDX: i32 = (MN3IDX + 1);
const BTMIDX: i32 = (MX3IDX + 1);
const ETMIDX: i32 = (BTMIDX + 1);
const DSKDSZ: i32 = ETMIDX;
const SVFCLS: i32 = 1;
const GENCLS: i32 = 2;
const LATSYS: i32 = 1;
const CYLSYS: i32 = 2;
const RECSYS: i32 = 3;
const PDTSYS: i32 = 4;
pub const LBCELL: i32 = -5;
const TOKLEN: i32 = 4;
/// DSK, get object IDs
///
/// Find the set of body ID codes of all objects for which
/// topographic data are provided in a specified DSK file.
///
/// # Required Reading
///
/// * [CELLS](crate::required_reading::cells)
/// * [DAS](crate::required_reading::das)
/// * [DSK](crate::required_reading::dsk)
/// * [SETS](crate::required_reading::sets)
/// * [NAIF_IDS](crate::required_reading::naif_ids)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// DSKFNM I Name of DSK file.
/// BODIDS I-O Set of ID codes of objects in DSK file.
/// ```
///
/// # Detailed Input
///
/// ```text
/// DSKFNM is the name of a DSK file. This file will be opened for
/// read access by this routine.
///
/// BODIDS is an initialized SPICE set data structure.
///
/// BODIDS optionally may contain a set of body ID codes on
/// input; on output, the data already present in BODIDS will
/// be combined with ID code set found for the file DSKFNM.
///
/// If BODIDS contains no data on input, its size and
/// cardinality still must be initialized.
/// ```
///
/// # Detailed Output
///
/// ```text
/// BODIDS is a SPICE set data structure that contains the union
/// of its contents upon input with the set of body ID codes
/// of segments in the indicated DSK file.
///
/// The elements of SPICE sets are unique; each ID code in
/// BODIDS appears only once, even if the DSK file contains
/// multiple segments for that ID code.
///
/// See the $Examples section below for a complete example
/// program showing how to retrieve the body and surface ID
/// codes from a DSK file.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the input file has transfer format, the error
/// SPICE(INVALIDFORMAT) is signaled.
///
/// 2) If the input file is not a transfer file but has architecture
/// other than DAS, the error SPICE(INVALIDARCHTYPE) is signaled.
///
/// 3) If the input file is a binary DAS file of type other than DSK,
/// the error SPICE(INVALIDFILETYPE) is signaled.
///
/// 4) If the DSK file cannot be opened or read, an error is signaled
/// by a routine in the call tree of this routine.
///
/// 5) If the size of the output set argument BODIDS is insufficient
/// to contain the actual number of ID codes of objects covered by
/// the indicated DSK file, the error SPICE(CELLTOOSMALL) is
/// signaled.
/// ```
///
/// # Files
///
/// ```text
/// See the description of the argument DSKFNM above.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine provides an API via which applications can determine
/// the set of objects for which there are topographic data in a
/// specified DSK file.
/// ```
///
/// # 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) Display the coverage for each object in a specified DSK file.
/// Find the set of objects in the file. Loop over the contents
/// of the ID code set: find the surface ID for each item in the
/// set and display the surface ID.
///
///
/// Example code begins here.
///
///
/// C
/// C Examine a DSK file and identify the set of
/// C central bodies associated with the segments
/// C in the file. For each body, find the
/// C set of surfaces associated with that body.
/// C
/// PROGRAM DSKOBJ_EX1
/// IMPLICIT NONE
/// C
/// C SPICELIB functions
/// C
/// INTEGER CARDI
/// C
/// C Local parameters
/// C
/// INTEGER LBCELL
/// PARAMETER ( LBCELL = -5 )
///
/// INTEGER FILSIZ
/// PARAMETER ( FILSIZ = 255 )
///
/// INTEGER MAXID
/// PARAMETER ( MAXID = 10000 )
/// C
/// C Local variables
/// C
/// CHARACTER*(FILSIZ) DSKFNM
///
/// INTEGER BODIDS ( LBCELL : MAXID )
/// INTEGER I
/// INTEGER J
/// INTEGER SRFIDS ( LBCELL : MAXID )
///
/// C
/// C Initialize body ID and surface ID cells.
/// C
/// CALL SSIZEI ( MAXID, BODIDS )
/// CALL SSIZEI ( MAXID, SRFIDS )
///
/// C
/// C Prompt for the name of a DSK file.
/// C
/// CALL PROMPT ( 'Enter name of DSK file > ', DSKFNM )
///
/// C
/// C Obtain body ID set for the DSK.
/// C
/// CALL DSKOBJ ( DSKFNM, BODIDS )
///
/// DO I = 1, CARDI( BODIDS )
///
/// WRITE (*,*) ' '
/// WRITE (*,*) 'Body ID: ', BODIDS(I)
/// C
/// C Get the surface IDs for the Ith body.
/// C
/// CALL DSKSRF ( DSKFNM, BODIDS(I), SRFIDS )
///
/// DO J = 1, CARDI( SRFIDS )
/// WRITE (*,*) ' Surface ID: ', SRFIDS(J)
/// END DO
///
/// END DO
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, using the DSK file named phobos512.bds, the output
/// was:
///
///
/// Enter name of DSK file > phobos512.bds
///
/// Body ID: 401
/// Surface ID: 401
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) If an error occurs while this routine is updating the set
/// BODIDS, the set may be corrupted.
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 08-OCT-2021 (JDR) (NJB)
///
/// Changed input argument name "DSK" to "DSKFNM" for consistency
/// with other routines.
///
/// Bug fix: added call to FAILED after call to GETFAT.
///
/// Edited the header comments to comply with NAIF standard.
/// Changed the DKS file used in the code example's solution.
/// Added NAIF_IDS to the $Required_Reading section.
///
/// Corrected short error message in entries #2, #3 and #5 in
/// $Exceptions section.
///
/// - SPICELIB Version 1.0.0, 22-AUG-2016 (NJB)
/// ```
pub fn dskobj(ctx: &mut SpiceContext, dskfnm: &str, bodids: &mut [i32]) -> crate::Result<()> {
DSKOBJ(dskfnm.as_bytes(), bodids, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DSKOBJ ( DSK, get object IDs )
pub fn DSKOBJ(DSKFNM: &[u8], BODIDS: &mut [i32], ctx: &mut Context) -> f2rust_std::Result<()> {
let mut BODIDS = DummyArrayMut::new(BODIDS, LBCELL..);
let mut ARCH = [b' '; TOKLEN as usize];
let mut KERTYP = [b' '; TOKLEN as usize];
let mut DSKDSC = StackArray::<f64, 24>::new(1..=DSKDSZ);
let mut BID: i32 = 0;
let mut DLADSC = StackArray::<i32, 8>::new(1..=DLADSZ);
let mut HANDLE: i32 = 0;
let mut NXTDSC = StackArray::<i32, 8>::new(1..=DLADSZ);
let mut FOUND: bool = false;
//
// SPICELIB functions
//
//
// Local parameters
//
//
// Local variables
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"DSKOBJ", ctx)?;
//
// See whether GETFAT thinks we've got a DSK file.
//
GETFAT(DSKFNM, &mut ARCH, &mut KERTYP, ctx)?;
if FAILED(ctx) {
CHKOUT(b"DSKOBJ", ctx)?;
return Ok(());
}
if fstr::eq(&ARCH, b"XFR") {
SETMSG(b"Input file # has architecture #. The file must be a binary DSK file to be readable by this routine. If the input file is an DSK file in transfer format, run TOBIN on the file to convert it to binary format.", ctx);
ERRCH(b"#", DSKFNM, ctx);
ERRCH(b"#", &ARCH, ctx);
SIGERR(b"SPICE(INVALIDFORMAT)", ctx)?;
CHKOUT(b"DSKOBJ", ctx)?;
return Ok(());
} else if fstr::ne(&ARCH, b"DAS") {
SETMSG(b"Input file # has architecture #. The file must be a binary DSK file to be readable by this routine. Binary DSK files have DAS architecture. If you expected the file to be a binary DSK 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);
ERRCH(b"#", DSKFNM, ctx);
ERRCH(b"#", &ARCH, ctx);
SIGERR(b"SPICE(INVALIDARCHTYPE)", ctx)?;
CHKOUT(b"DSKOBJ", ctx)?;
return Ok(());
} else if fstr::ne(&KERTYP, b"DSK") {
SETMSG(b"Input file # has file type #. The file must be a binary DSK file to be readable by this routine. If you expected the file to be a binary DSK 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);
ERRCH(b"#", DSKFNM, ctx);
ERRCH(b"#", &KERTYP, ctx);
SIGERR(b"SPICE(INVALIDFILETYPE)", ctx)?;
CHKOUT(b"DSKOBJ", ctx)?;
return Ok(());
}
//
// Open the DSK for read access; start a forward search.
//
DASOPR(DSKFNM, &mut HANDLE, ctx)?;
DLABFS(HANDLE, NXTDSC.as_slice_mut(), &mut FOUND, ctx)?;
if FAILED(ctx) {
CHKOUT(b"DSKOBJ", ctx)?;
return Ok(());
}
while (FOUND && !FAILED(ctx)) {
//
// Get the DSK descriptor of the current segment.
// This is where we'll find the body ID code.
//
MOVEI(NXTDSC.as_slice(), DLADSZ, DLADSC.as_slice_mut());
DSKGD(HANDLE, DLADSC.as_slice(), DSKDSC.as_slice_mut(), ctx)?;
//
// The body ID is at location CTRIDX ("center index")
// of the DSK descriptor.
//
// Append, rather than insert, the new ID. We'll
// turn the cell into a set at the end of the loop.
//
// Before appending, make sure there's room in the cell
// for another entry. We can't afford to let APPNDI
// catch an out-of-room error, because we would lose
// the ability to close the file.
//
BID = intrinsics::IDNINT(DSKDSC[CTRIDX]);
if (CARDI(BODIDS.as_slice(), ctx)? == SIZEI(BODIDS.as_slice(), ctx)?) {
//
// We're going to signal an error. Close the DSK
// first.
//
DSKCLS(HANDLE, false, ctx)?;
SETMSG(
b"Cannot append body ID # to cell while reading DSK file #. Cell size is #.",
ctx,
);
ERRINT(b"#", BID, ctx);
ERRCH(b"#", DSKFNM, ctx);
ERRINT(b"#", SIZEI(BODIDS.as_slice(), ctx)?, ctx);
SIGERR(b"SPICE(CELLTOOSMALL)", ctx)?;
CHKOUT(b"DSKOBJ", ctx)?;
return Ok(());
}
APPNDI(BID, BODIDS.as_slice_mut(), ctx)?;
//
// Fetch the DLA descriptor of the next segment.
//
DLAFNS(
HANDLE,
DLADSC.as_slice(),
NXTDSC.as_slice_mut(),
&mut FOUND,
ctx,
)?;
}
VALIDI(
SIZEI(BODIDS.as_slice(), ctx)?,
CARDI(BODIDS.as_slice(), ctx)?,
BODIDS.as_slice_mut(),
ctx,
)?;
DASCLS(HANDLE, ctx)?;
CHKOUT(b"DSKOBJ", ctx)?;
Ok(())
}