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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// EK, close file
///
/// Close an E-kernel.
///
/// # Required Reading
///
/// * [EK](crate::required_reading::ek)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// HANDLE I EK file handle.
/// ```
///
/// # Detailed Input
///
/// ```text
/// HANDLE is the file handle of an EK to be closed. Note
/// that EKs open for writing must be closed by this
/// routine in order to be valid.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the indicated file is not recognized, no error is
/// signaled.
///
/// 2) If an I/O error occurs while reading or writing the indicated
/// file, the error is signaled by a routine in the call tree of
/// this routine.
/// ```
///
/// # Files
///
/// ```text
/// See the EK Required Reading ek.req for a discussion of the EK file
/// format.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine should be used to close open EK files. EK files
/// open for writing *must* be closed by this routine in order to be
/// valid. EK files open for read access should also be closed using
/// this routine.
///
/// EKs open for reading won't be corrupted if closed via a FORTRAN
/// CLOSE statement, but the underlying bookkeeping software will
/// become confused if an EK is closed this way---so we recommend
/// closing EK files with EKCLS exclusively.
/// ```
///
/// # 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) The following program demonstrates how to create a new EK and
/// add data to a character column in a given record within the
/// file, how to update the data in this record, and how to read
/// the data from it.
///
/// The example shows the effect of the EKCLS calls when the EK
/// file has been opened for write or read access.
///
///
/// Example code begins here.
///
///
/// PROGRAM EKCLS_EX1
/// IMPLICIT NONE
///
/// C
/// C Include the EK Column Name Size (CNAMSZ)
/// C
/// INCLUDE 'ekcnamsz.inc'
///
/// C
/// C Local constants.
/// C
/// CHARACTER*(*) EKNAME
/// PARAMETER ( EKNAME = 'ekcls_ex1.bdb' )
///
/// CHARACTER*(*) IFNAME
/// PARAMETER ( IFNAME = 'Test EK' )
///
/// CHARACTER*(*) TABLE
/// PARAMETER ( TABLE = 'CHR_DATA' )
///
/// INTEGER CVLEN
/// PARAMETER ( CVLEN = 9 )
///
/// INTEGER DECLEN
/// PARAMETER ( DECLEN = 200 )
///
/// INTEGER MAXVAL
/// PARAMETER ( MAXVAL = 4 )
///
/// INTEGER NCOLS
/// PARAMETER ( NCOLS = 2 )
///
/// INTEGER NROWS
/// PARAMETER ( NROWS = 6 )
///
/// INTEGER NRESVC
/// PARAMETER ( NRESVC = 0 )
///
/// C
/// C Local variables
/// C
/// CHARACTER*(DECLEN) CDECLS ( NCOLS )
/// CHARACTER*(CNAMSZ) CNAMES ( NCOLS )
/// CHARACTER*(CVLEN) CVALS ( MAXVAL )
///
/// INTEGER HANDLE
/// INTEGER I
/// INTEGER J
/// INTEGER NVALS
/// INTEGER RECNO
/// INTEGER SEGNO
///
/// LOGICAL ISNULL
///
///
/// C
/// C Open a new EK file. For simplicity, we won't
/// C reserve space for the comment area, so the
/// C number of reserved comment characters is zero.
/// C The constant IFNAME is the internal file name.
/// C
/// CALL EKOPN ( EKNAME, IFNAME, NRESVC, HANDLE )
///
/// C
/// C Set up the table and column names and declarations
/// C for the CHR_DATA segment. We'll index all of
/// C the columns.
/// C
/// CNAMES(1) = 'CHR_COL_1'
/// CDECLS(1) = 'DATATYPE = CHARACTER*(*), '
/// . // 'INDEXED = TRUE, NULLS_OK = TRUE'
///
/// CNAMES(2) = 'CHR_COL_2'
/// CDECLS(2) = 'DATATYPE = CHARACTER*(9), '
/// . // 'SIZE = VARIABLE, NULLS_OK = TRUE'
///
/// C
/// C Start the segment.
/// C
/// CALL EKBSEG ( HANDLE, TABLE, NCOLS,
/// . CNAMES, CDECLS, SEGNO )
///
/// DO I = 0, NROWS-1
///
/// CALL EKAPPR ( HANDLE, SEGNO, RECNO )
///
/// ISNULL = ( I .EQ. 1 )
///
/// CALL INTSTR ( I, CVALS(1) )
/// CALL EKACEC ( HANDLE, SEGNO, RECNO, CNAMES(1),
/// . 1, CVALS, ISNULL )
///
/// C
/// C Array-valued columns follow.
/// C
/// CALL INTSTR ( 10*I, CVALS(1) )
/// CALL INTSTR ( 10*I + 1, CVALS(2) )
/// CALL INTSTR ( 10*I + 2, CVALS(3) )
/// CALL INTSTR ( 10*I + 3, CVALS(4) )
/// CALL EKACEC ( HANDLE, SEGNO, RECNO, CNAMES(2),
/// . 4, CVALS, ISNULL )
///
/// END DO
///
/// C
/// C End the file.
/// C
/// CALL EKCLS ( HANDLE )
///
/// C
/// C Open the EK for write access.
/// C
/// CALL EKOPW ( EKNAME, HANDLE )
///
/// C
/// C Negate the values in the odd-numbered records
/// C using the update routines.
/// C
/// DO I = 1, NROWS, 2
///
/// RECNO = I+1
///
/// ISNULL = ( I .EQ. 1 )
///
/// CALL INTSTR ( -I, CVALS(1) )
/// CALL EKUCEC ( HANDLE, SEGNO, RECNO, CNAMES(1),
/// . 1, CVALS, ISNULL )
///
/// C
/// C Array-valued columns follow.
/// C
/// CALL INTSTR ( -10*I, CVALS(1) )
/// CALL INTSTR ( -(10*I + 1), CVALS(2) )
/// CALL INTSTR ( -(10*I + 2), CVALS(3) )
/// CALL INTSTR ( -(10*I + 3), CVALS(4) )
/// CALL EKUCEC ( HANDLE, SEGNO, RECNO, CNAMES(2),
/// . 4, CVALS, ISNULL )
///
/// END DO
///
/// C
/// C Close the file.
/// C
/// CALL EKCLS ( HANDLE )
///
/// C
/// C Open the created file. Show the values added.
/// C
/// CALL EKOPR ( EKNAME, HANDLE )
///
/// DO I = 1, NROWS
///
/// CALL EKRCEC ( HANDLE, SEGNO, I, CNAMES(1),
/// . NVALS, CVALS, ISNULL )
///
/// IF ( .NOT. ISNULL ) THEN
///
/// WRITE(*,*) 'Data from column: ', CNAMES(1)
/// WRITE(*,*) ' record number: ', I
/// WRITE(*,*) ' values : ',
/// . ( CVALS(J), J=1,NVALS )
/// WRITE(*,*) ' '
///
/// ELSE
///
/// WRITE(*,*) 'Record ', I, 'flag is NULL.'
/// WRITE(*,*) ' '
///
/// END IF
///
/// C
/// C Array-valued columns follow.
/// C
/// CALL EKRCEC ( HANDLE, SEGNO, I, CNAMES(2),
/// . NVALS, CVALS, ISNULL )
///
/// IF ( .NOT. ISNULL ) THEN
///
/// WRITE(*,*) 'Data from column: ', CNAMES(2)
/// WRITE(*,*) ' record number: ', I
/// WRITE(*,*) ' values : ',
/// . ( CVALS(J), J=1,NVALS )
/// WRITE(*,*) ' '
///
/// END IF
///
/// END DO
///
/// C
/// C Close the file.
/// C
/// CALL EKCLS ( HANDLE )
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Data from column: CHR_COL_1
/// record number: 1
/// values : 0
///
/// Data from column: CHR_COL_2
/// record number: 1
/// values : 0 1 2 3
///
/// Record 2 flag is NULL.
///
/// Data from column: CHR_COL_1
/// record number: 3
/// values : 2
///
/// Data from column: CHR_COL_2
/// record number: 3
/// values : 20 21 22 23
///
/// Data from column: CHR_COL_1
/// record number: 4
/// values : -3
///
/// Data from column: CHR_COL_2
/// record number: 4
/// values : -30 -31 -32 -33
///
/// Data from column: CHR_COL_1
/// record number: 5
/// values : 4
///
/// Data from column: CHR_COL_2
/// record number: 5
/// values : 40 41 42 43
///
/// Data from column: CHR_COL_1
/// record number: 6
/// values : -5
///
/// Data from column: CHR_COL_2
/// record number: 6
/// values : -50 -51 -52 -53
///
///
/// Note that the second record does not appear due to setting the
/// ISNULL flag to true for that record. The odd value record
/// numbers have negative values as a result of the update calls.
///
/// After run completion, a new EK exists in the output directory.
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 06-JUL-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Added complete
/// code example and removed non-applicable restriction.
///
/// - SPICELIB Version 1.0.1, 31-MAR-1998 (NJB)
///
/// Corrected $Index_Entries section.
///
/// - SPICELIB Version 1.0.0, 26-SEP-1995 (NJB)
/// ```
pub fn ekcls(ctx: &mut SpiceContext, handle: i32) -> crate::Result<()> {
EKCLS(handle, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure EKCLS ( EK, close file )
pub fn EKCLS(HANDLE: i32, ctx: &mut Context) -> f2rust_std::Result<()> {
//
// SPICELIB functions
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"EKCLS", ctx)?;
}
//
// Close the file as a DAS file.
//
DASCLS(HANDLE, ctx)?;
CHKOUT(b"EKCLS", ctx)?;
Ok(())
}