Accessing Files Programmer's Guide (32650-90885)

Chapter 9 135
Reading from a File
Reading a File Label from a Labeled Tape File
record_length := FREAD (tape_file_num, record, length);
if ccode = ccl then
handle_file_error (tape_file, 3)
else
if ccode = ccg then {FREAD returns ccg if EOF }
end_of_file := true {exit condition encountered }
else
begin
FWRITE( disk_file_num, {identity returned by HPFOPEN }
record, {read from tape_file_num }
record_length, {actual size of record }
control_code {default }
);
if ccode <> cce then {check condition code for error}
handle_file_error (disk_file, 5);
end
entil end_of_file;
end; {end procedure }
If an error is encountered by either FREAD or FWRITE, procedure handle_file_error is
invoked. For more information about FREAD intrinsic parameters, refer to the MPE/iX
Intrinsics Reference Manual. For more information about the FWRITE intrinsic, refer to
chapter 8, "Writing to a File". In appendix A, "HP Pascal/iX Program Examples", example
A-1 uses a similar procedure to copy records from a tape file to a disk file.
Reading a File Label from a Labeled Tape File
The FREADLABEL intrinsic is used to read a user-defined label located on a labeled magnetic
tape file or a labeled disk file. To read a user-defined header label, the FREADLABEL
intrinsic must be called before the first FREAD is issued for the file. Execution of the first
FREAD causes MPE/iX to skip past any unread user-defined header labels.
Example 9-5 is an HP Pascal/iX code segment that reads a user label located in the
user-defined label portion of data_file, a labeled magnetic tape file. The label is printed
to `STDLIST (identified by list_file) using the FWRITE intrinsic. Assume that both
data_file and list_file have been opened elsewhere with calls to HPFOPEN/FOPEN.
Example 9-5. Reading a User Label from a Labeled Magnetic Tape File
procedure read_user_label;
var
label : packed array [1..80] of char; {holds label from file }
length : shortint; {length of label }
control_code : 0..65535; {required by FWRITE }
begin
length := 40 {required ANSI label size}
control_code := 0 {set to default }