* /trunk/src/gpstools/postgres/Patch/track-id.patch
[gpstools.git] / gpsman2gpx
blob7a3df7f4f164e7b9dca82021b0171d89414255d1
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # $Id$
5 # Quick & dirty script for converting gpsman(1) sdata files to GPX.
7 # Character set: UTF-8
8 # ©opyleft 2006– Øyvind A. Holm <sunny@sunbase.org>
9 # License: GNU General Public License version 2 or later, see end of
10 # file for legal stuff.
11 #=======================================================================
13 BEGIN {
14 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
17 BEGIN {
18 our @version_array;
21 use strict;
22 use Getopt::Long;
24 use GPSTxml;
26 $| = 1;
28 our $Debug = 0;
30 our %Opt = (
32 'debug' => 0,
33 'help' => 0,
34 'verbose' => 0,
35 'version' => 0,
39 our $progname = $0;
40 $progname =~ s/^.*\/(.*?)$/$1/;
42 my $rcs_id = '$Id$';
43 my $id_date = $rcs_id;
44 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
46 push(@main::version_array, $rcs_id);
48 Getopt::Long::Configure("bundling");
49 GetOptions(
51 "debug" => \$Opt{'debug'},
52 "help|h" => \$Opt{'help'},
53 "verbose|v+" => \$Opt{'verbose'},
54 "version" => \$Opt{'version'},
56 ) || die("$progname: Option error. Use -h for help.\n");
58 $Opt{'debug'} && ($Debug = 1);
59 $Opt{'help'} && usage(0);
60 if ($Opt{'version'}) {
61 print_version();
62 exit(0);
65 print(<<END);
66 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
67 <gpx
68 version="1.1"
69 creator="gpsman2gpx - http://svn.sunbase.org/repos/utils/trunk/src/gpstools/gpsman2gpx"
70 xmlns="http://www.topografix.com/GPX/1/1"
71 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
72 xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
74 <!-- \$Id\$ -->
75 END
77 while (<>) {
78 my $Line = $_;
79 if (
80 $Line =~ /^
81 (.*?)\t # name
82 (.*?)\t # cmt
83 (.*?)\t # some kind of worthless date
84 ([NS].+?)\t # lat
85 ([WE].+?)\t # lon
86 (.*) # lots of uninteresting stuff but with altitude
89 ) {
90 my ($Name, $Cmt, $wl_date, $Lat, $Lon, $Rest) =
91 ( $1, $2, $3, $4, $5, $6);
92 my $Ele = "";
94 $Name = txt_to_xml($Name);
95 $Cmt = txt_to_xml($Cmt);
96 $Lat = conv_pos($Lat);
97 $Lon = conv_pos($Lon);
98 if ($Rest =~ /ele=([\d\.]+)\D/) {
99 $Ele = 1.0 * $1;
101 print(" <wpt lat=\"$Lat\" lon=\"$Lon\">\n");
102 print(" <ele>$Ele</ele>\n") if length($Ele);
103 print(" <name>$Name</name>\n") if length($Name);
104 print(" <cmt>$Cmt</cmt>\n") if length($Cmt);
105 print(" </wpt>\n");
109 print("</gpx>\n");
111 sub conv_pos {
112 # {{{
113 my $Retval = shift;
115 if ($Retval =~ /^([NSWE])([0-9\.]+)$/) {
116 my ($Pref, $Deg) = ($1, $2);
117 $Retval = ($Pref =~ /[SW]/)
118 ? 0-$Deg
119 : $Deg;
120 } else {
121 warn("\"$Retval\": Invalid coordinate\n");
123 return $Retval;
124 # }}}
127 sub print_version {
128 # Print program version {{{
129 for (@main::version_array) {
130 print("$_\n");
132 # }}}
133 } # print_version()
135 sub usage {
136 # Send the help message to stdout {{{
137 my $Retval = shift;
139 if ($Opt{'verbose'}) {
140 print("\n");
141 print_version();
143 print(<<END);
145 Usage: $progname [options] [file [files [...]]]
147 Options:
149 -h, --help
150 Show this help.
151 -v, --verbose
152 Increase level of verbosity. Can be repeated.
153 --version
154 Print version information.
155 --debug
156 Print debugging messages.
159 exit($Retval);
160 # }}}
161 } # usage()
163 sub msg {
164 # Print a status message to stderr based on verbosity level {{{
165 my ($verbose_level, $Txt) = @_;
167 if ($Opt{'verbose'} >= $verbose_level) {
168 print(STDERR "$progname: $Txt\n");
170 # }}}
171 } # msg()
173 sub D {
174 # Print a debugging message {{{
175 $Debug || return;
176 my @call_info = caller;
177 chomp(my $Txt = shift);
178 my $File = $call_info[1];
179 $File =~ s#\\#/#g;
180 $File =~ s#^.*/(.*?)$#$1#;
181 print(STDERR "$File:$call_info[2] $$ $Txt\n");
182 return("");
183 # }}}
184 } # D()
186 __END__
188 # Plain Old Documentation (POD) {{{
190 =pod
192 =head1 NAME
196 =head1 REVISION
198 $Id$
200 =head1 SYNOPSIS
202 [options] [file [files [...]]]
204 =head1 DESCRIPTION
208 =head1 OPTIONS
210 =over 4
212 =item B<-h>, B<--help>
214 Print a brief help summary.
216 =item B<-v>, B<--verbose>
218 Increase level of verbosity. Can be repeated.
220 =item B<--version>
222 Print version information.
224 =item B<--debug>
226 Print debugging messages.
228 =back
230 =head1 BUGS
234 =head1 AUTHOR
236 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
238 =head1 COPYRIGHT
240 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
241 This is free software; see the file F<COPYING> for legalese stuff.
243 =head1 LICENCE
245 This program is free software; you can redistribute it and/or modify it
246 under the terms of the GNU General Public License as published by the
247 Free Software Foundation; either version 2 of the License, or (at your
248 option) any later version.
250 This program is distributed in the hope that it will be useful, but
251 WITHOUT ANY WARRANTY; without even the implied warranty of
252 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
253 See the GNU General Public License for more details.
255 You should have received a copy of the GNU General Public License along
256 with this program; if not, write to the Free Software Foundation, Inc.,
257 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
259 =head1 SEE ALSO
261 =cut
263 # }}}
265 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
266 # End of file $Id$