Solar Position Algorithm For Solar Radiation Applications: Revised November 2005 - NREL/TP-560-34302
Solar Position Algorithm For Solar Radiation Applications: Revised November 2005 - NREL/TP-560-34302
NREL/TP-560-34302
NREL/TP-560-34302
Acknowledgment
We thank Bev Kay for all her support by manually typing all the data tables in the report into
text files, which made it easy and timely to transport to the report text and all of our software
code. We also thank Daryl Myers for all his technical expertise in solar radiation applications.
NOTICE
This report was prepared as an account of work sponsored by an agency of the United States
government. Neither the United States government nor any agency thereof, nor any of their employees,
makes any warranty, express or implied, or assumes any legal liability or responsibility for the accuracy,
completeness, or usefulness of any information, apparatus, product, or process disclosed, or represents
that its use would not infringe privately owned rights. Reference herein to any specific commercial
product, process, or service by trade name, trademark, manufacturer, or otherwise does not necessarily
constitute or imply its endorsement, recommendation, or favoring by the United States government or any
agency thereof. The views and opinions of authors expressed herein do not necessarily state or reflect
those of the United States government or any agency thereof.
Available electronically at http://www.osti.gov/bridge
Available for a processing fee to U.S. Department of Energy
and its contractors, in paper, from:
U.S. Department of Energy
Office of Scientific and Technical Information
P.O. Box 62
Oak Ridge, TN 37831-0062
phone: 865.576.8401
fax: 865.576.5728
email: [email protected]
Available for sale to the public, in paper, from:
U.S. Department of Commerce
National Technical Information Service
5285 Port Royal Road
Springfield, VA 22161
phone: 800.553.6847
fax: 703.605.6900
email: [email protected]
online ordering: http://www.ntis.gov/ordering.htm
Printed on paper containing at least 50% wastepaper, including 20% postconsumer waste
Table of Contents
Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Time Scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
SPA Evaluation and Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
List of Figures
Figure 1. Uncertainty of cosine the solar zenith angle resulting from 0.01/ and 0.0003/
uncertainty in the angle calculation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 2. Difference between the Almanac and SPA for the ecliptic longitude & latitude, and the
apparent right ascension & declination on the second day of each month at 0-TT for
the years 1994, 1995, 1996, and 2004 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 3. Difference between the Almanac and SPA for the solar zenith and azimuth angles on
the second day of each month at 0-TT for the years 1994, 1995, 1996, and 2004. . . . . 15
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Appendix
Equation of Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
Sunrise, Sun Transit, and Sunset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
Calculation of Calendar Date from Julian Day . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-6
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-15
C Code: SPA header file (SPA.h) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-17
C Code: SPA source file (SPA.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-19
iii
iv
Abstract
There have been many published articles describing solar position algorithms for solar radiation
applications. The best uncertainty achieved in most of these articles is greater than 0.01/ in
calculating the solar zenith and azimuth angles. For some, the algorithm is valid for a limited
number of years varying from 15 years to a hundred years. This report is a step by step procedure
for implementing an algorithm to calculate the solar zenith and azimuth angles in the period from
the year -2000 to 6000, with uncertainties of 0.0003/. The algorithm is described by Jean Meeus
[3]. This report is written in a step by step format to simplify the complicated steps described in
the book, with a focus on the sun instead of the planets and stars in general. It also introduces
some changes to accommodate for solar radiation applications. The changes include changing the
direction of measuring azimuth angles to be measured from north and eastward instead of being
measured from south and eastward, and the direction of measuring the observers geographical
longitude to be measured as positive eastward from Greenwich meridian instead of negative.
This report also includes the calculation of incidence angle for a surface that is tilted to any
horizontal and vertical angle, as described by Iqbal [4].
1.
Introduction
With the continuous technological advancements in solar radiation applications, there will
always be a demand for smaller uncertainty in calculating the solar position. Many methods to
calculate the solar position have been published in the solar radiation literature, nevertheless,
their uncertainties have been greater than 0.01/ in solar zenith and azimuth angle calculations,
and some are only valid for a specific number of years[1]. For example, Michalskys calculations
are limited to the period from 1950 to 2050 with uncertainty of greater than 0.01/ [2], and the
calculations of Blanco-Muriel et al.s are limited to the period from 1999 to 2015 with
uncertainty greater than > 0.01/ [1].
An example emphasizing the importance of reducing the uncertainty of calculating the solar
position to lower than 0.01/, is the calibration of pyranometers that measure the global solar
irradiance. During the calibration, the responsivity of the pyranometer is calculated at zenith
angles from 0/ to 90/ by dividing its output voltage by the reference global solar irradiance (G),
which is a function of the cosine of the zenith angle (cos 2). Figure 1 shows the magnitude of
errors that the 0.01/ uncertainty in 2 can contribute to the calculation of cos 2, and consequently
G that is used to calculate the responsivity. Figure 1 shows that the uncertainty in cos 2
exponentially increases as 2 reaches 90/(e.g. at 2 equal to 87/, the uncertainty in cos 2 is 0.7%,
which can result in an uncertainty of 0.35% in calculating G; because at such large zenith angles
the normal incidence irradiance is approximately equal to half the value of G). From this arises
the need to use a solar position algorithm with lower uncertainty for users that are interested in
measuring the global solar irradiance with smaller uncertainties in the full zenith angle range
from 0/ to 90/.
In this report we describe a procedure for a Solar Position Algorithm (SPA) to calculate the solar
zenith and azimuth angle with uncertainties equal to 0.0003/ in the period from the year -2000
to 6000. Figure 1 shows that the uncertainty of the reference global solar irradiance, resulting
from 0.0003/ in calculating the solar zenith angle in the range from 0/ to 90/ is negligible. The
procedure is adopted from The Astronomical Algorithms [3], which is based on the Variations
Sculaires des Orbites Plantaires Theory (VSOP87) that was developed by P. Bretagnon in 1982
then modified in 1987 by Bretagnon and Francou [3]. In this report, we summarize the complex
algorithm elements scattered throughout the book to calculate the solar position, and introduce
some modification to the algorithm to accommodate solar radiation applications. For example, in
The Astronomical Algorithms [3], the azimuth angle is measured westward from south, but for
solar radiation applications, it is measured eastward from north. Also, the observers
geographical longitude is considered positive west, or negative east from Greenwich, while for
solar radiation applications, it is considered negative west, or positive east from Greenwich.
We start this report by:
C
Describing the time scales because of the importance of using the correct time in the SPA
C
Providing a step by step procedure to calculate the solar position and the solar incidence
angle for an arbitrary surface orientation using the methods described in An Introduction
1
Because of the complexity of the algorithm we included some examples, in the Appendix, to give
the users confidence in their step by step calculations. We also included in the Appendix an
explanation of how to calculate the equation of time, sun transit (solar noon), sunrise, sunset, and
how to change the Julian Day to a Calendar Date. We also included a C source code with header
file, for all the calculations in this report (except for the Julian Day to Calendar Date conversion).
The users can incorporate this module into their own code by including the header file, declaring
the SPA structure, filling in the required input parameters into the structure, and then call the
SPA calculation function. This function will calculate all the output values and fill in the SPA
structure for the user.
The users should note that this report is used to calculate the solar position for solar radiation
applications only, and that it is purely mathematical and not meant to teach astronomy or to
describe the Earth rotation. For more description about the astronomical nomenclature that is
used through out the report, the user is encouraged to review the definitions in the Astronomical
Almanacs, or other astronomical reference.
2.
Time Scale
The Universal Time (UT), or Greenwich civil time, is based on the Earths rotation and
counted from 0-hour at midnight; the unit is mean solar day [3]. UT is the time used to
calculate the solar position in the described algorithm. It is sometimes referred to as UT1.
The International Atomic Time (TAI) is the duration of the System International Second
(SI-second) and based on a large number of atomic clocks [5].
The Coordinated Universal Time (UTC) is the bases of most radio time signals and the
legal time systems. It is kept to within 0.9 seconds of UT1 (UT) by introducing one
second steps to its value (leap second); to date the steps are always positive.
The Terrestrial Dynamical or Terrestrial Time (TDT or TT) is the time scale of
ephemerides for observations from the Earth surface.
The following equations describe the relationship between the above time scales (in seconds):
TT = TAI + 32.184 ,
(1)
UT = TT T
(2)
where )T is the difference between the Earth rotation time and the Terrestrial Time (TT).
It is derived from observation only and reported yearly in the Astronomical Almanac [5].
(3)
where )UT1 is a fraction of a second, positive or negative value, that is added to the
UTC to adjust for the Earth irregular rotational rate. It is derived from observation, but
predicted values are transmitted in code in some time signals, e.g. weekly by the U.S.
Naval Observatory (USNO) [6].
3.
Procedure
3.1.
Calculate the Julian and Julian Ephemeris Day, Century, and Millennium:
The Julian date starts on January 1, in the year - 4712 at 12:00:00 UT. The Julian Day (JD) is
calculated using UT and the Julian Ephemeris Day (JDE) is calculated using TT. In the following
steps, note that there is a 10-day gap between the Julian and Gregorian calendar where the Julian
calendar ends on October 4, 1582 (JD = 2299160), and after 10-days the Gregorian calendar
starts on October 15, 1582.
3.1.1 Calculate the Julian Day (JD),
(4)
where,
- INT is the Integer of the calculated terms (e.g. 8.7 = 8, 8.2 = 8, and -8.7 = 8..etc.).
-Y
is the year (e.g. 2001, 2002, ..etc.).
-M
is the month of the year (e.g. 1 for January, ..etc.). Note that if M > 2, then
Y and M are not changed, but if M = 1 or 2, then Y = Y-1 and M = M + 12.
-D
is the day of the month with decimal time (e.g. for the second day of the
month at 12:30:30 UT, D = 2.521180556).
-B
is equal to 0, for the Julian calendar {i.e. by using B = 0 in Equation 4, JD
< 2299160}, and equal to (2 - A + INT (A/4)) for the Gregorian calendar
{i.e. by using B = 0 in Equation 4, JD> 2299160}, where A = INT(Y/100).
For users who wish to use their local time instead of UT, change the time zone to a fraction of a
day (by dividing it by 24), then subtract the result from JD. Note that the fraction is subtracted
from JD calculated before the test for B<2299160 to maintain the Julian and Gregorian periods.
Table A4.1 shows examples to test any implemented program used to calculate the JD.
JDE = JD +
T
.
86400
(5)
3.1.3. Calculate the Julian century (JC) and the Julian Ephemeris Century (JCE) for the
2000 standard epoch,
JC =
JD 2451545
,
36525
JCE =
(6)
JDE 2451545
.
36525
(7)
3.1.4. Calculate the Julian Ephemeris Millennium (JME) for the 2000 standard epoch,
JME =
3.2.
JCE
.
10
(8)
Calculate the Earth heliocentric longitude, latitude, and radius vector (L, B,
and R):
Heliocentric means that the Earth position is calculated with respect to the center of the sun.
3.2.1. For each row of Table A4.2, calculate the term L0i (in radians),
L0i = Ai * cos ( Bi + Ci * JME )
(9)
where,
- i is the ith row for the term L0 in Table A4.2.
- Ai , Bi , and Ci are the values in the ith row and A, B, and C columns in Table
A4.2, for the term L0 (in radians).
3.2.2. Calculate the term L0 (in radians),
n
L0 =
L0
i=0
(10)
(11)
L (in Degrees) =
(12)
Geocentric means that the sun position is calculated with respect to the Earth center.
3.3.1. Calculate the geocentric longitude, 1 (in degrees),
= L + 180 .
(13)
= B .
(14)
3.4.
3.4.1. Calculate the mean elongation of the moon from the sun, X0 (in degrees),
(15)
3.4.2. Calculate the mean anomaly of the sun (Earth), X1 (in degrees),
(16)
(17)
(18)
3.4.5. Calculate the longitude of the ascending node of the moons mean orbit on the
ecliptic, measured from the mean equinox of the date, X4 (in degrees),
(19)
3.4.6. For each row in Table A4.3, calculate the terms )Ri and )gi (in 0.0001of arc
seconds),
4
(20)
j=0
(21)
j=0
where,
- ai , bi , ci , and di are the values listed in the ith row and columns a, b, c, and d in
Table A4.3.
- X j is the jth X calculated by using Equations 15 through 19.
- Yi, j is the value listed in ith row and jth Y column in Table A4.3.
3.4.7. Calculate the nutation in longitude, )R (in degrees),
n
i=0
(22)
36000000
where n is the number of rows in Table A4.3 (n equals 63 rows in the table).
3.4.8. Calculate the nutation in obliquity, )g (in degrees),
n
=
3.5.
i=0
36000000
(23)
3.5.1. Calculate the mean obliquity of the ecliptic, g0 (in arc seconds),
0 = 84381448
.
4680.93U 155
. U 2 + 1999.25U 3
5138
. U 4 249.67 U 5 39.05U 6 + 7.12 U 7 +
27.87 U 8 + 5.79 U 9 + 2.45U 10
(24)
where U = JME/10.
3.5.2. Calculate the true obliquity of the ecliptic, g (in degrees),
0
+ .
3600
(25)
3.6.
=
3.7.
20.4898
.
3600 * R
= + + .
3.8.
(26)
(27)
Calculate the apparent sidereal time at Greenwich at any given time, < (in
degrees):
3.8.1. Calculate the mean sidereal time at Greenwich, <0 (in degrees),
(28)
3.8.2. Limit <0 to the range from 0/ to 360/ as described in step 3.2.6.
3.8.3. Calculate the apparent sidereal time at Greenwich, < (in degrees),
= 0 + * cos ( ) .
3.9.
(29)
= Arc tan 2 (
(30)
where Arctan2 is an arctangent function that is applied to the numerator and the
denominator (instead of the actual division) to maintain the correct quadrant of the "
where " is in the rage from -B to B.
3.9.2. Calculate " in degrees using Equation 12, then limit it to the range from 0/ to
360/ using the technique described in step 3.2.6.
3.10. Calculate the geocentric sun declination, * (in degrees):
(31)
where * is positive or negative if the sun is north or south of the celestial equator,
respectively. Then change * to degrees using Equation 12.
3.11. Calculate the observer local hour angle, H (in degrees):
H=+ ,
(32)
Where F is the observer geographical longitude, positive or negative for east or west of
Greenwich, respectively.
Limit H to the range from 0/ to 360/ using step 3.2.6 and note that it is measured
westward from south in this algorithm.
3.12. Calculate the topocentric sun right ascension " (in degrees):
Topocentric means that the sun position is calculated with respect to the observer local position
at the Earth surface.
3.12.1. Calculate the equatorial horizontal parallax of the sun, > (in degrees),
8.794
3600 * R
(33)
(34)
where n is the observer geographical latitude, positive or negative if north or south of the
equator, respectively. Note that the 0.99664719 number equals (1 - f ), where f is the
Earths flattening.
3.12.3. Calculate the term x,
x = cos u +
E
* cos
6378140
(35)
where E is the observer elevation (in meters). Note that x equals D * cos n where D is
the observers distance to the center of Earth, and n is the observers geocentric latitude.
y = 0.99664719 * sin u +
E
* sin ,
6378140
(36)
= Arc tan 2 (
x * sin * sin H
) .
cos x * sin * cos H
(37)
' = + .
(38)
(39)
(40)
(41)
e =
283
P
*
*
1010 273 + T
102
.
10.3
60 * tan (e0 +
)
.
e0 + 511
(42)
10
where,
- P is the annual average local pressure (in millibars).
- T is the annual average local temperature (in /C).
- e0 is in degrees. Calculate the tangent argument in degrees, then convert to
radians if required by calculator or computer.
3.14.3. Calculate the topocentric elevation angle, e (in degrees),
e = e0 + e .
(43)
= 90 e .
(44)
= Arc tan 2 (
sin H '
) ,
cos H '*sin tan '*cos
(45)
Change ' to degrees using Equation 12, then limit it to the range from 0/ to 360/ using
step 3.2.6. Note that ' is measured westward from south.
3.15.2. Calculate the topocentric azimuth angle, M for navigators and solar radiation
users (in degrees),
= + 180 ,
(46)
Limit M to the range from 0/ to 360/ using step 3.2.6. Note that M is measured eastward
from north.
3.16. Calculate the incidence angle for a surface oriented in any direction, I (in
degrees):
I = Arc cos(cos * cos + sin * sin * cos ( )) ,
where,
(47)
4.
Because the solar zenith, azimuth, and incidence angles are not reported in the Astronomical
Almanac (AA), the following sun parameters are used for the evaluation: The main parameters
(ecliptic longitude and latitude for the mean Equinox of date, apparent right ascension, apparent
declination), and the correcting parameters (nutation in longitude, nutation in obliquity, obliquity
of ecliptic, and true geometric distance). Exact trigonometric functions are used with the AA
reported sun parameters to calculate the solar zenith and azimuth angles, therefore it is adequate
to evaluate the SPA uncertainty using these parameters. To evaluate the uncertainty of the SPA,
we chose the second day of each month, for each of the years 1994, 1995, 1996, and 2004, at 0hour Terrestrial Time (TT). Figures 2 shows that the maximum difference between the AA and
SPA main parameters is -0.00015/. Figure 3 shows that the maximum difference between the
AA and SPA for calculating the zenith or azimuth angle is 0.00003/ and 0.00008/, respectively.
This implies that the SPA is well within the stated uncertainty of 0.0003/.
12
2
1.9
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
0.01
0.0003
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
10
15
20
25
30
35
40
45
50
55
60
65
70
75
80
85
90
Figure 1. Uncertainty of cosine the solar zenith angle resulting from 0.01 and 0.0003
uncertainty in the angle calculation
13
0.0001
(in ) Almanac-SPA
0.00005
0
Ecliptic longitude
Ecliptic latitude
Apparent right ascention
Apparent declination
-0.00005
-0.0001
47
45
43
41
39
37
35
33
31
29
27
25
23
21
19
17
15
13
11
-0.00015
Day
Figure 2. Difference between the Almanac and SPA for the ecliptic longitude, ecliptic latitude, apparent right ascension,
and apparent declination on the second day of each month at 0-TT for the years 1994, 1995, 1996, and 2004
14
0.0001
(in ) Almanac-SPA
0.00005
Zenith
Azimuth
-0.00005
47
45
43
41
39
37
35
33
31
29
27
25
23
21
19
17
15
13
11
-0.0001
Day
Figure 3. Difference between the Almanac and SPA for the solar zenith and azimuth angles on the second day of each
month at 0-TT for the years 1994, 1995, 1996, 2004
15
References
1.
Blanco-Muriel, M., et al. Computing the Solar Vector. Solar Energy. Vol. 70, No. 5,
2001; pp. 431-441, 2001, Great Britain.
2.
3.
4.
5.
6.
16
Appendix
Note that some of the symbols used in the appendix are independent from the symbols used in
the main report.
A.1.
Equation of Time
The Equation of Time, E, is the difference between solar apparent and mean time. Use the
following equation to calculate E (in degrees),
E = M 0.0057183 + * cos
(A1)
where,
-M
,
49931 15300 2000000
(A2)
where JME is the Julian Ephemeris Millennium calculated from Equation 8, and
M is limited to the range from 0/ to 360/ using step 3.2.6.
-"
is the geocentric right ascention, from Equation 30 (in degrees).
- )R is the nutation in longitude, from Equation 22 (in degrees).
-g
is the obliquity of the ecliptic, from Equation 25 (in degrees).
Multiply E by 4 to change its unit from degrees to minutes of time. Limit E if its absolute value
is greater than 20 minutes, by adding or subtracting 1440.
A.2.
The value of 0.5667/ is typically adopted for the atmospheric refraction at sunrise and sunset
times. Thus for the sun radius of 0.26667/, the value -0.8333/ of sun elevation (h0 ) is chosen to
calculate the times of sunrise and sunset. On the other hand, the sun transit is the time when the
center of the sun reaches the local meridian.
A.2.1. Calculate the apparent sidereal time at Greenwich at 0 UT, < (in degrees), using
Equation 29.
A.2.2. Calculate the geocentric right ascension and declination at 0 TT, using Equations
30 and 31, for the day before the day of interest (D-1), the day of interest (D0),
A-1
1 1
0 0 ,
+1 +1
in degrees.
m0 =
0
360
(A3)
H 0 = Arc cos (
where,
- h0
-n
(A4)
equals -0.8333/.
is the observer geographical latitude, in degrees, positive north of the
equator.
Note that if the argument of the Arccosine is not in the range from -1 to 1, it means that
the sun is always above or below the horizon for that day.
Change H0 to degrees using Equation 12, then limit it to the range from 0/ to 180/ using
step 3.2.6 and replacing 360 by 180.
A.2.5. Calculate the approximate sunrise time, m1 , in fraction of day,
m1 = m0
H0
.
360
(A5)
m2 = m0 +
H0
.
360
(A6)
A.2.7. Limit the values of m0 , m1 , and m2 to a value between 0 and 1 fraction of day
using step 3.2.6 and replacing 360 by 1.
A-2
A.2.8. Calculate the sidereal time at Greenwich, in degrees, for the sun transit, sunrise,
and sunset, <i ,
i = + 360.985647 * mi
(A7)
where i equals 0, 1, and 2 for sun transit, sunrise, and sunset, respectively.
A.2.9. Calculate the terms ni ,
ni = mi +
T
,
86400
(A8)
where )T = TT-UT.
A.2.10. Calculate the values "i and *i , in degrees, where i equals 0, 1, and 2,
where,
'i = 0 +
and,
'i = 0 +
ni (a + b + c * ni )
2
(A9)
(A10)
where,
- a and a
equal ("0 - "-1 ) and (*0 - *-1 ), respectively.
- b and b
equal ("+1 - "0 ) and (*+1 - *0 ), respectively.
- c and c
equal (b - a) and (b - a), respectively.
If the absolute value of a, a, b, or b is greater than 2, then limit its value between
0 and 1 as shown in step A.2.7.
A.2.11. Calculate the local hour angle for the sun transit, sunrise, and sunset, Hi (in
degrees),
H 'i = i + 'i
(A11)
Hi in this case is measured as positive westward from the meridian, and negative
eastward from the meridian. Thus limit Hi between -180/ and 180/. To preserve the
quadrant sign of Hi limit it to 360/ first, then if Hi is less than or equal -180/, then add
360/ to force its value to be between 0/ and 180/. And if Hi is greater than or equal
180/, then add -360/ to force its value to be between 0/ and -180/.
A.2.12. Calculate the sun altitude for the sun transit, sunrise, and sunset, hi (in
degrees),
A-3
hi = Arc sin (sin * sin ' i + cos * cos ' i *cos H ' i ) .
(A12)
T = m0
H '0
.
360
(A13)
R = m1 +
h1 h' 0
360 * cos '1 *cos * sin H '1
(A14)
A.2.15. Calculate the sunset, S (in fraction of day), by using Equation A14 and
replacing R by S, and replacing the suffix number 1 by 2.
The fraction of day value is changed to UT by multiplying the value by 24.
To evaluate the uncertainty of the SPA, we chose the second day of each month, for each of the
years 1994, 1995, 1996, and 2004, at 0-hour Terrestrial Time (TT). Figure A2.1 shows that the
maximum difference between the AA and SPA sun transit time is -0.23 seconds.
Because the sunrise and sunset are recorded in the AA to a one minute resolution, we compared
the SPA calculations at only three data points at Greenwich meridian at 0-UT. The comparison
result in Table A2.1 shows that the maximum difference between AA and SPA is 15.4 seconds
(0.26 minute), which is well within the AA resolution of one minute.
Note that UT can be changed to local time by adding the time zone as a fraction of a day (time
zone is divided by 24), and limiting the result to the range from 0 to 1.
Table A2.1. The AA and SPA Results for Sunrise and Sunset at Greenwich
Meridian at 0-UT
Sunrise
Sunset
Date
Observer
Latitude
AA
SPA
AA
SPA
January 2, 1994
35/
7:08
7:08:12.8
17:00
16:59:55.9
July 5, 1996
-35/
7:08
7:08:15.4
17:00
17:01:04.5
December 4, 2004
-35/
4:39
4:38:57.1
19:02
19:02:2.5
A-4
-0.14
-0.15
-0.16
( in seconds) Almanac-SPA
-0.17
-0.18
-0.19
-0.2
-0.21
-0.22
-0.23
47
45
43
41
39
37
35
33
31
29
27
25
23
21
19
17
15
13
11
-0.24
Day
Figure A2.1. Difference between the Almanac and SPA for the Ephemeris Transit on the second day of each month at
0-TT for the years 1994, 1995, 1996, 2004
A-5
A.3.
A.3.1. Add 0.5 to the Julian Day (JD), then record the integer of the result as Z, and the
fraction decimal as F.
A.3.2. If Z is less than 2299161, then record A equals Z. Else, calculate the term B,
B = INT (
Z 1867216.25
) ,
36524.25
(A15)
B
A = Z + 1 + B INT ( ) .
4
(A16)
(A17)
C 122.1
) .
365.25
(A18)
G = INT (365.25 * D) .
(A19)
D = INT (
A.3.5. Calculate the term G,
C G
) .
30.6001
A.3.7. Calculate the day number of the month with decimals, d,
I = INT (
d = C G INT (30.6001 * I ) + F
(A20)
(A21)
m = I 1,
m = I 13 ,
IF I < 14 ,
IF I 14 .
(A22)
A-6
y = D 4716 ,
y = D 4715 ,
IF m > 2 ,
IF m 2 .
(A23)
Note that if local time is used to calculate the JD, then the local time zone is added to the JD in
step A.3.1 to calculate the local Calendar Date.
A.4.
Tables
Table A4.1. Examples for Testing any Program to Calculate the Julian Day
Date
UT
JD
Date
UT
JD
January 1, 2000
12:00:00
2451545.0
00:00:00
2305812.5
January 1, 1999
00:00:00
2451179.5
07:12:00
2026871.8
00:00:00
2446822.5
00:00:00
1676496.5
12:00:00
2446966.0
January 1, -122
00:00:00
1676497.5
00:00:00
2447187.5
12:00:00
1356001.0
12:00:00
2447332.0
00:00:00
1355866.5
January 1, 1900
00:00:00
2415020.5
21:36:00
1355671.4
January 1, 1600
00:00:00
2305447.5
January 1, -4712
12:00:00
0.0
Term
L0
C
0
6283.07585
12566.1517
5753.3849
3.5231
77713.7715
7860.4194
3930.2097
11506.7698
529.691
1577.3435
A-7
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
990
902
857
780
753
505
492
357
317
284
271
243
206
205
202
156
132
126
115
103
102
102
99
98
86
85
85
80
79
71
74
74
70
62
5.233
2.045
3.508
1.179
2.533
4.583
4.205
2.92
5.849
1.899
0.315
0.345
4.806
1.869
2.4458
0.833
3.411
1.083
0.645
0.636
0.976
4.267
6.21
0.68
5.98
1.3
3.67
1.81
3.04
1.76
3.5
4.68
0.83
3.98
5884.927
26.298
398.149
5223.694
5507.553
18849.228
775.523
0.067
11790.629
796.298
10977.079
5486.778
2544.314
5573.143
6069.777
213.299
2942.463
20.775
0.98
4694.003
15720.839
7.114
2146.17
155.42
161000.69
6275.96
71430.7
17260.15
12036.46
5088.63
3154.69
801.82
9437.76
8827.39
A-8
L1
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
61
57
56
56
52
52
51
49
41
41
39
37
37
36
36
33
30
30
25
628331966747
206059
4303
425
119
109
93
72
68
67
59
56
45
36
29
1.82
2.78
4.39
3.47
0.19
1.33
0.28
0.49
5.37
2.4
6.17
6.04
2.57
1.71
1.78
0.59
0.44
2.74
3.16
0
2.678235
2.6351
1.59
5.796
2.966
2.59
1.14
1.87
4.41
2.89
2.17
0.4
0.47
2.65
7084.9
6286.6
14143.5
6279.55
12139.55
1748.02
5856.48
1194.45
8429.24
19651.05
10447.39
10213.29
1059.38
2352.87
6812.77
17789.85
83996.85
1349.87
4690.48
0
6283.07585
12566.1517
3.523
26.298
1577.344
18849.23
529.69
398.15
5507.55
5223.69
155.42
796.3
775.52
7.11
A-9
L2
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
21
19
19
17
16
16
15
12
12
12
12
11
10
10
9
9
8
6
6
52919
8720
309
27
16
16
10
9
7
5
4
4
3
3
3
5.34
1.85
4.97
2.99
0.03
1.43
1.21
2.83
3.26
5.27
2.08
0.77
1.3
4.24
2.7
5.64
5.3
2.65
4.67
0
1.0721
0.867
0.05
5.19
3.68
0.76
2.06
0.83
4.66
1.03
3.44
5.14
6.05
1.19
0.98
5486.78
213.3
6275.96
2544.31
2146.17
10977.08
1748.02
5088.63
1194.45
4694
553.57
3286.6
1349.87
242.73
951.72
2352.87
9437.76
4690.48
0
6283.0758
12566.152
3.52
26.3
155.42
18849.23
77713.77
775.52
1577.34
7.11
5573.14
796.3
5507.55
242.73
A-10
L3
L4
L5
B0
B1
R0
15
16
17
18
19
0
1
2
3
4
5
6
0
1
2
0
0
1
2
3
4
0
1
0
1
2
3
4
5
6
7
8
9
10
3
3
3
2
2
289
35
17
3
1
1
1
114
8
1
1
280
102
80
44
32
9
6
100013989
1670700
13956
3084
1628
1576
925
542
472
346
329
6.12
0.31
2.28
4.38
3.75
5.844
0
5.49
5.2
4.72
5.3
5.97
3.142
4.13
3.84
3.14
3.199
5.422
3.88
3.7
4
3.9
1.73
0
3.0984635
3.05525
5.1985
1.1739
2.8469
5.453
4.564
3.661
0.964
5.9
529.69
398.15
553.57
5223.69
0.98
6283.076
0
12566.15
155.42
3.52
18849.23
242.73
0
6283.08
12566.15
0
84334.662
5507.553
5223.69
2352.87
1577.34
5507.55
5223.69
0
6283.07585
12566.1517
77713.7715
5753.3849
7860.4194
11506.77
3930.21
5884.927
5507.553
5223.694
A-11
R1
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
0
1
2
3
4
307
243
212
186
175
110
98
86
86
85
63
57
56
49
47
45
43
39
38
37
37
36
35
33
32
32
28
28
26
103019
1721
702
32
31
0.299
4.273
5.847
5.022
3.012
5.055
0.89
5.69
1.27
0.27
0.92
2.01
5.24
3.25
2.58
5.54
6.01
5.36
2.39
0.83
4.9
1.67
1.84
0.24
0.18
1.78
1.21
1.9
4.59
1.10749
1.0644
3.142
1.02
2.84
5573.143
11790.629
1577.344
10977.079
18849.228
5486.778
6069.78
15720.84
161000.69
17260.15
529.69
83996.85
71430.7
2544.31
775.52
9437.76
6275.96
4694
8827.39
19651.05
12139.55
12036.46
2942.46
7084.9
5088.63
398.15
6286.6
6279.55
10447.39
6283.07585
12566.1517
0
18849.23
5507.55
A-12
R2
R3
R4
5
6
7
8
9
0
1
2
3
4
5
0
1
0
25
18
10
9
9
4359
124
12
9
6
3
145
7
4
1.32
1.42
5.91
1.42
0.27
5.7846
5.579
3.14
3.63
1.87
5.47
4.273
3.92
2.56
5223.69
1577.34
10977.08
6275.96
5486.78
6283.0758
12566.152
0
77713.77
5573.14
18849
6283.076
12566.15
6283.08
Table A4.3. Periodic Terms for the Nutation in Longitude and Obliquity
Y0
0
-2
0
0
0
0
-2
0
0
-2
-2
-2
0
2
0
2
Y4
1
2
2
2
0
0
2
1
2
2
0
1
2
0
1
2
0
0
-2
0
2
0
0
-2
0
-2
0
0
2
-2
0
-2
0
0
2
2
0
-2
0
2
2
-2
-2
2
2
0
-2
-2
0
-2
0
0
0
0
0
0
0
0
0
0
0
2
0
2
1
0
-1
0
0
0
1
1
-1
0
0
0
0
0
0
-1
-1
0
0
0
-1
1
2
-2
0
2
2
1
0
0
-1
0
-1
0
0
1
0
2
-1
1
0
1
0
0
1
2
1
-2
0
1
0
0
2
2
0
2
0
2
2
2
0
2
2
2
2
0
0
2
0
0
0
-2
2
2
2
0
2
2
0
2
2
0
0
0
2
0
2
0
1
1
0
1
2
2
0
2
0
0
1
0
1
2
1
1
1
0
1
2
2
0
2
1
0
2
1
1
1
0
1
1
1
1
-58
-51
48
46
-38
-31
29
29
26
-22
21
17
16
-16
-15
-13
-12
11
-10
-8
7
-7
-7
-7
6
6
6
-6
-6
5
-5
-5
-5
4
-0.1
32
27
-24
16
13
-12
-10
-0.1
0.1
-8
7
9
7
6
5
3
-3
3
3
-3
-3
3
3
3
3
3
A-14
-2
0
-1
-2
1
0
0
-1
0
0
2
0
2
A.5.
1
0
0
1
0
0
0
-1
1
-1
-1
0
-1
0
1
1
0
0
1
-2
1
1
1
-1
3
0
2
-2
0
0
0
2
2
0
0
2
2
2
2
1
0
0
0
0
0
2
0
0
2
2
2
2
4
4
-4
-4
-4
3
-3
-3
-3
-3
-3
-3
-3
Example
The results for the following site parameters are listed in Table A5.1:
- Date = October 17, 2003.
- Time = 12:30:30 Local Standard Time (LST).
- Time zone(TZ) = -7 hours.
- Longitude = -105.1786/.
- Pressure = 820 mbar.
- Latitude = 39.742476/.
- Elevation = 1830.14 m.
- Temperature = 11/C.
- Surface slope = 30/.
- Surface azimuth rotation = -10/.
- )T = 67 Seconds.
LST must be changed to UT by subtracting TZ from LST, and changing the date if necessary.
Table A5.1. Results for Example
2452930.312847
JD
L0
172067564.737444
L1
628332010643.684814
L2
61368.682493
L3
-26.902819
L4
-121.279536
L5
-0.999999
24.0182635175/
L
B0
-176.502688
3.067582
-0.0001011219/
B
R0
B1
99653829.608470
R1
100378.567146
A-15
R2
-1140.950890
R4
1.232361
R3
-141.115419
0.9965421031 AU
204.0182635175/
0.0001011219/
)R
-0.00399840/
)g
0.00166657/
23.440465/
204.0085537528/
"
202.22741/
-9.31434/
11.105900/
11.10629/
"
202.22704/
-9.316179/
50.11162/
194.34024/
25.18700/
205.8971722516/
14.641503 minutes
Transit
18:46:04.97 UT
Sunrise
13:12:43.46 UT
Sunset
00:20:19.19 UT
A-16
/////////////////////////////////////////////
//
HEADER FILE for SPA.C
//
//
//
//
Solar Position Algorithm (SPA)
//
//
for
//
//
Solar Radiation Application
//
//
//
//
May 12, 2003
//
//
//
//
Filename: SPA.H
//
//
//
//
Afshin Michael Andreas
//
//
[email protected] (303)384-6383 //
//
//
//
Measurement & Instrumentation Team
//
//
Solar Radiation Research Laboratory
//
//
National Renewable Energy Laboratory //
//
1617 Cole Blvd, Golden, CO 80401
//
/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//
//
// Usage:
//
//
//
//
1) In calling program, include this header file,
//
//
by adding this line to the top of file:
//
//
#include "spa.h"
//
//
//
//
2) In calling program, declare the SPA structure:
//
//
spa_data spa;
//
//
//
//
3) Enter the required input values into SPA structure
//
//
(input values listed in comments below)
//
//
//
//
4) Call the SPA calculate function and pass the SPA structure
//
//
(prototype is declared at the end of this header file):
//
//
spa_calculate(&spa);
//
//
//
//
Selected output values (listed in comments below) will be
//
//
computed and returned in the passed SPA structure. Output
//
//
will based on function code selected from enumeration below.
//
//
//
//
Note: A non-zero return code from spa_calculate() indicates that //
//
one of the input values did not pass simple bounds tests. //
//
The valid input ranges and return error codes are also
//
//
listed below.
//
//
//
////////////////////////////////////////////////////////////////////////
#ifndef __solar_position_algorithm_header
#define __solar_position_algorithm_header
//enumeration for function codes to select desired final outputs from SPA
enum {
SPA_ZA,
//calculate zenith and azimuth
SPA_ZA_INC,
//calculate zenith, azimuth, and incidence
SPA_ZA_RTS,
//calculate zenith, azimuth, and sun rise/transit/set values
SPA_ALL,
//calculate all SPA output values
};
typedef struct
{
//----------------------INPUT VALUES-----------------------int year;
int month;
int day;
int hour;
int minute;
int second;
float delta_t;
float timezone;
//
//
//
//
//
//
//
//
//
//
//
4-digit year,
valid range: -2000 to 6000, error code: 1
2-digit month,
valid range: 1 to 12, error code: 2
2-digit day,
valid range: 1 to 31, error code: 3
Observer local hour,
valid range: 0 to 24, error code: 4
Observer local minute, valid range: 0 to 59, error code: 5
Observer local second, valid range: 0 to 59, error code: 6
Difference between earth rotation time and terrestrial time
(from observation)
valid range: -8000 to 8000 seconds, error code: 7
Observer time zone (negative west of Greenwich)
valid range: -12
to
12 hours,
error code: 8
A-17
float longitude;
//
//
float latitude;
//
//
float elevation;
//
//
float pressure;
//
//
float temperature;
//
//
float slope;
//
//
float azm_rotation; //
//
//
float atmos_refract; //
//
int function;
//
jd;
jc;
jde;
jce;
jme;
l;
b;
r;
theta;
beta;
x0;
x1;
x2;
x3;
x4;
del_psi;
del_epsilon;
epsilon0;
epsilon;
del_tau;
lamda;
nu0;
nu;
alpha;
delta;
h;
xi;
del_alpha;
delta_prime;
alpha_prime;
h_prime;
e0;
del_e;
e;
eot;
srha;
ssha;
sta;
//Julian day
//Julian century
//Julian ephemeris day
//Julian ephemeris century
//Julian ephemeris millennium
//earth heliocentric longitude [degrees]
//earth heliocentric latitude [degrees]
//earth radius vector [Astronomical Units, AU]
//geocentric longitude [degrees]
//geocentric latitude [degrees]
//mean elongation (moon-sun) [degrees]
//mean anomaly (sun) [degrees]
//mean anomaly (moon) [degrees]
//argument latitude (moon) [degrees]
//ascending longitude (moon) [degrees]
//nutation longitude [degrees]
//nutation obliquity [degrees]
//ecliptic mean obliquity [arc seconds]
//ecliptic true obliquity [degrees]
//aberration correction [degrees]
//apparent sun longitude [degrees]
//Greenwich mean sidereal time [degrees]
//Greenwich sidereal time [degrees]
//geocentric sun right ascension [degrees]
//geocentric sun declination [degrees]
//observer hour angle [degrees]
//sun equatorial horizontal parallax [degrees]
//sun right ascension parallax [degrees]
//topocentric sun declination [degrees]
//topocentric sun right ascension [degrees]
//topocentric local hour angle [degrees]
//topocentric elevation angle (uncorrected) [degrees]
//atmospheric refraction correction [degrees]
//topocentric elevation angle (corrected) [degrees]
//equation of time [minutes]
//sunrise hour angle [degrees]
//sunset hour angle [degrees]
//sun transit altitude [degrees]
zenith;
azimuth180;
azimuth;
incidence;
suntransit;
sunrise;
sunset;
} spa_data;
//Calculate SPA output values (in structure) based on input values passed in structure
int spa_calculate(spa_data *spa);
#endif
A-18
/////////////////////////////////////////////
//
Solar Position Algorithm (SPA)
//
//
for
//
//
Solar Radiation Application
//
//
//
//
May 12, 2003
//
//
//
//
Filename: SPA.C
//
//
//
//
Afshin Michael Andreas
//
//
[email protected] (303)384-6383 //
//
//
//
Measurement & Instrumentation Team
//
//
Solar Radiation Research Laboratory
//
//
National Renewable Energy Laboratory //
//
1617 Cole Blvd, Golden, CO 80401
//
/////////////////////////////////////////////
/////////////////////////////////////////////
//
See the SPA.H header file for usage
//
//
//
//
This code is based on the NREL
//
//
technical report "Solar Position
//
//
Algorithm for Solar Radiation
//
//
Application" by I. Reda & A. Andreas //
/////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
// Revised 27-FEB-2004 Andreas
//
Added bounds check on inputs and return value for spa_calculate().
// Revised 10-MAY-2004 Andreas
//
Changed temperature bound check minimum from -273.15 to -273.
// Revised 17-JUN-2004 Andreas
//
Corrected a problem that caused a bogus sunrise/set/transit on the equinox.
// Revised 18-JUN-2004 Andreas
//
Added a "function" input variable that allows the selecting of desired outputs.
// Revised 21-JUN-2004 Andreas
//
Added 3 new intermediate output values to SPA structure (srha, ssha, & sta).
// Revised 23-JUN-2004 Andreas
//
Enumerations for "function" were renamed and 2 were added.
//
Prevented bound checks on inputs that are not used (based on function).
// Revised 01-SEP-2004 Andreas
//
Changed a local variable from integer to double, which caused some C compilers
//
to display a warning message.
// Revised 12-JUL-2005 Andreas
//
Put a limit on the EOT calculation, so that the result is between -20 and 20.
///////////////////////////////////////////////////////////////////////////////////////////////
#include <math.h>
#include "spa.h"
#define PI
3.1415926535897932384626433832795028841971
#define SUN_RADIUS 0.26667
#define
#define
#define
#define
#define
#define
#define
enum
enum
enum
enum
enum
L_COUNT 6
B_COUNT 2
R_COUNT 5
Y_COUNT 63
L_MAX_SUBCOUNT 64
B_MAX_SUBCOUNT 5
R_MAX_SUBCOUNT 40
A-19
///////////////////////////////////////////////////
/// Earth Periodic Terms
///////////////////////////////////////////////////
const double L_TERMS[L_COUNT][L_MAX_SUBCOUNT][TERM_COUNT]=
{
{
{175347046.0,0,0},
{3341656.0,4.6692568,6283.07585},
{34894.0,4.6261,12566.1517},
{3497.0,2.7441,5753.3849},
{3418.0,2.8289,3.5231},
{3136.0,3.6277,77713.7715},
{2676.0,4.4181,7860.4194},
{2343.0,6.1352,3930.2097},
{1324.0,0.7425,11506.7698},
{1273.0,2.0371,529.691},
{1199.0,1.1096,1577.3435},
{990,5.233,5884.927},
{902,2.045,26.298},
{857,3.508,398.149},
{780,1.179,5223.694},
{753,2.533,5507.553},
{505,4.583,18849.228},
{492,4.205,775.523},
{357,2.92,0.067},
{317,5.849,11790.629},
{284,1.899,796.298},
{271,0.315,10977.079},
{243,0.345,5486.778},
{206,4.806,2544.314},
{205,1.869,5573.143},
{202,2.4458,6069.777},
{156,0.833,213.299},
{132,3.411,2942.463},
{126,1.083,20.775},
{115,0.645,0.98},
{103,0.636,4694.003},
{102,0.976,15720.839},
{102,4.267,7.114},
{99,6.21,2146.17},
{98,0.68,155.42},
{86,5.98,161000.69},
{85,1.3,6275.96},
{85,3.67,71430.7},
{80,1.81,17260.15},
{79,3.04,12036.46},
{71,1.76,5088.63},
{74,3.5,3154.69},
{74,4.68,801.82},
{70,0.83,9437.76},
{62,3.98,8827.39},
{61,1.82,7084.9},
{57,2.78,6286.6},
{56,4.39,14143.5},
{56,3.47,6279.55},
{52,0.19,12139.55},
{52,1.33,1748.02},
{51,0.28,5856.48},
{49,0.49,1194.45},
{41,5.37,8429.24},
{41,2.4,19651.05},
{39,6.17,10447.39},
{37,6.04,10213.29},
{37,2.57,1059.38},
{36,1.71,2352.87},
{36,1.78,6812.77},
{33,0.59,17789.85},
{30,0.44,83996.85},
{30,2.74,1349.87},
{25,3.16,4690.48}
},
{
{628331966747.0,0,0},
{206059.0,2.678235,6283.07585},
A-20
},
{
},
{
},
{
},
{
};
{4303.0,2.6351,12566.1517},
{425.0,1.59,3.523},
{119.0,5.796,26.298},
{109.0,2.966,1577.344},
{93,2.59,18849.23},
{72,1.14,529.69},
{68,1.87,398.15},
{67,4.41,5507.55},
{59,2.89,5223.69},
{56,2.17,155.42},
{45,0.4,796.3},
{36,0.47,775.52},
{29,2.65,7.11},
{21,5.34,0.98},
{19,1.85,5486.78},
{19,4.97,213.3},
{17,2.99,6275.96},
{16,0.03,2544.31},
{16,1.43,2146.17},
{15,1.21,10977.08},
{12,2.83,1748.02},
{12,3.26,5088.63},
{12,5.27,1194.45},
{12,2.08,4694},
{11,0.77,553.57},
{10,1.3,3286.6},
{10,4.24,1349.87},
{9,2.7,242.73},
{9,5.64,951.72},
{8,5.3,2352.87},
{6,2.65,9437.76},
{6,4.67,4690.48}
{52919.0,0,0},
{8720.0,1.0721,6283.0758},
{309.0,0.867,12566.152},
{27,0.05,3.52},
{16,5.19,26.3},
{16,3.68,155.42},
{10,0.76,18849.23},
{9,2.06,77713.77},
{7,0.83,775.52},
{5,4.66,1577.34},
{4,1.03,7.11},
{4,3.44,5573.14},
{3,5.14,796.3},
{3,6.05,5507.55},
{3,1.19,242.73},
{3,6.12,529.69},
{3,0.31,398.15},
{3,2.28,553.57},
{2,4.38,5223.69},
{2,3.75,0.98}
{289.0,5.844,6283.076},
{35,0,0},
{17,5.49,12566.15},
{3,5.2,155.42},
{1,4.72,3.52},
{1,5.3,18849.23},
{1,5.97,242.73}
{114.0,3.142,0},
{8,4.13,6283.08},
{1,3.84,12566.15}
{1,3.14,0}
A-21
A-22
},
{
},
{
};
{9,3.63,77713.77},
{6,1.87,5573.14},
{3,5.47,18849}
{145.0,4.273,6283.076},
{7,3.92,12566.15}
{4,2.56,6283.08}
////////////////////////////////////////////////////////////////
/// Periodic Terms for the nutation in longitude and obliquity
////////////////////////////////////////////////////////////////
const int Y_TERMS[Y_COUNT][TERM_Y_COUNT]=
{
{0,0,0,0,1},
{-2,0,0,2,2},
{0,0,0,2,2},
{0,0,0,0,2},
{0,1,0,0,0},
{0,0,1,0,0},
{-2,1,0,2,2},
{0,0,0,2,1},
{0,0,1,2,2},
{-2,-1,0,2,2},
{-2,0,1,0,0},
{-2,0,0,2,1},
{0,0,-1,2,2},
{2,0,0,0,0},
{0,0,1,0,1},
{2,0,-1,2,2},
{0,0,-1,0,1},
{0,0,1,2,1},
{-2,0,2,0,0},
{0,0,-2,2,1},
{2,0,0,2,2},
{0,0,2,2,2},
{0,0,2,0,0},
{-2,0,1,2,2},
{0,0,0,2,0},
{-2,0,0,2,0},
{0,0,-1,2,1},
{0,2,0,0,0},
{2,0,-1,0,1},
{-2,2,0,2,2},
{0,1,0,0,1},
{-2,0,1,0,1},
{0,-1,0,0,1},
{0,0,2,-2,0},
{2,0,-1,2,1},
{2,0,1,2,2},
{0,1,0,2,2},
{-2,1,1,0,0},
{0,-1,0,2,2},
{2,0,0,2,1},
{2,0,1,0,0},
{-2,0,2,2,2},
{-2,0,1,2,1},
{2,0,-2,0,1},
{2,0,0,0,1},
{0,-1,1,0,0},
{-2,-1,0,2,1},
{-2,0,0,0,1},
{0,0,2,2,1},
{-2,0,2,0,1},
{-2,1,0,2,1},
{0,0,1,-2,0},
{-1,0,1,0,0},
{-2,1,0,0,0},
{1,0,0,0,0},
{0,0,1,2,0},
A-23
};
{0,0,-2,2,2},
{-1,-1,1,0,0},
{0,1,1,0,0},
{0,-1,1,2,2},
{2,-1,-1,2,2},
{0,0,3,2,2},
{2,-1,0,2,2},
A-24
///////////////////////////////////////////////
double rad2deg(double radians)
{
return (180.0/PI)*radians;
}
double deg2rad(double degrees)
{
return (PI/180.0)*degrees;
}
double limit_degrees(double degrees)
{
double limited;
degrees /= 360.0;
limited = 360.0*(degrees-floor(degrees));
if (limited < 0) limited += 360.0;
}
return limited;
/= 360.0;
= 360.0*(degrees-floor(degrees));
(limited < -180.0) limited += 360.0;
(limited > 180.0) limited -= 360.0;
return limited;
return limited;
return limited;
return limited;
A-25
///////////////////////////////////////////////////////////////////////////////////////////////
int validate_inputs(spa_data *spa)
{
if ((spa->year
< -2000) || (spa->year
> 6000)) return 1;
if ((spa->month
< 1
) || (spa->month
> 12 )) return 2;
if ((spa->day
< 1
) || (spa->day
> 31 )) return 3;
if ((spa->hour
< 0
) || (spa->hour
> 24 )) return 4;
if ((spa->minute
< 0
) || (spa->minute
> 59 )) return 5;
if ((spa->second
< 0
) || (spa->second
> 59 )) return 6;
if ((spa->pressure
< 0
) || (spa->pressure
> 5000)) return 12;
if ((spa->temperature <= -273) || (spa->temperature > 6000)) return 13;
if ((spa->hour
== 24 ) && (spa->minute
> 0
)) return 5;
if ((spa->hour
== 24 ) && (spa->second
> 0
)) return 6;
if
if
if
if
if
(fabs(spa->delta_t)
(fabs(spa->timezone)
(fabs(spa->longitude)
(fabs(spa->latitude)
(
spa->elevation
>
>
>
>
<
8000
)
12
)
180
)
90
)
-6500000)
return
return
return
return
return
7;
8;
9;
10;
11;
return julian_day;
A-26
return sum;
return sum;
return theta;
double geocentric_latitude(double b)
{
return -b;
}
A-27
return sum;
*del_psi
= sum_psi
/ 36000000.0;
*del_epsilon = sum_epsilon / 36000000.0;
A-28
return rad2deg(asin(sin(beta_rad)*cos(epsilon_rad) +
cos(beta_rad)*sin(epsilon_rad)*sin(deg2rad(lamda))));
return rad2deg(asin(sin(lat_rad)*sin(delta_prime_rad) +
cos(lat_rad)*cos(delta_prime_rad) * cos(deg2rad(h_prime))));
A-29
return rad2deg(atan2(sin(h_prime_rad),
cos(h_prime_rad)*sin(lat_rad) tan(deg2rad(delta_prime))*cos(lat_rad)));
return rad2deg(acos(cos(zenith_rad)*cos(slope_rad) +
sin(slope_rad )*sin(zenith_rad) * cos(deg2rad(azimuth180 azm_rotation))));
return h0;
A-30
m_rts[SUN_RISE]
= limit_zero2one(m_rts[SUN_TRANSIT] - h0_dfrac);
m_rts[SUN_SET]
= limit_zero2one(m_rts[SUN_TRANSIT] + h0_dfrac);
m_rts[SUN_TRANSIT] = limit_zero2one(m_rts[SUN_TRANSIT]);
return rad2deg(asin(sin(latitude_rad)*sin(delta_prime_rad) +
cos(latitude_rad)*cos(delta_prime_rad)*cos(deg2rad(h_prime))));
(360.0*cos(deg2rad(delta_prime[sun]))*cos(deg2rad(latitude))
*sin(deg2rad(h_prime[sun])));
////////////////////////////////////////////////////////////////////////////////////////////////
// Calculate required SPA parameters to get the right ascension (alpha) and declination (delta)
// Note: JD must be already calculated and in structure
////////////////////////////////////////////////////////////////////////////////////////////////
void calculate_geocentric_sun_right_ascension_and_declination(spa_data *spa)
{
double x[TERM_X_COUNT];
spa->jc = julian_century(spa->jd);
spa->jde = julian_ephemeris_day(spa->jd, spa->delta_t);
spa->jce = julian_ephemeris_century(spa->jde);
spa->jme = julian_ephemeris_millennium(spa->jce);
spa->l = earth_heliocentric_longitude(spa->jme);
spa->b = earth_heliocentric_latitude(spa->jme);
spa->r = earth_radius_vector(spa->jme);
spa->theta = geocentric_longitude(spa->l);
spa->beta = geocentric_latitude(spa->b);
x[TERM_X0]
x[TERM_X1]
x[TERM_X2]
x[TERM_X3]
x[TERM_X4]
=
=
=
=
=
spa->x0
spa->x1
spa->x2
spa->x3
spa->x4
=
=
=
=
=
mean_elongation_moon_sun(spa->jce);
mean_anomaly_sun(spa->jce);
mean_anomaly_moon(spa->jce);
argument_latitude_moon(spa->jce);
ascending_longitude_moon(spa->jce);
=
=
=
=
aberration_correction(spa->r);
apparent_sun_longitude(spa->theta, spa->del_psi, spa->del_tau);
greenwich_mean_sidereal_time (spa->jd, spa->jc);
greenwich_sidereal_time (spa->nu0, spa->del_psi, spa->epsilon);
A-31
////////////////////////////////////////////////////////////////////////
// Calculate Equation of Time (EOT) and Sun Rise, Transit, & Set (RTS)
////////////////////////////////////////////////////////////////////////
void calculate_eot_and_sun_rise_transit_set(spa_data *spa)
{
spa_data sun_rts = *spa;
double nu, m, h0, n;
double alpha[JD_COUNT], delta[JD_COUNT];
double m_rts[SUN_COUNT], nu_rts[SUN_COUNT], h_rts[SUN_COUNT];
double alpha_prime[SUN_COUNT], delta_prime[SUN_COUNT], h_prime[SUN_COUNT];
double h0_prime = -1*(SUN_RADIUS + spa->atmos_refract);
int i;
m
= sun_mean_longitude(spa->jme);
spa->eot = eot(m, spa->alpha, spa->del_psi, spa->epsilon);
sun_rts.hour = sun_rts.minute = sun_rts.second = sun_rts.timezone = 0;
sun_rts.jd = julian_day (sun_rts.year, sun_rts.month, sun_rts.day,
sun_rts.hour, sun_rts.minute, sun_rts.second, sun_rts.timezone);
calculate_geocentric_sun_right_ascension_and_declination(&sun_rts);
nu = sun_rts.nu;
sun_rts.delta_t = 0;
sun_rts.jd--;
for (i = 0; i < JD_COUNT; i++) {
calculate_geocentric_sun_right_ascension_and_declination(&sun_rts);
alpha[i] = sun_rts.alpha;
delta[i] = sun_rts.delta;
sun_rts.jd++;
}
m_rts[SUN_TRANSIT] = approx_sun_transit_time(alpha[JD_ZERO], spa->longitude, nu);
h0 = sun_hour_angle_at_rise_set(spa->latitude, delta[JD_ZERO], h0_prime);
if (h0 >= 0) {
approx_sun_rise_and_set(m_rts, h0);
for (i = 0; i < SUN_COUNT; i++) {
nu_rts[i]
= nu + 360.985647*m_rts[i];
n
= m_rts[i] + spa->delta_t/86400.0;
alpha_prime[i] = rts_alpha_delta_prime(alpha, n);
delta_prime[i] = rts_alpha_delta_prime(delta, n);
h_prime[i]
h_rts[i]
spa->srha = h_prime[SUN_RISE];
spa->ssha = h_prime[SUN_SET];
spa->sta = h_rts[SUN_TRANSIT];
spa->suntransit = dayfrac_to_local_hr(m_rts[SUN_TRANSIT] - h_prime[SUN_TRANSIT] / 360.0,
spa->timezone);
spa->sunrise = dayfrac_to_local_hr(sun_rise_and_set(m_rts, h_rts, delta_prime,
spa->latitude, h_prime, h0_prime, SUN_RISE), spa->timezone);
spa->sunset
A-32
///////////////////////////////////////////////////////////////////////////////////////////
// Calculate all SPA parameters and put into structure
// Note: All inputs values (listed in header file) must already be in structure
///////////////////////////////////////////////////////////////////////////////////////////
int spa_calculate(spa_data *spa)
{
int result;
result = validate_inputs(spa);
if (result == 0)
{
spa->jd = julian_day (spa->year, spa->month, spa->day,
spa->hour, spa->minute, spa->second, spa->timezone);
calculate_geocentric_sun_right_ascension_and_declination(spa);
spa->h = observer_hour_angle(spa->nu, spa->longitude, spa->alpha);
spa->xi = sun_equatorial_horizontal_parallax(spa->r);
sun_right_ascension_parallax_and_topocentric_dec(spa->latitude, spa->elevation, spa->xi,
spa->h, spa->delta, &(spa->del_alpha), &(spa->delta_prime));
spa->alpha_prime = topocentric_sun_right_ascension(spa->alpha, spa->del_alpha);
spa->h_prime
= topocentric_local_hour_angle(spa->h, spa->del_alpha);
spa->e0
= topocentric_elevation_angle(spa->latitude, spa->delta_prime,
spa->h_prime);
spa->del_e
= atmospheric_refraction_correction(spa->pressure, spa->temperature,
spa->e0);
spa->e
= topocentric_elevation_angle_corrected(spa->e0, spa->del_e);
spa->zenith
= topocentric_zenith_angle(spa->e);
spa->azimuth180 = topocentric_azimuth_angle_neg180_180(spa->h_prime, spa->latitude,
spa->delta_prime);
spa->azimuth
= topocentric_azimuth_angle_zero_360(spa->azimuth180);
if ((spa->function == SPA_ZA_INC) || (spa->function == SPA_ALL))
spa->incidence = surface_incidence_angle(spa->zenith, spa->azimuth180,
spa->azm_rotation, spa->slope);
return result;
}
///////////////////////////////////////////////////////////////////////////////////////////
A-33
Form Approved
OMB NO. 0704-0188
Public reporting burden for this collection of information is estimated to average 1 hour per response, including the time for reviewing instructions, searching existing data sources,
gathering and maintaining the data needed, and completing and reviewing the collection of information. Send comments regarding this burden estimate or any other aspect of this
collection of information, including suggestions for reducing this burden, to Washington Headquarters Services, Directorate for Information Operations and Reports, 1215 Jefferson
Davis Highway, Suite 1204, Arlington, VA 22202-4302, and to the Office of Management and Budget, Paperwork Reduction Project (0704-0188), Washington, DC 20503.
2. REPORT DATE
Technical Report
5. FUNDING NUMBERS
WU1D5600
6. AUTHOR(S)
8. PERFORMING ORGANIZATION
REPORT NUMBER
NREL/TP-560-34302
10. SPONSORING/MONITORING
AGENCY REPORT NUMBER
1. This report is a step-by-step procedure for implementing an algorithm to calculate the solar zenith and azimuth angles in
the period from the year 2000 to 6000, with uncertainties of 0.0003/. It is written in a step-by-step format to simplify
otherwise complicated steps, with a focus on the sun instead of the planets and stars in general. The algorithm is written
in such a way to accommodate solar radiation applications.
15. NUMBER OF PAGES
algorithm; solar position algorithm; solar radiation; solar radiation applications; solar
zenith angles; solar azimuth angles
17. SECURITY CLASSIFICATION
OF REPORT
Unclassified
NSN 7540-01-280-5500
Unclassified
Unclassified
UL
Standard Form 298 (Rev. 2-89)
Prescribed by ANSI Std. Z39-18
298-102