SUBROUTINE READAHEAD(Unit, File)
* Release Information
* MFG - CUST - 6.0
*  - Asynchronous subroutine to pull a stream of selected records.
LastUpdated... = "Rev: 13:01 25Jun1997 andrewm1 31 /home/andrew/BP/READAHEAD"
***
* Abstract:
*    
*    Normally, once a series of records have been selected from a file,  each
* record is processed one-at-a-time.  This can be a very inefficient  process
* when considering that while the post-read processing is occuring, the  next
* record could have been read.  In that vein, this program was conceived.  In
* an attempt to take full advantage of the resources that might be available,
* this subroutine will read ahead as much data as is possible.
*
*    This subroutine is to  be called  with the  ASYNC option  from the  main
* calling program.  The  general theory  here is  that in  order to  maximize
* system resources, instead of waiting for  single stream of data to be  read
* from a file's select list, multiple instances of this subroutine are to  be
* called to increase the load (and hopefully the throughput) of a file.
*
*    This routine is to be called  for each parallel and simultaneous  stream
* of data that is to be established.  The argument list is as follows:
*  
*    Unit - The active select list to process plus one.
*    File - The file handle to read from.
*  
*    Caveats: This code can be called a multiple of times to further increase
* the load on a file being processed, though keep in mind data may arrive not
* necessarily in the same sequence that it was originally selected.  If order
* is important, only one  copy of this program  should be initiated for  each
* select list that is to be processed.
*
*    Once this program has started, it  will begin loading up the record  and
* key pipelines with  a stream of  data as directed  by the indicated  select
* list.  As each record  appears it and  it's key are  field appended to  the
* pipes.  The record's markers are downgraded to avoid confusion in the  list
* (@FM -> @VM, @VM -> @SM, @SM -> @IM).  
*
*    To process this information back  in the main  program, simply grab  the
* first field in each  pipe (KeyPipe(i)<1> and  RecordPipe(i)<1>) and do  a
* DEL to purge it.   Once the EofPipe(i)<1> element  goes true the stream  is
* complete and processing only need  continue until the pipelines are  empty.
* In order to access this  stream  of  data,  a  copy  of  the  common  block
* definition (found below named REDAHD)  must be copied  to the main  calling
* program.  The following is an example of how to call this routine:
*
*    COMMON /REDAHD/ RecordPipe(9), KeyPipe(9), EofPipe(9)
*    OPEN filename TO File yada, yada, yada...
*    SELECT File
*    Unit = 1
*    * The following calls establish four streams of data flow from the
*    * select list...
*    EofPipe(Unit) = 0
*    KeyPipe(Unit) = ""
*    RecordPipe(Unit) = ""
*    CALL READAHEAD(Unit,File) ASYNC
*    CALL READAHEAD(Unit,File) ASYNC
*    CALL READAHEAD(Unit,File) ASYNC
*    CALL READAHEAD(Unit,File) ASYNC
*    * The pipes should be filling starting now...
*    LOOP WHILE NOT(EofPipe(Unit)) AND RECORD(Unit)
*       KEY = KeyPipe(Unit)<1>
*       RECORD = RAISE(RecordPipe(Unit)<1>)
*       DEL KeyPipe(Unit)<1>
*       DEL RecordPipe(Unit)<1>
*       GOSUB ProcessRecord
*    REPEAT
*    RETURN
*
***
* R e v i s i o n   L o g
* Proj Who..... When.... Why................................................
* NONE andrewm1 06/25/97 Initial coding.
*
***
 
COMMON /REDAHD/ KeyPipe(9), RecordPipe(9), EofPipe(9)
 
LOOP
   READNEXT Key FROM Unit-1     ELSE EXIT
   READ Record  FROM File, Key  ELSE CONTINUE
   KeyPipe(Unit)<-1>    = Key
   RecordPipe(Unit)<-1> = LOWER(Record)
REPEAT
EofPipe(Unit) = 1
 
RETURN
 
END
