1 |
|
2 |
|
3 |
///////////////////////////////////////////// |
4 |
// SPA TESTER for SPA.C // |
5 |
// // |
6 |
// Solar Position Algorithm (SPA) // |
7 |
// for // |
8 |
// Solar Radiation Application // |
9 |
// // |
10 |
// August 12, 2004 // |
11 |
// // |
12 |
// Filename: SPA_TESTER.C // |
13 |
// // |
14 |
// Afshin Michael Andreas // |
15 |
// afshin_andreas@nrel.gov (303)384-6383 // |
16 |
// // |
17 |
// Measurement & Instrumentation Team // |
18 |
// Solar Radiation Research Laboratory // |
19 |
// National Renewable Energy Laboratory // |
20 |
// 1617 Cole Blvd, Golden, CO 80401 // |
21 |
///////////////////////////////////////////// |
22 |
|
23 |
///////////////////////////////////////////// |
24 |
// This sample program shows how to use // |
25 |
// the SPA.C code. // |
26 |
///////////////////////////////////////////// |
27 |
|
28 |
#include <stdio.h> |
29 |
#include "spa.h" //include the SPA header file |
30 |
|
31 |
int main (int argc, char *argv[]) |
32 |
{ |
33 |
spa_data spa; //declare the SPA structure |
34 |
int result; |
35 |
float min, sec; |
36 |
|
37 |
//enter required input values into SPA structure |
38 |
|
39 |
spa.year = 2003; |
40 |
spa.month = 10; |
41 |
spa.day = 17; |
42 |
spa.hour = 12; |
43 |
spa.minute = 30; |
44 |
spa.second = 30; |
45 |
spa.timezone = -7.0; |
46 |
spa.delta_t = 67; |
47 |
spa.longitude = -105.1786; |
48 |
spa.latitude = 39.742476; |
49 |
spa.elevation = 1830.14; |
50 |
spa.pressure = 820; |
51 |
spa.temperature = 11; |
52 |
spa.slope = 30; |
53 |
spa.azm_rotation = -10; |
54 |
spa.atmos_refract = 0.5667; |
55 |
spa.function = SPA_ALL; |
56 |
|
57 |
//call the SPA calculate function and pass the SPA structure |
58 |
|
59 |
result = spa_calculate(&spa); |
60 |
|
61 |
if (result == 0) //check for SPA errors |
62 |
{ |
63 |
//display the results inside the SPA structure |
64 |
|
65 |
printf("Julian Day: %.6f\n",spa.jd); |
66 |
printf("L: %.6e degrees\n",spa.l); |
67 |
printf("B: %.6e degrees\n",spa.b); |
68 |
printf("R: %.6f AU\n",spa.r); |
69 |
printf("H: %.6f degrees\n",spa.h); |
70 |
printf("Delta Psi: %.6e degrees\n",spa.del_psi); |
71 |
printf("Delta Epsilon: %.6e degrees\n",spa.del_epsilon); |
72 |
printf("Epsilon: %.6f degrees\n",spa.epsilon); |
73 |
printf("Zenith: %.6f degrees\n",spa.zenith); |
74 |
printf("Azimuth: %.6f degrees\n",spa.azimuth); |
75 |
printf("Incidence: %.6f degrees\n",spa.incidence); |
76 |
|
77 |
min = 60.0*(spa.sunrise - (int)(spa.sunrise)); |
78 |
sec = 60.0*(min - (int)min); |
79 |
printf("Sunrise: %02d:%02d:%02d Local Time\n", (int)(spa.sunrise), (int)min, (int)sec); |
80 |
|
81 |
min = 60.0*(spa.sunset - (int)(spa.sunset)); |
82 |
sec = 60.0*(min - (int)min); |
83 |
printf("Sunset: %02d:%02d:%02d Local Time\n", (int)(spa.sunset), (int)min, (int)sec); |
84 |
|
85 |
} else printf("SPA Error Code: %d\n", result); |
86 |
|
87 |
return 0; |
88 |
} |
89 |
|
90 |
///////////////////////////////////////////// |
91 |
// The output of this program should be: |
92 |
// |
93 |
//Julian Day: 2452930.312847 |
94 |
//L: 2.401826e+01 degrees |
95 |
//B: -1.011219e-04 degrees |
96 |
//R: 0.996542 AU |
97 |
//H: 11.105902 degrees |
98 |
//Delta Psi: -3.998404e-03 degrees |
99 |
//Delta Epsilon: 1.666568e-03 degrees |
100 |
//Epsilon: 23.440465 degrees |
101 |
//Zenith: 50.111622 degrees |
102 |
//Azimuth: 194.340241 degrees |
103 |
//Incidence: 25.187000 degrees |
104 |
//Sunrise: 06:12:43 Local Time |
105 |
//Sunset: 17:20:19 Local Time |
106 |
// |
107 |
///////////////////////////////////////////// |
108 |
|