-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathspa_tester.c
109 lines (92 loc) · 3.66 KB
/
spa_tester.c
1
2
3
4
5
6
7
8
9
10
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/////////////////////////////////////////////
// SPA TESTER for SPA.C //
// //
// Solar Position Algorithm (SPA) //
// for //
// Solar Radiation Application //
// //
// August 12, 2004 //
// //
// Filename: SPA_TESTER.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 //
/////////////////////////////////////////////
/////////////////////////////////////////////
// This sample program shows how to use //
// the SPA.C code. //
/////////////////////////////////////////////
#include <stdio.h>
#include "spa.h" //include the SPA header file
int main (int argc, char *argv[])
{
spa_data spa; //declare the SPA structure
int result;
float min, sec;
//enter required input values into SPA structure
spa.year = 2003;
spa.month = 10;
spa.day = 17;
spa.hour = 12;
spa.minute = 30;
spa.second = 30;
spa.timezone = -7.0;
spa.delta_ut1 = 0;
spa.delta_t = 67;
spa.longitude = -105.1786;
spa.latitude = 39.742476;
spa.elevation = 1830.14;
spa.pressure = 820;
spa.temperature = 11;
spa.slope = 30;
spa.azm_rotation = -10;
spa.atmos_refract = 0.5667;
spa.function = SPA_ALL;
//call the SPA calculate function and pass the SPA structure
result = spa_calculate(&spa);
if (result == 0) //check for SPA errors
{
//display the results inside the SPA structure
printf("Julian Day: %.6f\n",spa.jd);
printf("L: %.6e degrees\n",spa.l);
printf("B: %.6e degrees\n",spa.b);
printf("R: %.6f AU\n",spa.r);
printf("H: %.6f degrees\n",spa.h);
printf("Delta Psi: %.6e degrees\n",spa.del_psi);
printf("Delta Epsilon: %.6e degrees\n",spa.del_epsilon);
printf("Epsilon: %.6f degrees\n",spa.epsilon);
printf("Zenith: %.6f degrees\n",spa.zenith);
printf("Azimuth: %.6f degrees\n",spa.azimuth);
printf("Incidence: %.6f degrees\n",spa.incidence);
min = 60.0*(spa.sunrise - (int)(spa.sunrise));
sec = 60.0*(min - (int)min);
printf("Sunrise: %02d:%02d:%02d Local Time\n", (int)(spa.sunrise), (int)min, (int)sec);
min = 60.0*(spa.sunset - (int)(spa.sunset));
sec = 60.0*(min - (int)min);
printf("Sunset: %02d:%02d:%02d Local Time\n", (int)(spa.sunset), (int)min, (int)sec);
} else printf("SPA Error Code: %d\n", result);
return 0;
}
/////////////////////////////////////////////
// The output of this program should be:
//
//Julian Day: 2452930.312847
//L: 2.401826e+01 degrees
//B: -1.011219e-04 degrees
//R: 0.996542 AU
//H: 11.105902 degrees
//Delta Psi: -3.998404e-03 degrees
//Delta Epsilon: 1.666568e-03 degrees
//Epsilon: 23.440465 degrees
//Zenith: 50.111622 degrees
//Azimuth: 194.340241 degrees
//Incidence: 25.187000 degrees
//Sunrise: 06:12:43 Local Time
//Sunset: 17:20:19 Local Time
//
/////////////////////////////////////////////