| daswbr |
|
Table of contents
Procedure
DASWBR ( DAS, write buffered records )
ENTRY DASWBR ( HANDLE )
Abstract
Write out all buffered records of a specified DAS file.
Required_Reading
DAS
Keywords
ASSIGNMENT
DAS
FILES
Declarations
INTEGER HANDLE
Brief_I/O
VARIABLE I/O DESCRIPTION
-------- --- --------------------------------------------------
HANDLE I Handle of DAS file.
Detailed_Input
HANDLE is the handle of a DAS file opened for writing.
Detailed_Output
None.
See $Particulars for a description of the action of this routine.
Parameters
None.
Exceptions
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.
Files
See the description of the argument HANDLE in $Detailed_Input.
Particulars
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 (DASADC,
DASADD, DASADI) and DAS update data (DASUDC, DASUDD, 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 SPICELIB
routine 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 SPICELIB will generally not need to
call this routine directly.
Examples
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) 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 DASWBR, and closes the file without segregating the
data by calling 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.
PROGRAM DASWBR_EX1
IMPLICIT NONE
C
C Local parameters
C
INTEGER FILSIZ
PARAMETER ( FILSIZ = 255 )
INTEGER FTYPLN
PARAMETER ( FTYPLN = 3 )
INTEGER CHRLEN
PARAMETER ( CHRLEN = 50 )
INTEGER IBUFSZ
PARAMETER ( IBUFSZ = 20 )
INTEGER DBUFSZ
PARAMETER ( DBUFSZ = 30 )
C
C Local variables
C
CHARACTER*(CHRLEN) CHRBUF
CHARACTER*(FILSIZ) FNAME
CHARACTER*(FTYPLN) FTYPE
CHARACTER*(CHRLEN) XCHRBF
DOUBLE PRECISION DPBUF ( DBUFSZ )
DOUBLE PRECISION XDPBUF ( DBUFSZ )
INTEGER FIRSTC
INTEGER FIRSTD
INTEGER FIRSTI
INTEGER HANDLE
INTEGER I
INTEGER INTBUF ( IBUFSZ )
INTEGER J
INTEGER LASTC
INTEGER LASTD
INTEGER LASTI
INTEGER NCALL
INTEGER NCOMR
INTEGER NPASS
INTEGER PASSNO
INTEGER XINTBF ( IBUFSZ )
C
C Initial values
C
DATA FNAME / 'daswbr_ex1.das' /
DATA FTYPE / 'ANG' /
DATA NCALL / 1000 /
DATA NCOMR / 10 /
DATA NPASS / 3 /
C
C Open a new DAS file. We'll allocate NCOMR records
C for comments. The file type is not one of the standard
C types recognized by SPICE; however it can be used to
C ensure the database file is of the correct type.
C
C We'll use the file name as the internal file name.
C
CALL DASONW ( FNAME, FTYPE, FNAME, NCOMR, HANDLE )
C
C Add data of character, integer, and double precision
C types to the file in interleaved fashion. We'll add to
C the file over NPASS "passes," in each of which we close
C the file after writing.
C
DO PASSNO = 1, NPASS
IF ( PASSNO .GT. 1 ) THEN
WRITE (*,*) 'Opening file for write access...'
CALL DASOPW( FNAME, HANDLE )
END IF
DO I = 1, NCALL
C
C Add string data to the file.
C
CHRBUF = 'Character value #'
CALL REPMI( CHRBUF, '#', I, CHRBUF )
CALL DASADC ( HANDLE, CHRLEN, 1, CHRLEN, CHRBUF )
C
C Add double precision data to the file.
C
DO J = 1, DBUFSZ
DPBUF(J) = DBLE( 100000000*PASSNO + 100*I + J )
END DO
CALL DASADD ( HANDLE, DBUFSZ, DPBUF )
C
C Add integer data to the file.
C
DO J = 1, IBUFSZ
INTBUF(J) = 100000000*PASSNO + 100 * I + J
END DO
CALL DASADI ( HANDLE, IBUFSZ, INTBUF )
END DO
C
C Write buffered data to the file.
C
WRITE (*,*) 'Writing buffered data...'
CALL DASWBR ( HANDLE )
C
C Close the file without segregating it.
C
WRITE (*,*) 'Closing DAS file...'
CALL DASLLC ( HANDLE )
END DO
WRITE (*,*) 'File write is done.'
C
C Check file contents.
C
CALL DASOPR( FNAME, HANDLE )
C
C Read data from the file; compare to expected values.
C
C Initialize end addresses.
C
LASTC = 0
LASTD = 0
LASTI = 0
DO PASSNO = 1, NPASS
DO I = 1, NCALL
C
C Check string data.
C
XCHRBF = 'Character value #'
CALL REPMI( XCHRBF, '#', I, XCHRBF )
FIRSTC = LASTC + 1
LASTC = LASTC + CHRLEN
CALL DASRDC ( HANDLE, FIRSTC, LASTC,
. 1, CHRLEN, CHRBUF )
IF ( CHRBUF .NE. XCHRBF ) THEN
WRITE (*,*) 'Character data mismatch: '
WRITE (*,*) 'PASS = ', PASSNO
WRITE (*,*) 'I = ', I
WRITE (*,*) 'Expected = ', XCHRBF
WRITE (*,*) 'Actual = ', CHRBUF
STOP
END IF
C
C Check double precision data.
C
DO J = 1, DBUFSZ
XDPBUF(J) = DBLE( 100000000*PASSNO
. + 100*I + J )
END DO
FIRSTD = LASTD + 1
LASTD = LASTD + DBUFSZ
CALL DASRDD ( HANDLE, FIRSTD, LASTD, DPBUF )
DO J = 1, DBUFSZ
IF ( DPBUF(J) .NE. XDPBUF(J) ) THEN
WRITE (*,*)
. 'Double precision data mismatch: '
WRITE (*,*) 'PASS = ', PASSNO
WRITE (*,*) 'I = ', I
WRITE (*,*) 'J = ', J
WRITE (*,*) 'Expected = ', XDPBUF(J)
WRITE (*,*) 'Actual = ', DPBUF(J)
STOP
END IF
END DO
C
C Check integer data.
C
DO J = 1, IBUFSZ
XINTBF(J) = 100000000*PASSNO + 100 * I + J
END DO
FIRSTI = LASTI + 1
LASTI = LASTI + IBUFSZ
CALL DASRDI ( HANDLE, FIRSTI, LASTI, INTBUF )
DO J = 1, IBUFSZ
IF ( INTBUF(J) .NE. XINTBF(J) ) THEN
WRITE (*,*) 'Integer data mismatch: '
WRITE (*,*) 'PASS = ', PASSNO
WRITE (*,*) 'I = ', I
WRITE (*,*) 'J = ', J
WRITE (*,*) 'Expected = ', XINTBF(J)
WRITE (*,*) 'Actual = ', INTBUF(J)
STOP
END IF
END DO
END DO
END DO
WRITE (*,*) 'File check is done.'
C
C Close the file.
C
CALL DASCLS ( HANDLE )
END
When this program was executed on a Mac/Intel/gfortran/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.
Restrictions
None.
Literature_References
None.
Author_and_Institution
N.J. Bachman (JPL)
J. Diaz del Rio (ODC Space)
K.R. Gehringer (JPL)
W.L. Taber (JPL)
Version
SPICELIB Version 2.0.1, 19-MAY-2021 (NJB) (JDR)
Edited the header to comply with NAIF standard. Added complete
code example.
Updated $Particulars in order to provide information about the
high level APIs that actually use this routine.
SPICELIB Version 2.0.0, 30-JUL-2014 (NJB)
Upgraded to support handle manager integration.
SPICELIB Version 1.0.2, 03-NOV-1995 (NJB)
Removed weird spaces from ENTRY statement.
SPICELIB Version 1.0.1, 28-OCT-1993 (KRG)
Removed references to specific DAS file open routines in the
$Detailed_Input section of the header. This was done in order
to minimize documentation changes if the DAS open routines ever
change.
SPICELIB Version 1.0.0, 30-JUN-1992 (NJB) (WLT)
|
Fri Dec 31 18:36:12 2021