* /trunk/src/gpstools/doc/gpst.xml
[gpstools.git] / gpsman2gpx
blobc437487bd7b3fc860a05770c5322fd88a4003d94
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, see end of file for legal stuff.
10 #=======================================================================
12 BEGIN {
13 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
16 use strict;
17 use Getopt::Long;
19 use GPSTxml;
21 $| = 1;
23 our $Debug = 0;
25 our %Opt = (
26 'debug' => 0,
27 'help' => 0,
28 'version' => 0,
31 our $progname = $0;
32 $progname =~ s#^.*/(.*?)$#$1#;
34 my $rcs_id = '$Id$';
35 my $id_date = $rcs_id;
36 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
38 Getopt::Long::Configure("bundling");
39 GetOptions(
40 "debug" => \$Opt{'debug'},
41 "help|h" => \$Opt{'help'},
42 "version" => \$Opt{'version'},
43 ) || die("$progname: Option error. Use -h for help.\n");
45 $Opt{'debug'} && ($Debug = 1);
46 $Opt{'help'} && usage(0);
47 $Opt{'version'} && print_version();
49 print(<<END);
50 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
51 <gpx
52 version="1.1"
53 creator="gpsman2gpx - http://svn.sunbase.org/repos/utils/trunk/src/gpstools/gpsman2gpx"
54 xmlns="http://www.topografix.com/GPX/1/1"
55 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
56 xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
58 <!-- \$Id\$ -->
59 END
61 while (<>) {
62 my $Line = $_;
63 if (
64 $Line =~ /^
65 (.*?)\t # name
66 (.*?)\t # cmt
67 (.*?)\t # some kind of worthless date
68 ([NS].+?)\t # lat
69 ([WE].+?)\t # lon
70 (.*) # lots of uninteresting stuff but with altitude
73 ) {
74 my ($Name, $Cmt, $wl_date, $Lat, $Lon, $Rest) =
75 ( $1, $2, $3, $4, $5, $6);
76 my $Ele = "";
78 $Name = txt_to_xml($Name);
79 $Cmt = txt_to_xml($Cmt);
80 $Lat = conv_pos($Lat);
81 $Lon = conv_pos($Lon);
82 if ($Rest =~ /ele=([\d\.]+)\D/) {
83 $Ele = 1.0 * $1;
85 print(" <wpt lat=\"$Lat\" lon=\"$Lon\">\n");
86 print(" <ele>$Ele</ele>\n") if length($Ele);
87 print(" <name>$Name</name>\n") if length($Name);
88 print(" <cmt>$Cmt</cmt>\n") if length($Cmt);
89 print(" </wpt>\n");
93 print("</gpx>\n");
95 sub conv_pos {
96 # {{{
97 my $Retval = shift;
99 if ($Retval =~ /^([NSWE])([0-9\.]+)$/) {
100 my ($Pref, $Deg) = ($1, $2);
101 $Retval = ($Pref =~ /[SW]/)
102 ? 0-$Deg
103 : $Deg;
104 } else {
105 warn("\"$Retval\": Invalid coordinate\n");
107 return $Retval;
108 # }}}
111 sub print_version {
112 # Print program version {{{
113 print("$rcs_id\n");
114 exit(0);
115 # }}}
116 } # print_version()
118 sub usage {
119 # Send the help message to stdout {{{
120 my $Retval = shift;
122 print(<<END);
124 $rcs_id
126 Usage: $progname [options] [file [files [...]]]
128 Options:
130 -h, --help
131 Show this help.
132 --version
133 Print version information.
134 --debug
135 Print debugging messages.
138 exit($Retval);
139 # }}}
140 } # usage()
142 sub D {
143 # Print a debugging message {{{
144 $Debug || return;
145 my @call_info = caller;
146 chomp(my $Txt = shift);
147 my $File = $call_info[1];
148 $File =~ s#\\#/#g;
149 $File =~ s#^.*/(.*?)$#$1#;
150 print(STDERR "$File:$call_info[2] $$ $Txt\n");
151 return("");
152 # }}}
153 } # D()
155 __END__
157 # Plain Old Documentation (POD) {{{
159 =pod
161 =head1 NAME
165 =head1 REVISION
167 $Id$
169 =head1 SYNOPSIS
171 [options] [file [files [...]]]
173 =head1 DESCRIPTION
177 =head1 OPTIONS
179 =over 4
181 =item B<-h>, B<--help>
183 Print a brief help summary.
185 =item B<--version>
187 Print version information.
189 =item B<--debug>
191 Print debugging messages.
193 =back
195 =head1 BUGS
199 =head1 AUTHOR
201 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
203 =head1 COPYRIGHT
205 Copyleft © Øyvind A. Holm &lt;sunny@sunbase.org&gt;
206 This is free software; see the file F<COPYING> for legalese stuff.
208 =head1 LICENCE
210 This program is free software; you can redistribute it and/or modify it
211 under the terms of the GNU General Public License as published by the
212 Free Software Foundation; either version 2 of the License, or (at your
213 option) any later version.
215 This program is distributed in the hope that it will be useful, but
216 WITHOUT ANY WARRANTY; without even the implied warranty of
217 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
218 See the GNU General Public License for more details.
220 You should have received a copy of the GNU General Public License along
221 with this program; if not, write to the Free Software Foundation, Inc.,
222 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
224 =head1 SEE ALSO
226 =cut
228 # }}}
230 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
231 # End of file $Id$