Guardian Programmer's Guide

Table Of Contents
Communicating With Magnetic Tape
Guardian Programmer’s Guide 421922-014
12 - 53
Writing the Program
FILESEQ attribute must be set to 1 because the file is the first and only file on the tape.
Therefore three DEFINEs are created as shown below.
The program opens the following DEFINE for reading from the tape:
1> SET DEFINE CLASS TAPE, LABELS ANSI, USE IN, VOLUME MYVOL,
FILESEQ 1,FILEID FILE1
2> ADD DEFINE =READ^TAPE
For appending to the tape:
3> SET DEFINE CLASS TAPE, LABELS ANSI, USE EXTEND,
VOLUME MYVOL, FILESEQ 1, FILEID FILE1, BLOCKLEN 2048,
RECLEN 512, RECFORM F
4> ADD DEFINE =APPEND^TAPE
For creating the file and writing to the new file:
5> SET DEFINE CLASS TAPE, LABELS ANSI, USE OUT, VOLUME MYVOL,
FILESEQ 1, FILEID FILE1, BLOCKLEN 2048, RECLEN 512,
RECFORM F
6> ADD DEFINE =CREATE^FILE
Writing the Program
The sample program allows the user to read records from the file, append records to
the file, or create the file and write records to it. The program consists of the following
procedures:
The LOGGER procedure is the MAIN procedure. It calls GET^COMMAND to
prompt the user to select a function (read, append, create, or exit), and then calls
the appropriate procedure.
The INIT and SAVE^STARTUP^MESSAGE procedures save the Startup message
in the global data area and open the process IN file for terminal I/O. In addition,
the INIT procedure checks that labeled tape support has been turned on.
The READ^RECORD procedure opens the file for reading and prompts the user
for a record number. The procedure calculates the record-block number by
dividing the record number by 4 and then reads the corresponding record block.
Using modulo division, the procedure calculates which of the four records
contained in the record block is required, and then it prints the date and
commentary text on the terminal.
After printing out the record, the procedure prompts the user to read the next
record. If the user declines, then the procedure returns control to LOGGER.
Otherwise, the program displays the next record. If the next record is part of a
different record block, then the procedure reads in the next record block from tape.
The APPEND^RECORD procedure opens the file for appending. Once the tape
file is open, the procedure prompts the user to enter the date and commentary text.
The procedure then prompts the user to enter another record. If the user declines,