Classic Computer Magazine Archive COMPUTE! ISSUE 43 / DECEMBER 1983 / PAGE 86

Gas Mileage

Ron Blue

Here's a valuable program if you're economy-minded. You can monitor your vehicle's performance with a hi-res graphics display of your odometer reading, gas mileage, standard deviation of mileage data, and reference dates. Originally written for the Apple, versions for the Atari, 64, and VIC (with Super Expander) are included. A disk drive is required.

"Gas Mileage," originally written for the Apple, is a simple but effective program that displays, in high-resolution (hi-res) graphics, the total cumulative average gas mileage for up to 200 (50 for VIC version) fill-ups. Also, mileage, gas mileage, standard deviation of gas mileage data, and reference dates are displayed at the bottom of the screen.

If you compulsively keep records of gas mileage of your car or cars, you probably have noticed that there is often significant variability. Many factors can cause this: whether you are getting a "total" fill, which gas station you are getting your gas from, what type of driving you have been doing, the mechanical condition of your car, and weather conditions. If you own a small economy car, you have probably experienced the frustration of seeing results ranging from 10 to 40 miles to the gallon. Such data is use-less to reveal whether or not changes you've made in your vehicle or driving habits are effective. If you own more than one vehicle, you might want to make a scientific comparison to determine which vehicle is giving you the best service.

Operating The Program

Gas Mileage is menu-driven and designed for use with a disk drive. The main menu consists of three choices:

  1. GAS MILEAGE DISPLAY
  2. PROGRAM FOR THOSE WANTING A PRINTER OPTION
  3. OPTION FOR CREATING A NEW DATA FILE FOR ANOTHER VEHICLE

When you first run the program and the main menu is displayed, you'll have to choose option 3 to create an initial data file. The program will branch to line 610, which asks you to INPUT CAR'S NAME:. The car's name (N$) becomes the data file's name. Any number of data files can be created and used in the program as long as no name is used twice. (This file naming technique can be valuable for other programs as it allows maximum use of the same program for different data files.) When using any N$ input string variable to equal your desired data files, you can save yourself some typing by using the following sequence: "OPEN";N$:"READ OR WRITE";N$: "CLOSE";N$.

Lines 620 – 700 create a data file that can be READ without causing an END OF DATA ERROR message. The Z variable used at line 680 will be used to tell the READ command how many DATA statements are to be read — in other words, how many entries have been made for mileage and distance. This technique is useful when the number of data entries is constantly changing. If you use the APPEND DOS command for adding new data to your data files, the Z variable can be corrected if you POSITION DOS to location zero and then WRITE in the value of Z and CLOSE the data file. If you are making multiple entries of new data to your data file, I recommend that you not use the APPEND command for writing in data files.

Data Options

After you have run the program and created the data file, the next display on the screen will be CHOOSE YOUR PROGRAM OPTIONS. Lines 200 – 260 allow you to select one of four program options:

  1. DISPLAY GAS MILEAGE
  2. INPUT NEW DATA
  3. CREATE BACKUP DATA FILE
  4. RETURN TO MAIN MENU

I used a GET X$ request at line 240 and then changed the X$ to an X variable number. The reason: If a letter is accidentally pressed, the program will crash and you will have to reload your data file.

Since you do not yet have any gas mileage data to be displayed, we'll discuss option 1 last. Option 2, INPUT NEW DATA (lines 490 – 570), lets you input your mileage readings and the amount of gas used to fill the vehicle. The I variable is used as a data interval. Since data is to be added to the data file, the interval variable equals the total current number of DATA statements. The data interval and the Z variable (total number of DATA statements) are then increased by one.

Since the variables used to represent current odometer reading and gas are dimensioned to 200 variable statements each, you should be able to store data representing about 35,000 miles before you will have to increase the number of dimensioned variable statements. Your data will eventually run into the hi-res screen as you run out of memory. You can then create new data files to contain your additional data, or delete parts of the program you find unnecessary.

The screen displays the last stored mileage and asks you to INPUT CURRENT MILEAGE. To get your data file running, your first mileage is used as a starting location and stored as if you'd used no gas, regardless of what you had typed in. (Gas mileage calculations are actually started with your second data entry.) Next, you simply input the odometer reading at the time you filled up your vehicle. For example: 37324 miles, and gas used since last fill-up, 12.3 gallons.

The next screen display (lines 500 – 560) permits correction of an entry before it is stored in the data file:

SUB-MENU

  1. TO END DATA INPUT & STORE DATA
  2. TO RE-ENTER LAST DATA ENTRY
  3. TO ENTER MORE DATA
  4. TO ENTER REFERENCE DATE FOR FILL UP

Option 2 allows you to correct a mistyped entry. Use option 3 to continue inputting data until you're finished. Option 1 ends data input and stores your data file on disk. Option 4 processes a date for future reference and display. Keep your reference dates to a minimum to save memory.

After the data has been stored in your data file, you are automatically sent back to the program options. After doing all that data entry, you should now use option 3, CREATE BACKUP DATA FILE.

The Heart Of The Program

When you choose option 1, DISPLAY GAS MILEAGE (lines 270 – 480), the screen display asks you to INPUT ESTIMATED AVERAGE GAS MILEAGE. Your input (XG) is then acted on by lines 270 – 290 and line 440 in adjusting the hi-res screen position of the data that will be displayed. Depending on the individual characteristics of your vehicle, you might like to change the value of the XG variable to position your data display to suit your taste.

The total cumulative average gas mileage is calculated for each input of current mileage and total gas used. The average gas mileage is plotted as a point on the hi-res screen. In addition, gas mileage and standard deviation are provided at the bottom of the screen. When a bell sounds, a new reference date is printed at the bottom of the screen.

For those unfamiliar with standard deviation, it is a mathematical expression of the variability of data about a mean. The standard deviation can be used to clarify the meaning and the causes of events. The hi-res screen display does for you visually what science relies on statistical analysis to accomplish.

Line 330 is used to increase the data interval by one, so that gas and current odometer readings can be translated and used to calculate gas mileage. X is the total distance traveled, and F is the total fuel used to travel that distance. MG represents the total average miles per gallon. Ml is the total cumulative sum of the squares of miles per gallon, and M2 is the sum of the miles per gallon. Using Ml, M2, and N (the total number of entries), the standard deviation is calculated. Lines 350 – 370 carry out these functions.

Line 390 displays at the bottom of the hi-res screen the following: mileage, miles per gallon (MG), and standard deviation (SD). Line 400 displays the reference dates.

Next, each total cumulative gas mileage is translated into a coordinate to be plotted on the hi-res screen at lines 440 – 480. The A variable represents this coordinate. The Y variable is used to position the next graphic plotting of gas mileage slightly to the right of the last gas mileage plotted. The gas mileage is multiplied by the constant pro-vided at lines 270 – 290, and the value subtracted from 600. This enhances graphic display of data and allows for normal graphic display of higher and lower gas mileage as would be expended in the upper-right graphic coordinate system. The hi-res plotting system is in the lower right of the normal graphic coordinate system. Lines 420 and 430 can be changed to stop the erasure of the hi-res screen if your data exceeds the right side of the screen: Simply type in the last statement in line 420Y = l: REM HGR.

For those unfamiliar with statistical analysis, visual examination of the data can be a useful indicator for changing oil, getting a tune-up, changing air filters, etc. Don't be too concerned with the graphics display at the first part of data display. This is normal randomness that must be worked out of the data before meaningful patterns can be seen. At least 30 data plots should be input before statistical analysis or visual examination of data can be considered relevant.

Printer Options

Those with a printer may initialize their printer options at any time by returning to the main menu and choosing option 2, PROGRAM FOR THOSE WANTING A PRINTER OPTION. This option gives you the following menu:

  1. PRINT MILEAGE AND GAS MILEAGE DATA
  2. PRINT HI-RES GRAPHICS
  3. PRINT BOTH OPTIONS 1 AND 2
  4. TURN PRINTER OFF

Lines 760 – 830 are used to accomplish the above functions. The printer commands used are at lines 310 – 320 and 420.