Creating top-level Makefile.
[gpstools.git] / GPSTgeo.pm
blob8c179ae538f28d58b9feef7b66c541f5c560954d
1 package GPSTgeo;
3 #=======================================================================
4 # $Id$
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 ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
19 my $rcs_id = '$Id$';
20 push(@main::version_array, $rcs_id);
21 $VERSION = ($rcs_id =~ / (\d+) /, $1);
23 @ISA = qw(Exporter);
24 @EXPORT = qw(&list_nearest_waypoints &ddd_to_dms);
25 %EXPORT_TAGS = ();
27 our @EXPORT_OK;
29 sub list_nearest_waypoints {
30 # {{{
31 my ($Lat, $Lon, $Count) = @_;
33 # FIXME: Hardcoding
34 my $waypoint_file = "/home/sunny/gps/waypoints.gpx";
36 # FIXME: Incredible unfinished and kludgy.
37 if (open(WaypFP, "$main::Cmd{'gpsbabel'} -i gpx -f $waypoint_file " .
38 "-x radius,lat=$Lat,lon=$Lon,distance=1000 " .
39 "-o gpx -F - |")
40 ) {
41 my $Str = join("", <WaypFP>);
42 $Str =~ s{
43 ^.*?<wpt\s.*?>.*?<name>(.+?)</name>.*?</wpt>.*?
44 .*?<wpt\s.*?>.*?<name>(.+?)</name>.*?</wpt>.*?
45 .*?<wpt\s.*?>.*?<name>(.+?)</name>.*?</wpt>.*$
47 "($1, $2, $3)";
48 }sex;
49 return($Str);
50 } else {
51 die("$main::progname: Cannot open $main::Cmd{'gpsbabel'} pipe: $!\n");
53 # }}}
56 sub ddd_to_dms {
57 # Convert floating-point degrees into D°M'S.S" (ISO-8859-1).
58 # Necessary for import into GPSman. Based on toDMS() from
59 # gpstrans-0.39 to ensure compatibility.
60 # {{{
61 my $ddd = shift;
62 my $Neg = 0;
63 my ($Hour, $Min, $Sec) =
64 ( 0, 0, 0);
65 my $Retval = "";
67 ($ddd =~ /^\-?(\d*)(\.\d+)?$/) || return(undef);
68 length($ddd) || ($ddd = 0);
70 if ($ddd < 0.0) {
71 $ddd = 0 - $ddd;
72 $Neg = 1;
74 $Hour = int($ddd);
75 $ddd = ($ddd - $Hour) * 60.0;
76 $Min = int($ddd);
77 $Sec = ($ddd - $Min) * 60.0;
79 if ($Sec > 59.5) {
80 $Sec = 0.0;
81 $Min += 1.0;
83 if ($Min > 59.5) {
84 $Min = 0.0;
85 $Hour += 1.0;
87 $Retval = sprintf("%s%.0f\xB0%02.0f'%04.1f\"",
88 $Neg
89 ? "-"
90 : "",
91 $Hour, $Min, $Sec);
92 return $Retval;
93 # }}}