1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.5 |
static const char RCSid[] = "$Id: sun.c,v 2.4 2003/11/16 10:29:38 schorsch Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
greg |
1.2 |
/* |
5 |
greg |
1.1 |
* SOLAR CALCULATIONS |
6 |
|
|
* |
7 |
|
|
* 3/31/87 |
8 |
|
|
* |
9 |
|
|
*/ |
10 |
|
|
|
11 |
greg |
2.2 |
#include <math.h> |
12 |
|
|
|
13 |
greg |
2.5 |
#ifdef M_PI |
14 |
|
|
#define PI M_PI |
15 |
|
|
#else |
16 |
|
|
#define PI 3.141592653589793 |
17 |
|
|
#endif |
18 |
greg |
1.1 |
|
19 |
|
|
double s_latitude = 0.66; /* site latitude (radians) */ |
20 |
|
|
double s_longitude = 2.13; /* site longitude (radians) */ |
21 |
|
|
double s_meridian = 2.0944; /* standard meridian (radians) */ |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
int |
25 |
schorsch |
2.4 |
jdate( /* Julian date (days into year) */ |
26 |
|
|
int month, |
27 |
|
|
int day |
28 |
|
|
) |
29 |
greg |
1.1 |
{ |
30 |
|
|
static short mo_da[12] = {0,31,59,90,120,151,181,212,243,273,304,334}; |
31 |
|
|
|
32 |
|
|
return(mo_da[month-1] + day); |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
|
36 |
|
|
double |
37 |
schorsch |
2.4 |
stadj( /* solar time adjustment from Julian date */ |
38 |
|
|
int jd |
39 |
|
|
) |
40 |
greg |
1.1 |
{ |
41 |
|
|
return( 0.170 * sin( (4*PI/373) * (jd - 80) ) - |
42 |
|
|
0.129 * sin( (2*PI/355) * (jd - 8) ) + |
43 |
|
|
12 * (s_meridian - s_longitude) / PI ); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
double |
48 |
schorsch |
2.4 |
sdec( /* solar declination angle from Julian date */ |
49 |
|
|
int jd |
50 |
|
|
) |
51 |
greg |
1.1 |
{ |
52 |
|
|
return( 0.4093 * sin( (2*PI/368) * (jd - 81) ) ); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
double |
57 |
schorsch |
2.4 |
salt( /* solar altitude from solar declination and solar time */ |
58 |
|
|
double sd, |
59 |
|
|
double st |
60 |
|
|
) |
61 |
greg |
1.1 |
{ |
62 |
|
|
return( asin( sin(s_latitude) * sin(sd) - |
63 |
|
|
cos(s_latitude) * cos(sd) * cos(st*(PI/12)) ) ); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
double |
68 |
schorsch |
2.4 |
sazi( /* solar azimuth from solar declination and solar time */ |
69 |
|
|
double sd, |
70 |
|
|
double st |
71 |
|
|
) |
72 |
greg |
1.1 |
{ |
73 |
|
|
return( -atan2( cos(sd)*sin(st*(PI/12)), |
74 |
|
|
-cos(s_latitude)*sin(sd) - |
75 |
|
|
sin(s_latitude)*cos(sd)*cos(st*(PI/12)) ) ); |
76 |
|
|
} |