1 /* dskcls.f -- translated by f2c (version 19980913).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
8 /* $Procedure DSKCLS ( DSK, close file ) */
dskcls_(integer * handle,logical * optmiz)9 /* Subroutine */ int dskcls_(integer *handle, logical *optmiz)
10 {
11 /* Builtin functions */
12 integer s_cmp(char *, char *, ftnlen, ftnlen);
13
14 /* Local variables */
15 extern /* Subroutine */ int chkin_(char *, ftnlen), dasham_(integer *,
16 char *, ftnlen), dasllc_(integer *), dascls_(integer *);
17 char method[10];
18 extern /* Subroutine */ int daswbr_(integer *), chkout_(char *, ftnlen);
19 extern logical return_(void);
20
21 /* $ Abstract */
22
23 /* Close a DSK file. */
24
25 /* $ Disclaimer */
26
27 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
28 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
29 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
30 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
31 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
32 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
33 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
34 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
35 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
36 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
37
38 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
39 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
40 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
41 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
42 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
43 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
44
45 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
46 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
47 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
48 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
49
50 /* $ Required_Reading */
51
52 /* DAS */
53 /* DSK */
54
55 /* $ Keywords */
56
57 /* DAS */
58 /* DSK */
59 /* FILES */
60
61 /* $ Declarations */
62
63 /* Include file dla.inc */
64
65 /* This include file declares parameters for DLA format */
66 /* version zero. */
67
68 /* Version 3.0.1 17-OCT-2016 (NJB) */
69
70 /* Corrected comment: VERIDX is now described as a DAS */
71 /* integer address rather than a d.p. address. */
72
73 /* Version 3.0.0 20-JUN-2006 (NJB) */
74
75 /* Changed name of parameter DSCSIZ to DLADSZ. */
76
77 /* Version 2.0.0 09-FEB-2005 (NJB) */
78
79 /* Changed descriptor layout to make backward pointer */
80 /* first element. Updated DLA format version code to 1. */
81
82 /* Added parameters for format version and number of bytes per */
83 /* DAS comment record. */
84
85 /* Version 1.0.0 28-JAN-2004 (NJB) */
86
87
88 /* DAS integer address of DLA version code. */
89
90
91 /* Linked list parameters */
92
93 /* Logical arrays (aka "segments") in a DAS linked array (DLA) file */
94 /* are organized as a doubly linked list. Each logical array may */
95 /* actually consist of character, double precision, and integer */
96 /* components. A component of a given data type occupies a */
97 /* contiguous range of DAS addresses of that type. Any or all */
98 /* array components may be empty. */
99
100 /* The segment descriptors in a SPICE DLA (DAS linked array) file */
101 /* are connected by a doubly linked list. Each node of the list is */
102 /* represented by a pair of integers acting as forward and backward */
103 /* pointers. Each pointer pair occupies the first two integers of a */
104 /* segment descriptor in DAS integer address space. The DLA file */
105 /* contains pointers to the first integers of both the first and */
106 /* last segment descriptors. */
107
108 /* At the DLA level of a file format implementation, there is */
109 /* no knowledge of the data contents. Hence segment descriptors */
110 /* provide information only about file layout (in contrast with */
111 /* the DAF system). Metadata giving specifics of segment contents */
112 /* are stored within the segments themselves in DLA-based file */
113 /* formats. */
114
115
116 /* Parameter declarations follow. */
117
118 /* DAS integer addresses of first and last segment linked list */
119 /* pointer pairs. The contents of these pointers */
120 /* are the DAS addresses of the first integers belonging */
121 /* to the first and last link pairs, respectively. */
122
123 /* The acronyms "LLB" and "LLE" denote "linked list begin" */
124 /* and "linked list end" respectively. */
125
126
127 /* Null pointer parameter. */
128
129
130 /* Segment descriptor parameters */
131
132 /* Each segment descriptor occupies a contiguous */
133 /* range of DAS integer addresses. */
134
135 /* The segment descriptor layout is: */
136
137 /* +---------------+ */
138 /* | BACKWARD PTR | Linked list backward pointer */
139 /* +---------------+ */
140 /* | FORWARD PTR | Linked list forward pointer */
141 /* +---------------+ */
142 /* | BASE INT ADDR | Base DAS integer address */
143 /* +---------------+ */
144 /* | INT COMP SIZE | Size of integer segment component */
145 /* +---------------+ */
146 /* | BASE DP ADDR | Base DAS d.p. address */
147 /* +---------------+ */
148 /* | DP COMP SIZE | Size of d.p. segment component */
149 /* +---------------+ */
150 /* | BASE CHR ADDR | Base DAS character address */
151 /* +---------------+ */
152 /* | CHR COMP SIZE | Size of character segment component */
153 /* +---------------+ */
154
155 /* Parameters defining offsets for segment descriptor elements */
156 /* follow. */
157
158
159 /* Descriptor size: */
160
161
162 /* Other DLA parameters: */
163
164
165 /* DLA format version. (This number is expected to occur very */
166 /* rarely at integer address VERIDX in uninitialized DLA files.) */
167
168
169 /* Characters per DAS comment record. */
170
171
172 /* End of include file dla.inc */
173
174 /* $ Brief_I/O */
175
176 /* Variable I/O Description */
177 /* -------- --- -------------------------------------------------- */
178 /* HANDLE I Handle assigned to the opened DSK file. */
179 /* OPTMIZ I Flag indicating whether to segregate the DSK. */
180
181 /* $ Detailed_Input */
182
183 /* HANDLE is the DAS file handle associated with the file. */
184 /* The file may be open for read or write access. */
185
186 /* OPTMIZ is a logical flag indicating whether the DSK */
187 /* should be segregated before it is closed. This */
188 /* option applies only to files open for write */
189 /* access. The value of OPTMIZ has no effect for */
190 /* files opened for read access. */
191
192 /* See the DAS Required Reading das.req for a */
193 /* discussion of segregation of DAS files. */
194
195 /* $ Detailed_Output */
196
197 /* None. This routine operates by side effects. */
198
199 /* $ Parameters */
200
201 /* None. */
202
203 /* $ Exceptions */
204
205 /* 1) If an error occurs when the file is closed, the error will be */
206 /* diagnosed by routines in the call tree of this routine. */
207
208 /* $ Files */
209
210 /* See argument HANDLE. */
211
212 /* $ Particulars */
213
214 /* This routine provides a DSK-level interface for closing DSK files. */
215
216 /* In cases where DSKs opened for write access are to be closed */
217 /* without segregation, this interface is slightly simpler than that */
218 /* available at the DAS level. */
219
220 /* $ Examples */
221
222 /* 1) Close a new DSK file using DAS segregation. HANDLE */
223 /* is the DAS file handle of the DSK. */
224
225 /* This is the normal choice for DSK creation. */
226
227 /* CALL DSKCLS ( HANDLE, .TRUE. ) */
228
229 /* 2) Close a new DSK file without using DAS segregation. The */
230 /* close operation will be fast, but reading the file will be */
231 /* less efficient than if the file had been segregated. */
232
233 /* CALL DSKCLS ( HANDLE, .TRUE. ) */
234
235 /* 3) Close an existing DSK file that had been opened */
236 /* for read access. In this case OPTMIZ is ignored: */
237
238 /* CALL DSKCLS ( HANDLE, .FALSE. ) */
239
240 /* or */
241
242 /* CALL DSKCLS ( HANDLE, .TRUE. ) */
243
244 /* $ Restrictions */
245
246 /* 1) This routine should not be called by user applications */
247 /* that have loaded a DSK file via FURNSH. Such applications */
248 /* should call the KEEPER entry points UNLOAD or KCLEAR instead. */
249
250 /* $ Literature_References */
251
252 /* None. */
253
254 /* $ Author_and_Institution */
255
256 /* N.J. Bachman (JPL) */
257
258 /* $ Version */
259
260 /* - SPICELIB Version 1.0.0, 08-FEB-2017 (NJB) */
261
262
263 /* 09-OCT-2009 (NJB) */
264
265 /* Updated header. */
266
267 /* 20-OCT-2006 (NJB) */
268
269 /* Original DSKLIB version. */
270
271 /* -& */
272 /* $ Index_Entries */
273
274 /* close a dsk file */
275
276 /* -& */
277
278 /* SPICELIB functions */
279
280
281 /* Local parameters */
282
283
284 /* Local variables */
285
286 if (return_()) {
287 return 0;
288 }
289 chkin_("DSKCLS", (ftnlen)6);
290 if (*optmiz) {
291
292 /* Segregate the file to enable fast read access. This is */
293 /* the "normal" way to close a DSK. Segregating a large file */
294 /* can be slow, however. */
295
296 dascls_(handle);
297 } else {
298
299 /* Close the file without first segregating it; this allows */
300 /* the caller to close the file quickly, but results in a */
301 /* file that will be read more slowly. */
302
303 /* Any buffered data to be written must be explicitly flushed */
304 /* to the file, if the file is open for write access. */
305
306 dasham_(handle, method, (ftnlen)10);
307 if (s_cmp(method, "WRITE ", (ftnlen)10, (ftnlen)6) == 0) {
308
309 /* Write out any buffered records belonging to the */
310 /* indicated file. */
311
312 daswbr_(handle);
313 }
314
315 /* Close the file without segregating records. */
316
317 dasllc_(handle);
318 }
319 chkout_("DSKCLS", (ftnlen)6);
320 return 0;
321 } /* dskcls_ */
322
323