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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const IFNLEN: i32 = 60;
/// DAF delete comments
///
/// Delete the entire comment area of a previously opened binary
/// DAF attached to HANDLE.
///
/// # Required Reading
///
/// * [DAF](crate::required_reading::daf)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// HANDLE I The handle of a binary DAF opened for writing.
/// ```
///
/// # Detailed Input
///
/// ```text
/// HANDLE is the handle of a binary DAF that is to have its entire
/// comment area deleted. The DAF must have been opened
/// with write access.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the binary DAF attached to HANDLE is not open with write
/// access, an error is signaled by a routine in the call tree of
/// this routine.
/// ```
///
/// # Files
///
/// ```text
/// See argument HANDLE in $Detailed_Input.
/// ```
///
/// # Particulars
///
/// ```text
/// A binary DAF contains an area which is reserved for storing
/// annotations or descriptive textual information about the data
/// contained in a file. This area is referred to as the ``comment
/// area'' of the file. The comment area of a DAF is a line
/// oriented medium for storing textual information. The comment
/// area preserves any leading or embedded white space in the line(s)
/// of text which are stored, so that the appearance of the of
/// information will be unchanged when it is retrieved (extracted) at
/// some other time. Trailing blanks, however, are NOT preserved,
/// due to the way that character strings are represented in
/// standard Fortran 77.
///
/// This routine will delete the entire comment area from the binary
/// DAF attached to HANDLE. The size of the binary DAF will remain
/// unchanged. The space that was used by the comment records
/// is reclaimed.
/// ```
///
/// # 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) Delete the entire comment area of a DAF file. Note that this
/// action should only be performed if fresh new comments are to
/// be placed within the DAF file.
///
/// Use the SPK kernel below as input DAF file for the program.
///
/// earthstns_itrf93_201023.bsp
///
///
/// Example code begins here.
///
///
/// PROGRAM DAFDC_EX1
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions
/// C
/// INTEGER RTRIM
///
/// C
/// C Local parameters
/// C
/// CHARACTER*(*) KERNEL
/// PARAMETER ( KERNEL =
/// . 'earthstns_itrf93_201023.bsp' )
///
/// INTEGER BUFFSZ
/// PARAMETER ( BUFFSZ = 10 )
///
/// INTEGER LINLEN
/// PARAMETER ( LINLEN = 1000 )
///
/// C
/// C Local variables.
/// C
/// CHARACTER*(LINLEN) BUFFER ( BUFFSZ )
///
/// INTEGER HANDLE
/// INTEGER I
/// INTEGER N
///
/// LOGICAL DONE
///
/// C
/// C Open a DAF for write. Return a HANDLE referring to the
/// C file.
/// C
/// CALL DAFOPW ( KERNEL, HANDLE )
///
/// C
/// C Print the first 10 lines of comments from the DAF file.
/// C
/// WRITE(*,'(A)') 'Comment area of input DAF file '
/// . // '(max. 10 lines): '
/// WRITE(*,'(A)') '---------------------------------------'
/// . // '-----------------------'
///
/// CALL DAFEC ( HANDLE, BUFFSZ, N, BUFFER, DONE )
///
/// DO I = 1, N
///
/// WRITE (*,*) BUFFER(I)(:RTRIM(BUFFER(I)))
///
/// END DO
///
/// WRITE(*,'(A)') '---------------------------------------'
/// . // '-----------------------'
/// WRITE(*,*) ' '
/// WRITE(*,*) 'Deleting entire comment area...'
///
/// C
/// C Delete all the comments from the DAF file.
/// C
/// CALL DAFDC ( HANDLE )
///
/// C
/// C Close the DAF file and re-open it for read
/// C access to work around the DAFEC restriction
/// C on comments not to be modified while they are
/// C being extracted.
/// C
/// CALL DAFCLS( HANDLE )
///
/// CALL DAFOPR( KERNEL, HANDLE )
///
/// C
/// C Check if the comments have indeed been deleted.
/// C
/// CALL DAFEC ( HANDLE, BUFFSZ, N, BUFFER, DONE )
///
/// IF ( DONE .AND. N .EQ. 0 ) THEN
///
/// WRITE(*,*) ' '
/// WRITE(*,*) ' Successful operation.'
///
/// ELSE
///
/// WRITE(*,*) ' '
/// WRITE(*,*) ' Operation failed.'
///
/// END IF
///
/// C
/// C Safely close the DAF.
/// C
/// CALL DAFCLS ( HANDLE )
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Comment area of input DAF file (max. 10 lines):
/// --------------------------------------------------------------
///
/// SPK for DSN Station Locations
/// ========================================================***
///
/// Original file name: earthstns_itrf93_2***
/// Creation date: 2020 October 28 12:30
/// Created by: Nat Bachman (NAIF***
///
///
/// Introduction
/// --------------------------------------------------------------
///
/// Deleting entire comment area...
///
/// Successful operation.
///
///
/// Warning: incomplete output. 3 lines extended past the right
/// margin of the header and have been truncated. These lines are
/// marked by "***" at the end of each line.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// K.R. Gehringer (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 25-NOV-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
/// Added complete code example.
///
/// - SPICELIB Version 1.0.0, 23-SEP-1994 (KRG)
/// ```
pub fn dafdc(ctx: &mut SpiceContext, handle: i32) -> crate::Result<()> {
DAFDC(handle, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DAFDC ( DAF delete comments )
pub fn DAFDC(HANDLE: i32, ctx: &mut Context) -> f2rust_std::Result<()> {
let mut IFNAME = [b' '; IFNLEN as usize];
let mut BWARD: i32 = 0;
let mut FREE: i32 = 0;
let mut FWARD: i32 = 0;
let mut NCOMR: i32 = 0;
let mut ND: i32 = 0;
let mut NI: i32 = 0;
//
// SPICELIB functions
//
//
// Local parameters
//
// Length of a DAF file internal filename.
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"DAFDC", ctx)?;
}
//
// Verify that the DAF attached to HANDLE was opened with write
// access.
//
DAFSIH(HANDLE, b"WRITE", ctx)?;
if FAILED(ctx) {
CHKOUT(b"DAFDC", ctx)?;
return Ok(());
}
//
// Read the file record to obtain the current number of comment
// records in the DAF attached to HANDLE. We will also get back some
// extra stuff that we do not use.
//
DAFRFR(
HANDLE,
&mut ND,
&mut NI,
&mut IFNAME,
&mut FWARD,
&mut BWARD,
&mut FREE,
ctx,
)?;
NCOMR = (FWARD - 2);
if FAILED(ctx) {
CHKOUT(b"DAFDC", ctx)?;
return Ok(());
}
//
// Now we will attempt to remove the comment records, if there are
// any, otherwise we do nothing.
//
if (NCOMR > 0) {
//
// We have some comment records, so remove them.
//
DAFRRR(HANDLE, NCOMR, ctx)?;
if FAILED(ctx) {
CHKOUT(b"DAFDC", ctx)?;
return Ok(());
}
}
//
// We're done now, so goodbye.
//
CHKOUT(b"DAFDC", ctx)?;
Ok(())
}