Makefile: remotes: Add bitbucket. Welcome.
[gpstools.git] / vg
blobc570ed28e5d8f9590b4217e8b7913dddf0b5b6bb
1 #!/usr/bin/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 my @cmdl = @ARGV;
49 Getopt::Long::Configure("bundling");
50 GetOptions(
52 "2d|2" => \$Opt{'2d'},
53 "debug" => \$Opt{'debug'},
54 "help|h" => \$Opt{'help'},
55 "keep-files|k" => \$Opt{'keep-files'},
56 "label-file|l=s" => \$Opt{'label-file'},
57 "time|t" => \$Opt{'time'},
58 "verbose|v+" => \$Opt{'verbose'},
59 "version" => \$Opt{'version'},
60 "with|w=s" => \$Opt{'with'},
62 ) || die("$progname: Option error. Use -h for help.\n");
64 $Opt{'debug'} && ($Debug = 1);
65 $Opt{'help'} && usage(0);
66 if ($Opt{'version'}) {
67 print_version();
68 exit(0);
71 ($Opt{'2d'} && $Opt{'time'}) && die("$progname: Cannot mix --2d and --time options\n");
72 ($Opt{'with'} =~ /^(d|l|lp|p)$/) || die("$progname: $Opt{'with'}: Invalid value of --with option, see $progname -h for help\n");
74 my $cmdl_str = join(" ", @cmdl);
75 my ($dat_file, $cmd_file);
76 my $fp;
78 if ($Opt{'time'}) {
79 $dat_file = sprintf("/tmp/vg-t.%u.%u.tmp", time, $$);
80 open($fp, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
81 my @gpst_array = ("gpst", "-o", "csv", "-rt", "-e", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
82 print($fp `@gpst_array`);
83 close($fp);
84 $cmd_file = sprintf("/tmp/vg-t-cmd.%u.%u.tmp", time, $$);
85 open($fp, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
86 print($fp <<END);
87 set mouse format "%.6f"
88 load "$Opt{'label-file'}"
89 set zdata time
90 # set timefmt "%Y-%m-%dT%H:%M:%SZ"
91 set timefmt "%s"
92 splot "$dat_file" using 2:3:1 w $Opt{'with'} palette
93 pause -1 "Trykk Enter..."
94 END
95 close($fp);
96 system("gnuplot -persist $cmd_file");
97 } elsif ($Opt{'2d'}) {
98 $dat_file = sprintf("/tmp/vg-2.%u.%u.tmp", time, $$);
99 open($fp, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
100 my @gpst_array = ("gpst", "-o", "clean", "-rp", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
101 print($fp `@gpst_array`);
102 close($fp);
103 $cmd_file = sprintf("/tmp/vg-2-cmd.%u.%u.tmp", time, $$);
104 open($fp, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
105 print($fp <<END);
106 set mouse format "%.6f"
107 load "$Opt{'label-file'}"
108 plot "$dat_file" using 1:2 w $Opt{'with'}
109 pause -1 "Trykk Enter..."
111 close($fp);
112 system("gnuplot -persist $cmd_file");
113 } else {
114 $dat_file = sprintf("/tmp/vg.%u.%u.tmp", time, $$);
115 open($fp, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
116 my @gpst_array = ("gpst", "-o", "clean", "-ret", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
117 print($fp `@gpst_array`);
118 close($fp);
119 $cmd_file = sprintf("/tmp/vg-cmd.%u.%u.tmp", time, $$);
120 open($fp, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
121 print($fp <<END);
122 set mouse format "%.6f"
123 load "$Opt{'label-file'}"
124 splot "$dat_file" w $Opt{'with'} palette
125 pause -1 "Trykk Enter..."
127 close($fp);
128 system("gnuplot -persist $cmd_file");
130 $Opt{'keep-files'} || unlink($dat_file, $cmd_file);
132 sub print_version {
133 # Print program version {{{
134 print("$progname v$VERSION\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 -k, --keep-files
158 Don’t remove temporary files after program execution.
159 -l X, --label-file X
160 Use X as label file.
161 Default: $Std{'label-file'}
162 -t, --time
163 Use time as Z axis instead of elevation.
164 -v, --verbose
165 Increase level of verbosity. Can be repeated.
166 -w X, --with X
167 Use line type X:
168 d - dots
169 l - lines
170 p - points
171 lp - lines with points
172 Default: $Std{'with'}
173 --version
174 Print version information.
175 --debug
176 Print debugging messages.
179 exit($Retval);
180 # }}}
181 } # usage()
183 sub msg {
184 # Print a status message to stderr based on verbosity level {{{
185 my ($verbose_level, $Txt) = @_;
187 if ($Opt{'verbose'} >= $verbose_level) {
188 print(STDERR "$progname: $Txt\n");
190 # }}}
191 } # msg()
193 sub D {
194 # Print a debugging message {{{
195 $Debug || return;
196 my @call_info = caller;
197 chomp(my $Txt = shift);
198 my $File = $call_info[1];
199 $File =~ s#\\#/#g;
200 $File =~ s#^.*/(.*?)$#$1#;
201 print(STDERR "$File:$call_info[2] $$ $Txt\n");
202 return("");
203 # }}}
204 } # D()
206 __END__
208 # Plain Old Documentation (POD) {{{
210 =pod
212 =head1 NAME
216 =head1 SYNOPSIS
218 [options] [file [files [...]]]
220 =head1 DESCRIPTION
224 =head1 OPTIONS
226 =over 4
228 =item B<-h>, B<--help>
230 Print a brief help summary.
232 =item B<-v>, B<--verbose>
234 Increase level of verbosity. Can be repeated.
236 =item B<--version>
238 Print version information.
240 =item B<--debug>
242 Print debugging messages.
244 =back
246 =head1 BUGS
250 =head1 AUTHOR
252 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
254 =head1 COPYRIGHT
256 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
257 This is free software; see the file F<COPYING> for legalese stuff.
259 =head1 LICENCE
261 This program is free software: you can redistribute it and/or modify it
262 under the terms of the GNU General Public License as published by the
263 Free Software Foundation, either version 3 of the License, or (at your
264 option) any later version.
266 This program is distributed in the hope that it will be useful, but
267 WITHOUT ANY WARRANTY; without even the implied warranty of
268 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
269 See the GNU General Public License for more details.
271 You should have received a copy of the GNU General Public License along
272 with this program.
273 If not, see L<http://www.gnu.org/licenses/>.
275 =head1 SEE ALSO
277 =cut
279 # }}}
281 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :