HP Pascal/iX Programmer's Guide (31502-90023)

3-: 19
The procedures readdir, writedir, seek, read, and write have this
relationship:
This Is equivalent to this
readdir(f,i,x); seek(f,i);
read(f,x);
writedir(f,i,x); seek(f,i);
write(f,x);
Example 1
PROGRAM prog;
TYPE
dirfile = FILE OF integer;
VAR
f : dirfile;
i1,i2,i3,i4 : integer;
BEGIN
open(f); {Opens f for direct input/output}
{READ TWO SPECIFIC COMPONENTS USING readdir AND read}
readdir(f,50,i1); {Puts the current position index at component 50.
Assigns component 50 to i1.
Advances the current position index.
Component 51 becomes the current component.}
read(f,i2); {Assigns component 51 to i2.}
{READ TWO SPECIFIC COMPONENTS USING seek AND read}
seek(f,70); {Puts the current position index at component 70.}
read(f,i3); {Assigns component 70 to i3.
Advances the current position index.
Component 71 becomes the current component.}
read(f,i4); {Assigns component 71 to i4.}
{WRITE TWO SPECIFIC COMPONENTS USING writedir AND write}
writedir(f,10,i1); {Puts the current position index at component 10.
Assigns i1 to component 10.
Advances the current position index.
Component 11 becomes the current component.}
write(f,i2); {Assigns i2 to component 11.}
{WRITE TWO SPECIFIC COMPONENTS USING seek AND write}
seek(f,30); {Puts the current position index at component 30.}
write(f,i3); {Assigns i3 to component 30.
Advances the current position index.
Component 31 becomes the current component.}
write(f,i4); {Assigns i4 to component 31.}
END.
All of the sequential I/O procedures work the same way on direct files;
that is, they treat them like sequential files. If you use both
sequential and direct I/O procedures on a file, the following guidelines
apply:
* After the sequential input procedure
read
, any reference to the
buffer--even an explicit assignment to the buffer such as f^ :=
30--assigns the value of the next component to the buffer.
* Because the components of a direct file can be written in any
order, your program can skip components when it writes to a file
directly. If your program reads the file sequentially later, the
values of the skipped components are unpredictable.
* The file-opening procedure open and the direct I/O procedures seek
and writedir leave the buffer undefined. After calling one of
these procedures, your program must call get, read, or readdir