gpsfold: Remove $Id$ at EOF.
[gpstools.git] / branches / gpst.gpsman-format / gpsman2gpx
blob679c444a7a0525e6d89d8171db7a30f4ef355add
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 = (
31 'debug' => 0,
32 'help' => 0,
33 'verbose' => 0,
34 'version' => 0,
37 our $progname = $0;
38 $progname =~ s/^.*\/(.*?)$/$1/;
40 my $rcs_id = '$Id$';
41 my $id_date = $rcs_id;
42 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
44 push(@main::version_array, $rcs_id);
46 Getopt::Long::Configure("bundling");
47 GetOptions(
48 "debug" => \$Opt{'debug'},
49 "help|h" => \$Opt{'help'},
50 "verbose|v+" => \$Opt{'verbose'},
51 "version" => \$Opt{'version'},
52 ) || die("$progname: Option error. Use -h for help.\n");
54 $Opt{'debug'} && ($Debug = 1);
55 $Opt{'help'} && usage(0);
56 $Opt{'version'} && print_version();
58 print(<<END);
59 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
60 <gpx
61 version="1.1"
62 creator="gpsman2gpx - http://svn.sunbase.org/repos/utils/trunk/src/gpstools/gpsman2gpx"
63 xmlns="http://www.topografix.com/GPX/1/1"
64 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
65 xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
67 <!-- \$Id\$ -->
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");
116 return $Retval;
117 # }}}
120 sub print_version {
121 # Print program version {{{
122 for (@main::version_array) {
123 print("$_\n");
125 exit(0);
126 # }}}
127 } # print_version()
129 sub usage {
130 # Send the help message to stdout {{{
131 my $Retval = shift;
133 print(<<END);
135 $rcs_id
137 Usage: $progname [options] [file [files [...]]]
139 Options:
141 -h, --help
142 Show this help.
143 -v, --verbose
144 Increase level of verbosity. Can be repeated.
145 --version
146 Print version information.
147 --debug
148 Print debugging messages.
151 exit($Retval);
152 # }}}
153 } # usage()
155 sub msg {
156 # Print a status message to stderr based on verbosity level {{{
157 my ($verbose_level, $Txt) = @_;
159 if ($Opt{'verbose'} >= $verbose_level) {
160 print(STDERR "$progname: $Txt\n");
162 # }}}
163 } # msg()
165 sub D {
166 # Print a debugging message {{{
167 $Debug || return;
168 my @call_info = caller;
169 chomp(my $Txt = shift);
170 my $File = $call_info[1];
171 $File =~ s#\\#/#g;
172 $File =~ s#^.*/(.*?)$#$1#;
173 print(STDERR "$File:$call_info[2] $$ $Txt\n");
174 return("");
175 # }}}
176 } # D()
178 __END__
180 # Plain Old Documentation (POD) {{{
182 =pod
184 =head1 NAME
188 =head1 REVISION
190 $Id$
192 =head1 SYNOPSIS
194 [options] [file [files [...]]]
196 =head1 DESCRIPTION
200 =head1 OPTIONS
202 =over 4
204 =item B<-h>, B<--help>
206 Print a brief help summary.
208 =item B<-v>, B<--verbose>
210 Increase level of verbosity. Can be repeated.
212 =item B<--version>
214 Print version information.
216 =item B<--debug>
218 Print debugging messages.
220 =back
222 =head1 BUGS
226 =head1 AUTHOR
228 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
230 =head1 COPYRIGHT
232 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
233 This is free software; see the file F<COPYING> for legalese stuff.
235 =head1 LICENCE
237 This program is free software; you can redistribute it and/or modify it
238 under the terms of the GNU General Public License as published by the
239 Free Software Foundation; either version 2 of the License, or (at your
240 option) any later version.
242 This program is distributed in the hope that it will be useful, but
243 WITHOUT ANY WARRANTY; without even the implied warranty of
244 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
245 See the GNU General Public License for more details.
247 You should have received a copy of the GNU General Public License along
248 with this program; if not, write to the Free Software Foundation, Inc.,
249 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
251 =head1 SEE ALSO
253 =cut
255 # }}}
257 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
258 # End of file $Id$