Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 9, NO. 3 / MARCH 1983 / PAGE 216

Library catalog; a program for creating a personal computer based library catalog (small and home libraries) Jeremy M. Hellman.

Library Catalog

A Program For Creating A Personal Computer Based Library Catalog

Home, school, and office libraries eventually fall victim to the one characteristic that makes libraries unique; they are the only business whose inventory is constantly growing.

My house is a good example of the problems that this constant expansion can cause. Our living room, master bedroom, children's bedrooms, my office, my wife's study room, the kitchen, and even the dining room are lined with bookshelves. Every year I trudge to the lumber yard for more wood to make more bookshelves.

Through much searching over the years I have gotten a general idea of where different books are kept, and once I even tried to put them on shelves in a systematic fashion. Now, however, most of the systematization has been lost, and it is more a matter of where there is room on the shelf than where the book came from or should be that governs where it will be returned.

Further complicating matters is the fact that many of my bookshelves have been built with shelf spacing that will accommodate only small paperback books. Additional problems arise in looking for a book which has been lent to someone.

Large libraries have traditionally kept track of their books with a card catalog and a system of check out slips to track the books out on loan. The card catalog indexes books in three ways: by title, by author, and by subject. Each nonfiction book is given a catalog number according to either the Dewey Decimal System or the Library of Congress system, and fiction books are catalogued alphabetically by author. Some large libraries have recently implemented computerized check in/check out procedures, but the card catalog is still a universal fixture in most libraries.

Small libraries, those with fewer than 6000 books, have had to either make do with a librarian (usually self-appointed) with a good memory, or implement the full scale card catalog and sign in/sign out systems used by a larger library.

Home libraries, with fewer than 2000 books, usually go without any sort of organization at all. The main price that must be paid for running a small library without any type of catalog and sign out system is not being able to find a particular book when it is wanted. Another is that no record of books owned is available for insurance purposes.

A small computer with a disk drive provides an ideal tool for keeping track of books in a small library. The computer has the ability to store data on large numbers of books and sort the data by title, author, subject, borrower name, or even size, if desired. The availability of small computers in homes, offices, and schools leads to the use of the machine as a book cataloguer.

What The Program Does

The Library Catalog Program described here allows you to create and use a computer based card catalog. It is written for an Apple II+ computer with one disk drive and 48K of memory.

With the Library Catalog Program books can be entered or searched for, records modified, books checked in or out, information on borrowers or borrowed books obtained, and all books in the catalog listed. Data for approximately 1000 books can be placed on a mini-floppy disk. If your library is larger than 1000 volumes, use additional disks for data storage. This program is written to lead you through a file for which data is contained on more than one disk.

The program is versatile. For example, a search by author will turn up all books by the desired author or authors. Thus if you are looking for books by Masters, Library Catalog will turn up all books by Masters as well as those by Masters and Johnson. A search on Masters and Johnson will sort out all those by Masters and Johnson, but not by each author individually. In searches on subject, any of three levels of specialization can be selected. Entries are easily modified, and all output data is presented in readable form.

What sets this program apart from other data base routines is a sequence in which the catalog number of the book is determined. Menus which lead to greater and greater specialization of the book subject matter are provided. The Dewey Decimal System has been used and provides for three levels of detail; the division, the category, and the subcategory. For example, the book Thermodynamics, by Sears would be catalogued into the division Pure Science, the category Physics, and the subcategory Heat.

A library school graduate would probably have very definite ideas as to exactly how books should be catalogued. For example, should a book on the history of science be catalogued under science or history? Established libraries have a set policy on this type of decision. For an uncatalogued or home library you are the judge and common sense and consistency in assigning numbers will enable a search to turn up all pertinent books.

The program is completely menu driven and all inputs are made as "bomb-proof' as possible. The length of the program is in a large part due to the checking of the validity of each input and an attempt to make the instructions very friendly and clear.

The program is written so that no knowledge of computer programming is necessary to do any of the cataloguing operations. The detailed description of the program given in this article is presented to enable the more advanced programmer to modify the routines, and the beginning programmer to understand the program logic. If your only interest is in cataloguing your library, simply type in the program exactly as listed, and use it as described in the next section.

How To Use The Program

Once you have successfully entered the program and created the data files using the routines supplied, entering books into the catalog can begin.

The first step is to go through the house or library and establish an identification number (ID) consisting of two letters and one digit for each shelf. I use room initial, bookshelf location, and shelf number. For example, the ID of a bookshelf with the description "Melissa's room, desk bookshelf, top shelf' would be MD1.

Run Catalog Master, and the computer will ask for the number of disks containing catalog data (zero in this initial case), and the menu shown in Figure 1 will appear on the screen. Select the bookshelf option (6), and a new menu will appear (Figure 2). Choose (1) to add shelves to the library, and follow the instructions to supply ID, size (S-short; N-normal; T-tall), and location description. When all shelves are entered, return to the menu and select (4), END SHELF OPERATIONS.

The primary menu will appear once more, and selection (1) will permit book entry. A message asking you to replace the Catalog Master disk with a disk for book data storage will appear. When this is done the program will tell you how many books are currently in storage on the disk. Once again, it is zero in this initial case.

The computer then requests title, author, location ID, and whether the book is fiction or nonfiction. If the book is nonfiction, the cataloguing process proceeds. For example, the book I Hear America Talking would produce the set of classification data shown in Figures 3a, 3b, and 3c as selections 4, 2, and 1 were chosen to catalog the book as Written and Spoken English, catalog number 421. If the book had been fiction, the menu shown in Figure 3d would have been displayed.

At this time a listing of all the data typed in for the book is presented (Figure 4), and you are given the opportunity to make changes. When the entry is correct, the next book is

When all books are entered, the Library Catalog Program can be used for searches, recording borrowed and returned books, and listing all books on file. The menu for searches is shown in Figure 5.

If the SUBJECT/FICTION TYPE selection is made, the classifications are once again presented to aid in subject selection. For information on borrowing, the menu shown in Figure 6 enables several selections. Option 3 from the main menu, permits any record to be modified, from check in/ check out to correction of spelling to complete deletion of the book from the file.

The remainder of this article is devoted to the technical details of the program and need not be read if you have no desire to do anything but use your computer to keep track of your books. However, before you rush to your keyboard, please read the following few notes of importance.

The program consists of a series of routines that are called from a Catalog Master routine. Additional routines are Catalog Enter, Catalog Search, Catalog Borrow, Catalog Bookshelf, and Catalog List. All of these routines should be stored on a single Catalog Master disk which will also contain files with the catalog classification data and information on bookshelf location and sizes. The length of the routines forces this type of structure. A benefit of this breakdown is the added ease of debugging each routine separately. The book data are stored on separate disks.

A series of ten programs with titles of the form SC PROGRAM 3 is used to create text files with the library classification data needed to derive the specific catalog number for each book. Once these programs have been used to create these files, they can be DELETEd from your Catalog Master disk. These ten programs must be run prior to the first use of the Enter routine.

A few words of caution before you start typing. Since the Catalog Master disk is in active use while cataloguing it is possible to write over all or part of the routines by accident. LOCK them after they are entered and keep a backup disk. It is also a good idea to run backup disks of your book data disks periodically--just in case.

Program Structure

The structure of the Library Catalog Program is shown schematically in Figure 7. The primary menu is contained in Master, and selection from this menu runs the other routines. Information that needs to be transmitted from one program routine to another is done via POKEing the data into memory locations in one routine and PEEKing into these locations to recover it in the next routine.

The catalog classification and bookshelf identification are called as required by the Enter, Search, and Bookshelf routines. When each of the functional routines is exited, Master is run automatically and the primary menu is displayed once again. This type of structure, where only the specific routine that is needed is in memory makes it possible to run on a 48K machine programs that would otherwise require a much larger memory.

Book data are stored in random access files (named LIBREC-120) on disks separate from the Catalog Master disk. Record length for this file is 120 bytes. Information on shelf identification numbers, sizes, and location descriptions is stored on the Catalog Master disk in a sequential text file named SHELF.

What The Routines Do

Catalog Master (Listing 1) is the traffic director for the Library Catalog Program. When the program is run, memory location 770 is examined. If the value stored is anything but 56, a number which I selected randomly, the descriptive information on lines 50 to 260 is presented on the screen. On later occasions, when this routine is called from the other routines in the program, the value 56 will have been POKEd into this location and the introduction will not be printed. This random number was selected so that there is only a small probability that the introduction will be skipped if the Catalog program is run after some other program which utilizes this memory location.

The remainder of the routine formulates the menu which is used to call the Enter, Search, and other routines for the actual work. If the decision is made to modify a record, the value 92 is POKEd into 773 to tell the Search routine that it is to be used in its modify mode.

When the selection of the desired operation is made, the Catalog Master program goes to the appropriate statement and runs the necessary routine.

Catalog Enter

Catalog Enter (Listing 2) is the routine that requests data on books to be added to the catalog, provides an opportunity to revise the data, checks to make sure that the data are within the expected range, formats the data as required for storage, and prints the data to the disk. For nonfiction books the determination of catalog number for each entry is provided by selection from an ever narrowing listing of subject areas. Provision is made for returning to a broader description of the subject if an error is made in the original selection.

The listing of the catalog descriptors is stored in the array SC$, which has 1000 elements. During the initial access to the Enter program, this array is filled from ten sequential text files stored on the Catalog Master disk. This read-in process takes about a minute and a half, during which descriptive material is on the screen. Once this data are read in, the Master disk is removed and replaced with the disk to be used for the storage of data.

The data are stored in the file named LIBREC-120. Details of the file format are given below. The Enter routine opens the file and reads the first record, which contains the number of books currently stored on the disk. If no books are on the disk, the error routine is used to place a zero in the necessary location, and the processing continues. The screen then requests title, author, location, book height (remember, some of my bookshelves are suitable only for small books, and others will accommodate oversize books), and whether the book is fiction or nonfiction.

The title and author are allocated 40 characters each in the data file. The title can contain any characters except the comma or quotation mark. No commas, quotation marks, or spaces are permitted in the author list. Multiple author names are separated with slashes (/), giving the Search program a key to find each name individually.

If the book is fiction, the program jumps to a series of steps that generate the menu for selection of the fiction type, e.g., novel, western, sciencefiction, etc. If the book is nonfiction, the primary menu for subject classification is presented, showing the 10 divisions. Upon selection from this menu the appropriate 10 categories for the division are shown, and following selection from this menu, the appropriate 10 subcategories are shown and a selection is made. The routine automatically inserts in the data file the information that the book is not out on loan. The routine also computes the number of authors based on the input. This information is used in the Search routine.

During data entry, each entry you type in is verified to be within the expected range. No protection can be given against spelling errors in the title or author entries, but, for example, the size entry must be either S, N, or T, and the location must be a letter, letter, number sequence for the entry to be accepted. After all necessary data are entered, a listing is presented of the total record, and an opportunity is presented to change incorrect entries. If all are correct, the data are stored in the arrays reserved for them. The operator then has the choice of continuing to add books or to end data entry.

The location of the book must be specified at the time it is entered into the catalog. When the three-character shelf ID is entered, the Enter routine checks that the ID is in the correct format, that the ID has been entered (in the Bookshelf routine) as an existing shelf, and for an inconsistency in the specified book height and the height of the specified bookshelf. For example, a book of "normal' height cannot be placed on a "short' shelf. If a mismatch occurs during any of the checks the operator is given the choice of reviewing a shelf directory as an aid in correct placement of the book.

After five entries are made, or if the selection has been made to terminate data entry, a subroutine is called to write the stored data to the disk. With 48K memory, there is actually room to store a greater number of records between interruptions for disk storage, but five has been selected to minimize data loss in case of power interruption or other disaster.

After all records are entered, the number of records on the disk, stored in record 0, is increased. If during the writing process the disk becomes full, the drive door is left open after a disk switch, of if the disk has been write protected, an appropriate message is shown and the data are saved. All of the information stored in the computer memory from the books that are to be entered is then written when the drive door is closed or a new disk is inserted.

After the catalog classification data are read into the program, lines 330-390, HIMEM is set to 20000. The reason for this change is given below.

When data entry is completed instructions are given to reinsert the Catalog Master disk in the drive, and the Catalog Master routine is run.

Catalog Search

The Search routine (Listing 3) is the most complex in the program and is used to find books based on any of several keys, and also to modify the book records. If the routine has been called by the Master routine for record modification, address 773 will contain 92, setting MOD=1, and bypassing program lines 160 through 390. The data needed for catalog number selection are not read in, and the program proceeds directly to the request for the book title. If a search is to be made on title, subject, or author, the cataloguing data are read in from the SCSEQ LIST text files.

After the necessary initializations, a menu is presented, and you select the type of search to be performed. If title is selected, the name of the book is entered, the first words or the entire title, and then the search is conducted on all data records. Instructions are given to insert data disks sequentially, with the total number of disks containing catalog data found in location 771, where it was POKEd by the Master routine.

When a match is found, the entire file is presented, as shown in Figure 8, and you then have the opportunity to end the search or to continue looking for other books with the same title. When the search is completed, the Search menu is returned to the screen.

The search on author is more complex since it is necessary to find all books by the given author or authors, even when they are included among the authors of a book with additional writers. The name(s) of the author is requested. For the case of multiple authors, the routine determines the number, and stores each name in an array.

In the case of a single author, the search proceeds through the datacontaining disks. Byte 94, which contains the number of authors in the individual record, is examined. If the number is 1, then the name of the author is extracted from the record and compared to the given name. If the number on the record is greater than 1, then each of the authors in the record is compared to the given name. If the search is for a book with more than one author, the search immediately proceeds to look at only books with that or a greater number of authors for a match.

In all cases, if a match is found, the entire record is shown on the screen, and the operator has the opportunity to end the search or to continue the search for additional books by the author or authors.

The search on subject goes through the same process as the entry procedure in that the catalog divisions are shown on the screen and you have the opportunity to select the area of interest. The one change here is that the opportunity is given to search on any of the three levels of categorization. Once the catalog number is selected, the routine jumps to a section which searches each of the data records at byte 82 for a match. The entire record and continue/stop option are presented.

In the modify usage of the Search program, the cataloguing data are not read in, and after entry of the title, the search proceeds for the book. When found, the choice of modifying the record, deleting the record, or leaving the record unchanged is presented. If modification is selected, the first choice is to check in/check out the book. If this is the need, the book is either checked in and the shelf location shown, or the borrower's name is requested. These data are then inserted in the book record.

If the record is to be changed, each entry in it is presented individually, with the option of change/no change available each time. Once again, with a modification, you have the opportunity to continue the search for different books with the same title or to end the search.

When a record is selected for deletion, the last record on the disk is rewritten over the record to be deleted, and the number of records stored in record zero is decreased by one. A message is printed to the screen when the disk is emptied of catalog data.

HIMEM is changed during the running of this routine, as in the Enter routine, for reasons given below.

Catalog List, Catalog Borrow, And Catalog Bookshelf

Catalog List (Listing 4) is provided for those times when you don't really know what book you want, but would just like to browse through your collection. The only information provided here is the title and author, as the listing is scrolled on the screen.

Catalog Borrow (Listing 5) presents two options. A selection is made by listing either all books out on loan or all books on loan to a given person. The key upon which this search is made is byte 96 of each record. If this byte is 0 the book should be on the shelf, and if it is 1 the book is out on loan.

Catalog Bookshelf (Listing 6) is the first routine that must be run when the Library Catalog program is used for the first time. The Enter routine will not permit a book to be entered on a non-existent shelf.

The menu presented by this routine offers a choice of new shelf entry, shelf removal, directory of all existing shelves, and ending shelf operations. For shelf entry the information required is the shelf ID, the tallest book the shelf can accommodate--in the form S-short, N-normal, T-tall--and a short free-form description of where the shelf is. This description is placed in the directory for later reference. Only the usual commas and quotation marks are prohibited from this statement.

The routine checks for the proper ID format, i.e., Letter Letter Number; existence of a shelf prior to its removal; and duplication of a shelf ID prior to the addition of a new shelf. The routine currently allows 200 shelves, but this can be changed by modifying statement 50. The last operation the Borrow routine does prior to running Master is to alphabetize the shelf ID listing and restore it to the SHELF text file.

Program Particulars Data

The format for the book record file is shown in Table 2. Programmers are encouraged to modify this program to fit the more particular needs of their own library, but care must be taken, such as allowing space in the file for returns and possible varia bility of data length. As explained above, the program looks for certain data at given byte locations in the file, and changes will destroy the input.

Increasing Search Speed

In working with strings, one characteristic that the Apple has that can become annoying is the stockpiling of "old' strings after they have been updated. As described on page 53 of the Applesoft manual, if the title variable TL WAR AND PEACE one time and GRIMM'S FAIRY TALES the next, the string WAR AND PEACE remains in the attic of memory, and GRIMM'S is placed below it.

As dozens of strings with book information are manipulated and compared, the available memory constantly decreases until string storage runs into program and array storage which is working its way up from the basement. Old strings can be cleared away periodically in a program with the statement X=FRE(0), or the machine will do the job itself when the available memory is depleted.

With the large number of strings that the Enter and Search programs require for the catalog classification data (approximately 15K bytes) the housekeeping, which examines all strings in memory, can take almost two minutes. I found it very disconcerting during a search to listen to the hum of the disk drive looking for the desired book only to have the whole process stop dead while the machine cleaned house.

The solution to this problem is found in the way the Apple treats the strings. String storage starts at HIMEM and works down towards the program and array storage area. The Enter and Search routines have been structured so that the 1000 strings of catalog classification data are read in at the beginning of the routines, filling the space below the original setting of HIMEM, 38400 ($9600). Recall that as shown on the memory map in the DOS manual the memory between the top of a 48K machine, 49151 ($BFFF) and 38400 ($9600) is lost to DOS use.

After the Enter and Search routines load the catalog classifications, HIMEM is set at 20000 ($4E20), leaving only a few thousand locations available for the new strings that are entered and manipulated. This is ample room, but only requires tenths of a second for the Apple to houseclean when the need arises. Moving HIMEM down has eliminated the unnecessary search through the catalog classification data strings during each housecleaning. Prior to running the Master program, HIMEM is once again set to the original value.

Entering Catalog Classification Data

The heart of the catalog classification routine is the selection process from the 1000 subcategories of the Dewey Decimal System. The information required for this classification is stored in ten subcategory sequential data files, for example, SC SEQ LIST 3. These files can be created from the programs shown in Listing 7. The use of a file editor such as EDASM in the Applesoft Tool Kit greatly simplifies correction and entering of these files. The subcategory information is written in abbreviated form to reduce memory requirements.

Key Parameters

Table 2 lists the major parameters used in the program. As far as possible the names have been carried through from one routine to another to simplify the debugging process.

Modifying The Program

This program has been structured to enable you to modify easily the input and output to suit your special needs. Subroutines are used extensively for searching, data entry checking, and result presentation, localizing the areas that must be examined if changes are to be made. Space has been left on the book record file so that you may easily add other information that you desire to file, such as publication or acquisition date for each book.

With the advent of megabyte capacity hard disks for use with personal computers such as the Apple the necessity of using multiple disks for book data storage will disappear. This program will then be suitable for use with much larger libraries.


I would like to thank the reference librarians at the Monroeville, PA Public Library for their help in obtaining the listing of the Deway Decimal System classifications and in teaching me some of the particulars of cataloguing books.

Table: Listing 1.

Table: Listing 2.

Table: Figure 1. The primary menu.

Table: Figure 2. The bookshelf menu.

Table: Figure 3a. The division menu.

Table: Figure 3b. The category menu.

Table: Figure 3c. The subcategory menu.

Table: Figure 3d. Catalog menu for fiction books.

Table: Figure 4. Listing for checking entry.

Table: Figure 5. Menu for book search.

Table: Figure 6. Menu for borrowing information.

Table: Listing 3. entered. When all books have been entered, the primary menu is once more displayed.

Table: Listing 4.

Table: Figure 7. Structure of Library Catalog Program.

Table: Listing 5.

Table: Listing 6.

Table: Listing 7.

Table: Figure 8. Sample Results of Search program.

Table: Record Structure For LIBREC-120.

Table: Key Parameters Used In Library Catalog Program