Removing all log/ directories under tests/
[gpstools.git] / GPSTgeo.pm
blobbb683c6759e3ca90abca7502e667af7c321a5961
1 package GPSTgeo;
3 #=======================================================================
4 # GPSTgeo.pm
5 # File ID: 6ac1a50e-fafa-11dd-a267-000475e441b9
7 # Character set: UTF-8
8 # ©opyleft 2002– Øyvind A. Holm <sunny@sunbase.org>
9 # License: GNU General Public License, see end of file for legal stuff.
10 #=======================================================================
12 use strict;
13 use warnings;
15 BEGIN {
16 use Exporter ();
17 our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
19 @ISA = qw(Exporter);
20 @EXPORT = qw(&list_nearest_waypoints &ddd_to_dms);
21 %EXPORT_TAGS = ();
23 our @EXPORT_OK;
25 sub list_nearest_waypoints {
26 # {{{
27 my ($Lat, $Lon, $Count) = @_;
29 # FIXME: Hardcoding
30 my $waypoint_file = "/home/sunny/gps/waypoints.gpx";
32 # FIXME: Incredible unfinished and kludgy.
33 if (open(WaypFP, "$main::Cmd{'gpsbabel'} -i gpx -f $waypoint_file " .
34 "-x radius,lat=$Lat,lon=$Lon,distance=1000 " .
35 "-o gpx -F - |")
36 ) {
37 my $Str = join("", <WaypFP>);
38 $Str =~ s{
39 ^.*?<wpt\s.*?>.*?<name>(.+?)</name>.*?</wpt>.*?
40 .*?<wpt\s.*?>.*?<name>(.+?)</name>.*?</wpt>.*?
41 .*?<wpt\s.*?>.*?<name>(.+?)</name>.*?</wpt>.*$
43 "($1, $2, $3)";
44 }sex;
45 return($Str);
46 } else {
47 die("$main::progname: Cannot open $main::Cmd{'gpsbabel'} pipe: $!\n");
49 # }}}
52 sub ddd_to_dms {
53 # Convert floating-point degrees into D°M'S.S" (ISO-8859-1).
54 # Necessary for import into GPSman. Based on toDMS() from
55 # gpstrans-0.39 to ensure compatibility.
56 # {{{
57 my $ddd = shift;
58 my $Neg = 0;
59 my ($Hour, $Min, $Sec) =
60 ( 0, 0, 0);
61 my $Retval = "";
63 ($ddd =~ /^\-?(\d*)(\.\d+)?$/) || return(undef);
64 length($ddd) || ($ddd = 0);
66 if ($ddd < 0.0) {
67 $ddd = 0 - $ddd;
68 $Neg = 1;
70 $Hour = int($ddd);
71 $ddd = ($ddd - $Hour) * 60.0;
72 $Min = int($ddd);
73 $Sec = ($ddd - $Min) * 60.0;
75 if ($Sec > 59.5) {
76 $Sec = 0.0;
77 $Min += 1.0;
79 if ($Min > 59.5) {
80 $Min = 0.0;
81 $Hour += 1.0;
83 $Retval = sprintf("%s%.0f\xB0%02.0f'%04.1f\"",
84 $Neg
85 ? "-"
86 : "",
87 $Hour, $Min, $Sec);
88 return $Retval;
89 # }}}