gpst: Removing --near option. Things like that happen in the database.
[gpstools.git] / gpsman2gpx
blob41423e688cace4b1fbcfdc83a16da92c9fb2ae4f
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # gpsman2gpx
5 # File ID: f66b9fe8-f923-11dd-a087-0001805bf4b1
6 # Quick & dirty script for converting gpsman(1) sdata files to GPX.
8 # Character set: UTF-8
9 # ©opyleft 2006– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 3 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 BEGIN {
15 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
18 use strict;
19 use Getopt::Long;
21 use GPSTxml;
23 $| = 1;
25 our $Debug = 0;
27 our %Opt = (
29 'debug' => 0,
30 'help' => 0,
31 'quiet' => 0,
32 'verbose' => 0,
33 'version' => 0,
37 our $progname = $0;
38 $progname =~ s/^.*\/(.*?)$/$1/;
39 our $VERSION = "0.00";
41 Getopt::Long::Configure("bundling");
42 GetOptions(
44 "debug" => \$Opt{'debug'},
45 "help|h" => \$Opt{'help'},
46 "quiet|q" => \$Opt{'quiet'},
47 "verbose|v+" => \$Opt{'verbose'},
48 "version" => \$Opt{'version'},
50 ) || die("$progname: Option error. Use -h for help.\n");
52 $Opt{'debug'} && ($Debug = 1);
53 $Opt{'help'} && usage(0);
54 if ($Opt{'version'}) {
55 print_version();
56 exit(0);
59 print(<<END);
60 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
61 <gpx
62 version="1.1"
63 creator="gpsman2gpx - http://sunny256.github.com/gpstools/"
64 xmlns="http://www.topografix.com/GPX/1/1"
65 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66 xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
68 END
70 while (<>) {
71 my $Line = $_;
72 if (
73 $Line =~ /^
74 (.*?)\t # name
75 (.*?)\t # cmt
76 (.*?)\t # some kind of worthless date
77 ([NS].+?)\t # lat
78 ([WE].+?)\t # lon
79 (.*) # lots of uninteresting stuff but with altitude
82 ) {
83 my ($Name, $Cmt, $wl_date, $Lat, $Lon, $Rest) =
84 ( $1, $2, $3, $4, $5, $6);
85 my $Ele = "";
87 $Name = txt_to_xml($Name);
88 $Cmt = txt_to_xml($Cmt);
89 $Lat = conv_pos($Lat);
90 $Lon = conv_pos($Lon);
91 if ($Rest =~ /ele=([\d\.]+)\D/) {
92 $Ele = 1.0 * $1;
94 print(" <wpt lat=\"$Lat\" lon=\"$Lon\">\n");
95 print(" <ele>$Ele</ele>\n") if length($Ele);
96 print(" <name>$Name</name>\n") if length($Name);
97 print(" <cmt>$Cmt</cmt>\n") if length($Cmt);
98 print(" </wpt>\n");
102 print("</gpx>\n");
104 sub conv_pos {
105 # {{{
106 my $Retval = shift;
108 if ($Retval =~ /^([NSWE])([0-9\.]+)$/) {
109 my ($Pref, $Deg) = ($1, $2);
110 $Retval = ($Pref =~ /[SW]/)
111 ? 0-$Deg
112 : $Deg;
113 } else {
114 warn("\"$Retval\": Invalid coordinate\n") unless $Opt{'quiet'};
116 return $Retval;
117 # }}}
120 sub print_version {
121 # Print program version {{{
122 print("$progname v$VERSION\n");
123 # }}}
124 } # print_version()
126 sub usage {
127 # Send the help message to stdout {{{
128 my $Retval = shift;
130 if ($Opt{'verbose'}) {
131 print("\n");
132 print_version();
134 print(<<END);
136 Usage: $progname [options] [file [files [...]]]
138 Options:
140 -h, --help
141 Show this help.
142 -v, --verbose
143 Increase level of verbosity. Can be repeated.
144 -q, --quiet
145 Be quiet, don’t warn about unknown lines and stuff.
146 --version
147 Print version information.
148 --debug
149 Print debugging messages.
152 exit($Retval);
153 # }}}
154 } # usage()
156 sub msg {
157 # Print a status message to stderr based on verbosity level {{{
158 my ($verbose_level, $Txt) = @_;
160 if ($Opt{'verbose'} >= $verbose_level) {
161 print(STDERR "$progname: $Txt\n");
163 # }}}
164 } # msg()
166 sub D {
167 # Print a debugging message {{{
168 $Debug || return;
169 my @call_info = caller;
170 chomp(my $Txt = shift);
171 my $File = $call_info[1];
172 $File =~ s#\\#/#g;
173 $File =~ s#^.*/(.*?)$#$1#;
174 print(STDERR "$File:$call_info[2] $$ $Txt\n");
175 return("");
176 # }}}
177 } # D()
179 __END__
181 # Plain Old Documentation (POD) {{{
183 =pod
185 =head1 NAME
189 =head1 SYNOPSIS
191 [options] [file [files [...]]]
193 =head1 DESCRIPTION
197 =head1 OPTIONS
199 =over 4
201 =item B<-h>, B<--help>
203 Print a brief help summary.
205 =item B<-v>, B<--verbose>
207 Increase level of verbosity. Can be repeated.
209 =item B<--version>
211 Print version information.
213 =item B<--debug>
215 Print debugging messages.
217 =back
219 =head1 BUGS
223 =head1 AUTHOR
225 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
227 =head1 COPYRIGHT
229 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
230 This is free software; see the file F<COPYING> for legalese stuff.
232 =head1 LICENCE
234 This program is free software: you can redistribute it and/or modify it
235 under the terms of the GNU General Public License as published by the
236 Free Software Foundation, either version 3 of the License, or (at your
237 option) any later version.
239 This program is distributed in the hope that it will be useful, but
240 WITHOUT ANY WARRANTY; without even the implied warranty of
241 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
242 See the GNU General Public License for more details.
244 You should have received a copy of the GNU General Public License along
245 with this program.
246 If not, see L<http://www.gnu.org/licenses/>.
248 =head1 SEE ALSO
250 =cut
252 # }}}
254 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :