Autocar

by Peter Franey

 

 

Issue 15

May/Jun 85

 

<< Prev Article

 

 

 

An Analysis utility for your Petrol and Oil Consumption

Program Requirements 48K DISK

Formatting data for screen display is a very powerful feature of Atari basic. It is well known that the tab stops on the screen can be changed and reset from within a string. Apart from formatted display, formatted input can be produced in the same way. By far the easier method of changing tab stops is by the use of strings. Once the strings are set up, they need only be printed to the screen to produce the desired results. There is one other method, which is to poke in directly the values required. This technique is used in the main program presented here. The decimal locations 675 to 689 control all the tab locations on the screen display. The screen is 40 columns across and each of the above locations controls eight bits or eight potential tabs on it. The reason there are so many locations is that they control one logical line, or three screen lines. To change the tabs for display, only the first five locations need be changed. To cancel all tabs a zero is into poked each location. If a zero is poked into 675 then there would be no tab in the first eight columns (00000000). If the same was done with location 676 then the first two bytes or 16 bits or 16 screen columns would look like this, 0000000000000000. This means:

Location 675 controls columns 0 to 7

Location 676 controls columns 8 to 15 

Location 677 controls columns 16 to 23 

Location 678 controls columns 24 to 31 

Location 679 controls columns 32 to 39

If you wish to place a tab stop in column 25 then you must use location 678. However there is a problem, supposing you want to set tab stops at columns 25, 27 and 30, how do you do it? The answer is that the eight tab stops covered by each location is really a binary number. The decimal equivalent must be poked into that location. If we wish to have tab stops at columns 25, 27 and 30, the eight bits or single byte covered by 678 should look like this, 01010010. There is a one at each tab position. We need to poke the decimal equivalent into location 678. In this case the value that must be poked into 678 is 82. To reset the default tabs press system reset. The tab stops should not be confused with PTABW location 201, which controls the distance between print statements using commas. Once the tab positions are set, the cursor can be moved to each position by pressing the [TAB] key.

It is not the purpose of this article to delve into conversion of binary to decimal, but before I continue with details of the program I will say that a good conversion utility (BINARY-HEX-DECIMAL) can be found in Mapping the Atari, a Compute! publication.

PLANNING THE PROGRAM

Before starting any programming project such as this it is very important to have a clear objective in mind. Even before the planning starts there must be a clear idea of what is to be achieved and if possible how. Only then can any program begin to take shape in the mind. This is particularly important if you do not want things to come to a sudden halt, when the ideas run out, or the results do not turn out as expected.

The first thing to do is to ask yourself a series of questions. They usually begin with "What do I want the program to do". In the case of Autocar this was easy but "What is the best way of analysing your cars petrol consumption" was a little harder. Further questions come to mind like "How much does the tank hold" and "Will I run out of petrol if I run the tank too low." These questions are relevant because you need to know how much fuel is used. Happily there is a simpler answer to all this confusion.

When you next fill up with petrol, and I mean FILL UP or the system will not work. Make a note of the DATE, QUANTITY, PRICE and clock mileage. Enter the data into the program. When you next decide to visit a petrol station make a note of the details again and ENSURE that the tank is filled. The amount now replaced in the tank is totally representative of the mileage covered. Continue with this until a number of data entries have been made. The program will show clear differences between the consumption for town work, medium distances, and motorway long hauls. There are still inaccuracies using this method but over a period of time, the true facts will emerge.

If when buying petrol you do not fill the tank, then save the details and add them together before entering them into the program, with the clock mileage at the time of the last fill up. REMEMBER before using this addition method, you must have completely filled the petrol tank at the point at which you decide to enter the details, otherwise the results will be meaningless.

SUMMARY OF THE PROGRAM FUNCTIONS

There are two program listings for Autocar. The main listing is here and the second listing covering the graph functions will appear next issue. The programs enable the user to enter the clock mileage, the date, the quantity in gallons, or pints, and the cost. The programs will then analyse costs and consumption, in figures or graphical form. The graph option has been disabled in this first listing but the program can be used as it stands.
The program features ANALYSIS BETWEEN ANY TWO DATES and ANALYSIS OF ALL DATA. The average values are given for MILES/GALLON or MILES/PINT and PRICE/GALLON or PRICE/PINT. Totals are given for MILES COVERED, GALLONS OR PINTS CONSUMED and COSTS.

PROGRAM OPERATION

Anyone who is only interested in entering the program, and using it, should first read the PLANNING section, in order to obtain practical information on the use of Autocar.

GETTING STARTED

The listing in this issue is the main program. Type it in carefully, using TYPO II if you have a copy, and save the program to disk using SAVE"D:CAR". Before running the program delete line number 200. Run the program. The main menu will now appear. The program will not allow any selection to be made, from this menu, until Oil 'O' is pressed, or Petrol 'P' is pressed. The main menu will now display the selection made at the top of the screen.

Creating the disk data file: Select option '7' from the main menu. The computer will now save a data file to disk. The data for both Oil and Petrol are saved together in the same file. Re - enter line number 200, or re-load the program from disk

Every time the program is now run, all data previously saved by it will be automatically loaded, before the main menu appears.

USING THE PROGRAM

Data is entered and saved using the program in this issue. The graphics program to be published next issue will chart the data entered from program one. Both programs will be chained together on the disk drive. Each program runs the other. It is therefore important that the correct filenames are used for each, when saving them to disk. Listing one should be saved using SAVE"D:CAR", while SAVE"D:GRAPH" should be used when you add the GRAPH listing.

1 .. ENTERING DATA

When this option is selected the next screen will ask for 'E'-EXIT or `D'-ENTER DATA to be pressed. Exit will return the program to the main menu. If data entry was selected the screen will go blank for some seconds and the next screen will show a formatted data entry including ENTRY No., DATE, MILES, GALLONS (or PINTS) and PRICE. The entry number will already be displayed at the far left of the screen. Make the entries in each field in the format shown above each field title. After each entry press the `TAB' key. The cursor will now jump to the next field. Continue this process until the last field is reached. After the entry in the last field, do not press the `TAB' key, press `RETURN. At the bottom of the screen the option to add more data `A' or to exit `E' will be given. Exit will return the program to the main menu. If the add option is chosen the cursor will update the available memory at the top of the screen, and return to directly under the previous entry, where the process may be repeated. The new entry number will also be displayed. When the screen is filled with data entries, the program will clear the screen and give the option to exit, or make further entries.

2 .. DELETE DATA

This routine asks for a simple date entry in the format of MMDDYY, as displayed on the screen. Enter the date and press RETURN. If the entry is not found the program will ring the bell, and the option to re-enter the date or to exit, will be given. If the date entered here is found the data will appear instantly. A machine language subroutine is used in the program to provide such a fast response. When the entry is found the choice to continue search, exit or re-enter the date will be given. The continue search option is provided on the slim chance that two dates which are the same may be in the records. This could happen if a long journey is involved, or the date was entered incorrectly in the first place. If delete data has been chosen (SELECT) the program will display, 'ERASING DATA PLEASE WAIT'. After deleting the data, if it occurs in the middle of the file, a gap will now exist. The program will now take a few more seconds to close this gap (CONCATENATE THE FILE). If the entry which was deleted was in in the middle of the file and it is necessary to replace it in a similar position, OPTION 6, the insert data routine must be used from the main menu. (SEE 6.. INSERT/DELETE ALL DATA).

3 .. VIEW DATA

This part of the program is a series of routines, to display the data entries to screen. Among the options are; STEP THROUGH DATA, SINGLE DATA SEARCH and DATE RANGE OF DATA

Step through data: This routine will display all data to the screen.

Single data search: This selection will require a single date entry. `END OF SEARCH PRESS ANY KEY', will appear. If the entry was found, it will appear instantly. If not, then nothing will be displayed.

Date range of data: The purpose of this option is for the user to enter a range of dates, between which the program will display all data. (DATE1 & DATE2). The dates which are entered for these may be dates which are not actually in the records. The program will still display all data entries between them.

4 .. PRINT DATA

This option will print all data in the memory to the printer. SEE PRINTER SUPPORT, for more information.

5 .. SPECIAL CALCULATIONS

Among the options given in this set of routines are ALL TOTALS AND AVERAGES, GRAPHICAL ANALYSIS, and COST ANALYSIS.

All Totals and Averages: This routine can, if used correctly, be the most useful in the whole program. The program prompts the user to enter two dates. The first date must be earlier than the second. If RETURN is pressed without entering anything for either prompt the program will default to analysing all the data entries in the memory. The instructions for using this routine are clearly shown on the screen. Whatever combination is used, the dates entered, must be dates actually in the records, or the program will again default to analysing all data. If the results are unexpected, check your dates by using option 3 from the main menu, VIEW DATA or, if you have a printer, option 4 PRINT ALL DATA.
The first choice is to press RETURN for the first date, and enter the second. The program will then analyse all data up to that date. Choice two is the reverse, enter date one, and press RETURN for the second date. The program will then analyse all data from the date entered, up to the last entry. If both dates are entered then the program will analyse any entries between them. All results may be sent to the printer.

Graphical Analysis: If 2 is pressed, the computer will load, and run the graphing program (to be published next issue).

Cost Analysis: Before selecting this part of the program, whether for oil or petrol, ensure that more than one data entry is in the program, or the display will be blank.

The program will analyse the data between each pair of entries, giving the dates, (datel to date2,date2 to date3), the mileage between them, the corresponding consumption in MILES/GALLON or MILES/PINT and the COST/ GALLON or COST/PINT. These last two items are shown in graphical form if GRAPHICAL ANALYSIS is chosen. 

All results may be sent to the printer.

6 .. INSERT/DELETE ALL DATA

When data is entered into the program using option one, it is not sorted into date order. The enter data routine assumes that each successive date is later than the first. The insert routine presented here will insert data between existing entries. This will be carried out according to date and mileage. It must follow that if a date entry neatly fits in chronological order, between two existing entries, the clock mileage must also fit in at the same point. However for long journeys, the petrol tank could be filled up twice on the same day. This will also be taken into account If the program will not accept any entry in which the date is later, insert the new entry with reference to the mileage. The program will not except any entry in which the date is later, or the mileage greater, than the last entry. The last entry will be displayed.

One further point should be made about this routine, and that is that the greater the number of entries, the longer this process will take.

Delete all Data: The purpose of this routine is that once the memory is full, all the records may be cleared to start again.

7.. SAVE DATA TO DISK

This option is used to save oil and petrol records to disk It should be used after any new data entries are made. I recommend that you keep at least one backup copy of your data file on another disk.

8 .. LOAD DATA FROM DISK.

This part of the program maybe used to re-load a data file from disk. It may also be used to load different data files, for example, for another vehicle. When a different data file is loaded, any previous file will be erased.

PRINTER SUPPORT

All printer output is tailored to forty columns. The program supports output to an 80 column dot matrix printer. As presented the code is designed for forty column DOUBLE WIDTH output for the Epson type of printer. If you have a dot matrix printer and the codes are not compatible with the Epson, then you will have to change lines 6000 and 7400 in the program to the appropriate codes for your printer. If your printer is not dot matrix then alter lines 6000 and 7400 to TRAP 9000 only.

LINE BY LINE

3 - 200 INITIALISATION
500 - 770 MAIN MENU & SELECTION ROUTINES
780 - 1330 ENTER DATA ROUTINE
1340 - 1420  VIEW DATA MENU & SELECTION
1425 - 1508 SINGLE STEP THROUGH DATA
1510-1640 SINGLE DATA SEARCH
1650 - 1800  DELETE DATA ENTRY ROUTINE
1810-1970  DELETE DATA ROUTINE
1980-2170 RANGE OF DATA ROUTINE
3000 - 3140  SPECIAL CALCULATIONS MENU
3142 - 3258  CALCULATION OF TOTALS & AVERAGES
3265 - 3350  DISPLAY RESULTS
4000 - 4030  STRING SEARCH ROUTINE
5000 - 5020 SAVE DATA ROUTINE
5030 - 5060  LOAD DATA ROUTINE
6000 - 6130 PRINTER ROUTINE
7000 - 7340  COST ANALYSIS
20000 - 20150 DATA FOR STRING SEARCH ROUTINE

 

AtariLister - requires Java

top