Programs to Calculate Sun Rise-Set Data

by J. R. Mathison

May 2020

Almost twenty-five years ago I wrote two programs to calculate sunrise and sunset times. Back then the only operating system I knew was Microsoft DOS and my programming language was PASCAL.

My interest in this project came from the wanting to better understand spherical trigonometery and elliptical integrals which I had encountered in aviation and celestial navigation.

The first program, was written to execute at computer start-up and outputs one line of data for the date in the operating system.

The second program, is user interactive and outputs sun data for all the days of the year of interest.

An example of output from

    Sun Data for  2020

   44 48  0  DMS Location Latitude
  106 58  0  DMS Location Longitude  Refraction: 0.83 degrees

 Date  Day     Rise    Brg     Set    Brg  Daylite  MxAlt  Decln   Anna    Trans
 7- 8  190   5:31.1   56.6  8:55.1  303.4  15:23.9   67.6   22.4   -5.2  13:13.1
 7- 9  191   5:31.9   56.8  8:54.6  303.2  15:22.6   67.4   22.2   -5.4  13:13.2
 7-10  192   5:32.7   57.0  8:54.0  303.0  15:21.3   67.3   22.1   -5.5  13:13.4
 7-11  193   5:33.6   57.2  8:53.5  302.8  15:19.9   67.2   22.0   -5.6  13:13.5
 7-12  194   5:34.4   57.4  8:52.9  302.6  15:18.4   67.0   21.8   -5.8  13:13.6
There are eleven columns of output: month and day, day of year, time of sunrise, true bearing of sunrise, time of sunset, true bearing of sunset, duration of time sun is up, maximum altitude attained by sun, declination of sun, anelema, and time of sun transit of meridian. The location is for Sheridan, Wyoming.

The first few years after I wrote these programs, I compared their output to data downloaded from the U.S. Naval Observatory. Their output was within the same minute approx eighty percent of the time otherwise it was in the minute before or after. My programs output times rounded to the nearest one-tenth of a second but the U.S. Naval Observatory outputs to the nearest minute. The comparison was made with the latude and longitude location set to that of the local airport weather station.

These programs use the center of the sun as the reference point. I would guess the U.S. Naval Observatory uses the first (or last) appearance of the sun's upper limb as its reference. You will probably not be able to get exact agreement with any official source, but experimenting with the 'refraction' setting in sunread.txt may get closer agreement.

These programs will run under the Microsoft Windows 'command prompt'. I have tested them in XP Pro and Windows 7 and I believe they 'should' run in the later Windows also. They will also run in Unix or Linux under a DOS emulator. I use 'doxbox' in Fedora linux.

The file, when unzipped will dump five files into the current directory: sunline.pas,, sunyear.pas and sunread.txt. The *.pas files are the source code and the *.com are the two executables. The file sunread.txt is the configuration file and the MANUAL. The two *.com files will not execute without it. The seven lines at the top are configuration and the rest is the manual.

The *.pas files were compiled into executable *.com using the 'surpas' compiler running under DOS 6.22 in a hard drive image runing under 'dosbox'. The five files were zipped using 'pkzip'.

Download '' here.

I offer no guarantee that these programs will do what you want them to do. If they do not, you have the *.pas source code to change as you wish and then re-compile on your own.

GO TO Home Page


Last revision 5-15-20