CALORIE COUNTER
BY RON SCHAEFER, M.D. AND KATHY SCHAEFER, M.D.
Approximately 40% of Americans are over-weight, and they spend billions of dollars each year trying to shed these unwanted pounds. In addition to a decrease in self esteem, obesity is a tremendous health problem that can cut years from your life. One of the keys to successful dieting is to limit the number of calories that you eat. But totaling up the number of calories that you have eaten can be a tiresome process.
Calorie Counter to the rescue! This short program will make counting your calories a snap—just point and click. Calorie Counter will work in medium or high resolution on any Atari ST.
To run the program, double-click on the CAL_CNT.PRG file (or run Listing 1 with GFA BASIC 2.0). The opening screen will appear, giving you the choice of: Count = counting calories, Help = display a help screen, or Quit = end the program. If you select Count, the program will automatically load the file CALORIE.DAT if it is in the same directory as the program. If it is not, an item selector will appear, asking you to select the file that contains the calorie database.
Calorie Counter allows you to plan a menu for a meal, a day or a week at a time. After the program has read in the data from the file CALORIE.DAT, you will be asked to input the number of desired calories. This number will serve as a goal, and the computer will categorize the calories in terms of grams of protein, fat and carbohydrates.
Next the Menu Planner screen will be displayed. At the top you will see your goal number of calories, grams of protein, fat and carbohydrate, and below this the running total. Your goal is based on the ideal American diet and has the following breakdown: protein (12%), fat (30%) and carbohydrate (58%). In the center of the screen are the food items that can be selected. Selection is done with the mouse, clicking the left mouse button to add an item and clicking the right button to subtract the item from the total. Once an item is selected it will turn red if you are using a color monitor or bold face if you are using monochrome. More than one of a given item can be added to the total by clicking repeatedly on that item; the quantity column will tell you how many of an item you have selected.
At the bottom of the Menu Planner screen are four other options: NEXT PAGE, LAST PAGE, LIST and QUIT. Clicking on NEXT PAGE will display the next page of food items, LAST PAGE will display the previous page of food items. LIST will allow you to create a list of the food items that you have selected. This list can then be displayed on the screen or printed out so that you can take it with you when you go shopping. The QUIT option will take you back to the opening screen.
The food item data file, CALORIE.DAT, can be easily added to by using any word processor with an ASCII mode. (This month's disk version contains the CALORIE.DAT file; if you don't have the disk version, you'll have to create this file yourself.) The first line of the file contains the number of food items in the file. This is followed by a listing of the various food items. It is important that the same format be used when adding a food item to the list. The first column contains the food item and must be 20 characters long; add spaces to the end of the name if necessary. This is followed by the calories, the grams of protein, the grams of fat and the grams of carbohydrates; each of these items separated by commas. This type of dietary information can be found in almost all books on dieting and nutrition and allows you to individualize the list to include your food preferences.
The following is a short sample of a CALORIE.DAT file:
6 Apple 1 ,100, 0, 1, 25 Apple juice 3 oz. ,48,.1, 0, 14 Avocado 1 ,375, 5, 37, 13 Bacon 1 strip ,48, 2, 4, .2 Bagel 1 ,165, 6, 2, 28 Baloney 1 slice ,85, 3, 8, 0
I would recommend keeping the food items in alphabetical order. The same item could be placed under two different names; for instance, Big Mac under the letter B and also under the letter H for hamburger. The only factor limiting the number of food items that can be in this list is the amount of memory in your computer.
Calorie Counter to the rescue! This short program will make counting your calories a snap—just point and click. Calorie Counter will work in medium or high resolution on any Atari ST.About the source code
This program was written and compiled with GFA BASIC 2.0. If you have Version 3.0, you will need to modify the open window commands as explained in your GFA 3.0 manual. I have tried to put enough comments in the program listing to make it easy to follow.
Basically, the file CALORIE.DAT is loaded into multiple arrays:
N$(T%) = food item name
CALS(T%) = number of calories
FATS(T%) = grams of fat
CARBOS(T%) = grams of carbohydrates
PROTS(T%) = grams of protein
QUANT(T%) = the quantity of a given food item
This information is then displayed on the screen. The position of the mouse is determined in relation to which food item it is over, and when a button is pressed the quantity of that item is updated. To print out a list of the selected food items on a printer the LPRINT command is used.
To allow the program to run in both medium and high resolution, the variables REZ% and TF% are used. The resolution is determined with the XBIOS(4) command, and REZ% is set based on the return, 1 for medium resolution and 2 for high resolution. REZ% is then used to modify the Y position of items on the screen. The Y coordinate has a maximum value of 200 in medium resolution and 400 in high resolution; for high resolution every Y coordinate is multiplied by 2.
TF% is used to adjust the size of the text displayed on the screen. The DEFTEXT command sets the text size; a size of 6 in medium resolution is equivalent to 13 in high resolution. So for high resolution, TF% is set to 7 and added to the size of the text in medium resolution, 6 + 7 = 13.
We hope that you'll use Calorie Counter in good health.
Ron and Kathy are both practicing internal medicine in Los Angeles. Together they run Schaefer SuperGraphics, which has a line of medically oriented software for the Atari ST.