Guardian Programmer's Guide

Table Of Contents
Communicating With Magnetic Tape
Guardian Programmer’s Guide 421922-014
12 - 41
Writing to a File on Multiple Labeled Tape Volumes
DEFAULT^NAMES);
IF ERROR <> 0 THEN ...
!Create the DEFINE:
DEFINE^NAME ':=' "=MY^TAPE^UPDATE ";
ERROR := DEFINEADD(DEFINE^NAME);
IF ERROR <> 0 THEN ...
Writing to the File
Use the DEFINE created in the previous example for writing to the file as described
below. Note that the DEFINE refers to the last tape reel of a four-tape file. You can
write or append only to the last tape in the file.
1. Open the DEFINE using the FILE_OPEN_ procedure. If the file section exists and
the DEFINE attributes match those on the tape label, then the file is opened.
The returned file number refers to the tape drive that the tape is mounted on.
2. Turn on buffered mode, if desired, using SETMODE function 99.
3. Write records to the file using the WRITE[X] procedure.
The following code fragment updates records on the tape using the DEFINE created
above. Note that because the record block is four times the size of the record, the
application needs to block four records into one record block before the record block is
written to tape in one write operation.
LITERAL SPACE^FORWARD = 9,
BUFFERED^MODE = 99,
ON = 1;
.
.
!Open the tape file:
FILE^NAME ':=' "=MY^TAPE^UPDATE" -> @S^PTR;
ERROR := FILE_OPEN_(FILE^NAME:@S^PTR '-' @FILE^NAME,
TAPE^NUM);
IF ERROR <> 0 THEN ...
!Set buffered mode:
CALL SETMODE(TAPE^NUM,
BUFFERED^MODE,ON);
IF <> THEN ...
.
.
!Block four records into the output buffer:
SBUFFER[0] ':=' LOGICAL^BUFFER^1[0] FOR 512 -> @S^PTR;
S^PTR ':=' LOGICAL^BUFFER^2[0] FOR 512 -> @S^PTR;
S^PTR ':=' LOGICAL^BUFFER^3[0] FOR 512 -> @S^PTR;
S^PTR ':=' LOGICAL^BUFFER^4[0] FOR 512 -> @S^PTR;
!Write a record block to the tape file:
CALL WRITEX(TAPE^NUM,SBUFFER,
@S^PTR '-' @SBUFFER);