home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / SIMTEL / CPMUG / CPMUG090.ARK / GLCKSORT.BAS < prev    next >
BASIC Source File  |  1984-04-29  |  3KB  |  129 lines

  1.     rem This is the Check Disbursements Entry Sort Program
  2.  
  3.  
  4.     rem This program creates a backup file and copies all undeleted
  5.     rem records to that file. Simultaneously it creates a RAM resident
  6.     rem list of either tag numbers, account numbers, or reference numbers
  7.     rem -  S(xxxx) - and Relative Record KEYS - T(xxxx).
  8.  
  9.     rem The tag, account, or reference numbers are then sorted via a Shell
  10.     rem Metzler algorithm and the Relative Record KEYS carried along.
  11.  
  12.     rem When the sort is complete, the Relative Record KEYS are used to
  13.     rem restore the backed up records to the original file in sorted order.
  14.  
  15.  
  16. %INCLUDE ALL.BAS
  17.  
  18.     dim s(z2),t(z2),n(2,20)
  19.  
  20.     z5$="b:glck":z6$="b:glckback":z7$="b:glcksize":RL=250
  21.  
  22. 8000    INPUT "SORT ON TAG OR REFERENCE # (T OR A)";LINE SORT.KEY$
  23.     IF SORT.KEY$="t" OR SORT.KEY$="T" THEN A9=1:GOTO 8020
  24.     IF SORT.KEY$="a" OR SORT.KEY$="A" THEN A9=2:GOTO 8020
  25.     GOTO 8000
  26.  
  27. 8020    PRINT clear$:PRINT
  28.     PRINT "*** BACKING UP FILE ***"
  29.     PRINT:PRINT "*** NOTE - BACKUP IGNORES DELETED RECORDS ***"
  30.  
  31.     open z5$ recl RL as 1
  32.     create z6$ recl RL as 2
  33.  
  34.  
  35.     Z1=0
  36.  
  37.     FOR Z=1 TO Z2-1
  38.     read #1,z;N(2,1),N(2,2),N$,N(2,7),N(2,8),\
  39.             N(2,9),N(2,10),N(2,11),N(2,12),N(2,13),N(2,14),\
  40.             N(2,15),N(2,16),N(2,17),N(2,18),N(2,19),FLAG$
  41.     IF N(2,1)=0 THEN 8065
  42.     IF N(2,2)=0 THEN 8070
  43.     Z1=Z1+1
  44.     print #2,z1;N(2,1),N(2,2),N$,N(2,7),N(2,8),\
  45.             N(2,9),N(2,10),N(2,11),N(2,12),N(2,13),N(2,14),\
  46.             N(2,15),N(2,16),N(2,17),N(2,18),N(2,19),FLAG$
  47.     T(Z1)=Z1:S(Z1)=N(2,A9)
  48. 8065        NEXT Z
  49. 8070            close 1
  50.             close 2
  51.  
  52.     PRINT clear$:PRINT
  53.     PRINT "*** SORTING ON";
  54.     IF A9=1 THEN PRINT " TAG ***"
  55.     IF A9=2 THEN PRINT " REFERENCE NUMBER ***":PRINT
  56.     PRINT "THIS SORT TAKES FROM 30 SECONDS FOR 100 RECORDS"
  57.     PRINT "TO 10 MINUTES FOR 1000 RECORDS":PRINT
  58.     PRINT "*** PLEASE WAIT ***":PRINT
  59.  
  60.  
  61.     rem This is the actual sort routine
  62.  
  63.     N9=Z1
  64.     M9=N9
  65. 8515    M9=INT(M9/2)
  66.     IF M9=0 THEN 8580
  67.         J9=1:K9=N9-M9
  68.  
  69. 8530    I9=J9
  70. 8535    L9=I9+M9
  71.     IF S(I9)<S(L9) THEN 8565
  72.  
  73.         Z=S(I9):S(I9)=S(L9):S(L9)=Z
  74.         Z=T(I9):T(I9)=T(L9):T(L9)=Z
  75.         I9=I9-M9
  76.  
  77.     IF I9<1 THEN 8565
  78.  
  79.     GOTO 8535
  80.  
  81. 8565    J9=J9+1
  82.     IF J9>K9 THEN 8515
  83.     GOTO 8530
  84.  
  85.  
  86. 8580    PRINT clear$:PRINT
  87.     PRINT "SORT COMPLETED - YOU MAY STILL ABORT":PRINT
  88.     PRINT "IF YOU WISH TO ABORT - JUST TYPE ABORT":PRINT
  89.     PRINT "OTHERWISE TYPE A CARRIAGE RETURN TO CONTINUE !"
  90.     PRINT
  91.         INPUT LINE TEMP$
  92.         IF TEMP$="abort" OR TEMP$="ABORT" THEN 10000
  93.  
  94.             if T(1)=0 then 10000
  95.  
  96.     open z5$ recl RL as 1
  97.     open z6$ recl RL as 2
  98.         open z7$ as 3:read #3;z2,z3:close 3
  99.  
  100.  
  101.     Z2=Z1+1
  102.  
  103.     FOR Z=1 TO Z2-1
  104.     READ #2,T(Z);N(2,1),N(2,2),N$,N(2,7),N(2,8),\
  105.             N(2,9),N(2,10),N(2,11),N(2,12),N(2,13),N(2,14),\
  106.             N(2,15),N(2,16),N(2,17),N(2,18),N(2,19),FLAG$
  107.     PRINT #1,Z;N(2,1),N(2,2),N$,N(2,7),N(2,8),\
  108.             N(2,9),N(2,10),N(2,11),N(2,12),N(2,13),N(2,14),\
  109.             N(2,15),N(2,16),N(2,17),N(2,18),N(2,19),FLAG$
  110.     NEXT Z
  111.  
  112.             for z=1 to 20:n(2,z)=0:next z:n$=""
  113.  
  114.     FOR Z=Z2 TO Z3+2
  115.     print #1,z;N(2,1),N(2,2),N$,N(2,7),N(2,8),\
  116.             N(2,9),N(2,10),N(2,11),N(2,12),N(2,13),N(2,14),\
  117.             N(2,15),N(2,16),N(2,17),N(2,18),N(2,19),FLAG$
  118.     NEXT Z
  119.         close 1
  120.         delete 2
  121.         open z7$ as 3:print #3;z2,z3:close 3
  122.  
  123. chain "glcktran"
  124.  
  125.  
  126. 10000 open z6$ recl RL as 1
  127.     delete 1
  128.     chain "glcktran"
  129.