* /trunk/vg
[gpstools.git] / vg
blobb881873f2662a52fcca12e9f1bddd6d9332aad12
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # $Id$
5 # File ID: 58ece940-08f3-11de-ab14-000475e441b9
6 # View GPX files in gnuplot(1)
8 # Character set: UTF-8
9 # ©opyleft 2009– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 BEGIN {
15 our @version_array;
18 use strict;
19 use Getopt::Long;
21 $| = 1;
23 our $Debug = 0;
25 our %Std = (
27 'label-file' => "$ENV{'HOME'}/gps/poi/labels.gnuplot",
31 our %Opt = (
33 '2d' => 0,
34 'debug' => 0,
35 'help' => 0,
36 'label-file' => "$Std{'label-file'}",
37 'time' => 0,
38 'verbose' => 0,
39 'version' => 0,
43 our $progname = $0;
44 $progname =~ s/^.*\/(.*?)$/$1/;
46 my $rcs_id = '$Id$';
47 my $id_date = $rcs_id;
48 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
50 push(@main::version_array, $rcs_id);
51 my @cmdl = @ARGV;
53 Getopt::Long::Configure("bundling");
54 GetOptions(
56 "2d|2" => \$Opt{'2d'},
57 "debug" => \$Opt{'debug'},
58 "help|h" => \$Opt{'help'},
59 "label-file|l=s" => \$Opt{'label-file'},
60 "time|t" => \$Opt{'time'},
61 "verbose|v+" => \$Opt{'verbose'},
62 "version" => \$Opt{'version'},
64 ) || die("$progname: Option error. Use -h for help.\n");
66 $Opt{'debug'} && ($Debug = 1);
67 $Opt{'help'} && usage(0);
68 if ($Opt{'version'}) {
69 print_version();
70 exit(0);
73 ($Opt{'2d'} && $Opt{'time'}) && die("$progname: Cannot mix --2d and --time options\n");
75 my $cmdl_str = join(" ", @cmdl);
77 if ($Opt{'time'}) {
78 my $dat_file = "/tmp/vg-t.tmp";
79 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
80 my @gpst_array = ("gpst", "-o", "csv", "-rt", "-e", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
81 print(FP `@gpst_array`);
82 close(FP);
83 my $cmd_file = "/tmp/vg-t-cmd.tmp";
84 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
85 print(FP <<END);
86 set mouse
87 load "$Opt{'label-file'}"
88 set zdata time
89 # set timefmt "%Y-%m-%dT%H:%M:%SZ"
90 set timefmt "%s"
91 splot "$dat_file" using 2:3:1 w l palette
92 pause -1 "Trykk Enter..."
93 END
94 close(FP);
95 system("gnuplot -persist $cmd_file");
96 } elsif ($Opt{'2d'}) {
97 my $dat_file = "/tmp/vg-2.tmp";
98 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
99 my @gpst_array = ("gpst", "-o", "clean", "-rp", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
100 print(FP `@gpst_array`);
101 close(FP);
102 my $cmd_file = "/tmp/vg-2-cmd.tmp";
103 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
104 print(FP <<END);
105 set mouse
106 load "$Opt{'label-file'}"
107 plot "$dat_file" using 1:2 w l
108 pause -1 "Trykk Enter..."
110 close(FP);
111 system("gnuplot -persist $cmd_file");
112 } else {
113 my $dat_file = "/tmp/vg.tmp";
114 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
115 my @gpst_array = ("gpst", "-o", "clean", "-ret", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
116 print(FP `@gpst_array`);
117 close(FP);
118 my $cmd_file = "/tmp/vg-cmd.tmp";
119 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
120 print(FP <<END);
121 set mouse
122 load "$Opt{'label-file'}"
123 splot "$dat_file" w l palette
124 pause -1 "Trykk Enter..."
126 close(FP);
127 system("gnuplot -persist $cmd_file");
130 sub print_version {
131 # Print program version {{{
132 for (@main::version_array) {
133 print("$_\n");
135 # }}}
136 } # print_version()
138 sub usage {
139 # Send the help message to stdout {{{
140 my $Retval = shift;
142 if ($Opt{'verbose'}) {
143 print("\n");
144 print_version();
146 print(<<END);
148 Usage: $progname [options] [file [files [...]]]
150 Options:
152 -2, --2d
153 Create 2D plot instead of 3D. Bigger window by default in gnuplot,
154 and it’s faster when plotting lots of data.
155 -h, --help
156 Show this help.
157 -l X, --label-file X
158 Use X as label file.
159 Default: $Std{'label-file'}
160 -t, --time
161 Use time as Z axis instead of elevation.
162 -v, --verbose
163 Increase level of verbosity. Can be repeated.
164 --version
165 Print version information.
166 --debug
167 Print debugging messages.
170 exit($Retval);
171 # }}}
172 } # usage()
174 sub msg {
175 # Print a status message to stderr based on verbosity level {{{
176 my ($verbose_level, $Txt) = @_;
178 if ($Opt{'verbose'} >= $verbose_level) {
179 print(STDERR "$progname: $Txt\n");
181 # }}}
182 } # msg()
184 sub D {
185 # Print a debugging message {{{
186 $Debug || return;
187 my @call_info = caller;
188 chomp(my $Txt = shift);
189 my $File = $call_info[1];
190 $File =~ s#\\#/#g;
191 $File =~ s#^.*/(.*?)$#$1#;
192 print(STDERR "$File:$call_info[2] $$ $Txt\n");
193 return("");
194 # }}}
195 } # D()
197 __END__
199 # Plain Old Documentation (POD) {{{
201 =pod
203 =head1 NAME
207 =head1 REVISION
209 $Id$
211 =head1 SYNOPSIS
213 [options] [file [files [...]]]
215 =head1 DESCRIPTION
219 =head1 OPTIONS
221 =over 4
223 =item B<-h>, B<--help>
225 Print a brief help summary.
227 =item B<-v>, B<--verbose>
229 Increase level of verbosity. Can be repeated.
231 =item B<--version>
233 Print version information.
235 =item B<--debug>
237 Print debugging messages.
239 =back
241 =head1 BUGS
245 =head1 AUTHOR
247 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
249 =head1 COPYRIGHT
251 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
252 This is free software; see the file F<COPYING> for legalese stuff.
254 =head1 LICENCE
256 This program is free software; you can redistribute it and/or modify it
257 under the terms of the GNU General Public License as published by the
258 Free Software Foundation; either version 2 of the License, or (at your
259 option) any later version.
261 This program is distributed in the hope that it will be useful, but
262 WITHOUT ANY WARRANTY; without even the implied warranty of
263 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
264 See the GNU General Public License for more details.
266 You should have received a copy of the GNU General Public License along
267 with this program; if not, write to the Free Software Foundation, Inc.,
268 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
270 =head1 SEE ALSO
272 =cut
274 # }}}
276 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
277 # End of file $Id$