gpst: Removing --near option. Things like that happen in the database.
[gpstools.git] / vg
blob1843b8e45733a7e37d8043a10013d676e57fa5f7
1 #!/usr/bin/perl -w
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 Getopt::Long;
17 $| = 1;
19 our $Debug = 0;
21 our %Std = (
23 'label-file' => "$ENV{'HOME'}/gps/poi/labels.gnuplot",
24 'with' => 'l',
28 our %Opt = (
30 '2d' => 0,
31 'debug' => 0,
32 'help' => 0,
33 'label-file' => "$Std{'label-file'}",
34 'time' => 0,
35 'verbose' => 0,
36 'version' => 0,
37 'with' => $Std{'with'},
41 our $progname = $0;
42 $progname =~ s/^.*\/(.*?)$/$1/;
43 our $VERSION = "0.00";
45 my @cmdl = @ARGV;
47 Getopt::Long::Configure("bundling");
48 GetOptions(
50 "2d|2" => \$Opt{'2d'},
51 "debug" => \$Opt{'debug'},
52 "help|h" => \$Opt{'help'},
53 "label-file|l=s" => \$Opt{'label-file'},
54 "time|t" => \$Opt{'time'},
55 "verbose|v+" => \$Opt{'verbose'},
56 "version" => \$Opt{'version'},
57 "with|w=s" => \$Opt{'with'},
59 ) || die("$progname: Option error. Use -h for help.\n");
61 $Opt{'debug'} && ($Debug = 1);
62 $Opt{'help'} && usage(0);
63 if ($Opt{'version'}) {
64 print_version();
65 exit(0);
68 ($Opt{'2d'} && $Opt{'time'}) && die("$progname: Cannot mix --2d and --time options\n");
69 ($Opt{'with'} =~ /^(d|l|lp|p)$/) || die("$progname: $Opt{'with'}: Invalid value of --with option, see $progname -h for help\n");
71 my $cmdl_str = join(" ", @cmdl);
72 my ($dat_file, $cmd_file);
74 if ($Opt{'time'}) {
75 $dat_file = sprintf("/tmp/vg-t.%u.%u.tmp", time, $$);
76 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
77 my @gpst_array = ("gpst", "-o", "csv", "-rt", "-e", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
78 print(FP `@gpst_array`);
79 close(FP);
80 $cmd_file = sprintf("/tmp/vg-t-cmd.%u.%u.tmp", time, $$);
81 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
82 print(FP <<END);
83 set mouse format "%.6f"
84 load "$Opt{'label-file'}"
85 set zdata time
86 # set timefmt "%Y-%m-%dT%H:%M:%SZ"
87 set timefmt "%s"
88 splot "$dat_file" using 2:3:1 w $Opt{'with'} palette
89 pause -1 "Trykk Enter..."
90 END
91 close(FP);
92 system("gnuplot -persist $cmd_file");
93 } elsif ($Opt{'2d'}) {
94 $dat_file = sprintf("/tmp/vg-2.%u.%u.tmp", time, $$);
95 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
96 my @gpst_array = ("gpst", "-o", "clean", "-rp", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
97 print(FP `@gpst_array`);
98 close(FP);
99 $cmd_file = sprintf("/tmp/vg-2-cmd.%u.%u.tmp", time, $$);
100 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
101 print(FP <<END);
102 set mouse format "%.6f"
103 load "$Opt{'label-file'}"
104 plot "$dat_file" using 1:2 w $Opt{'with'}
105 pause -1 "Trykk Enter..."
107 close(FP);
108 system("gnuplot -persist $cmd_file");
109 } else {
110 $dat_file = sprintf("/tmp/vg.%u.%u.tmp", time, $$);
111 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
112 my @gpst_array = ("gpst", "-o", "clean", "-ret", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
113 print(FP `@gpst_array`);
114 close(FP);
115 $cmd_file = sprintf("/tmp/vg-cmd.%u.%u.tmp", time, $$);
116 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
117 print(FP <<END);
118 set mouse format "%.6f"
119 load "$Opt{'label-file'}"
120 splot "$dat_file" w $Opt{'with'} palette
121 pause -1 "Trykk Enter..."
123 close(FP);
124 system("gnuplot -persist $cmd_file");
126 unlink($dat_file, $cmd_file);
128 sub print_version {
129 # Print program version {{{
130 print("$progname v$VERSION\n");
131 # }}}
132 } # print_version()
134 sub usage {
135 # Send the help message to stdout {{{
136 my $Retval = shift;
138 if ($Opt{'verbose'}) {
139 print("\n");
140 print_version();
142 print(<<END);
144 Usage: $progname [options] [file [files [...]]]
146 Options:
148 -2, --2d
149 Create 2D plot instead of 3D. Bigger window by default in gnuplot,
150 and it’s faster when plotting lots of data.
151 -h, --help
152 Show this help.
153 -l X, --label-file X
154 Use X as label file.
155 Default: $Std{'label-file'}
156 -t, --time
157 Use time as Z axis instead of elevation.
158 -v, --verbose
159 Increase level of verbosity. Can be repeated.
160 -w X, --with X
161 Use line type X:
162 d - dots
163 l - lines
164 p - points
165 lp - lines with points
166 Default: $Std{'with'}
167 --version
168 Print version information.
169 --debug
170 Print debugging messages.
173 exit($Retval);
174 # }}}
175 } # usage()
177 sub msg {
178 # Print a status message to stderr based on verbosity level {{{
179 my ($verbose_level, $Txt) = @_;
181 if ($Opt{'verbose'} >= $verbose_level) {
182 print(STDERR "$progname: $Txt\n");
184 # }}}
185 } # msg()
187 sub D {
188 # Print a debugging message {{{
189 $Debug || return;
190 my @call_info = caller;
191 chomp(my $Txt = shift);
192 my $File = $call_info[1];
193 $File =~ s#\\#/#g;
194 $File =~ s#^.*/(.*?)$#$1#;
195 print(STDERR "$File:$call_info[2] $$ $Txt\n");
196 return("");
197 # }}}
198 } # D()
200 __END__
202 # Plain Old Documentation (POD) {{{
204 =pod
206 =head1 NAME
210 =head1 SYNOPSIS
212 [options] [file [files [...]]]
214 =head1 DESCRIPTION
218 =head1 OPTIONS
220 =over 4
222 =item B<-h>, B<--help>
224 Print a brief help summary.
226 =item B<-v>, B<--verbose>
228 Increase level of verbosity. Can be repeated.
230 =item B<--version>
232 Print version information.
234 =item B<--debug>
236 Print debugging messages.
238 =back
240 =head1 BUGS
244 =head1 AUTHOR
246 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
248 =head1 COPYRIGHT
250 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
251 This is free software; see the file F<COPYING> for legalese stuff.
253 =head1 LICENCE
255 This program is free software: you can redistribute it and/or modify it
256 under the terms of the GNU General Public License as published by the
257 Free Software Foundation, either version 3 of the License, or (at your
258 option) any later version.
260 This program is distributed in the hope that it will be useful, but
261 WITHOUT ANY WARRANTY; without even the implied warranty of
262 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
263 See the GNU General Public License for more details.
265 You should have received a copy of the GNU General Public License along
266 with this program.
267 If not, see L<http://www.gnu.org/licenses/>.
269 =head1 SEE ALSO
271 =cut
273 # }}}
275 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :