Documentation for SOLAR.BA by Louis C. Graue
From Portable 100 August 1987
This program for the Model 100 calculates the azimuth and altitude of the sun for every hour of the day at a specified spot on the earth. The date, latitude, longitude, times azimuths and altitudes are printed right on the screen. In addition, the path of the sun during the daytime is plotted against local time. The times of the local sunrise and sunset for the date are also printed on the screen.
The program is mostly just for fun, but has some practical uses as well. If you wanted to plan window shading then the solar coordinates for various times of the year might be very useful. Modifications could be made to track the sun's path for a solar energy device. Fisherman and hunters can determine the legal times to operate, accident reports involving sun glare can be documented, and so on.
You can estimate the local time of the maximum altitude of the sun. When the sun crosses your meridian of longitude, it is due south of you. Hence, the shadow cast by a vertical object will point true north. This can then be used to calibrate your rotator of your television or radio antenna.
The method for finding solar coordinates is given in the Almanac for Computers 1980, published by the Nautical Almanac Office.
The calculations use the current months, day and year to generate the Julian date, Greenwich mean time, sidereal time, Greenwich hour angle and local hour angle. Trigonometry is then used to produce the solar azimuth and altitude.
Greenwich is a borough of London, England. Mean solar time for the meridian at Greenwich is used as a basis for calculating time throughout most of the world. Julius Caesar introduced the Julian calendar in Rome n 46 B.C. The Julian date is a count of days and fraction of days beginning at Greenwich Mean Noon, January 1, 4713 B.C. The formula for calculating this from the current date is given in line 390 of the program.
Sidereal time is based on the axial and orbital rotation of the earth with reference to the background of stars. A sidereal day is 23 hours, 56 minutes, 4.09 second in unites of mean solar time.
Formulas from the Nautical Almanac are used to calculate the right ascension and declination of the sun. These are then used with the logical longitude and latitude to calculate the azimuth and altitude of the sun at that location. To obtain a good understanding of how this is done requires some study of an astronomy or navigational textbook.
Lines 100 through 195 set up the screen with a coordinate system and headings. After the calculations are made, data is displayed and points are plotted for each hour of the day within this framework. The constant KC - 57.29578 in line 310 is used to convert degrees to radians.
Lines 350 through 370 pick out the month, day and year stored in DATE$, which is maintained by the Model 100. Line 380 converts the year from two to four digits and line 390 calculates the Julian date.
The FOR - NEXT loop from line 400 through line 670 calculates the sun's azimuth and altitude for each hour of the day. The variable UT is Universal (Greenwich) time and ES is the corresponding Eastern Standard Time. I will explain then to you so you will be able to change to your own local time. Zero hours UT is 1900 hours EST. Five hours UT is 0 hours EST; EST is five hours behind UT. In the program we run UT from 5 to 29 so that EST will run from zero to 24 hours. This is necessary so that the graph will be correct. For example, to adjust from the Pacific Standard Time (PST) zone we use the fact that PST is eight hours behind UT. Lines 400 and 410 should be changed to read as follows:
400 FOR UT = 8 TO 32
410 ES = 1600 + UT * 100
If you want to output to agree with your watch and hour watch is "h" hours less than UT, then subtract "h" hours from ES and run UT "h" to h+24.
Line 658 sends us to a subroutine that updates the display of local time, altitude and azimuth numbers. We come back to line 659 where we check for a change in the sign of the sun's altitude. If there is a change we go to a subroutine to calculate the time of sunrise or sunset. If this is the first change then the time of sunrise is computed. If this is the second change then the time of sunset is computed. This subroutine uses linear interpolation between the two altitudes to get the approximate time of zero altitude. Since the sun's path is concave downward, these approximations will give a sunrise time slightly later and a sunset time a little earlier than true values.
If you want to obtain very precise sunrise and sunset times then you can write a program using the main calculating loop repeatedly to search for the time when the sun's altitude is zero.
Line 665 checks for a positive altitude. If it is found to be positive, then the sun is above the horizon and we go to a subroutine that plots the sun's altitude versus local time.
When the FOR - NEXT loop is finished, the program prints the sunrise and sunset times previously calculated and ends at line 800. The program remains in a loop at line 800 so that the screen will not be disturbed by the usual ending routine of BASIC. You can press Shift-Break to exit the program.
Type in the program, changing line 175 to contain the latitude and longitude of your location. I scaled these off of a road map that had latitude and longitude along the edges. The coordinates must be in decimal form (no minutes or seconds).
If necessary, change lines 400 and 410 to fit your local time zone as described above. Before running the program, enter the date you want to run if it is not already in the machine. You just type DATE$="mm/dd/yy" to set the date.
If your applications of the program would require frequent changes of the date of coordinates then you may wish to modify the program to ask for these values as input from the keyboard. It is interesting to substitute a variety of coordinates and dates. You'll notice quite a variation of the path of the sun for different dates or latitudes.