DECLARE FUNCTION LOWCAS$ (GRP$) DECLARE FUNCTION FILL$ (DIGITS$, LENG!) DEFDBL R ' Julie Anne Watko [SSDOO/ADC] November 1995 ' (based on a program by Leith Holloway) ' This program searches for records from a star catalog containing ' one of several specified string variables in a specified byte range. ' It can skip records and limit the search, or it can search an entire file. ' It writes output to specified file path and name. caret$ = CHR$(13) linfed$ = CHR$(10) HITMAX& = 0 SEARCHED% = 0 SIZE% = 8 'searches for up to 8 strings CLOSE CLS PRINT "Please type information requested followed by the [return] key." PRINT "Do not enclose string input within quotes." PRINT "Numeric input should be in either standard or scientific notation," PRINT " and should not include commas." PRINT "For example, 4,200,000 may be entered as 4200000 or as 4.2E+4." PRINT BEGIN: CON$ = "" INFILE$ = "" HITS& = 0 REDIM NAME1$(1 TO SIZE%) FOR D = 1 TO SIZE% NAME1$(D) = "" NEXT D ' ' ***Input search criteria*** ' INPUT "File path and name of catalog to search (default is d:\catalogs\8031\38mhz.dat): ", FILE1$ IF SEARCHED% < 1 THEN INPUT "Output file path and name (be sure this is a blank file): ", FILE2$ INPUT "Number of records to skip (default is 0): ", RECSKIP INPUT "Number of records to search (default is 1000): ", RECNUM INPUT "Starting byte (column) number of searched field (default is 1): ", IST INPUT "Ending byte (column) number of searched field (default is starting byte number): ", IEND INPUT "Are search strings located in a file? (y or n, default is n): ", INFILE$ IF INFILE$ = "y" OR INFILE$ = "Y" THEN INPUT "Name of file containing search strings: ", FILE3$ INPUT "High estimate of number of strings in the file (default is 255): ", APPROX& ELSE PRINT "You may search for up to "; SIZE%; " numbers or strings." INPUT "Please enter the first number or string to find: ", NAME1$(1) FOR S = 2 TO SIZE% INPUT "Next number or string to find: ", NAME1$(S) IF NAME1$(S) = "" THEN EXIT FOR NEXT S END IF INPUT "Limit number of hits to how many? (default is no limit): ", HITMAX& INPUT "Write date and time to output file? (y or n, default is y): ", DT$ ' ' ***Interpret search criteria*** INTERPRET: IF IST = 0 THEN IST = 1 IF IEND = 0 THEN IEND = IST LENG = IEND - IST + 1 LE = LEN(FILE1$) IF LE <= 1 THEN GOSUB IDEFAULT IF SEARCHED% < 1 THEN LE2 = LEN(FILE2$) IF LE2 <= 1 THEN GOSUB ODEFAULT END IF IF INFILE$ = "y" OR INFILE$ = "Y" THEN GOSUB GETSTRINGS ELSE ENUM% = S - 1 REDIM NAME$(1 TO ENUM%) FOR A = 1 TO ENUM% ALLC$ = FILL$(NAME1$(A), LENG) NAME$(A) = LOWCAS$(ALLC$) NEXT A END IF IF RECNUM = 0 THEN RECNUM = 10 ^ 3 IF DT$ = "" OR DT$ = "Y" THEN DT$ = "y" ' ' ***print criteria for confirmation*** CONFIRM: PRINT PRINT "Input is read from disk file: "; FILE1$ PRINT "Output is written to disk file: "; FILE2$ PRINT "Searching bytes "; IST; " through "; IEND PRINT "of records "; RECSKIP + 1; " through "; RECSKIP + RECNUM PRINT " for "; IF HITMAX& = 0 THEN PRINT "all"; ELSE PRINT HITMAX&; PRINT " incidences of:" IF ENUM% <= SIZE% THEN FOR E = 1 TO ENUM% PRINT "|"; NAME$(E); "|" NEXT E ELSE PRINT ENUM%; "strings from file "; FILE3$; " including:" FOR E = 1 TO SIZE% PRINT "|"; NAME$(E); "|" NEXT E END IF INPUT "Is this correct? (y or n)", CON$ PRINT IF NOT CON$ = "y" AND NOT CON$ = "Y" THEN GOTO BEGIN ' ' ***Open files for reading and writing*** OPENING: PRINT "Opening files for reading and writing." OPEN FILE1$ FOR INPUT AS #1 IF SEARCHED% < 1 THEN OPEN FILE2$ FOR BINARY AS #2 PRINT "Skipping "; RECSKIP; " records." FOR F = 1 TO RECSKIP IF NOT EOF(1) THEN LINE INPUT #1, TXTLIN$ ELSE PRINT FILE1$; " contains only "; F - 1; " records." EXIT FOR END IF NEXT F ' ' ***Searching records for strings*** SEARCHING: IF EOF(1) THEN GOTO CLOSURE PRINT "Searching "; RECNUM; " records." FOR L = 1 TO RECNUM IF EOF(1) THEN PRINT FILE1$; " contains only "; L - 1 + RECSKIP; " records." GOTO CLOSURE ELSE LINE INPUT #1, TXTLIN$ SAME$ = LOWCAS$(MID$(TXTLIN$, IST, LENG)) FOR E = 1 TO ENUM% IF NAME$(E) = SAME$ THEN HITS& = HITS& + 1 star$ = LEFT$(TXTLIN$, 230) PRINT "Sequence Number "; PRINT USING "######"; L PRINT star$ PRINT "-------------------------------------------------------------------------------" PUT #2, , TXTLIN$ PUT #2, , caret$ PUT #2, , linfed$ EXIT FOR END IF NEXT E END IF IF HITMAX& <> 0 AND HITS& >= HITMAX& THEN EXIT FOR NEXT L ' ' ***Post-search*** CLOSURE: IF EOF(1) THEN PRINT "End of file reached." ELSEIF HITS& = HITMAX& THEN PRINT "Stopped search after "; HITS&; " hits." ELSE PRINT "Search complete." END IF SEARCHED% = SEARCHED% + 1 MARKER$ = DATE$ + " " + TIME$ + " hits: " + STR$(HITS&) IF DT$ = "y" THEN PUT #2, , MARKER$ PUT #2, , caret$ PUT #2, , linfed$ END IF PRINT MARKER$ INPUT "Type [return] to perform another search; Type 1 & [return] to STOP; ", DUM$ IF DUM$ = "" THEN CLOSE #1 GOTO BEGIN ELSE CLOSE END END IF ' ' ***Reads and interprets strings from a file*** GETSTRINGS: REDIM NAME1$(1 TO APPROX& + 100) LE3 = LEN(FILE3$) IF LE3 <= 1 THEN GOSUB SDEFAULT OPEN FILE3$ FOR INPUT AS #3 FOR I = 1 TO APPROX& + 100 IF NOT EOF(3) THEN INPUT #3, LINE$ NAME1$(I) = LINE$ ELSE EXIT FOR END IF NEXT I ENUM% = I - 1 REDIM NAME$(1 TO ENUM%) FOR A = 1 TO ENUM% ALLC$ = FILL$(NAME1$(A), LENG) NAME$(A) = LOWCAS$(ALLC$) NEXT A CLOSE #3 RETURN ' ' ***READ THIS AND SAVE YOURSELF LOTS OF TYPING*** ' 'Please create a table of frequently used input files. 'To create a default setting: ' Type the file path and name between the double quotes (""). ' Remove the apostrophe (') from the beginning of the line. ' Save the program to your disk. 'Feel free to add additional single-character codes. 'When running the program, you will be asked for the input file name. ' Simply type the single character code and hit [return]. IDEFAULT: IF FILE1$ = "" THEN FILE1$ = "d:\catalogs\8031\38MHz.dat" 'IF FILE1$ = "1" THEN FILE1$ = "" 'IF FILE1$ = "2" THEN FILE1$ = "" 'IF FILE1$ = "3" THEN FILE1$ = "" 'IF FILE1$ = "4" THEN FILE1$ = "" 'IF FILE1$ = "5" THEN FILE1$ = "" 'IF FILE1$ = "6" THEN FILE1$ = "" 'IF FILE1$ = "7" THEN FILE1$ = "" 'IF FILE1$ = "8" THEN FILE1$ = "" RETURN 'Please create a table of names for output files. 'Follow the directions provided above for the input default table. 'Be careful when using defaults lest you write over an existing file! ODEFAULT: 'IF FILE2$ = "" THEN FILE2$ = "" 'IF FILE2$ = "1" THEN FILE2$ = "" 'IF FILE2$ = "2" THEN FILE2$ = "" 'IF FILE2$ = "3" THEN FILE2$ = "" 'IF FILE2$ = "4" THEN FILE2$ = "" 'IF FILE2$ = "5" THEN FILE2$ = "" 'IF FILE2$ = "6" THEN FILE2$ = "" 'IF FILE2$ = "7" THEN FILE2$ = "" 'IF FILE2$ = "8" THEN FILE2$ = "" RETURN 'Please create a table of default filenames for string input. SDEFAULT: 'IF FILE3$ = "" THEN FILE3$ = "" 'IF FILE3$ = "1" THEN FILE3$ = "" 'IF FILE3$ = "2" THEN FILE3$ = "" 'IF FILE3$ = "3" THEN FILE3$ = "" 'IF FILE3$ = "4" THEN FILE3$ = "" 'IF FILE3$ = "5" THEN FILE3$ = "" 'IF FILE3$ = "6" THEN FILE3$ = "" 'IF FILE3$ = "7" THEN FILE3$ = "" 'IF FILE3$ = "8" THEN FILE3$ = "" RETURN FUNCTION FILL$ (DIGITS$, LENG) LS = LEN(DIGITS$) LL = LENG - LS IF LL = 0 THEN FILL$ = DIGITS$ ELSEIF LL > 0 THEN FILL$ = SPACE$(LL) + DIGITS$ ELSEIF LL < 0 THEN FILL$ = LEFT$(DIGITS$, LENG) END IF END FUNCTION FUNCTION LOWCAS$ (GRP$) LN = LEN(GRP$) LC$ = SPACE$(LN) FOR KK = 1 TO LN NN = ASC(MID$(GRP$, KK, 1)) IF NN > 64 AND NN < 91 THEN LL = NN + 32 ELSE LL = NN MID$(LC$, KK, 1) = CHR$(LL) NEXT KK LOWCAS$ = LC$ END FUNCTION