Rise Set

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

A Fortran program to calculate

sunrise and sunset


Nicholas Moe
23 April 2007

Introduction

This is a description of a program written in Fortran 90/95 to calculate the rise


and set ties of the sun, accurate to within a couple of minutes. It is based on
pseudocode given in Practical astronomy with your calculator by Peter DuffettSmith. The calculation relies on extrapolations on conditions present at a 0.0
January 1980 epoch. After the extrapolations are made, various conversions are
necessary to calculate the times of sunrise and sunset. Corrections for parallax
and atmospheric distortion are also made. The basic procedure is as follows:
1. Calculate the ecliptic coordinates of the sun on the date in question.
2. Convert the ecpliptic coordinates to declination and right ascension coordinates.
3. Calculate the ecliptic coordinates of the sun 24 hours later and convert
the position to equatorial coordinates.
4. Compute the times of rising and setting for the coordinates found in terms
of local sidereal time.
5. Interpolate between these times in order to find a more accurate rise and
set time.
6. Correct these times for parallax and atmospheric distortion.
7. Convert these corrected times to local civil time.
Some unfamiliar terms used in this brief outline will be explained in the sections
that follow.

1.1

Julian dates

For some of the calculations for this program, it is necessary to count the number
of days between the day in question and either the beginning of the year or the
beginning of the epoch. The method that is preferred by the books procedures
1

is easier for a human to do than a computer. The book suggests counting the
days between the beginning of the current year and the current date by adding
up the number of days in each month preceeding the current month, and then
adding the day number.
In order to do this, one has to consider whether the current year is a leap year
in order to determine how many days to add during February. If the number of
days since the beginning of the epoch is required, then one would have to execute
the above procedure and then add up the number of days in each year including
the epoch and preceeding the current year, taking into account whether the year
is a leap year or not.
I have found it easier to do these day-difference calculations by computing
Julian day numbers. The Julian date is the number of days that have passed since
Greenwich mean noon of January 1st 4713 B.C., that is midday as measured on
the Greenwich meridian on January 1st of that year.1 To compute the number
of days between two dates, it is only necessary to compute the Julian dates for
the two dates in question and find the difference between the two Julian dates.
The Julian date calculation takes leap years and the conversion between the
Julian and Gregorian calendar into account, so lookup tables are not necessary
in order to make the calculation.

1.2

Measures of time

Calculations in this program also rely on a few different types of time: Greenwich
mean time (GMT), now known as universal time (UT), local civil time, Greenwich
sidereal time (GST), and local sidereal time (LST). GMT is based on the local
civil time at 0 longitude. Local civil time is determined by the mean motion of
the sun; noon in local civil time is the time at which the mean sun is highest in
the sky. The mean sun is a fictitious sun whose motion is uniform as it travels
along the equator.2 The real sun has non-uniform motion due to the elliptical
nature of Earths orbit and the tilt of its axis. The difference between the two
times is found using the equation of time.
Sidereal time is based on the motion of the stars. A sidereal day is the time
it takes for a star to return to the same position in the sky. A sidereal day is
thus shorter than a solar day23h 56m as opposed to 24h. The prefixes of
Greenwich and local specify where the measurement of sidereal time is taken.
In the program, it is necessary to convert from GMT to GST and back again.
These conversions depend on constants that do not change from year to year, as
well as a constant that is different for each year. A function, called constant_B,
uses an algorithm to calculate this not-so-constant constant.
Both conversions from GMT to GST and from GST to GMT rely on the
number of days between the day in question and January 0.0. January 0.0 is
defined as midnight between December 30th and 31st of the previous year.3
This simplifies the calculations needed for other astronomical calculations.
1 9.
2 92
3 6.

The local sidereal time is easily calculated by correcting GST by the hourequivalent of the difference in longitude (there is one hour per 15 degrees of
longitude).

Ecliptic coordinates

The ecliptic plane is the plane on which the Earth moves as it revolves around
the sun. To observers on Earth, the Sun appears to move around the Earth on a
path in the sky, called the ecliptic, defined by this plane. Since the sun moves
exactly on this path, it is therefore easy to compute its angular distance away
from the path; this coordinate, , is always zero. The only coordinate that
needs to be calculated, then, is the ecliptic longitude, . The ecliptic longitude
is defined as the angular distance from the first point of Ares, the point at which
the ecliptic crosses the celestial equator. The celestial equator, in turn, is a line
in the sky where the plane of the Earths equator would intersect the celestial
sphere. The ecliptic longitude is measured in the direction that the Sun moves
along the eclipticeastwardand the angle at which the ecliptic intersects the
equatorial plane is symbolized by .
Because the Earth orbits around the Sun in an elliptical orbitor it appears
that the Sun orbits around the Earth in an elliptical orbitit is easier to pretend
that the orbit is circular and then to make corrections for the elliptical orbit.
The mean anomaly, M , is the angle through which the sun has passed since
perigee:
360
M=
D + g $g ,
(1)
365.2422
where g and $g are the mean longitude of the sun at the epoch and perigee
respectively.4 D is the number of days since the epoch. The program then adds
or subtracts multiples of 360 until M is in the range 0 360 .
Once the mean anomaly is known, corrections can be made to allow for the
elliptical orbit of the Sun. The eccentric anomaly, E, is found by numerically
solving the trancendental equation,
E e sin E = M,
where E and M are expressed as radians.
Once the eccentric anomaly is found, the true anomaly, , by solving

1

1+e 2
E
tan
tan =
2
1e
2

(2)

(3)

with all the angles expressed as radians. The ecliptic longitude is then found
with
= + $g ,
(4)
where the variables are expressed in degrees. Here again, the program then adds
or subtracts multiples of 360 until is in the range 0 360 .
4 81

Conversion of ecliptic coordinates to equatorial coordinates

Once the equatorial coordinates are known, it is fairly easy to convert them to
equatorial coordinates, expressed as right ascension, , and declination, . Right
ascension is ordinarily expressed in hours, and declination is ordinarily expressd
as degrees.
If , the opliquity of the ecliptic (the angle between the ecliptic plane and
the equatorial plane) is known, then the right ascension (in degrees) is given by


sin cos  tan sin 
= tan1
,
(5)
cos
and the declination (in degrees) is given by
= sin1 (sin cos  + cos sin  sin ) .

(6)

It is necessary to make sure that tan1 gives an angle in the correct quadrant.
Fortunately, Fortran has the ATAN2 function which gives the correct angle, taking
the numerator and denominator of the argument of tan1 as its arguments.
Also, since is given in degrees by this method, it must be converted to
hours by dividing by 15.

Rising and setting times

The equations that follow give a rough calculation of the rise and set times of a
celestial object, given its equatorial coordinates, date, local latitude, and local
longitude. These are rough calculations because they do not take parallax and
atmospheric distortion into account.
If the local latitude is expressed by , then
LSTr = 24
LSTs =

1
cos1 ( tan tan ) +
15

1
cos1 ( tan tan ) +
15

(7)
(8)

give the LST of rising and LST of setting, respectively. Once the LST times are
found, they can be converted to GMT times.
Since rise and set times are found for two timesone for the date in question
and one 24 hours lateran interpolation can be used to improve the accuracy of
the rise and set times:
T =

24.07 ST1
hours,
24.07 + ST1 ST2

(9)

where ST1 and ST2 represent the two sets of times found for rising and setting
(a T is found for both rising and setting, known as Tr and Ts , respectively).
4

Corrections for atmospheric effects

The Earths atmosphere can cause the apparent time of rising or setting to differ
by a few minutes from the actual time or rising. If the vertical displacement is x
(which accounts for both the suns finite angular diameter, horizontal parallax,
and atmospheric refraction), then the time correction is
t =
where
y = sin1
and
= cos

240y
seconds,
cos


sin x
sin

sin
sin

(10)

degrees

(11)

degrees.

(12)

The Suns angular diameter is 0 .533, its horizontal parallax is 8.79 arcseconds,
and the atmosphere contributes 34 minutes of arc of refraction, so
x=

0 .533
+ 800 .79 + 340 .
2

(13)

For this calculation, is the average declination for the two days for which the
Suns position was calculated.
Once t has been found, it can be converted to seconds and added to Ts and
subtracted from Tr .

Final steps

Tr and Ts at this stage are LST times. In order to convert them to local civil
times, they first need to be converted to GST times. The GST times are then
converted to GMT times. Finally, the time zone offset is applied to the GMT
times, resulting in the local civil times for sunrise and sunset.

Testing

To see whether the output of my program was any good, I compared its calculated times to times calculated by the U.S. Naval Observatory, using a web form
at http://aa.usno.navy.mil/data/docs/RS OneDay.html. I compared times
for several dates for an observer in Avon, MN (45.6 N, 94.5 W) as seen in the
table below:

Date
01 January 1980
24 August 1980
07 September 1980
01 January 2007
24 August 2007
07 September 2007

USNO Tr
07h 58m
06h 30m
06h 47m
07h 59m
06h 29m
06h 46m

Program Tr
07h 55m
06h 28m
06h 45m
07h 55m
06h 27m
06h 45m

USNO Ts
16h 44m
20h 10m
19h 44m
16h 45m
20h 11m
19h 45m

Program Ts
16h 40m
20h 09m
19h 43m
16h 40m
20h 10m
19h 44m

Conclusion

The results from the Fortran program seem reasonably accurate; the times it
predicts are within five minutes of the times predicted by the USNO. The results
match exactly those which were given by the book for an observer on 7 September
1979 at longitude 0 , 52 N.

Bibliography
Duffett-Smith, Peter. Practical astronomy with your calculator. Second Edition.
Cambridge, 1981.

You might also like