Accessing Files Programmer's Guide (32650-90885)

134 Chapter9
Reading from a File
Reading From a Magnetic Tape File
massage :='Please input a valid file reference'; {specify prompt }
length := -35; {length of prompt }
control_code := 0 {default condition }
expected_length := -80
PRINT (message,
length,
control_code
);
if ccode <> cce then handle_file_error;
else begin
read_length := READ ( file_name, {read data to output parm}
expected_length {length of file_name }
);
if ccode <> cce then handle_file_error;
end
end;
If an error is encountered by either READ or PRINT, procedure handle_file_error is
invoked. For more information about READ parameters, refer to the MPE/iX Intrinsics
Reference Manual. For more information about using the PRINT intrinsic, refer to chapter
8, "Writing to a File". For more information about opening a file, refer to chapter 5,
"Opening a File". For more information about file designators, refer to chapter 3,
"Specifying a File Designator". In appendix A, "HP Pascal/iX Program Examples", example
A-2 uses a routine similar to example 9-3 to prompt the user for a valid file reference.
Reading From a Magnetic Tape File
Example 9-4 is an HP Pascal/iX code segment that reads records sequentially from an
unlabeled magnetic tape file (indicated by variable tape_file_num) and uses FWRITE to
write them to a disk file (indicated by variable disk_file_num). The operation is
performed in a loop. The loop ends when the FREAD intrinsic encounters an EOF marker on
the tape (indicating the end of the tape file).
Example 9-4. Reading From a Magnetic Tape File
procedure copy_tape_to_disk_file;
var
record : packed array [1..30] of char; {declare record }
end_of_file : boolean; {declare exit condition }
record_length : shortint; {size of record read }
length : shortint; {declare parameter }
control_code : 0..65535; {declare parameter }
begin
end_of_file := false; {initialize exit condition}
control_code := 0; {initialize to default }
length := -80; {size of record to be copied}
repeat {loop until exit condition}