line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Functions; |
2
|
1
|
|
|
1
|
|
7732
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw(@ISA @EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
5
|
|
|
|
|
|
|
require Exporter; |
6
|
1
|
|
|
1
|
|
447
|
use Geo::Constants qw{RAD DEG KNOTS}; |
|
1
|
|
|
|
|
354
|
|
|
1
|
|
|
|
|
730
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
@EXPORT_OK = (qw{deg_rad rad_deg deg_dms rad_dms dms_deg dm_deg round mps_knots knots_mps}); |
10
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Geo::Functions - Package for standard Geo:: functions. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Geo::Functions qw{deg_rad deg_dms rad_deg}; #import into namespace |
19
|
|
|
|
|
|
|
print "Degrees: ", deg_rad(3.14/4), "\n"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Geo::Functions; |
22
|
|
|
|
|
|
|
my $obj = Geo::Functions->new; |
23
|
|
|
|
|
|
|
print "Degrees: ", $obj->deg_rad(3.14/2), "\n"; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Package for standard Geo:: functions. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 CONVENTIONS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
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". |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The new() constructor |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $obj = Geo::Functions->new(); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
44
|
1
|
|
|
1
|
1
|
126
|
my $this = shift(); |
45
|
1
|
|
33
|
|
|
8
|
my $class = ref($this) || $this; |
46
|
1
|
|
|
|
|
2
|
my $self = {}; |
47
|
1
|
|
|
|
|
2
|
bless $self, $class; |
48
|
1
|
|
|
|
|
4
|
$self->initialize(@_); |
49
|
1
|
|
|
|
|
3
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 METHODS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 initialize |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub initialize { |
59
|
1
|
|
|
1
|
1
|
1
|
my $self = shift(); |
60
|
1
|
|
|
|
|
6
|
%$self = @_; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 deg_dms |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Degrees given degrees minutes seconds. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $deg = deg_dms(39, 29, 17.134); |
68
|
|
|
|
|
|
|
my $deg = deg_dms(39, 29, 17.134, 'N'); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub deg_dms { |
73
|
615
|
|
|
615
|
1
|
95842
|
my $self = shift(); |
74
|
615
|
100
|
50
|
|
|
953
|
my $d = ref($self) ? shift()||0 : $self; |
75
|
615
|
|
100
|
|
|
1128
|
my $m = shift()||0; |
76
|
615
|
|
50
|
|
|
848
|
my $s = shift()||0; |
77
|
615
|
|
100
|
|
|
900
|
my $nsew = shift()||'N'; |
78
|
615
|
100
|
|
|
|
1417
|
my $sign = ($nsew=~m/[SW-]/i) ? -1 : 1; #matches "-" to support -1 |
79
|
615
|
|
|
|
|
1620
|
return $sign * ($d + ($m + $s/60)/60); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 deg_rad |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Degrees given radians. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $deg = deg_rad(3.14); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub deg_rad { |
91
|
2
|
|
|
2
|
1
|
115
|
my $self = shift(); |
92
|
2
|
100
|
|
|
|
6
|
my $rad = ref($self) ? shift() : $self; |
93
|
2
|
|
|
|
|
5
|
return $rad*DEG(); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 rad_deg |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Radians given degrees. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $rad = rad_deg(90); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub rad_deg { |
105
|
9
|
|
|
9
|
1
|
241
|
my $self = shift(); |
106
|
9
|
100
|
|
|
|
18
|
my $deg = ref($self) ? shift() : $self; |
107
|
9
|
|
|
|
|
16
|
return $deg*RAD(); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 rad_dms |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Radians given degrees minutes seconds. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $rad = rad_dms(45 30 20.0); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub rad_dms { |
119
|
2
|
|
|
2
|
1
|
5
|
return rad_deg(deg_dms(@_)); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 round |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Round to the nearest integer. This formula rounds toward +/- infinity. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $int = round(42.2); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub round { |
131
|
8
|
|
|
8
|
1
|
139
|
my $self = shift(); |
132
|
8
|
100
|
|
|
|
16
|
my $number = ref($self) ? shift() : $self; |
133
|
8
|
|
|
|
|
36
|
return int($number + 0.5 * ($number <=> 0)); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 dms_deg |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Degrees minutes seconds given degrees. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my ($d, $m, $s, $sign) = dms_deg($degrees, qw{N S}); |
141
|
|
|
|
|
|
|
my ($d, $m, $s, $sign) = dms_deg($degrees, qw{E W}); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub dms_deg { |
146
|
400
|
|
|
400
|
1
|
452
|
my $self = shift(); |
147
|
400
|
50
|
|
|
|
533
|
my $number = ref($self) ? shift() : $self; |
148
|
400
|
|
|
|
|
661
|
my @sign = @_; |
149
|
400
|
100
|
50
|
|
|
809
|
my $sign = $number >= 0 ? $sign[0]||1 : $sign[1]||-1; |
|
|
|
50
|
|
|
|
|
150
|
400
|
|
|
|
|
432
|
$number = abs($number); |
151
|
400
|
|
|
|
|
479
|
my $d = int($number); |
152
|
400
|
|
|
|
|
584
|
my $m = int(($number-$d) * 60); |
153
|
400
|
|
|
|
|
507
|
my $s = ((($number-$d) * 60) - $m) * 60; |
154
|
400
|
|
|
|
|
634
|
my @dms = ($d, $m, $s, $sign); |
155
|
400
|
50
|
|
|
|
1175
|
return wantarray ? @dms : join(' ', @dms); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 dm_deg |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Degrees minutes given degrees. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
my ($d, $m, $sign) = dm_deg($degrees, qw{N S}); |
163
|
|
|
|
|
|
|
my ($d, $m, $sign) = dm_deg($degrees, qw{E W}); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub dm_deg { |
168
|
200
|
|
|
200
|
1
|
246
|
my $self = shift(); |
169
|
200
|
50
|
|
|
|
275
|
my $number = ref($self) ? shift() : $self; |
170
|
200
|
|
|
|
|
317
|
my @sign = @_; |
171
|
200
|
100
|
50
|
|
|
396
|
my $sign = $number >= 0 ? $sign[0]||1 : $sign[1]||-1; |
|
|
|
50
|
|
|
|
|
172
|
200
|
|
|
|
|
210
|
$number = abs($number); |
173
|
200
|
|
|
|
|
233
|
my $d = int($number); |
174
|
200
|
|
|
|
|
286
|
my $m = ($number-$d) * 60; |
175
|
200
|
|
|
|
|
267
|
my @dm = ($d, $m, $sign); |
176
|
200
|
50
|
|
|
|
498
|
return wantarray ? @dm : join(' ', @dm); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 mps_knots |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
meters per second given knots |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
my $mps = mps_knots(50.0); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub mps_knots { |
188
|
8
|
|
|
8
|
1
|
40
|
my $self = shift(); |
189
|
8
|
100
|
|
|
|
12
|
my $number = ref($self) ? shift() : $self; |
190
|
8
|
|
|
|
|
20
|
return $number * KNOTS(); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 knots_mps |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
knots given meters per second |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
my $knots = knots_mps(25.0); |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub knots_mps { |
202
|
8
|
|
|
8
|
1
|
508
|
my $self = shift(); |
203
|
8
|
100
|
|
|
|
32
|
my $number = ref($self) ? shift() : $self; |
204
|
8
|
|
|
|
|
19
|
return $number / KNOTS(); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 BUGS |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Please log on GitHub |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 AUTHOR |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Michael R. Davis |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 LICENSE |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
MIT License |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Copyright (c) 2022 Michael R. Davis |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 SEE ALSO |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
L, L |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=cut |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1; |