 CLS
 PRINT "This program will search through all backup and/or all history files"
 PRINT "to extract the latest position of each station.  It outputs these summaries"
 PRINT "to the ALLBAKS.hst and ALLHSTS.hst files."
 PRINT
 PRINT "These files are saved as HISTORY files.  This is so that they"
 PRINT "can be REPLAYED at any time to find out where someone is without"
 PRINT "destroying data on the P or L list."
 PRINT
 PRINT "Just select FILE-REPLAY and after selecting the ALLBAKS.hst or the"
 PRINT "ALLHSTS.hst file, then select the callsign of the station you are looking"
 PRINT "for.  If that station is in the file, APRS will draw the map with that"
 PRINT "station on it."
 PRINT
 PRINT "Or you can use the file to see everyone in a given area.  Just choose"
 PRINT "the map area you are interested in, and replay the file.  Every call in "
 PRINT "the file that is in that area will appear on the map!"
 PRINT
 LOCATE 25, 1: INPUT "Hit ENTER to continue..."; a$
 CLS
 PRINT "Once you run this program ONCE, then save the two summary files in a new"
 PRINT "Directory where you will accumulate new data just for the purpose of building"
 PRINT "this overall SUMMARY file."
 PRINT
 PRINT "From then on, whenever you want to clean up your normal APRS\HSTS directory,"
 PRINT "instead of just deleting all the old TKxxxxx.HST files, simply copy them"
 PRINT "instead into this SUMMARY directory.  Then, run this program on this SUMMARY"
 PRINT "directory.  It will combine the existing summary files and all the new"
 PRINT "TKxxxxx.HST files into another single summary file!  Once you are sure it"
 PRINT "is a good copy, you can delete all of the old TKxxxxx.HST files if you no"
 PRINT "longer need them."
 PRINT
 DIM P$(700)

 INPUT "Search all BK or HST files (H)"; a$
 IF LEFT$(UCASE$(a$), 1) = "B" THEN GOTO BAKS

HSTS: HSTpath$ = "\APRS\HSTS"
      PRINT "Enter path to your APRS\HSTS directory if not "; HSTpath$;
      INPUT a$: IF a$ <> "" THEN HSTpath$ = a$
      SHELL "dir " + HSTpath$ + " >temp.hst"

     OPEN "temp.hst" FOR INPUT AS #1
     DO UNTIL EOF(1)
        LINE INPUT #1, a$: REM PRINT a$
        IF LEN(a$) > 38 AND LEFT$(a$, 1) <> "." AND LEFT$(a$, 1) <> " " THEN
           F$ = LEFT$(a$, 8) + "." + MID$(a$, 10, 3)
           PRINT "Opening "; F$
           OPEN HSTpath$ + "\" + F$ FOR INPUT AS #2
           DO UNTIL EOF(2)
              LINE INPUT #2, a$
              IF LEN(a$) > 40 THEN
                 NxPosC$ = MID$(a$, 1, 9)
                 NxPosT$ = MID$(a$, 19, 6)
                 REM PRINT LEFT$("        Found " + a$, 79)
                 Haveit = 0
                 FOR i = 1 TO NumPos
                     IF NxPosC$ = LEFT$(P$(i), 9) THEN
                        Haveit = -1
                        REM now compare times
                        IF NxPosT$ > MID$(P$(i), 12, 6) THEN 'it is later so swap
                           P$(i) = a$: PRINT LEFT$("      NEWER POSIT: " + P$(i), 79)
                        END IF 'if it was newer
                     END IF' if it is the same callsign
                 NEXT i ' compare to all existing P$(i)
                 IF Haveit = 0 THEN
                    NumPos = NumPos + 1
                    P$(NumPos) = a$
                    PRINT NumPos; LEFT$("      Add pos: " + P$(NumPos), 73)
                 END IF
              END IF' if it was a POSITION (p,)
           LOOP 'read the next line in the BK file
           CLOSE #2 ' Finished all of that file
        END IF 'if it was a valid file name
     LOOP 'to the next BK file
     CLOSE #1 ' Finished that all files in that directory

     F$ = "ALLHSTS.hst"
     PRINT "Enter name of OUTPUT file if other than "; F$;
     INPUT a$: IF a$ <> "" THEN F$ = a$
     OPEN F$ FOR OUTPUT AS #3: PRINT "OPENING OUTPUT FILE..."; F$
     FOR i = 1 TO NumPos: PRINT #3, P$(i): NEXT i
     CLOSE #3
     PRINT : PRINT "DONE!"
     STOP
    
BAKS: BKpath$ = "\APRS\BAKS"
      PRINT "Enter path to your APRS\BAKS directory if not "; BKpath$;
      INPUT a$: IF a$ <> "" THEN BKpath$ = a$
      SHELL "dir " + BKpath$ + " >temp.bk"

     OPEN "temp.bk" FOR INPUT AS #1
     DO UNTIL EOF(1)
        LINE INPUT #1, a$: REM print a$
        IF LEN(a$) > 38 AND LEFT$(a$, 1) <> "." AND LEFT$(a$, 1) <> " " THEN
           F$ = LEFT$(a$, 8) + "." + MID$(a$, 10, 3)
           PRINT "Opening "; F$
           OPEN BKpath$ + "\" + F$ FOR INPUT AS #2
           DO UNTIL EOF(2)
              LINE INPUT #2, a$
              IF LEFT$(a$, 1) = "p" THEN
                 NxPosC$ = MID$(a$, 3, 9)
                 NxPosT$ = MID$(a$, 21, 6)
                 REM PRINT LEFT$("        Found " + a$, 79)
                 Haveit = 0
                 FOR i = 1 TO NumPos
                     IF NxPosC$ = LEFT$(P$(i), 9) THEN
                        Haveit = -1
                        REM now compare times
                        IF NxPosT$ > MID$(P$(i), 12, 6) THEN 'it is later so swap
                           P$(i) = MID$(a$, 3): PRINT LEFT$("      NEWER POSIT: " + P$(i), 79)
                        END IF 'if it was newer
                     END IF' if it is the same callsign
                 NEXT i ' compare to all existing P$(i)
                 IF Haveit = 0 THEN
                    NumPos = NumPos + 1
                    P$(NumPos) = MID$(a$, 3)
                    PRINT NumPos; LEFT$("      Add pos: " + P$(NumPos), 73)
                 END IF
              END IF' if it was a POSITION (p,)
           LOOP 'read the next line in the BK file
           CLOSE #2 ' Finished all of that file
        END IF 'if it was a valid file name
     LOOP 'to the next BK file
     CLOSE #1 ' Finished all files in that directory

     F$ = "ALLBAKS.hst"
     PRINT "Enter output file if other than "; F$;
     INPUT a$: IF a$ <> "" THEN F$ = a$
     OPEN F$ FOR OUTPUT AS #3: PRINT "OPENING OUTPUT FILE..."; F$
     FOR i = 1 TO NumPos: PRINT #3, P$(i): NEXT i
     CLOSE #3


     END






