REM.. D.ANALYZE
REM.. BY C J Waldock
REM.. (C) The Micro User
REM.. use COSORTD first
REM.. and leave sorted file in TEXT

REM.. reset total
 T%=0
REM.. define constant, carriage return
 R$=c.13

select text

repeat
 procPICKUP
 procCOUNT
until false

display
END

.PICKUP
 select text
 cursor top
 REM.. find first unreversed marker
  find">"
  S$=glt$
 REM.. look for end marker
  if S$=">END" t.g.END
 REM.. set up search string
  S$=S$+R$+gct$+gct$
 REM.. go back to reverse record marker
  cursor at 0
  cursor up
  repl.">","<"
 REM.. start count C%
  C%=1
endproc

.COUNT
 repeat
  REM.. look for string
   find S$
  REM.. reverse marker
   replace">","<"
 REM.. increment counter for this class
   C%=C%+1
 until EOT  
  REM.. adjust counter
   C%=C%-1
  REM.. add class count to total count
   T%=T%+C%
  REM.. add class total to record
   procRECORD
endproc

.RECORD
 select segment 1
 type S$+":  "+str$C%
 type " member(s)"+R$+R$
 display
endproc

.END
 select segment 1
 type"TOTAL OF MEMBERS: "+STR$T%+R$+R$
 REM.. correct reversed record markers
  select text
  cursor top
  repeat
   replace"<",">"
  until EOT
 select segment 1
 display
END
=======================
REM.. D.BISORTD
REM.. BY C J Waldock
REM.. (C) The Micro User
REM.. Reads records from disc, uses
REM.. binary search for record place

REM.. reset record counter C%
 C%=0
REM.. set constants
REM.. R$=carriage return
 R$=chr$13
REM.. Z$=endmarker in file
 Z$=">END"

 procOPENFILE

REM.. reset timer
 TIME=0

 procHEAD
 procTAIL

repeat
 procREAD
 procLOCATE
until false

.OPENFILE
 cls
 vdu10,10,10
 print "ENTER FILE NAME TO BE SORTED"
 print "==>";
 F$=glk$
 F%=openinF$
 print
 print "WORKING . ."
 print
 print "This may take a few minutes"
endproc

REM.. reserve heading in segment 0
.HEAD
 select segment 0
 delete text
 REM.. read and save top four lines
 dothis
  type glf$F%+R$
 times 4
endproc

REM.. Set up start and end markers
REM.. for sorting
.TAIL
 select text
 delete text
 REM.. ASCII code "!" precedes all
 REM..  and ASCII code "~" follows all
 REM..  alphabetic characters
 REM.. Build markers into dummy records
  Y$="!"
  procDUMMIES
  Y$="~"  
  procDUMMIES
endproc

REM.. insert dummy records
.DUMMIES
 dothis
  type ">"
  dothis
   type Y$+R$
  times 9
 times 3
endproc

REM.. read first four lines of record
.READ
 A$=glf$F%
 REM.. check for file end
  if A$=Z$ then goto END
 B$=glf$F%
 C$=glf$F%
 D$=glf$F%
 REM.. S$=surname+forename
  S$=C$+D$
 REM.. increment record count C%
  C%=C%+1
 REM.. set scope of search D%
  D%=C%
endproc

.LOCATE
 REM.. move to third dummy
  cursor top
  cursor down 20
.SEEK
 REM at each search scope D% is halved
   if D%>1 then D%=D%/2
 REM.. compare S$ with name in record
   if S$<glt$+glt$ then goto UP
 REM.. jump to next record
  cursor down 7
 REM.. compare S$ with name in record
   ifS$>glt$+glt$ then goto DOWN
 cursor up 4
 procINSERT
 display
endproc

REM.. S$ was "less than" name found
REM.. so move back in records
REM.. to look again
.UP
 cursor up(D%*9)+2
goto SEEK

REM.. S$ was "greater than" name found
REM.. so move forward in records
REM.. to look again
.DOWN
 cursor up 2
 cursor down(D%*9)
goto SEEK

REM.. add record to correct place
.INSERT
REM.. enter lines already read
 type A$+R$
 type B$+R$
 type C$+R$
 type D$+R$
REM.. read rest of record from disc
REM.. and enter lines as read
 dothis
  type glf$F%+R$
 times 5
endproc 

.END
close#0
procTIDY
procTIME
display
END

.TIDY
REM.. set markers around dummy records
REM.. at start of file
 cursor top
 fkey 3
 cursor down 27
 cursor at 0
 fkey 3
REM.. and delete them
 fkey 7
REM.. set markers around dummy records
REM.. at end of file
 cursor bottom
 fkey 3
 cursor up 27
 cursor at 0
 fkey 3
REM.. and delete
 fkey 7
REM.. add endmarker to file
 type Z$+R$+R$
REM.. retrieve heading from segment 0
 cursor top
 type segment 0
 select segment 0
 delete text
 select text
endproc

.TIME
 T%=TIME
 cls
 vdu10,10,10
 print"TIME to SORT ";
 print str$C%+" RECORDS"
 print "was "+str$(T%DIV100)+".";
 print str$(T%MOD100)+" seconds"
 G%=get
endproc
================
REM.. D.COSORTD
REM.. BY C J Waldock
REM.. (C) The Micro User
REM.. Sorts on code and date
REM.. Reads records from disc, uses
REM..  binary search for record place

REM.. reset record counter C%
 C%=0
REM.. set constants
REM.. R$=carriage return
 R$=chr$13
REM.. Z$=endmarker in file
 Z$=">END"

 procOPENFILE

REM.. reset timer
 TIME=0

 procHEAD
 procTAIL

repeat
 procREAD
 procLOCATE
until false

.OPENFILE
 cls
 vdu10,10,10
 print "ENTER FILE NAME TO BE SORTED"
 print "==>";
 F$=glk$
 F%=openinF$
 print
 print "WORKING . ."
 print
 print "This may take a few minutes"
endproc

REM.. reserve heading in segment 0
.HEAD
 select segment 0
 delete text
 REM.. read and save top four lines
 dothis
  type glf$F%+R$
 times 4
endproc

REM.. Set up start and end markers
REM..  for sorting
.TAIL
 select text
 delete text
 REM.. ASCII code "!" precedes all
 REM.. and ASCII code "~" follows all
 REM.. alphabetic characters
 REM.. build markers into dummy records
  Y$="!"
  procDUMMIES
  Y$="~"  
  procDUMMIES
endproc

REM.. insert dummy records
.DUMMIES
 dothis
  type ">"
  dothis
   type Y$+R$
  times 9
 times 3
endproc

REM.. read first four lines of record
REM.. from disc files
.READ
 A$=glf$F%
 REM.. check for file end
  if A$=Z$ then goto END
 B$=glf$F%
 C$=glf$F%
 D$=glf$F%
 REM.. S$ is search string ("code")
 REM.. S$=field 1 + field 2
  S$=A$+B$
 REM.. increment record count C%
  C%=C%+1
 REM.. set scope of search D%
  D%=C%
endproc

.LOCATE
 REM.. move to third dummy
  cursor top
  cursor down 18
.SEEK
 REM.. compare S$ with code in record
   if S$<glt$+glt$ then goto UP
 REM.. jump to next record
  cursor down 7
 REM.. compare S$ with code in record
   ifS$>glt$+glt$ then goto DOWN
 cursor up 2
 procINSERT
 display
endproc

REM.. S$ was "less than" code found
REM..  so move back in records
REM..  to look again
.UP
 REM at each search scope D% is halved
  if D%>1 then D%=D%/2
 cursor up(D%*9)+2
goto SEEK

REM.. S$ was "greater than" code found
REM..  so move forward in records
REM..  to look again
.DOWN
 REM at each search scope D% is halved
  if D%>1 then D%=D%/2
 cursor down(D%*9)-2
goto SEEK

REM.. add record to correct place
.INSERT
REM.. enter lines already read
 type A$+R$
 type B$+R$
 type C$+R$
 type D$+R$
REM.. Read rest of record from disc
REM..  and enter lines as read
 dothis
  type glf$F%+R$
 times 5
endproc 

.END
close#0
REM.. close file
procTIDY
procTIME
display
END

.TIDY
REM.. Set markers around dummy records
REM..  at start of file
 cursor top
 fkey 3
 cursor at 0
 cursor down 27
 fkey 3
REM..  and delete them
 fkey 7
REM.. Set markers around dummy records
REM..  at end of file
 cursor bottom
 fkey 3
 cursor up 27
 cursor at 0
 fkey 3
REM..  and delete
 fkey 7
REM.. add endmarker to file
 type Z$+R$+R$
REM.. retrieve heading from segment 0
 cursor top
 type segment 0
 select segment 0
 delete text
 select text
endproc

.TIME
 T%=TIME
 cls
 vdu10,10,10
 print"TIME to SORT ";
 print str$C%+" RECORDS"
 print "was "+str$(T%DIV100)+".";
 print str$(T%MOD100)+" seconds"
 G%=get
endproc
====================
REM.. D.COUNT
REM.. BY C J Waldock
REM.. (C) The Micro User
REM.. Simple count of records

REM.. first clear bottom of text
 select text
 cursor top
 find ">END"
 cursor down
 fkey 3
 cursor bottom
 fkey 3
 fkey 7

REM.. initialize record counter C%
 C%=0

REM.. count operation
 cursor top
 repeat
  find ">"
  cursor right
  C%=C%+1
 until EOT

REM.. Adjust C% for ">END"
REM..  and subsequent seek
 C%=C%-2

REM.. advise result
 cursor bottom
 type STR$(C%)+" MEMBERS"
display
====================
REM.. D.GLOBDEL
REM.. BY C J Waldock
REM.. (C) The Micro User
REM.. Global delete of all records
REM..  in text, with selected code

REM.. set constant, carriage return
 R$=chr$13
REM.. reset record counter
 C%=0

 select text
 cursor top

 REM.. Get file required
 REM..  and code for records to delete
cls
 print
 print
 print
 print"DELETES ALL SELECTED RECORDS"
 print
 print" - ARE YOU SURE: Y/N? ";
 procOPTOUT
cls
 print
 print
 print
 print"ENTER CODE(S) for records to be DELETED"
 print
 print"WILDCARD ""#"" may be used"
 print
 print"==> ";
 S$=glk$
 if ascS$<>62 then procADD
 print
 print"OK - Y/N?";
 procOPTOUT
 print
 print"DELETING RECORDS as requested"
 print
 print"Please wait a while . . ."

REM.. deletion of records
 repeat
  find R$+S$
  C%=C%+1
  REM mark record
   fkey3
   cursor down 9
   fkey 3
  PEM delete marked record
   fkey 7
 until EOT
REM.. adjust count for final search
 C%=C%-1

.END
 type R$+str$C%+" RECORDS CODED: "
 type S$+ " DELETED"
 display
END

.OPTOUT
 print"  ==> ";
 Z$=gck$
 printZ$
  ifZ$="y" then Z$="Y"
  ifZ$<>"Y"then goto END
endproc

.ADD
 S$=">"+S$
 print
 print"corrected to: "+S$
endproc
===================
