1 /* dasudi.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 /* Table of constant values */
9
10 static integer c__3 = 3;
11
12 /* $Procedure DASUDI ( DAS, update data, integer ) */
dasudi_(integer * handle,integer * first,integer * last,integer * data)13 /* Subroutine */ int dasudi_(integer *handle, integer *first, integer *last,
14 integer *data)
15 {
16 /* System generated locals */
17 integer i__1, i__2;
18
19 /* Local variables */
20 integer n;
21 extern /* Subroutine */ int chkin_(char *, ftnlen);
22 integer lastc, lastd, recno, lasti;
23 extern /* Subroutine */ int dasa2l_(integer *, integer *, integer *,
24 integer *, integer *, integer *, integer *);
25 extern logical failed_(void);
26 integer clbase;
27 extern /* Subroutine */ int daslla_(integer *, integer *, integer *,
28 integer *), dasuri_(integer *, integer *, integer *, integer *,
29 integer *);
30 integer clsize;
31 extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
32 ftnlen), setmsg_(char *, ftnlen), errint_(char *, integer *,
33 ftnlen);
34 integer wordno, numint;
35 extern logical return_(void);
36 integer nwritn;
37
38 /* $ Abstract */
39
40 /* Update data in a specified range of integer addresses in a DAS */
41 /* file. */
42
43 /* $ Disclaimer */
44
45 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
46 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
47 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
48 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
49 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
50 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
51 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
52 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
53 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
54 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
55
56 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
57 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
58 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
59 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
60 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
61 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
62
63 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
64 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
65 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
66 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
67
68 /* $ Required_Reading */
69
70 /* DAS */
71
72 /* $ Keywords */
73
74 /* ARRAY */
75 /* ASSIGNMENT */
76 /* DAS */
77 /* FILES */
78
79 /* $ Declarations */
80 /* $ Brief_I/O */
81
82 /* Variable I/O Description */
83 /* -------- --- -------------------------------------------------- */
84 /* HANDLE I DAS file handle. */
85 /* FIRST, */
86 /* LAST I Range of integer addresses to write to. */
87 /* DATA I An array of integers. */
88
89 /* $ Detailed_Input */
90
91 /* HANDLE is a file handle of a DAS file opened for writing. */
92
93 /* FIRST, */
94 /* LAST are the first and last of a range of DAS logical */
95 /* addresses of integers. These addresses satisfy the */
96 /* inequality */
97
98 /* 1 < FIRST < LAST < LASTI */
99 /* _ - - */
100
101 /* where LASTI is the last integer logical address in */
102 /* use in the DAS file designated by HANDLE. */
103
104 /* DATA is an array of integers. The array elements */
105 /* DATA(1) through DATA(N) will be written to the */
106 /* indicated DAS file, where N is LAST - FIRST + 1. */
107
108 /* $ Detailed_Output */
109
110 /* See $Particulars for a description of the effect of this routine. */
111
112 /* $ Parameters */
113
114 /* None. */
115
116 /* $ Exceptions */
117
118 /* 1) If the input file handle is invalid, the error will be */
119 /* diagnosed by routines called by this routine. */
120
121 /* 2) Only logical addresses that already contain data may be */
122 /* updated: if either FIRST or LAST are outside the range */
123
124 /* [ 1, LASTI ] */
125
126 /* where LASTI is the last integer logical address that */
127 /* currently contains data in the indicated DAS file, the error */
128 /* SPICE(INVALIDADDRESS) is signalled. The DAS file will not be */
129 /* modified. */
130
131 /* 3) If FIRST > LAST but both addresses are valid, this routine */
132 /* will not modify the indicated DAS file. No error will be */
133 /* signalled. */
134
135 /* 4) If an I/O error occurs during the data update attempted */
136 /* by this routine, the error will be diagnosed by routines */
137 /* called by this routine. FIRST and LAST will not be modified. */
138
139 /* $ Files */
140
141 /* See the description of the argument HANDLE in $Detailed_Input. */
142
143 /* $ Particulars */
144
145 /* This routine replaces the integer data in the specified range of */
146 /* logical addresses within a DAS file with the contents of the */
147 /* input array DATA. */
148
149 /* The actual physical write operations that update the indicated */
150 /* DAS file with the contents of the input array DATA may not take */
151 /* place before this routine returns, since the DAS system buffers */
152 /* data that is written as well as data that is read. In any case, */
153 /* the data will be flushed to the file at the time the file is */
154 /* closed, if not earlier. A physical write of all buffered */
155 /* records can be forced by calling the SPICELIB routine DASWBR */
156 /* (DAS, write buffered records). */
157
158 /* In order to append integer data to a DAS file, filling in a range */
159 /* of integer logical addresses that starts immediately after the */
160 /* last integer logical address currently in use, the SPICELIB */
161 /* routine DASADI ( DAS add data, integer ) should be used. */
162
163 /* $ Examples */
164
165 /* 1) Write to addresses 1 through 500 in a DAS file in */
166 /* random-access fashion by updating the file. Recall */
167 /* that data must be present in the file before it can */
168 /* be updated. */
169
170
171 /* PROGRAM UP */
172
173 /* CHARACTER*(4) TYPE */
174
175 /* INTEGER DATA ( 500 ) */
176
177 /* INTEGER HANDLE */
178 /* INTEGER I */
179
180 /* C */
181 /* C Open the new DAS file RAND.DAS. Use the file name */
182 /* C as the internal file name. */
183 /* C */
184 /* TYPE = 'TEST' */
185 /* CALL DASONW ( 'TEST.DAS', TYPE, 'TEST.DAS', HANDLE ) */
186
187 /* C */
188 /* C Append 500 integers to the file; after the data is */
189 /* C present, we're free to update it in any order we */
190 /* C please. (CLEARI zeros out an integer array.) */
191 /* C */
192 /* CALL CLEARI ( 500, DATA ) */
193 /* CALL DASADI ( HANDLE, 500, DATA ) */
194
195 /* C */
196 /* C Now the integer logical addresses 1:500 can be */
197 /* C written to in random-access fashion. We'll fill them */
198 /* C in in reverse order. */
199 /* C */
200 /* DO I = 500, 1, -1 */
201 /* CALL DASUDI ( HANDLE, I, I, I ) */
202 /* END DO */
203
204 /* C */
205 /* C Close the file. */
206 /* C */
207 /* CALL DASCLS ( HANDLE ) */
208
209 /* C */
210 /* C Now make sure that we updated the file properly. */
211 /* C Open the file for reading and dump the contents */
212 /* C of the integer logical addresses 1:500. */
213 /* C */
214 /* CALL DASOPR ( 'RAND.DAS', HANDLE ) */
215
216 /* CALL CLEARI ( 500, DATA ) */
217 /* CALL DASRDI ( HANDLE, 1, 500, DATA ) */
218
219 /* WRITE (*,*) 'Contents of RAND.DAS:' */
220 /* WRITE (*,*) ' ' */
221 /* WRITE (*,*) DATA */
222
223 /* END */
224
225 /* $ Restrictions */
226
227 /* None. */
228
229 /* $ Literature_References */
230
231 /* None. */
232
233 /* $ Author_and_Institution */
234
235 /* K.R. Gehringer (JPL) */
236 /* N.J. Bachman (JPL) */
237 /* W.L. Taber (JPL) */
238
239 /* $ Version */
240
241 /* - SPICELIB Version 1.2.0 10-APR-2014 (NJB) */
242
243 /* Deleted declarations of unused parameters. */
244
245 /* Corrected header comments: routine that flushes */
246 /* written, buffered records is DASWBR, not DASWUR. */
247
248 /* - SPICELIB Version 1.1.1 19-DEC-1995 (NJB) */
249
250 /* Corrected title of permuted index entry section. */
251
252 /* - SPICELIB Version 1.1.0, 12-MAY-1994 (KRG) (NJB) */
253
254 /* Test of FAILED() added to loop termination conditions. */
255
256 /* Removed references to specific DAS file open routines in the */
257 /* $ Detailed_Input section of the header. This was done in order */
258 /* to minimize documentation changes if the DAS open routines ever */
259 /* change. */
260
261 /* Modified the $ Examples section to demonstrate the new ID word */
262 /* format which includes a file type and to include a call to the */
263 /* new routine DASONW, open new for write, which makes use of the */
264 /* file type. Also, a variable for the type of the file to be */
265 /* created was added. */
266
267 /* - SPICELIB Version 1.0.0, 11-NOV-1992 (NJB) (WLT) */
268
269 /* -& */
270 /* $ Index_Entries */
271
272 /* update integer data in a DAS file */
273
274 /* -& */
275 /* $ Revisions */
276
277 /* - SPICELIB Version 1.1.0, 12-MAY-1994 (KRG) (NJB) */
278
279 /* Test of FAILED() added to loop termination condition. Without */
280 /* this test, an infinite loop could result if DASA2L or DASURI */
281 /* signaled an error inside the loop. */
282
283 /* Removed references to specific DAS file open routines in the */
284 /* $ Detailed_Input section of the header. This was done in order */
285 /* to minimize documentation changes if the DAS open routines ever */
286 /* change. */
287
288 /* Modified the $ Examples section to demonstrate the new ID word */
289 /* format which includes a file type and to include a call to the */
290 /* new routine DASONW, open new for write, which makes use of the */
291 /* file type. Also, a variable for the type of the file to be */
292 /* created was added. */
293
294 /* - SPICELIB Version 1.0.0, 11-NOV-1992 (NJB) (WLT) */
295
296 /* -& */
297
298 /* SPICELIB functions */
299
300
301 /* Local parameters */
302
303
304 /* Local variables */
305
306
307 /* Standard SPICE error handling. */
308
309 if (return_()) {
310 return 0;
311 } else {
312 chkin_("DASUDI", (ftnlen)6);
313 }
314
315 /* Get the last logical addresses in use in this DAS file. */
316
317 daslla_(handle, &lastc, &lastd, &lasti);
318
319 /* Validate the input addresses. */
320
321 if (*first < 1 || *first > lasti || *last < 1 || *last > lasti) {
322 setmsg_("FIRST was #. LAST was #. Valid range is [1,#].", (ftnlen)46);
323 errint_("#", first, (ftnlen)1);
324 errint_("#", last, (ftnlen)1);
325 errint_("#", &lasti, (ftnlen)1);
326 sigerr_("SPICE(INVALIDADDRESS)", (ftnlen)21);
327 chkout_("DASUDI", (ftnlen)6);
328 return 0;
329 }
330
331 /* Let N be the number of addresses to update. */
332
333 n = *last - *first + 1;
334
335 /* We will use the variables RECNO and OFFSET to determine where to */
336 /* write data in the DAS file. RECNO will be the record containing */
337 /* the physical location to write to; WORDNO will be the word */
338 /* location that we will write to next. */
339
340 /* Find the first location to write to. CLBASE and CLSIZE are the */
341 /* base record number and size of the cluster of integer records that */
342 /* the address FIRST lies within. */
343
344 dasa2l_(handle, &c__3, first, &clbase, &clsize, &recno, &wordno);
345
346 /* Set the number of integer words already written. Keep */
347 /* writing to the file until this number equals the number of */
348 /* elements in DATA. */
349
350 /* Note that if N is non-positive, the loop doesn't get exercised. */
351
352
353 nwritn = 0;
354 while(nwritn < n && ! failed_()) {
355
356 /* Write as much data as we can (or need to) into the current */
357 /* record. We assume that CLBASE, RECNO, WORDNO, and NWRITN have */
358 /* been set correctly at this point. */
359
360 /* Find out how many words to write into the current record. */
361 /* There may be no space left in the current record. */
362
363 /* Computing MIN */
364 i__1 = n - nwritn, i__2 = 256 - wordno + 1;
365 numint = min(i__1,i__2);
366 if (numint > 0) {
367
368 /* Write NUMINT words into the current record. */
369
370 i__1 = wordno + numint - 1;
371 dasuri_(handle, &recno, &wordno, &i__1, &data[nwritn]);
372 nwritn += numint;
373 wordno += numint;
374 } else {
375
376 /* It's time to start on a new record. If the record we */
377 /* just finished writing to (or just attempted writing to, */
378 /* if it was full) was not the last of the cluster, the next */
379 /* record to write to is the immediate successor of the last */
380 /* one. Otherwise, we'll have to look up the location of the */
381 /* next integer logical address. */
382
383 if (recno < clbase + clsize - 1) {
384 ++recno;
385 wordno = 1;
386 } else {
387 i__1 = *first + nwritn;
388 dasa2l_(handle, &c__3, &i__1, &clbase, &clsize, &recno, &
389 wordno);
390 }
391 }
392 }
393 chkout_("DASUDI", (ftnlen)6);
394 return 0;
395 } /* dasudi_ */
396
397