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
//
// 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 METHLN: i32 = 10;
/// DSK, close file
///
/// Close a DSK file.
///
/// # Required Reading
///
/// * [DAS](crate::required_reading::das)
/// * [DSK](crate::required_reading::dsk)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// HANDLE I Handle assigned to the opened DSK file.
/// OPTMIZ I Flag indicating whether to segregate the DSK.
/// ```
///
/// # Detailed Input
///
/// ```text
/// HANDLE is the DAS file handle associated with the file.
/// The file may be open for read or write access.
///
/// OPTMIZ is a logical flag indicating whether the DSK
/// should be segregated before it is closed. This
/// option applies only to files open for write
/// access. The value of OPTMIZ has no effect for
/// files opened for read access.
///
/// See the DAS Required Reading das.req for a
/// discussion of segregation of DAS files.
/// ```
///
/// # Detailed Output
///
/// ```text
/// None. This routine operates by side effects.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If an error occurs when the file is closed, the error is
/// signaled by a routine in the call tree of this routine.
/// ```
///
/// # Files
///
/// ```text
/// See argument HANDLE.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine provides a DSK-level interface for closing DSK files.
///
/// In cases where DSKs opened for write access are to be closed
/// without segregation, this interface is slightly simpler than that
/// available at the DAS level.
/// ```
///
/// # Examples
///
/// ```text
/// 1) Close a new DSK file using DAS segregation. HANDLE
/// is the DAS file handle of the DSK.
///
/// This is the normal choice for DSK creation.
///
/// CALL DSKCLS ( HANDLE, .TRUE. )
///
/// 2) Close a new DSK file without using DAS segregation. The
/// close operation will be fast, but reading the file will be
/// less efficient than if the file had been segregated.
///
/// CALL DSKCLS ( HANDLE, .TRUE. )
///
/// 3) Close an existing DSK file that had been opened
/// for read access. In this case OPTMIZ is ignored:
///
/// CALL DSKCLS ( HANDLE, .FALSE. )
///
/// or
///
/// CALL DSKCLS ( HANDLE, .TRUE. )
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) This routine should not be called by user applications
/// that have loaded a DSK file via FURNSH. Such applications
/// should call the KEEPER entry points UNLOAD or KCLEAR instead.
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 12-OCT-2021 (JDR) (NJB)
///
/// Bug fix: now calls FAILED after call to DASHAM.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.0.0, 08-FEB-2017 (NJB)
///
///
/// 09-OCT-2009 (NJB)
///
/// Updated header.
///
/// 20-OCT-2006 (NJB)
///
/// Original DSKLIB version.
/// ```
pub fn dskcls(ctx: &mut SpiceContext, handle: i32, optmiz: bool) -> crate::Result<()> {
DSKCLS(handle, optmiz, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DSKCLS ( DSK, close file )
pub fn DSKCLS(HANDLE: i32, OPTMIZ: bool, ctx: &mut Context) -> f2rust_std::Result<()> {
let mut METHOD = [b' '; METHLN as usize];
//
// SPICELIB functions
//
//
// Local parameters
//
//
// Local variables
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"DSKCLS", ctx)?;
if OPTMIZ {
//
// Segregate the file to enable fast read access. This is
// the "normal" way to close a DSK. Segregating a large file
// can be slow, however.
//
DASCLS(HANDLE, ctx)?;
} else {
//
// Close the file without first segregating it; this allows
// the caller to close the file quickly, but results in a
// file that will be read more slowly.
//
// Any buffered data to be written must be explicitly flushed
// to the file, if the file is open for write access.
//
DASHAM(HANDLE, &mut METHOD, ctx)?;
if FAILED(ctx) {
CHKOUT(b"DSKCLS", ctx)?;
return Ok(());
}
if fstr::eq(&METHOD, b"WRITE ") {
//
// Write out any buffered records belonging to the
// indicated file.
//
DASWBR(HANDLE, ctx)?;
}
//
// Close the file without segregating records.
//
DASLLC(HANDLE, ctx)?;
}
CHKOUT(b"DSKCLS", ctx)?;
Ok(())
}