FastSort Manual

Sorting Programmatically
FastSort Manual429834-003
4-17
Sorting From TAL Programs
!!-----------------------------------------------------------!
?PAGE "Start of MAIN Procedure"
!-----------------------------------------------------------!
PROC main^proc MAIN;
BEGIN
INT length;
INT index;
INT(32) buf^addr := $XADR(block^buffer);
INT(32) buf^addr2 := $XADR(block^buffer2);
INT(32) rec^addr := $XADR(inbuf);
!-----------------------------------------------------------!
! Perform standard initialization. !
!-----------------------------------------------------------!
CALL MYTERM (home^term^name);
CALL OPEN (home^term^name, home^term^filenum);
IF <> THEN CALL DEBUG;
CALL INITIALIZER; ! Read the startup message.
!-----------------------------------------------------------!
! Initialize SORT key definitions array. !
!-----------------------------------------------------------!
key^array[0] := 1; ! Number of keys
key^array[1] := 9; ! Definition = binary, signed, ascending
key^array[2] := 2; ! Key length = 2 bytes
key^array[3] := 0; ! Key offset = 0 bytes
!-----------------------------------------------------------!
! Call SORTBUILDPARM to Initialize SORTPROG control block. !
! Request blocked, double-buffered interface. !
!-----------------------------------------------------------!
error := SORTBUILDPARM (ctlblk,,,
buf^addr, buf^addr2,
block^length);
!-----------------------------------------------------------!
! Call SORTMERGESTART to start the SORTPROG process. !
!-----------------------------------------------------------!
error := SORTMERGESTART (ctlblk,
key^array,,1,,,
dcount,,,,,,
flags,,,,,,,,,,
flags2);
IF error THEN ! Check for SORTMERGESTART error.
BEGIN
length := SORTERRORSUM (ctlblk,
error^buf,
error^code,
error^source);
! Process the SORTMERGESTART error.
END;
!-----------------------------------------------------------!
! Call SORTMERGESEND to send records to SORTPROG. !
! (Note: This program sends successive negative values in !
! descending order to SORTPROG. SORTPROG then returns the !
! values sorted in ascending order. An actual program !
! would get input values from another source.) !
!-----------------------------------------------------------!
Example 4-3. TAL Example of a Serial Sort Run (page 2 of 3)