Classic Computer Magazine Archive COMPUTE! ISSUE 39 / AUGUST 1983 / PAGE 60

Weather Forecaster

George W. Miller

This program enables you to make quite accurate local weather predictions. Written for the T/S 1000 with 16K, versions are included for computers with Microsoft and modifications for Commodore, Apple, and the Color Computer.

The National Weather Service uses computers when forecasting the weather, so why not use your home computer for your own local forecast?

You will need some easily obtainable data. Since you don't have access to a network of reporting stations or satellites orbiting the earth, about the best device available is a barometer. Everyone knows a falling barometer means bad weather is approaching, but this information coupled with wind direction, will allow you to make a fairly accurate local forecast.

If you're able to interface with the outside world, you could even have a dedicated weather forecasting machine which can update the forecast as often as you like and provide a continuous monitor of changing weather conditions. However, our concern here is to demonstrate how you can forecast the weather with very little effort and a great deal of accuracy.

You will need a barometer, available at most hardware stores, and ideally some device to indicate wind direction, such as a weather vane. A less accurate, but still effective method is to use a compass and observe the wind yourself.

One word of warning. This is a very long program and will fill 16K RAM on the Timex/Sinclair. SAVE it often while you are making your entries. It can be very frustrating to lose the program after several hours work due to a glitch.

This program is based on very simple, but sound scientific facts. In the Northern Hemisphere, winds blow counterclockwise around a low pressure system, and clockwise around a high pressure system. So, if you stand outside, with the wind at your back, a low pressure system will be on your left. If the barometer is falling, this low is heading in your direction.

The wind direction and barometric pressure, combined with scientific observation, indicate what weather Changes to expect. Your T/S 1000 can figure this out for you in a matter of seconds, and the program will even tell you what the normal weather for the month is.

You'll have to make a visit to the local library for information on your local weather conditions, but we'll get to that in a minute.

Let's take a look at the T/S version of the program. First you'll notice a list of variables in lines 5 through 56. Enter them from the listing, except for line 10, which should read:

10 DIM A$(1,31)

This will allow enough room in memory to make the necessary entries in the later portions of the program. We'll change this to a larger DIMension before we're finished.

Line 59 will GOSUB 2000, which displays the title block and gives some preliminary instructions.

After displaying the title and instructions, line 2075 advises us to "PRESS ANY KEY TO CONTINUE". There is no input statement following, only the command PAUSE 40000. The way ROM is organized, any number following PAUSE that is greater than 32,767 causes the program to halt and wait for any key to be pressed. Pressing any key causes the program to drop through to line 2085. We're using the pause this way so that any user has a chance to read the message completely.

Line 2090 RETURNs us to the main program at line 60, and lines 60 to 95 print the menu.

Optional Extras

If you want to dress up your program a little, use the graphics mode to print the inverse form of the letter for each command, but be sure to use the regular mode for the letters in lines 105 to 125 to satisfy the argument for Y$. Otherwise, you'll find the menu becomes clumsy as you must shift to the graphics mode for every command entry.

The menu offers a lot. For example, you can store data in RAM, generate a weather forecast, display the data you have stored, display normal conditions for your area, STOP the program, search for a specific date, and make corrections.

Now we're ready to begin working on our data file. Line 143 checks to see if there is any room left in the file. If L = 190, you have stored data for 190 days in the file, and any additional data will generate an error. When you do reach this point, SAVE the data and program on tape if you want to refer to it later, or just enter RUN. RUN will clear all of your variables, and you can start over. To use your data file in this program you must start the program by entering GOTO 59.

The raw data is stored in string variables, in this case A$(X), with all the data held in one variable. A$ is a two-dimensional array, which will be 190 entries long, and will hold 31 characters in each entry. A$(X,1 TO 2) holds the number of the month; A$(X,3 TO 4) holds the number of the day; and A$(X,5 TO 6) holds the year.

High and low temperatures are entered as four characters, such as + 076. In order to avoid the necessity of right justifying, each entry must have four characters. High temperature for each entry is stored in A$(X,7 TO 10) and the low temperature is stored in A$(X, 11 TO 14).

The barometric pressure is stored in A$(X, 15 TO 19) as five characters, for example, 30.18.

Notes To Weather Forecaster

(Microsoft Version)

Patrick Parrish, Programming Assistant

The Microsoft Version (Program 2) of Weather Forecaster will run with minor modifications on the 64, all PETs (40- or 80-column screens) with at least 16K of memory, the Color Computer, and the Apple. Programs 3, 4, and 5 are the necessary data storage routines to be typed in with Program 2 depending on which computer you have.

Commodore

If you are programming the 64 or 32K PET (you can try it with a 16K VIC, but you'll need to reformat the display for 22 columns), type in Programs 2 arid 3. With the 16K PET, DIMension A$ in line 100 to 150 rather than 365. Each day of weather data is stored in A$(I), so with the 16K PET, you will only have enough memory to store data corresponding to 150 days under one file name.

Program 3 is written to accommodate either a disk or cassette data file. The subroutine within Program 3 beginning at line 3100 is used to detect disk errors. When a disk error is encountered, line 3103 will display four parameters: error number, error description, track accessed, and sector accessed. If a disk error does occur and you can resolve it, return to the main program menu by typing:

GOTO 110

To avoid a "file not found" error, be sure that you have previously saved the data file before you attempt to recall it.

TRS-80 Color Computer

If you have a Color Computer with at least 16K, you will need to make three changes to Program 2. First, replace PRINT" {CLR}" with CLS in lines 17 and 2010. Also, DIMension A$ in line 100 to 150. Of course, this reserves space in memory for only 150 days of data. You may vary this limit depending on the memory available. You can use another weather file when you exceed the limit.

Program 4 is the data storage routine for the Color Computer. Type it in along with Program 2. Program 4 only lets you save or load the weather data to or from cassette. If you own a disk drive, you can easily modify this routine by reading about data files in your disk drive manual.

Apple II/Apple II Plus

If you are using an Apple, Program 2 should be typed in with the data storage routine (Program 5). Two changes are necessary in Program 2. Lines 17 and 2010 should read HOME rather than PRINT"{CLR}".

Program 5 is the data storage routine for use with the Apple disk drive. It contains a disk error trapping routine (line 3200) giving you the disk error number and the line in the program where it has occurred. If a disk error occurs that you can correct, return to the main program and re-SAVE the data so that no data is lost.

General weather conditions are entered into A$(X,20) from the following table:

1 = FAIR
2 = CLOUDY
3 = RAIN
4 = SNOW
5 = THUNDERSHOWERS
6 = SNOW FLURRIES
7 = HEAVY RAIN

Line 235 prompts for precipitation amounts. This must be a five-character entry (such as 02.75), and is stored in A$(X,21 TO 25).

Snowfall amounts are two characters stored inA$(X,26 TO 27).

Wind direction is stored in A$(X,28 TO 31) as a four-character entry with the first two characters being the wind direction from the following table:

01 = N
02 = NE
03 = E
04 = SE
05 = S
06 = SW
07 = W
08 = NW

The last two characters are wind speed and are entered as part of the code called for in line 285. Your entry would look like "0705" for a wind from the west at 5 miles per hour.

Lines 300 to 350 print out your data entries and ask if all is correct. If an error is found, line 360 restarts the entry process at line 135.

Lines 355-740 contain more inputs, calculations, and the forecasting results of your input. Line 750 returns to the main menu.

You'll have to determine the average temperatures, rainfall, and snowfall amounts for your area. A good source of this information is The Weather Almanac, edited by James A. Ruffner and Frank E. Bair, published by Avon Books. It's available from most libraries. Look up the city nearest you and make your substitutions in lines 940 to 1025.

The subroutine starting in line 3000 allows you to check the weather conditions on any day in your file. You enter the date in question, and the computer searches for that date. If the date is in memory, lines 3066 to 4000 will display the information.

When it's necessary to make a correction, lines 5005 to 6010 find the date in question and prompt for the correct information. Line 6005 assigns the value of N to X, and the information you've just entered is placed into the file in place of the incorrect information.

Now go back to line 10. Change your statement to DIM A$(190,31) and enter RUN to establish and reserve space in RAM for your file. From now on, be sure to start your program with a GOTO 59, not RUN. RUN clears all variables, so you'll lose your file in RAM.

The program takes about 7 minutes to load from tape and it will use all 16K. If any changes are necessary, go back and change line 10. You must first delete the entry, enter RUN, and then make whatever changes are needed.