Table of contents
CSPICE_DASWBR writes out all buffered records of a specified DAS file.
Given:
handle the handle of a DAS file opened for writing.
help, handle
LONG = Scalar
the call:
cspice_daswbr, handle
returns:
None.
See -Particulars for a description of the action 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 daswbr_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 = 'daswbr_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.
This routine writes buffered records out to the DAS file to which
they correspond.
Because the DAS system buffers records that are written as well as those
that are read, data supplied to the DAS add data (cspice_dasadc,
cspice_dasadd, cspice_dasadi) and DAS update data (cspice_dasudc,
cspice_dasudd, cspice_dasudi) routines on input has not necessarily been
physically written to the DAS file specified by the caller of those
routines, at the time those routines return. Before closing a DAS file
that has been opened for writing, the DAS system must write out to the
file any updated records present in the DAS buffers. The Icy routine
cspice_dascls uses this routine to perform this function. The routines
DASAC and DASDC, through the use of the SPICELIB routines DASACR and
DASRCR, which respectively add comment records to or delete comment
records from a DAS file, use this routine to ensure that the SPICELIB
routine DASRWR record buffers don't become out of sync with the file they
operate upon.
In addition, this routine can be used by application programs
that create or update DAS files. The reason for calling this
routine directly would be to provide a measure of safety when
writing a very large file: if the file creation or update were
interrupted, the amount of work lost due to the loss of buffered,
unwritten records could be reduced.
However, routines outside of Icy will generally not need to
call this routine directly.
1) If the input file handle is invalid, an error is signaled
by a routine in the call tree of this routine. The indicated
file will not be modified.
2) If a write operation attempted by this routine fails, an
error is signaled by a routine in the call tree of this
routine. The status of the DAS file written to is uncertain
in this case.
3) If the input argument `handle' is undefined, an error is
signaled by the IDL error handling system.
4) 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)
write buffered records to a DAS file
|