IDL 5220 Week 3 - Strings, File I/O, and Data Manipulation



  1. String Operations:
  2. FITS file I/O:
  3. Reading from a file:
    Most file I/O is formatted I/O to an ASCII file. ASCII files can be viewed or modified in any text editor.
  4. Writing to a file:
    File output is very similar to file input. Instead of OPENR, you use OPENW and instead of READF, you use PRINTF.

Homework 3: Interactive Database. Write an interactive database that keeps track of Florida basketball players' first names, last names, year, and scoring average. It should read a file of the following format:
      14.9000       4     Bonner, Matt
      7.50000       4     Nelson, Brett
      8.00000       4     Hamilton, Justin
      10.9000       2     Lee, David
      14.3000       1     Roberson, Anthony
      14.5000       1     Walsh, Matt
Where the first number is the scoring average and the second number is their year. Your main menu should give the following choices:
***Interactive Database***
1. Load a file
2. Save to a file
3. Create new database
4. Add a record
5. Delete a record
6. Modify a record
7. Display Records
8. Sort Records
9. Search for a Record
10. Quit
Enter a choice:
and prompt the user to make a choice. Load prompts the user for a filename and loads the database. Save prompts the user for a filename and saves the database to an output file such as the one above. You can also create a new database, add, delete, or modify any record, or display the records. The display should look like:
Matt Bonner               Sr.      14.9000
Justin Hamilton           Sr.      8.00000
David Lee                 So.      10.9000
Brett Nelson              Sr.      7.50000
Anthony Roberson          Fr.      14.3000
Matt Walsh                Fr.      14.5000
Where year 1 is displayed by Fr., year 2 So., year 3 Jr., and year 4 Sr. If the user chooses 8. Sort, then they should receive the following submenu:
***Sort Records***
1. Sort by Last Name
2. Sort by Year
3. Sort by Scoring Average
Enter a choice:
For sorting, use the IDL SORT command to sort by last name and by scoring average but use a bubble sort to sort by year. 9. Search should work like this:
Enter a choice: 9

Enter last name: Bonner
Matt Bonner     Sr.      14.9000
and 10. Quit ends the program.

Hints: The following IDL commands are used: STRCOMPRESS, STRMID, STRPOS, STRLEN, READ, OPENR, OPENW, READF, PRINTF, WHERE, SORT, REVERSE. My program is 157 lines long. Remember, you don't have to write the whole program at once. Try just getting 1. Load to work first, then move onto another choice and get them working one at a time. Do it in pieces like this, debugging each piece of code as you go instead of trying to write it all at once.

My version of the program can be run by typing .run gator_database at an IDL prompt. You can run it to see how the program is supposed to work and what information it is supposed to display.