KEY.BAS DMS Science Fair, May 1996. June 1997 by Marc Kummel aka Treebeard. Contact mkummel@rain.org, http://www.rain.org/~mkummel/ This is recent code from the vault (1996) to build a plant database for my FLORA webpage at http://www.rain.org/~mkummel/flora/. This code makes a database with separate definition and data files, and lets you test it. Separate HTML and CGI PERL scripts search the database and make it work on the Web. My ISP doesn't allow user CGI-BIN, so I've only tested this by running my own HTTPD server on my home computer. Works fine. Details on the project, including my method for developing PERL CGI scripts without CGI access, are available at http://www.rain.org/~mkummel/flora/intro.html. Usually the goal of plant identification is a name, but my program works with lists instead. For many purposes, a list is more interesting than a single species. For example, as part of an insect survey it might be useful to have a list of all shrubs with yellow, tubular flowers along the Santa Ynez River in August. My KEY program and search form can provide that list. This program makes a simple ASCII database that allows complex searches. It looks for my FLORA database by default, but it could be useful for other projects with minor modifications. Type KEY to start the program with the default plant database. (Or type (no extention) to load a different database.) These are all trees and shrubs that grow in the Santa Ynez Mountains near my home in Santa Barbara, California. Press to try a search. The screen will list a bunch of search catagories. Bring the select bar down to "leaf color" and press to open a window of choices. Toggle a choice by pressing and press when done. Multiple choices within a category are usually OR'd together, eg you can search for plants with green OR white leaves. But a few categories are AND'd, eg "habitat" lets you check for plants that grow in areas that are disturbed AND in full sun. A few categories also take text input, so you can type "oak" in the "common name" field to find any plant with "oak" in its name. Multiple choices between categories are AND'd together. Blank fields are ignored (and recommended). Press to begin a search and you will get back a list of plants, eg a list of shrubs with white or green leaves that are flowering in August. On the Web, this could return a list of active links to separate pages about each species. Simple and powerful. The hard part is making the database, since you have to provide information for each plant about each field. Press to add a new item and see what it's like. That's why I wrote this program, and why I've only done 34 species so far. The actual flora contains several HUNDRED species of trees and shrubs, so I have a lot to do (and learn). To see how the database is structured, take a look at the two files FLORA.DEF and FLORA.DAT using any ASCII editor/viewer. The DEF file is a list of all the fields and options while the DAT file contains the actual data for each species in comma delineated form. The first field in the DEF file contains the actual ASCII text that is stored in the database. This can be much compressed as long as the choices are unique, but I prefer text that makes sense in case I have to repair a file by hand or answer a mailto email request. Separate categories are separated by blank lines. The first line within a category is the name of the category. That's all there is for a text field, otherwise a list of options follow. Options are OR'd together unless the first character of the category is a "@", in which case AND logic is implied. The DAT file contains info for each species. The first line is a row of numbers that describe each comma delineated field. 0 means text, 1 means OR, and 2 means AND. Then comes the actual data, one species per line. Multiple choices are joined with "+" characters, eg "green+white" means green OR white leaves (type 1) and "sun+disturbed" means full sun AND disturbed area (type 2). This format is easy to process with BASIC or (especially) PERL which have powerful string commands. The DAT file is read line by line so it can grow without bounds. A search request from a web form to find plants with alternate leaves that are aromatic might look like this: "leafattach=alternate&char=smell". (HTML uses "&" as a separator.) The search program checks the DEF file to find which fields are the "leafattach" and "char" fields, and then checks through the DAT file line by line to see if "alternate" and "smell" are in the right places. And so it builds up a list of matches which can then be formatted on the fly as a web page and returned to the user. Complicated, but this is for machines not people, and these files are mostly maintained automatically by the KEY program. DEF and DAT files represent a lot of work. KEY makes backups whenever they are modified (as FLORA.DE_ and FLORA.DA_), but I make backups of the backups as well. Never throw away the last version of anything that you know worked! In addition to KEY.BAS, the archive also contains two other files that might be of interest. SEARCH.HTM is an HTML search form with input fields for the flora database. It calls FLORA.PL which is the PERL CGI script that actually searches the DEF and DAT files and returns a formatted HTML list of links. It will take a lot of setup to actually use these files. This became a truly multi-lingual project! I wrote this program to do a job, not to be a general purpose database program. You'll have to study the source code for more help. I wrote KEY using MS Basic PDS v7.10. The code uses the multiple text screens available with VGA to do easy windows, so it will NOT run in a DOS window under Win 3.1x, though it does fine full screen. It will not run under QBasic since it uses DOS interrupts and multiple modules. I haven't tried QuickBasic. Be sure to start Basic with the /l option to load the default interrupt library. The files: KEY.EXE DOS executable KEY.ICO an icon for Win3.1 KEY.PIF run KEY full screen under Win3.1 FLORA.DEF definition file for flora database FLORA.DAT data file for flora database FLORA.DE_ backup database files FLORA.DA_ README.TXT this file TBVAULT.TXT about Treebeard's Basic Vault ------------ KEY12.MAK file list for PDS/QB KEY12.BAS source code: main module KEYSUP01.BAS source code: support routines SEARCH.HTM a HTML search form for the flora FLORA.PL a PERL CGI script to process a search request XQB.BAT batch file to start PDS with source code MAKE.BAT batch file to compile and link from DOS prompt This program and source code are yours to use and modify as you will, but they are offered as freeware with no warranty whatsoever. Give me credit, but do not distribute any changes under my name, or attribute such changes to me in any way. You're on your own! Send comments and fixes to: Marc Kummel aka Treebeard mkummel@rain.org http://www.rain.org/~mkummel/ For more interesting Basic software with source code, check out Treebeard's Basic Vault at http://www.rain.org/~mkummel/basic/