Table of contents
CSPICE_DASLLC closes the DAS file associated with a given handle, without
flushing buffered data or segregating the file.
Given:
handle the handle of a previously opened DAS file.
help, handle
LONG = Scalar
the call:
cspice_dasllc, handle
returns:
None.
See -Particulars for a description of the effect of this routine.
None.
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) Write a DAS file by adding data to it over multiple passes.
Avoid spending time on file segregation between writes.
Each pass opens the file, adds character, double precision,
and integer data to the file, writes out buffered data by
calling cspice_daswbr, and closes the file without segregating the
data by calling cspice_dasllc.
The program also checks the file: after the final write,
the program reads the data and compares it to expected values.
Note that most user-oriented applications should segregate a
DAS file after writing it, since this greatly enhances file
reading efficiency. The technique demonstrated here may be
useful for cases in which a file will be written via many
small data additions, and in which the file is read between
write operations.
Example code begins here.
PRO dasllc_ex1
;;
;; Local parameters
;;
CHRLEN = 50L
IBUFSZ = 20L
DBUFSZ = 30L
;;
;; Local variables
;;
dpbuf = dblarr( DBUFSZ )
intbuf = lonarr( IBUFSZ )
xdpbuf = dblarr( DBUFSZ )
xintbf = lonarr( IBUFSZ )
;;
;; Initial values
;;
fname = 'dasllc_ex1.das'
ftype = 'ANG'
ncall = 1000
ncomr = 10
npass = 3
;;
;; Open a new DAS file. We'll allocate `ncomr' records
;; for comments. The file type is not one of the standard
;; types recognized by SPICE; however it can be used to
;; ensure the database file is of the correct type.
;;
;; We'll use the file name as the internal file name.
;;
cspice_dasonw, fname, ftype, fname, ncomr, handle
;;
;; Add data of character, integer, and double precision
;; types to the file in interleaved fashion. We'll add to
;; the file over `npass' "passes," in each of which we close
;; the file after writing.
;;
for passno=1L, npass do begin
if ( passno gt 1L ) then begin
print, 'Opening file for write access...'
cspice_dasopw, fname, handle
endif
for i=1L, ncall do begin
;;
;; Add string data to the file.
;;
chrbuf = 'Character value #'
cspice_repmi, chrbuf, '#', i, chrbuf
;;
;; Make sure that the chrbuf is a BYTE array of at
;; least CHRLEN items: convert the string data to
;; BYTE and append CHRLEN BYTE elements set to 0.
;;
chrbuf = [BYTE( chrbuf ), bytarr( CHRLEN )]
cspice_dasadc, handle, CHRLEN, 0L, CHRLEN-1, chrbuf
;;
;; Add double precision data to the file.
;;
for j=1L, DBUFSZ do begin
dpbuf[j-1] = DOUBLE( 100000000L*passno + 100L*i + j )
endfor
cspice_dasadd, handle, dpbuf
;;
;; Add integer data to the file.
;;
for j=1L, IBUFSZ do begin
intbuf[j-1] = 100000000L*passno + 100L * i + j
endfor
cspice_dasadi, handle, intbuf
endfor
;;
;; Write buffered data to the file.
;;
print, 'Writing buffered data...'
cspice_daswbr, handle
;;
;; Close the file without segregating it.
;;
print, 'Closing DAS file...'
cspice_dasllc, handle
endfor
print, 'File write is done.'
;;
;; Check file contents.
;;
cspice_dasopr, fname, handle
;;
;; Read data from the file; compare to expected values.
;;
;; Initialize end addresses.
;;
lastc = 0L
lastd = 0L
lasti = 0L
for passno=1L, npass do begin
for i=1L, ncall do begin
;;
;; Check string data.
;;
xchrbf = 'Character value #'
cspice_repmi, xchrbf, '#', i, xchrbf
firstc = lastc + 1L
lastc = lastc + CHRLEN
cspice_dasrdc, handle, firstc, lastc, 0, CHRLEN-1, chrbuf
if ( STRING(chrbuf) ne xchrbf ) then begin
print, 'Character data mismatch: '
print, 'PASS = ', passno
print, 'I = ', i
print, 'Expected = ', xchrbf
print, 'Actual = ', STRING(chrbuf)
exit
endif
;;
;; Check double precision data.
;;
for j=1L, DBUFSZ do begin
xdpbuf[j-1] = DOUBLE( 100000000L*passno + 100L*i + j )
endfor
firstd = lastd + 1L
lastd = lastd + DBUFSZ
cspice_dasrdd, handle, firstd, lastd, dpbuf
for j=0L, DBUFSZ-1L do begin
if ( dpbuf[j] ne xdpbuf[j] ) then begin
print, 'Double precision data mismatch: '
print, 'PASS = ', passno
print, 'I = ', i
print, 'J = ', j
print, 'Expected = ', xdpbuf[j]
print, 'Actual = ', dpbuf[j]
exit
endif
endfor
;;
;; Check integer data.
;;
for j=1L, IBUFSZ do begin
xintbf[j-1] = 100000000L*passno + 100L * i + j
endfor
firsti = lasti + 1L
lasti = lasti + IBUFSZ
cspice_dasrdi, handle, firsti, lasti, intbuf
for j=0L, IBUFSZ-1L do begin
if ( intbuf[j] ne xintbf[j] ) then begin
print, 'Integer data mismatch: '
print, 'PASS = ', passno
print, 'I = ', i
print, 'J = ', j
print, 'Expected = ', xintbf[j]
print, 'Actual = ', intbuf[j]
exit
endif
endfor
endfor
endfor
print, 'File check is done.'
;;
;; Close the file.
;;
cspice_dascls, handle
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Writing buffered data...
Closing DAS file...
Opening file for write access...
Writing buffered data...
Closing DAS file...
Opening file for write access...
Writing buffered data...
Closing DAS file...
File write is done.
File check is done.
Note that after run completion, a new DAS file exists in the
output directory.
Normally, routines outside of Icy will not need to call this
routine. Application programs should close DAS files by calling
the Icy routine cspice_dascls. This routine is a lower-level
routine that is called by cspice_dascls, but (obviously) does not have
the full functionality of cspice_dascls.
This routine closes a DAS file and updates the DAS file manager's
bookkeeping information on open DAS files. Because the DAS file
manager must keep track of which files are open at any given time,
it is important that DAS files be closed only with cspice_dascls or
cspice_dasllc, to prevent the remaining DAS routines from failing,
sometimes mysteriously.
Note that when a file is opened more than once for read or write
access, cspice_dasopr returns the same handle each time it is re-opened.
Each time the file is closed, cspice_dasllc checks to see if any other
claims on the file are still active before physically closing
the file.
Unlike cspice_dascls, this routine does not force a write of updated,
buffered records to the indicated file, nor does it segregate the
data records in the file.
1) If the specified handle does not belong to a DAS file that is
currently open, this routine returns without signaling an
error.
2) If the input argument `handle' is undefined, an error is
signaled by the IDL error handling system.
3) If the input argument `handle' is not of the expected type, or
it does not have the expected dimensions and size, an error is
signaled by the Icy interface.
See the description of the argument `handle' in -I/O.
None.
DAS.REQ
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
-Icy Version 1.0.0, 09-JUN-2021 (JDR)
close a DAS file
|