line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Sun::Bearing; |
2
|
2
|
|
|
2
|
|
26383
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
90
|
|
3
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
66
|
|
4
|
2
|
|
|
2
|
|
1792
|
use Geo::Inverse 0.05; #GPS::Point->distance need array context |
|
2
|
|
|
|
|
7570
|
|
|
2
|
|
|
|
|
226
|
|
5
|
2
|
|
|
2
|
|
17
|
use base qw{Geo::Sun}; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
678
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
2
|
|
|
2
|
|
12
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
74
|
|
9
|
2
|
|
|
2
|
|
931
|
$VERSION = '0.04'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Geo::Sun::Bearing - Calculates the bearing from a station on the surface of the Earth to the Sun. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Geo::Sun::Bearing; |
19
|
|
|
|
|
|
|
use GPS::Point; |
20
|
|
|
|
|
|
|
my $datetime=DateTime->now; |
21
|
|
|
|
|
|
|
my $station=GPS::Point->new(lat=>39, lon=>-77); |
22
|
|
|
|
|
|
|
my $gs=Geo::Sun::Bearing->new->set_datetime($datetime)->set_station($station); |
23
|
|
|
|
|
|
|
printf "Bearing from Station to Sun is %s\n", $gs->bearing; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
The Geo::Sun::Bearing is a L object. This package calculates the bearing from a station on the surface of the Earth to the point where the Sun is directly over at the given time. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 USAGE |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Geo::Sun::Bearing; |
32
|
|
|
|
|
|
|
my $gs=Geo::Sun::Bearing->new; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 new |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $gs=Geo::Sun::Bearing->new; #Inherited from Geo::Sun |
39
|
|
|
|
|
|
|
my $gs=Geo::Sun::Bearing->new(datetime=>$dt, station=>$station); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub initialize2 { |
44
|
2
|
|
|
2
|
0
|
3
|
my $self=shift; |
45
|
2
|
100
|
|
|
|
4
|
$self->bearing_recalculate if defined $self->station; |
46
|
2
|
|
|
|
|
8
|
$self->initialize3; #a hook if you need it |
47
|
2
|
|
|
|
|
4
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub initialize3 { |
51
|
2
|
|
|
2
|
0
|
3
|
my $self=shift; |
52
|
2
|
|
|
|
|
4
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 METHODS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Many methods are inherited from L. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 bearing |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Returns the bearing from the station to the Sun. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub bearing { |
66
|
2
|
|
|
2
|
1
|
4
|
my $self=shift; |
67
|
2
|
|
|
|
|
8
|
return $self->{'bearing'}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 bearing_dt_pt |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Returns bearing given a datetime and a station point. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $bearing=$gs->bearing_dt_pt($datetime, $station); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Implemented as |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $bearing=$gs->set_datetime($datetime)->set_station($station)->bearing; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub bearing_dt_pt { |
83
|
0
|
|
|
0
|
1
|
0
|
my $self=shift; |
84
|
0
|
|
|
|
|
0
|
my $datetime=shift; |
85
|
0
|
|
|
|
|
0
|
my $station=shift; |
86
|
0
|
|
|
|
|
0
|
return $self->set_datetime($datetime)->set_station($station)->bearing; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 station |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Sets or returns station. Station must be a valid point argument for L distance method. Currently, L and L. I'm planning to add {lat=>$lat, lon=>$lon} and [$lat, $lon] shortly. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub station { |
96
|
12
|
|
|
12
|
1
|
18
|
my $self=shift; |
97
|
12
|
100
|
|
|
|
31
|
if (@_) { |
98
|
1
|
|
|
|
|
3
|
$self->{"station"}=shift; |
99
|
1
|
|
|
|
|
5
|
$self->bearing_recalculate; |
100
|
|
|
|
|
|
|
} |
101
|
12
|
|
|
|
|
50
|
return $self->{"station"}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 set_station |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Sets station returns self |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub set_station { |
111
|
1
|
|
|
1
|
1
|
1035
|
my $self=shift; |
112
|
1
|
50
|
|
|
|
8
|
$self->station(@_) if @_; |
113
|
1
|
|
|
|
|
4
|
return $self; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 METHODS (INTERNAL) |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 point_onchange |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Overridden from Geo::Sun to recalculate the bearing when the point changes |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub point_onchange { |
125
|
4
|
|
|
4
|
1
|
7
|
my $self=shift; |
126
|
4
|
100
|
|
|
|
16
|
$self->bearing_recalculate if defined $self->station; |
127
|
4
|
|
|
|
|
9
|
return $self; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 bearing_recalculate |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Method which is called to recalculate the bearing when the datetime or the station is changed. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub bearing_recalculate { |
137
|
4
|
|
|
4
|
1
|
7
|
my $self=shift; |
138
|
4
|
|
|
|
|
17
|
my (undef, $baz, undef) = $self->point->distance($self->station); |
139
|
4
|
|
|
|
|
2243
|
$self->{'bearing'}=$baz; |
140
|
4
|
|
|
|
|
16
|
$self->bearing_onchange; #a hook if you need it |
141
|
4
|
|
|
|
|
6
|
return $self; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 bearing_onchange |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
In this base module this does nothing but to return the object |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Override this function if you want to calculate something when the bearing changes. By nature this hook also gets called when point_onchange is called so don't override both. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub bearing_onchange { |
153
|
4
|
|
|
4
|
1
|
6
|
my $self=shift; |
154
|
4
|
|
|
|
|
8
|
return $self; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 BUGS |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Please send to the geo-perl email list. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SUPPORT |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Try the geo-perl email list. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 LIMITATIONS |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Calculations are only good to about 3 decimal places. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 AUTHOR |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Michael R. Davis |
172
|
|
|
|
|
|
|
CPAN ID: MRDVT |
173
|
|
|
|
|
|
|
STOP, LLC |
174
|
|
|
|
|
|
|
domain=>stopllc,tld=>com,account=>mdavis |
175
|
|
|
|
|
|
|
http://www.stopllc.com/ |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 COPYRIGHT |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This program is free software licensed under the... |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
The BSD License |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
The full text of the license can be found in the |
184
|
|
|
|
|
|
|
LICENSE file included with this module. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 SEE ALSO |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
1; |