For random access the location of a d/s within its file is specified by its 'data-structure address', the DsA, consisting of 2 words:
If the file contains less than 2 Gigawords you can pack this into one word with:
JDSAP = (JDSA1-1) * LREC + JDSA2where
LREC
is the number of words in each physical record, as specified
to FZFILE.
For every successful call to FZOUT or FZIN Zebra returns the DsA
of the latest d/s in IQUEST(5)
and IQUEST(6)
,
provided the file-format is 'exchange' and even for a tape file.
To prepare a file for reading it randomly the user would construct
a table, the 'direct access table', or DaT, which contains the
relevant properties of the d/ss on the file plus their DsA's.
This can be done either by an extra read pass over the file
to collect the data, or more economically at the time when the
file is created.
In the latter case the DaT can be written to the file as
the last d/s before end-of-file,
and is then ready for use for any future reading of the file.
When reading a file initialized with mode D given to FZFILE, repeated calls to FZIN will read the data sequentially. To obtain a particular data-structure one has to call FZINXT specifying the DsA of the wanted d/s; this will reset the 'current read point' for the file and the next call to FZIN will then deliver the wanted d/s.
Do this:
CHOPT = 'DO'
or 'LDO'
for a disk file, or
CHOPT = 'TO'
or 'TLO'
for a tape file.
CALL FZODAT (LUN,0,0)
to create the
'DaT forward-reference record'.
This is a small record to provide 2 words to hold the DsA of the DaT
itself; they are initialized to zero and on the final call FZODAT will
try to update them with the true address if the file is ready for
random access.
This should be provided on every file which later one may want
to access randomly, like a tape file to be copied to disk.
This is useful only if this record is the very first record on the file.
IQUEST(5)
and (6)
returned from FZOUT.
CALL FZODAT (LUN,IXDIV,LBANK)
to store the bank with the DaT
onto the file and to update the forward reference record if possible;
Zebra will remember the DsA of this d/s in the control-bank for this file.
CALL FZENDO (LUN,'TX')
to terminate and close the file.
This will store the DsA of the DaT bank into the user header of
the special Zebra EoF record, which is the very last item on the file.
Do this:
1) call FZFILE with CHOPT = 'D'
or 'LD'
to permit random access.
2) retrieve the direct-access table:
CALL FZIDAT (LUN,IXDIV,LDAT,1) IF (IQUEST(1).NE.0) GO TO troubleThis will try to find the Direct access Table:
3) to get a wanted d/s: find it in the DaT, get its DsA
and call \Rind{FZINXT
(LUN,MDS1,MDS2)},
with MDS
the 2-word data-structure address.
This resets the read point, calling \Rind{FZIN
(LUN,...)} will then
deliver the wanted d/s.
If acccess to the table was not immediate, FZIDAT will try to update the forward reference record, if it exists, to ease future use. It can do this only if the file hase been opened for read/write, and this has to be signalled by giving CHOPT='DIO' to FZFILE.
Keeping the DaT on the file to be read is obviously the simplest way to proceed, but other organisations are possible. For example, if one has a large disk with many files as the data-base for the events of an experiment, one may want to have a separate global DaT for all the events on the disk, with a structure reflecting the files and holding their names.
Remember: if one needs a data-base with key-word access or update capability one should use the RZ package of Zebra.