Move gpst-pic.t to parent directory
[gpstools.git] / vg
blob35a2b9876eb7a79106e6267abf66a449d7965e16
1 #!/usr/bin/env perl
3 #=======================================================================
4 # vg
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 3 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 use strict;
15 use warnings;
16 use Getopt::Long;
18 $| = 1;
20 our $Debug = 0;
22 our %Std = (
24 'label-file' => "$ENV{'HOME'}/gps/poi/labels.gnuplot",
25 'with' => 'l',
29 our %Opt = (
31 '2d' => 0,
32 'debug' => 0,
33 'help' => 0,
34 'keep-files' => 0,
35 'label-file' => "$Std{'label-file'}",
36 'time' => 0,
37 'verbose' => 0,
38 'version' => 0,
39 'with' => $Std{'with'},
43 our $progname = $0;
44 $progname =~ s/^.*\/(.*?)$/$1/;
45 our $VERSION = "0.00";
47 Getopt::Long::Configure("bundling");
48 GetOptions(
50 "2d|2" => \$Opt{'2d'},
51 "debug" => \$Opt{'debug'},
52 "help|h" => \$Opt{'help'},
53 "keep-files|k" => \$Opt{'keep-files'},
54 "label-file|l=s" => \$Opt{'label-file'},
55 "time|t" => \$Opt{'time'},
56 "verbose|v+" => \$Opt{'verbose'},
57 "version" => \$Opt{'version'},
58 "with|w=s" => \$Opt{'with'},
60 ) || die("$progname: Option error. Use -h for help.\n");
62 $Opt{'debug'} && ($Debug = 1);
63 $Opt{'help'} && usage(0);
64 if ($Opt{'version'}) {
65 print_version();
66 exit(0);
69 ($Opt{'2d'} && $Opt{'time'}) && die("$progname: Cannot mix --2d and --time options\n");
70 ($Opt{'with'} =~ /^(d|l|lp|p)$/) || die("$progname: $Opt{'with'}: Invalid value of --with option, see $progname -h for help\n");
72 my ($dat_file, $cmd_file);
73 my $fp;
75 if ($Opt{'time'}) {
76 $dat_file = sprintf("/tmp/vg-t.%u.%u.tmp", time, $$);
77 open($fp, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
78 my @gpst_array = ("gpst", "-o", "csv", "-rt", "-e", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
79 print($fp `@gpst_array`);
80 close($fp);
81 $cmd_file = sprintf("/tmp/vg-t-cmd.%u.%u.tmp", time, $$);
82 open($fp, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
83 print($fp <<END);
84 set mouse format "%.6f"
85 load "$Opt{'label-file'}"
86 set zdata time
87 # set timefmt "%Y-%m-%dT%H:%M:%SZ"
88 set timefmt "%s"
89 splot "$dat_file" using 2:3:1 w $Opt{'with'} palette
90 pause -1 "Trykk Enter..."
91 END
92 close($fp);
93 system("gnuplot -persist $cmd_file");
94 } elsif ($Opt{'2d'}) {
95 $dat_file = sprintf("/tmp/vg-2.%u.%u.tmp", time, $$);
96 open($fp, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
97 my @gpst_array = ("gpst", "-o", "clean", "-rp", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
98 print($fp `@gpst_array`);
99 close($fp);
100 $cmd_file = sprintf("/tmp/vg-2-cmd.%u.%u.tmp", time, $$);
101 open($fp, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
102 print($fp <<END);
103 set mouse format "%.6f"
104 load "$Opt{'label-file'}"
105 plot "$dat_file" using 1:2 w $Opt{'with'}
106 pause -1 "Trykk Enter..."
108 close($fp);
109 system("gnuplot -persist $cmd_file");
110 } else {
111 $dat_file = sprintf("/tmp/vg.%u.%u.tmp", time, $$);
112 open($fp, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
113 my @gpst_array = ("gpst", "-o", "clean", "-ret", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
114 print($fp `@gpst_array`);
115 close($fp);
116 $cmd_file = sprintf("/tmp/vg-cmd.%u.%u.tmp", time, $$);
117 open($fp, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
118 print($fp <<END);
119 set mouse format "%.6f"
120 load "$Opt{'label-file'}"
121 splot "$dat_file" w $Opt{'with'} palette
122 pause -1 "Trykk Enter..."
124 close($fp);
125 system("gnuplot -persist $cmd_file");
127 $Opt{'keep-files'} || unlink($dat_file, $cmd_file);
129 sub print_version {
130 # Print program version {{{
131 print("$progname v$VERSION\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 -2, --2d
150 Create 2D plot instead of 3D. Bigger window by default in gnuplot,
151 and it’s faster when plotting lots of data.
152 -h, --help
153 Show this help.
154 -k, --keep-files
155 Don’t remove temporary files after program execution.
156 -l X, --label-file X
157 Use X as label file.
158 Default: $Std{'label-file'}
159 -t, --time
160 Use time as Z axis instead of elevation.
161 -v, --verbose
162 Increase level of verbosity. Can be repeated.
163 -w X, --with X
164 Use line type X:
165 d - dots
166 l - lines
167 p - points
168 lp - lines with points
169 Default: $Std{'with'}
170 --version
171 Print version information.
172 --debug
173 Print debugging messages.
176 exit($Retval);
177 # }}}
178 } # usage()
180 sub msg {
181 # Print a status message to stderr based on verbosity level {{{
182 my ($verbose_level, $Txt) = @_;
184 if ($Opt{'verbose'} >= $verbose_level) {
185 print(STDERR "$progname: $Txt\n");
187 # }}}
188 } # msg()
190 sub D {
191 # Print a debugging message {{{
192 $Debug || return;
193 my @call_info = caller;
194 chomp(my $Txt = shift);
195 my $File = $call_info[1];
196 $File =~ s#\\#/#g;
197 $File =~ s#^.*/(.*?)$#$1#;
198 print(STDERR "$File:$call_info[2] $$ $Txt\n");
199 return("");
200 # }}}
201 } # D()
203 __END__
205 # Plain Old Documentation (POD) {{{
207 =pod
209 =head1 NAME
213 =head1 SYNOPSIS
215 [options] [file [files [...]]]
217 =head1 DESCRIPTION
221 =head1 OPTIONS
223 =over 4
225 =item B<-h>, B<--help>
227 Print a brief help summary.
229 =item B<-v>, B<--verbose>
231 Increase level of verbosity. Can be repeated.
233 =item B<--version>
235 Print version information.
237 =item B<--debug>
239 Print debugging messages.
241 =back
243 =head1 BUGS
247 =head1 AUTHOR
249 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
251 =head1 COPYRIGHT
253 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
254 This is free software; see the file F<COPYING> for legalese stuff.
256 =head1 LICENCE
258 This program is free software: you can redistribute it and/or modify it
259 under the terms of the GNU General Public License as published by the
260 Free Software Foundation, either version 3 of the License, or (at your
261 option) any later version.
263 This program is distributed in the hope that it will be useful, but
264 WITHOUT ANY WARRANTY; without even the implied warranty of
265 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
266 See the GNU General Public License for more details.
268 You should have received a copy of the GNU General Public License along
269 with this program.
270 If not, see L<http://www.gnu.org/licenses/>.
272 =head1 SEE ALSO
274 =cut
276 # }}}
278 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :