| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
require Exporter; |
|
2
|
|
|
|
|
|
|
package Geo::Functions; |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Geo::Functions - Package for standard Geo:: functions. |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Geo::Functions qw{deg_rad deg_dms rad_deg}; #import into namespace |
|
11
|
|
|
|
|
|
|
print "Degrees: ", deg_rad(3.14/4), "\n"; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Geo::Functions; |
|
14
|
|
|
|
|
|
|
my $obj = Geo::Functions->new; |
|
15
|
|
|
|
|
|
|
print "Degrees: ", $obj->deg_rad(3.14/2), "\n"; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 CONVENTIONS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Function naming convention is "format of the return" underscore "format of the parameters." For example, you can read the deg_rad function as "degrees given radians" or "degrees from radians". |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
36719
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
48
|
|
|
26
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION $PACKAGE @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1120
|
|
|
27
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
28
|
|
|
|
|
|
|
@EXPORT_OK = (qw{deg_rad rad_deg deg_dms rad_dms dms_deg dm_deg round mps_knots knots_mps}); |
|
29
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q{Revision: 0.07} =~ /(\d+)\.(\d+)/); |
|
30
|
1
|
|
|
1
|
|
36976
|
use Geo::Constants qw{RAD DEG KNOTS}; |
|
|
1
|
|
|
|
|
643
|
|
|
|
1
|
|
|
|
|
885
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 new |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
The new() constructor |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $obj = Geo::Functions->new(); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
|
43
|
1
|
|
|
1
|
1
|
732
|
my $this = shift(); |
|
44
|
1
|
|
33
|
|
|
10
|
my $class = ref($this) || $this; |
|
45
|
1
|
|
|
|
|
2
|
my $self = {}; |
|
46
|
1
|
|
|
|
|
3
|
bless $self, $class; |
|
47
|
1
|
|
|
|
|
6
|
$self->initialize(@_); |
|
48
|
1
|
|
|
|
|
4
|
return $self; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 METHODS |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub initialize { |
|
56
|
1
|
|
|
1
|
0
|
2
|
my $self = shift(); |
|
57
|
1
|
|
|
|
|
2
|
my $param = shift(); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 deg_dms |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Degrees given degrees minutes seconds. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $deg=deg_dms(39, 29, 17.134); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $deg=deg_dms(39, 29, 17.134, 'N'); |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub deg_dms { |
|
71
|
615
|
|
|
615
|
1
|
235087
|
my $self=shift(); |
|
72
|
615
|
100
|
50
|
|
|
1400
|
my $d=ref($self) ? shift()||0 : $self; |
|
73
|
615
|
|
100
|
|
|
1648
|
my $m=shift()||0; |
|
74
|
615
|
|
50
|
|
|
1107
|
my $s=shift()||0; |
|
75
|
615
|
|
100
|
|
|
1208
|
my $nsew=shift()||'N'; |
|
76
|
615
|
100
|
|
|
|
1787
|
my $sign = ($nsew=~m/[SW-]/i) ? -1 : 1; #matches "-" to support -1 |
|
77
|
615
|
|
|
|
|
2348
|
return $sign * ($d + ($m + $s/60)/60); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 deg_rad |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Degrees given radians. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $deg=deg_rad(3.14); |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub deg_rad { |
|
89
|
2
|
|
|
2
|
1
|
451
|
my $self=shift(); |
|
90
|
2
|
100
|
|
|
|
9
|
my $rad=ref($self) ? shift() : $self; |
|
91
|
2
|
|
|
|
|
12
|
return $rad*DEG(); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 rad_deg |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Radians given degrees. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $rad=rad_deg(90); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub rad_deg { |
|
103
|
9
|
|
|
9
|
1
|
375
|
my $self=shift(); |
|
104
|
9
|
100
|
|
|
|
22
|
my $deg=ref($self) ? shift() : $self; |
|
105
|
9
|
|
|
|
|
23
|
return $deg*RAD(); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 rad_dms |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Radians given degrees minutes seconds. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $rad=rad_dms(45 30 20.0); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub rad_dms { |
|
117
|
2
|
|
|
2
|
1
|
8
|
return rad_deg(deg_dms(@_)); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 round |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Round to the nearest integer. This formula rounds toward +/- infinity. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $int=round(42.2); |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub round { |
|
129
|
8
|
|
|
8
|
1
|
264
|
my $self=shift(); |
|
130
|
8
|
100
|
|
|
|
20
|
my $number=ref($self) ? shift() : $self; |
|
131
|
8
|
|
|
|
|
43
|
return int($number + 0.5 * ($number <=> 0)); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 dms_deg |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Degrees minutes seconds given degrees. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my ($d, $m, $s, $sign)=dms_deg($degrees, qw{N S}); |
|
139
|
|
|
|
|
|
|
my ($d, $m, $s, $sign)=dms_deg($degrees, qw{E W}); |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub dms_deg { |
|
144
|
400
|
|
|
400
|
1
|
520
|
my $self=shift(); |
|
145
|
400
|
50
|
|
|
|
796
|
my $number=ref($self) ? shift() : $self; |
|
146
|
400
|
|
|
|
|
868
|
my @sign=@_; |
|
147
|
400
|
100
|
50
|
|
|
1719
|
my $sign=$number >= 0 ? $sign[0]||1 : $sign[1]||-1; |
|
|
|
|
50
|
|
|
|
|
|
148
|
400
|
|
|
|
|
673
|
$number=abs($number); |
|
149
|
400
|
|
|
|
|
535
|
my $d=int($number); |
|
150
|
400
|
|
|
|
|
666
|
my $m=int(($number-$d) * 60); |
|
151
|
400
|
|
|
|
|
667
|
my $s=((($number-$d) * 60) - $m) * 60; |
|
152
|
400
|
|
|
|
|
1333
|
my @dms=($d, $m, $s, $sign); |
|
153
|
400
|
50
|
|
|
|
5962
|
return wantarray ? @dms : join(" ", @dms); |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 dm_deg |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Degrees minutes given degrees. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my ($d, $m, $sign)=dm_deg($degrees, qw{N S}); |
|
161
|
|
|
|
|
|
|
my ($d, $m, $sign)=dm_deg($degrees, qw{E W}); |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub dm_deg { |
|
166
|
200
|
|
|
200
|
1
|
248
|
my $self=shift(); |
|
167
|
200
|
50
|
|
|
|
317
|
my $number=ref($self) ? shift() : $self; |
|
168
|
200
|
|
|
|
|
976
|
my @sign=@_; |
|
169
|
200
|
100
|
50
|
|
|
600
|
my $sign=$number >= 0 ? $sign[0]||1 : $sign[1]||-1; |
|
|
|
|
50
|
|
|
|
|
|
170
|
200
|
|
|
|
|
228
|
$number=abs($number); |
|
171
|
200
|
|
|
|
|
248
|
my $d=int($number); |
|
172
|
200
|
|
|
|
|
317
|
my $m=($number-$d) * 60; |
|
173
|
200
|
|
|
|
|
358
|
my @dm=($d, $m, $sign); |
|
174
|
200
|
50
|
|
|
|
752
|
return wantarray ? @dm : join(" ", @dm); |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 mps_knots |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
meters per second given knots |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
my $mps=mps_knots(50.0); |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub mps_knots { |
|
186
|
8
|
|
|
8
|
1
|
98
|
my $self=shift(); |
|
187
|
8
|
100
|
|
|
|
19
|
my $number=ref($self) ? shift() : $self; |
|
188
|
8
|
|
|
|
|
17
|
return $number * KNOTS(); |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 knots_mps |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
knots given meters per second |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
my $knots=knots_mps(25.0); |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub knots_mps { |
|
200
|
8
|
|
|
8
|
1
|
884
|
my $self=shift(); |
|
201
|
8
|
100
|
|
|
|
19
|
my $number=ref($self) ? shift() : $self; |
|
202
|
8
|
|
|
|
|
25
|
return $number / KNOTS(); |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
__END__ |