Accessing Files Programmer's Guide (32650-90885)

203
A Pascal/XL Program Examples
The HP Pascal/XL program examples in this appendix are provided to help you better
understand how to use MPE/iX file system intrinsics to perform common file access tasks.
Here is a short description of the task handled by each of the program examples in this
appendix:
Program Example A-1 illustrates how you can open three different files–an unlabeled
magnetic tape file, $STDLIST, and a new disk file–and copy records sequentially from
the tape file to the disk file, while concurrently writing the records to $STDLIST.
Program Example A-2 illustrates how you can open a labeled magnetic tape file and a
new disk file, print the user label to $STDLIST, then copy records sequentially from the
tape file to the disk file. Play close attention to how the program closes the new disk file
as a permanent file, and how it allows the user to specify alternate file designators if the
file name already exists.
Program Example A-3 illustrates how you can use the sequential access method of
reading records from an old disk file, then use the random access method of writing the
records to a new labeled disk file.
Program Example A-4 illustrates how you can read from a file using random access
method of data access. In addition, the program shows how you can use the FREADSEEK
intrinsic to increase program performance by prefetching records, thus minimizing I/O
wait-time.
Program Example A-5 illustrates how you can allow a user to update records in a
shared data file. This program makes use of file locking intrinsics, FLOCK and
FUNLOCK, to ensure exclusive access to the shared file during the update process.
Program example A-1
This program illustrates how you can open three different files–an unlabeled magnetic
tape file, $STDLIST, and a new disk file–and copy records sequentially from the tape file to
the disk file while concurrently writing the records to $STDLIST.
Program Algorithm
The task specified above is accomplished by following the steps described below. Also
indicated are the intrinsics used to accomplish file access tasks and the name of the
procedure where the task is accomplished:
1. Open (HPFOPEN) three files--an unlabeled magnetic tape file, and new disk file, and
$STDLIST (see procedure open_unlabeled_tape_file and procedure open_file).
2. In a loop, sequentially read (FREAD) records from tape file, then write (FWRITE) them to
both disk file and $STDLIST (see procedure copy_tapefile_to_disk_file).
Continue loop till tape file's EOF is reached.