Guardian Programmer's Guide

Table Of Contents
Communicating With Magnetic Tape
Guardian Programmer’s Guide 421922-014
12 - 60
Writing the Program
!------------------------------------------------------------
! This procedure executes when you press "r" in response to
! the function prompt in the main procedure. It prompts the
! user for the desired record, displays it on the terminal,
! then prompts for sequential reads.
!------------------------------------------------------------
PROC READ^RECORD;
BEGIN
INT COUNT^READ;
INT(32) RECORD^NUM;
STRING .EXT NEXT^ADDR;
INT STATUS;
INT ERROR;
! Open the tape DEFINE and set buffered mode:
CALL OPEN^TAPE^FILE;
! Prompt the user to select a record:
PROMPT^AGAIN:
PRINT^BLANK;
SBUFFER ':=' "Enter Record Number: " -> @S^PTR;
CALL WRITEREADX(TERMNUM,SBUFFER,@S^PTR '-' @SBUFFER,
BUFSIZE,COUNT^READ);
IF <> THEN CALL FILE^ERRORS(TERMNUM);
SBUFFER[COUNT^READ] := 0;
! Convert ASCII to numeric:
@NEXT^ADDR := DNUMIN(SBUFFER,RECORD^NUM,10,STATUS);
IF STATUS OR @NEXT^ADDR <> $XADR(SBUFFER[COUNT^READ])
THEN
BEGIN
PRINT^STR("Error in the record number");
GOTO PROMPT^AGAIN;
END;
! Calculate record block number, assuming blocking
! factor of 4:
RBLOCK := RECORD^NUM / 4D;
! Modulo divide to get record index:
INDEX := RECORD^NUM '\' 4;
! Space tape forward to start of record block:
CALL CONTROL(TAPENUM,9,$INT(RBLOCK));
IF <> THEN CALL FILE^ERRORS(TAPENUM);