|Introduction||MTB Statements||File System||Compiler||Applications||Reference Guide||Index|
Comet includes the ability to communicate with specialized external software routines. These interfaces are accomplished via Come gateways. The sort gateway provides an efficient sorting method for both he Reporter and your MTB applications.
If the data to be sorted takes up less than 64K bytes, the external sort driver routine performs the sort function in memory, and offers a the fastest sort yet available on a Comet system. For data greater than 64K, the sort driver performs its sorting using temporary disk files (either RAM disk or hard disk). Both the disk and memory sort routines are based on the popular "median of three recursive quicksort" algorithm published by Spontaneous Assembly, Inc.
The external sort driver routine is configured as a gateway device (via QCFIG or SYSGEN), and is named with the standard Comet gateway conventions of G00, G01, etc. You may configure more than one sort gateway, in the case of multiple users wanting to perform sorting operations simultaneously.
Each configured sort gateway requires 64K of system memory above and beyond the other memory required for Comet. This memory is allocated when Comet is started and is reserved for sorting purposes as long as Comet is executing. In effect, the sort areas function as "background" memory areas for Comet. But, instead of functioning as general purpose memory partitions, the sort areas are used exclusively for sorting data.
To implement the sort gateway, configure a type-2 gateway device using the QCFIG program. Configure one sort gateway for each simultaneous sort user. Subsequently, when Comet is started, 64K of memory will be allocated for each sort driver gateway.
For in-memory sorts (up to 64K of data), your program must write data records to the gateway sort area, then issue the appropriate control code to execute the sort (see the next page for the control parameters). For sorts larger than 64K, you must first create two Comet sequential work files. Then, as your program writes data records to the sort gateway, the records are placed in the work files and subsequently sorted and merged together.
Sorting is done from the left to the right in the data records. The quicksort algorithm determines when further sorting is not needed and terminates the sorting routine accordingly. During the sorting operation, your program is suspended (i.e., it does proceed to the next MTB instruction). Thus, from your program's point of view, sorting itself is a singngle instruction.
Once the sort operation is complete, your program may read the sorted records from the gateway in the same fashion it would read records from a sequential file.
The sort driver routine is called from your MTB program using the FILE statement.
The following control options are available for the sort driver gateway. All of these are implemented with the FILE statement.