Compucolor.org – Virtual Media

Listing of file='SORTDF.BAS;01' on disk='vmedia/chip_81-sector.ccvf'

1 REM  IDENT
2 REM
5 CLEAR 1024
10 PLOT 12:PRINT "SORTDF.BAS     VER 3.1":PRINT
20 PRINT "RANDOM DISK DATA FILE SORTING PROGRAM"
30 PRINT
40 PRINT "DEVELOPED BY":PRINT "   J L HELMS"
50 PRINT "   1009 LEYTE RD":PRINT "   CORONADO CA  92118"
60 PRINT :PRINT "UTILIZES THE MOUSE AND TREE SORT AS"
70 PRINT "DESCRIBED IN CREATIVE COMPUTING, JAN-FEB 78"
80 PRINT "VOL 4 NO 1 PGS 100-101"
90 FOR T= 1TO 1500:NEXT T
100 PRINT :PRINT "INSERT DATA FILE DISK IF REQUIRED"
110 PRINT "HIT -RETURN- TO CONTINUE"
120 POKE 33278,0
130 IF PEEK (33278)< > 13THEN 130
200 FILE "T",5000
210 FILE "R",1,"SORTID.RND",1
220 GET 1,1,1;F$[13],N,FR,LR,LI,N$[1],NI,X
230 ON XGOTO 300,400
300 PRINT "MAKE LINE CHANGES NOW"
305 PRINT "TYPE RUN TO CONTINUE PROGRAM WHEN READY"
310 PUT 1,1,35;2
320 FILE "C",1
330 FOR T= 1TO 1000:NEXT T
340 LIST
350 END
400 FILE "C",1
500 W= N+ LOG (N)+ 2
510 DIM N(N+ 3):DIM L(W+ 3)
520 FOR J= 1TO N
530 N(J)= FR+ J- 1
540 NEXT J
550 IF N$= "N"THEN NS= 1
560 IF N$= "S"THEN NS= 2
570 FILE "R",1,F$,4
580 FILE "A",1,CR,NR,RS,BF
1300 REM
1301 REM  SORT
1302 REM
1303 PRINT " "
1310 PLOT 12:PRINT "+++   STANDBY - SORTING   +++"
1330 KA= 0:I= 0:M= 0:TB= 0:TD= 0:J= N+ 1
1340 L(1)= 1:L(J)= 1:KB= 1:IF N< 2THEN 2000
1350 S= N
1360 IF S< 4THEN 1390
1370 KB= 2* KB:BB= S/ 2:S= INT (BB):TD= TD+ KB* (BB- S)
1380 GOTO 1360
1390 TD= KB- TD:BB= KB/ 2
1400 IF KA= KBTHEN 2000
1410 KA= KA+ 1:TA= KA:BA= BB:TC= TB
1420 TA= TA/ 2:IF INT (TA)< > TATHEN 1440
1430 M= M+ 1:TB= TB- BA:BA= BA/ 2:GOTO 1420
1440 TB= TB+ BA:IF S= 2THEN 1470
1450 IF TC< TDTHEN 1480
1460 M= - M:GOTO 1500
1470 IF TC< TDTHEN 1490
1480 M= M+ 1:I= I+ 1:L(I)= I:L(J)= I:J= J+ 1
1490 M= M+ 1
1500 I= I+ 1:LA= I:L(I)= I:L(J)= I
1510 LO= J:J= J+ 1:I= I+ 1:LB= I:L(I)= I
1520 L(J)= I:GOTO 1540
1530 J= J- 1:LO= J- 1:LA= L(LO):LB= L(J)
1540 RL= N(LA):RR= N(LB):ON NSGOTO 1541,1545
1541 GET 1,RL,LI;L
1542 GET 1,RR,LI;R
1543 IF L< = RTHEN 1650
1544 GOTO 1610
1545 GET 1,RL,LI;L$[NI]
1546 GET 1,RR,LI;R$[NI]
1600 IF L$< = R$THEN 1650
1610 L(LO)= LB
1620 LO= LB:LB= L(LO):IF LB= LOTHEN 1670
1621 RL= N(LA):RR= N(LB):ON NSGOTO 1622,1626
1622 GET 1,RL,LI;L
1623 GET 1,RR,LI;R
1624 IF L> RTHEN 1620
1625 GOTO 1640
1626 GET 1,RL,LI;L$[NI]
1627 GET 1,RR,LI;R$[NI]
1630 IF L$> R$THEN 1620
1640 L(LO)= LA
1650 LO= LA:LA= L(LO):IF LA< > LOTHEN 1540
1655 LA= L(LO):IF LA< > LOTHEN 1540
1660 L(LO)= LB:GOTO 1680
1670 L(LO)= LA
1680 M= M- 1:IF M> 0THEN 1530
1690 IF M= 0THEN 1400
1700 M= 1- M:GOTO 1640
2000 REM
2001 REM  SORT COMPLETE
2002 REM
2010 LO= N+ 1:PLOT 12:PRINT "SORT COMPLETE"
2020 PRINT :PRINT "IS DRIVE 1 RESERVED FOR SORTED FILE?  ";
2030 POKE 33278,0
2040 K= PEEK (33278):IF K= 0THEN 2040
2041 IF K= 78OR K= 89THEN PRINT " "
2045 IF K= 89THEN 2070
2050 IF K< > 78THEN 2030
2065 FILE "R",2,"SORTED.RND",8
2066 GOTO 2080
2070 REM
2075 FILE "R",2,"CD1:SORTED.RND",8
2080 REM
2120 PLOT 3,0,10:PRINT "STANDBY - WRITING SORTED FILE"
2140 FOR J= 1TO N
2150 LO= L(LO)
2160 PR= N(LO)
2180 REM  GET FILE SPECS     GET 1,PR,1;FILE SPECS
2230 REM  PUT FILE SPECS     PUT 2,J ,1;FILE SPECS
2240 REM  PRINT VARIABLES    PRINT FILE VARIABLES
2245 FOR T= 1TO 500:NEXT T
2250 NEXT J
2260 FILE "C",1,2
2270 FOR T= 1TO 3000:NEXT T
2400 REM
2401 REM  END
2402 REM
2410 PLOT 12
2415 PRINT "DATA FILE SORTED AND WRITTEN":PRINT
2420 PRINT "JOB COMPLETED":PRINT
2430 PRINT "SORTED DATA IN FILE -SORTED.RND-":PRINT
2440 PRINT "NUMBER OF RECORDS               ";N
2450 PRINT "RECORD LENGTH                   ";RS
2470 FOR T= 1TO 3000:NEXT T
3000 PLOT 12
3010 PRINT "ENTER   TO DO":PRINT
3020 PRINT "  1     ANOTHER SORT SAME FILE AND PARAMETERS"
3030 PRINT "  2     ANOTHER SORT SAME FILE NEW PARAMETERS"
3040 PRINT "  3     NEW SORT AND NEW DATA FILE"
3050 PRINT "  4     QUIT"
3060 PRINT :POKE 33278,0
3070 K= PEEK (33278):IF K= 0THEN 3070
3080 K= K- 48
3090 ON KGOTO 3500,3100,3100,3400
3095 GOTO 3060
3100 PRINT :PRINT "INSERT SORT PROGRAM DISK IF REQUIRED"
3110 PRINT "HIT -RETURN- TO CONTINUE"
3120 POKE 33278,0
3130 IF PEEK (33278)< > 13THEN 3130
3140 IF K= 3THEN 3300
3200 LOAD "SORTCT.BAS":RUN
3201 END
3300 LOAD "SORT.BAS":RUN
3301 END
3400 FOR T= 1TO 1000:NEXT T
3410 PLOT 12
3420 END
3500 RUN
3501 END
5000 PLOT 12
5010 FILE "E",F,ER,LN
5020 PRINT "FILE ERROR"
5030 PRINT "FILE NUMBER    ";F
5040 PRINT "ERROR CODE     ";ER
5050 PRINT "LINE NUMBER    ";LN
5070 END