line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Calendar::Any::Util::Solar; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Calendar::Any::Util::Solar::VERSION = '0.5'; |
4
|
|
|
|
|
|
|
} |
5
|
3
|
|
|
3
|
|
25113
|
use Calendar::Any::Gregorian; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
79
|
|
6
|
3
|
|
|
3
|
|
10682
|
use Math::Trig; |
|
3
|
|
|
|
|
73697
|
|
|
3
|
|
|
|
|
4946
|
|
7
|
|
|
|
|
|
|
our $timezone = _current_timezone(); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
12
|
|
|
|
|
|
|
timezone next_longitude_date longitude |
13
|
|
|
|
|
|
|
) ] ); |
14
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub timezone { |
17
|
0
|
|
|
0
|
0
|
0
|
my $longitude = shift; |
18
|
0
|
|
|
|
|
0
|
$longitude / 180 * 12 * 60; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my @data = ( |
22
|
|
|
|
|
|
|
[403406, 4.721964, 1.621043], |
23
|
|
|
|
|
|
|
[195207, 5.937458, 62830.348067], |
24
|
|
|
|
|
|
|
[119433, 1.115589, 62830.821524], |
25
|
|
|
|
|
|
|
[112392, 5.781616, 62829.634302], |
26
|
|
|
|
|
|
|
[3891, 5.5474, 125660.5691], |
27
|
|
|
|
|
|
|
[2819, 1.5120, 125660.984], |
28
|
|
|
|
|
|
|
[1721, 4.1897, 62832.4766], |
29
|
|
|
|
|
|
|
[0, 1.163, 0.813], |
30
|
|
|
|
|
|
|
[660, 5.415, 125659.31], |
31
|
|
|
|
|
|
|
[350, 4.315, 57533.85], |
32
|
|
|
|
|
|
|
[334, 4.553, -33.931], |
33
|
|
|
|
|
|
|
[314, 5.198, 777137.715], |
34
|
|
|
|
|
|
|
[268, 5.989, 78604.191], |
35
|
|
|
|
|
|
|
[242, 2.911, 5.412], |
36
|
|
|
|
|
|
|
[234, 1.423, 39302.098], |
37
|
|
|
|
|
|
|
[158, 0.061, -34.861], |
38
|
|
|
|
|
|
|
[132, 2.317, 115067.698], |
39
|
|
|
|
|
|
|
[129, 3.193, 15774.337], |
40
|
|
|
|
|
|
|
[114, 2.828, 5296.670], |
41
|
|
|
|
|
|
|
[99, 0.52, 58849.27], |
42
|
|
|
|
|
|
|
[93, 4.65, 5296.11], |
43
|
|
|
|
|
|
|
[86, 4.35, -3980.70], |
44
|
|
|
|
|
|
|
[78, 2.75, 52237.69], |
45
|
|
|
|
|
|
|
[72, 4.50, 55076.47], |
46
|
|
|
|
|
|
|
[68, 3.23, 261.08], |
47
|
|
|
|
|
|
|
[64, 1.22, 15773.85], |
48
|
|
|
|
|
|
|
[46, 0.14, 188491.03], |
49
|
|
|
|
|
|
|
[38, 3.44, -7756.55], |
50
|
|
|
|
|
|
|
[37, 4.37, 264.89], |
51
|
|
|
|
|
|
|
[32, 1.14, 117906.27], |
52
|
|
|
|
|
|
|
[29, 2.84, 55075.75], |
53
|
|
|
|
|
|
|
[28, 5.96, -7961.39], |
54
|
|
|
|
|
|
|
[27, 5.09, 188489.81], |
55
|
|
|
|
|
|
|
[27, 1.72, 2132.19], |
56
|
|
|
|
|
|
|
[25, 2.56, 109771.03], |
57
|
|
|
|
|
|
|
[24, 1.92, 54868.56], |
58
|
|
|
|
|
|
|
[21, 0.09, 25443.93], |
59
|
|
|
|
|
|
|
[21, 5.98, -55731.43], |
60
|
|
|
|
|
|
|
[20, 4.03, 60697.74], |
61
|
|
|
|
|
|
|
[18, 4.47, 2132.79], |
62
|
|
|
|
|
|
|
[17, 0.79, 109771.63], |
63
|
|
|
|
|
|
|
[14, 4.24, -7752.82], |
64
|
|
|
|
|
|
|
[13, 2.01, 188491.91], |
65
|
|
|
|
|
|
|
[13, 2.65, 207.81], |
66
|
|
|
|
|
|
|
[13, 4.98, 29424.63], |
67
|
|
|
|
|
|
|
[12, 0.93, -7.99], |
68
|
|
|
|
|
|
|
[10, 2.21, 46941.14], |
69
|
|
|
|
|
|
|
[10, 3.59, -68.29], |
70
|
|
|
|
|
|
|
[10, 1.50, 21463.25], |
71
|
|
|
|
|
|
|
[10, 2.55, 157208.40] |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#========================================================== |
75
|
|
|
|
|
|
|
# Input : Calendar object or absolute date, the degrees L, timezone |
76
|
|
|
|
|
|
|
# Output : The next *absolute date* that sun's longitude |
77
|
|
|
|
|
|
|
# is a multiple of L degrees at that timezone |
78
|
|
|
|
|
|
|
# Desc : timezone default is $timezone |
79
|
|
|
|
|
|
|
#========================================================== |
80
|
|
|
|
|
|
|
sub next_longitude_date { |
81
|
1
|
|
|
1
|
0
|
8
|
my ($d, $l, $tz) = @_; |
82
|
1
|
50
|
|
|
|
4
|
if ( ref $d ) { |
83
|
1
|
|
|
|
|
3
|
$d = $d->absolute_date; |
84
|
|
|
|
|
|
|
} |
85
|
1
|
|
|
|
|
2
|
my $long; |
86
|
1
|
|
|
|
|
3
|
my $start = $d; |
87
|
1
|
|
|
|
|
4
|
my $start_long = longitude($d, $tz); |
88
|
1
|
|
|
|
|
4
|
my $next = (int($start_long/$l) + 1) * $l % 360; |
89
|
1
|
|
|
|
|
3
|
my $end = $d + $l/360*400; |
90
|
1
|
|
|
|
|
2
|
my $end_long = longitude($end); |
91
|
1
|
|
|
|
|
6
|
while ( $end-$start > 0.00001 ) { |
92
|
22
|
|
|
|
|
29
|
$d = ($start + $end)/2; |
93
|
22
|
|
|
|
|
35
|
$long = longitude($d); |
94
|
22
|
100
|
66
|
|
|
176
|
if ( (($next != 0) && ($long < $next)) |
|
|
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
95
|
|
|
|
|
|
|
|| (($next==0) && ($l < $long)) ) { |
96
|
8
|
|
|
|
|
10
|
$start = $d; |
97
|
8
|
|
|
|
|
17
|
$start_long = $long; |
98
|
|
|
|
|
|
|
} else { |
99
|
14
|
|
|
|
|
17
|
$end = $d; |
100
|
14
|
|
|
|
|
34
|
$end_long = $long; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
1
|
|
|
|
|
8
|
return ($start+$end)/2; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#========================================================== |
107
|
|
|
|
|
|
|
# Input : Calendar object or absolute date, timezone |
108
|
|
|
|
|
|
|
# Output : The sun's longitude of the date at that timezone |
109
|
|
|
|
|
|
|
# Desc : To simplified convertion, use absolute date instead |
110
|
|
|
|
|
|
|
# of astronomical date |
111
|
|
|
|
|
|
|
#========================================================== |
112
|
|
|
|
|
|
|
sub longitude { |
113
|
24
|
|
|
24
|
0
|
32
|
my $date = shift; |
114
|
24
|
|
|
|
|
30
|
my $tz = shift; |
115
|
24
|
50
|
|
|
|
48
|
defined($tz) || ($tz = $timezone); |
116
|
|
|
|
|
|
|
# TODO: daylight time offset |
117
|
24
|
50
|
|
|
|
124
|
$date = Calendar::Any::Gregorian->new((ref $date ? $date->absolute_date : $date) - $tz/60/24); |
118
|
24
|
|
|
|
|
86
|
$date = $date->astro_date + _ephemeris_correction($date->year); |
119
|
24
|
|
|
|
|
81
|
my $U = ($date - 2451545)/3652500; |
120
|
24
|
|
|
|
|
27
|
my $longitude = 0; |
121
|
24
|
|
|
|
|
44
|
foreach ( @data ) { |
122
|
1200
|
|
|
|
|
2157
|
$longitude += $_->[0] * sin($_->[1]+$U*$_->[2]); |
123
|
|
|
|
|
|
|
} |
124
|
24
|
|
|
|
|
44
|
$longitude = 4.9353929 + 62833.1961680 * $U + 0.0000001 * $longitude; |
125
|
24
|
|
|
|
|
65
|
my $aberration = 0.0000001 *(17 * cos(3.10 + 62830.14 *$U) - 973); |
126
|
24
|
|
|
|
|
57
|
my $nutation = -0.0000001* (834 * sin(2.19+$U*(0.36*$U - 3375.70)) + 64 * sin(3.51+ $U*(125666.39 + 0.10*$U))); |
127
|
24
|
|
|
|
|
81
|
return _mod(rad2deg($longitude + $aberration + $nutation), 360); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _mod { |
131
|
24
|
|
|
24
|
|
201
|
my ($num, $base) = @_; |
132
|
24
|
|
|
|
|
32
|
$num = $num - int($num/$base)*$base; |
133
|
24
|
50
|
|
|
|
72
|
return $num*$base < 0 ? $num+$base : $num; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _ephemeris_correction { |
137
|
30
|
|
|
30
|
|
35
|
my $year = shift; |
138
|
30
|
50
|
33
|
|
|
131
|
if ( $year > 1988 && $year < 2020 ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
139
|
30
|
|
|
|
|
101
|
($year-2000+67)/60/60/24; |
140
|
|
|
|
|
|
|
} elsif ( $year>1900 && $year < 1988 ) { |
141
|
0
|
|
|
|
|
0
|
my $theta = (Calendar::Any::Gregorian->new(7, 1, $year)->astro_date - |
142
|
|
|
|
|
|
|
Calendar::Any::Gregorian->new(1, 1, 1900)->astro_date)/36525; |
143
|
0
|
|
|
|
|
0
|
my $theta2 = $theta * $theta; |
144
|
0
|
|
|
|
|
0
|
my $theta3 = $theta2 * $theta; |
145
|
0
|
|
|
|
|
0
|
my $theta4 = $theta2 * $theta2; |
146
|
0
|
|
|
|
|
0
|
return -0.00002 + 0.000297 * $theta + 0.025184 * $theta2 - 0.181133 * $theta3 + 0.553040 * $theta4 |
147
|
|
|
|
|
|
|
-0.861938 * $theta2 * $theta3 + 0.677066 * $theta3 * $theta3 |
148
|
|
|
|
|
|
|
- 0.212591 * $theta3 * $theta4; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
elsif ( $year>1800 && $year<1900 ) { |
151
|
0
|
|
|
|
|
0
|
my $theta = (Calendar::Any::Gregorian->new(7, 1, $year)->astro_date - |
152
|
|
|
|
|
|
|
Calendar::Any::Gregorian->new(1, 1, 1900)->astro_date)/36525; |
153
|
0
|
|
|
|
|
0
|
my $theta2 = $theta * $theta; |
154
|
0
|
|
|
|
|
0
|
my $theta3 = $theta2 * $theta; |
155
|
0
|
|
|
|
|
0
|
my $theta4 = $theta2 * $theta2; |
156
|
0
|
|
|
|
|
0
|
my $theta5 = $theta3 * $theta2; |
157
|
0
|
|
|
|
|
0
|
return -0.000009 + 0.003844*$theta + 0.083563*$theta2 + 0.865736*$theta3 |
158
|
|
|
|
|
|
|
+ 4.867575*$theta4 + 15.845535*$theta5 + 31.332267*$theta3*$theta3 |
159
|
|
|
|
|
|
|
+ 38.291999*$theta4*$theta3 + 28.316289*$theta4*$theta4 |
160
|
|
|
|
|
|
|
+ 11.636204*$theta4*$theta5 + 2.043794*$theta5*$theta5; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
elsif ( $year>1620 && $year<1800 ) { |
163
|
0
|
|
|
|
|
0
|
my $x = ($year-1600)/10; |
164
|
0
|
|
|
|
|
0
|
return (2.19167 * $x*$x - 40.675*$x + 196.58333)/60/60/24; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
else { |
167
|
0
|
|
|
|
|
0
|
my $tmp = Calendar::Any::Gregorian->new(1, 1, $year)->astro_date - 2382148; |
168
|
0
|
|
|
|
|
0
|
return ($tmp * $tmp / 41048480.0 - 15)/60/60/24; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub _current_timezone { |
173
|
3
|
|
|
3
|
|
67
|
my @gmtime = gmtime(0); |
174
|
3
|
|
|
|
|
1055
|
my @localtime = localtime(0); |
175
|
3
|
|
|
|
|
14
|
my $mins = 60*$localtime[2] + $localtime[1]; |
176
|
3
|
50
|
|
|
|
73
|
return ( $localtime[5] == 70 ) ? $mins : $mins - 24*60; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
1; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
__END__ |