Accessing Files Programmer's Guide (32650-90885)

102 Chapter5
Opening a File
Opening a Device File
opens a labeled magnetic tape file labltape. Use of the HPFOPEN
labeled tape label
option
indicates to the file system that the file is opened as a labeled magnetic tape file.
Example 5-6. Opening a Labeled Magnetic Tape File
procedure open_labeled_magnetic_tape_file;
const
formal_designator_option = 2; {defines HPFOPEN
itemnum
2 }
domain_option = 3; {defines HPFOPEN
itemnum
3 }
tape_label_option = 8; {defines HPFOPEN
itemnum
8 }
tape_expiration_option =31; {defines HPFOPEN
itemnum
31 }
device_class_option =42; {defines HPFOPEN
itemnum
42 }
type
pac80 = packed array [1..80] of char;
var
file_num : integer; {required HPFOPEN
filenum
parameter }
status : integer; {returns info if error/warning occurs }
file_name : pac80; {declares HPFOPEN
itemnum
2 }
old : integer; {declares HPFOPEN
itemnum
3 }
tape_label : pac80; {declares HPFOPEN
itemnum
8 }
expire_date : pac80 {declares HPFOPEN
itemnum
31 }
device_class : pac80 {declares HPFOPEN
itemnum
42 }
begin
file_num :=0;
status :=0;
file_name :='&labltape&'; {delimiter is "&" }
old :=3; {equivalent to specifying permanent}
tape_label :='&tape01&'; {ANSI tape label }
expire_date :='&05/20/87&' {when data is no longer useful }
device_class :='&tape&'; {system-configured device name }
HPFOPEN (file_num, status,
formal_designator_option, file_name, {
formaldesignator option
}
domain_option, old, {
domain option
}
tape_label_option, tape_label, {
labeled tape label option
}
tape_expiration_option, expire_date, {
labeled tape expiration option
}
device_class_option, device_class {
device class option
}
);
if status <> 0 then handle_file_error (file_num, status);
end;
If the HPFOPEN call is successful, a positive integer value is returned in file_num and
status returns a value of zero. The magnetic tape files is now open and ready to be
accessed. If an error or warning condition is encountered by HPFOPEN, status returns a
nonzero value, thus invoking the error-handling procedure handle_file_error.
In appendix A "HP Pascal/iX Program Examples," Example A-2 uses a similar procedure to
open a labeled magnetic tape file. For more information about HPFOPEN parameters, refer
to the MPE/iX Intrinsics Reference Manual.