When
the data file
is
closed. the
PET
writes a special mark. called
an
End
of
File
(EOF)
mark.
on
the data tape
following
the last data item. This mark signais
that
the end of the data file has been reached. Later, when the
PET
is
reading a
file, it
will
read no further when
it
encounters
an
EOF
mark, knowing that
it
has
reached the end of the file.
An
EOF
mark may be searched for
with
the STATUS
WORD command
(ST),
which
checks the file status.
ST
equals 64 when an
EOF
mark
has
been found. The status word
will
be
usefullater
when reading back data
tapes. (For further discussion of the status word, refer to Chapter
4,
"Basic
System Functions.")
Mounting the Data Tape
Mount
the data file cassette into the tape drive
after
you
have loaded
but before you have executed the program. If you run a program
which
is
to
read
to or
write
from
an
external data file (such
as
a cassette) and there
is
no
cassette to read to or
write
from, the
PET
will
search forever looking for a file
on
a
cassette that isn't even there! When the data cassette
is
mounted, the tape
must be positioned
so
that
the data file can be located. Certainly if the
cassette
is
mounted
but
the tape
is
wound to the end, the
PET
will
not
be
able to
locate, read, or
write
any data file.
When writing to a data tape, the PET begins writing
on
the tape
exactly
where
it
is
positioned. Therefore,
be
sure that there
is
nothing at that position
on
the cassette
which
you
don't
want
to lose if the
PET
writes over
it.
Also,
be
sure
there
is
plenty of empty space
on
the cassette
following
the initial position, so
that
as
the
PET
continues to
write
to the tape no further information gets
written
over.
When reading from a tape, the PET searches forward for the data file
name you have specified
in
your OPEN statement. Your data cassette should
therefore
be
positioned at some point prior to the beginning of the data file you
wish to read from. If the
PET
searches forward and never finds the data file
specified in the
OPEN
statement, a
FILE
NOT FOUND
ERROR
message
is
printed
on
the screen.
It
is
a good practice to
put
only one data file on each side of a cassette, al-
ways beginning the file at or near the start of the tape. By doing this. you
will
al-
ways position your tape at the beginning of the tape for both reading and writing.
Furthermore, when
writing
to the tape. you
will
never need to
worry
about
writing
over any other file.
WRITING A DATA
FILE
Creating a data file
is
an
important programming technique because
it
expands the PET's capabilities to
allow
processing of large quantities of
data. This
is
the emphasis of this section.
To create a data file, LOAD the program file. To use
an
external data file, you
must have three statements
within
the program file: an
OPEN
command, a read
or
write
command, and a
CLOSE
commando
242