Removing the import/ dir, have placed it on its own branch.
[gpstools.git] / vg
blobe3ff931772ccd13ae034b3614b1a1baa9013683f
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);
73 if ($Opt{'time'}) {
74 my $dat_file = "/tmp/vg-t.tmp";
75 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
76 my @gpst_array = ("gpst", "-o", "csv", "-rt", "-e", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
77 print(FP `@gpst_array`);
78 close(FP);
79 my $cmd_file = "/tmp/vg-t-cmd.tmp";
80 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
81 print(FP <<END);
82 set mouse
83 load "$Opt{'label-file'}"
84 set zdata time
85 # set timefmt "%Y-%m-%dT%H:%M:%SZ"
86 set timefmt "%s"
87 splot "$dat_file" using 2:3:1 w $Opt{'with'} palette
88 pause -1 "Trykk Enter..."
89 END
90 close(FP);
91 system("gnuplot -persist $cmd_file");
92 } elsif ($Opt{'2d'}) {
93 my $dat_file = "/tmp/vg-2.tmp";
94 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
95 my @gpst_array = ("gpst", "-o", "clean", "-rp", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
96 print(FP `@gpst_array`);
97 close(FP);
98 my $cmd_file = "/tmp/vg-2-cmd.tmp";
99 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
100 print(FP <<END);
101 set mouse
102 load "$Opt{'label-file'}"
103 plot "$dat_file" using 1:2 w $Opt{'with'}
104 pause -1 "Trykk Enter..."
106 close(FP);
107 system("gnuplot -persist $cmd_file");
108 } else {
109 my $dat_file = "/tmp/vg.tmp";
110 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
111 my @gpst_array = ("gpst", "-o", "clean", "-ret", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
112 print(FP `@gpst_array`);
113 close(FP);
114 my $cmd_file = "/tmp/vg-cmd.tmp";
115 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
116 print(FP <<END);
117 set mouse
118 load "$Opt{'label-file'}"
119 splot "$dat_file" w $Opt{'with'} palette
120 pause -1 "Trykk Enter..."
122 close(FP);
123 system("gnuplot -persist $cmd_file");
126 sub print_version {
127 # Print program version {{{
128 print("$progname v$VERSION\n");
129 # }}}
130 } # print_version()
132 sub usage {
133 # Send the help message to stdout {{{
134 my $Retval = shift;
136 if ($Opt{'verbose'}) {
137 print("\n");
138 print_version();
140 print(<<END);
142 Usage: $progname [options] [file [files [...]]]
144 Options:
146 -2, --2d
147 Create 2D plot instead of 3D. Bigger window by default in gnuplot,
148 and it’s faster when plotting lots of data.
149 -h, --help
150 Show this help.
151 -l X, --label-file X
152 Use X as label file.
153 Default: $Std{'label-file'}
154 -t, --time
155 Use time as Z axis instead of elevation.
156 -v, --verbose
157 Increase level of verbosity. Can be repeated.
158 -w X, --with X
159 Use line type X:
160 d - dots
161 l - lines
162 p - points
163 lp - lines with points
164 Default: $Std{'with'}
165 --version
166 Print version information.
167 --debug
168 Print debugging messages.
171 exit($Retval);
172 # }}}
173 } # usage()
175 sub msg {
176 # Print a status message to stderr based on verbosity level {{{
177 my ($verbose_level, $Txt) = @_;
179 if ($Opt{'verbose'} >= $verbose_level) {
180 print(STDERR "$progname: $Txt\n");
182 # }}}
183 } # msg()
185 sub D {
186 # Print a debugging message {{{
187 $Debug || return;
188 my @call_info = caller;
189 chomp(my $Txt = shift);
190 my $File = $call_info[1];
191 $File =~ s#\\#/#g;
192 $File =~ s#^.*/(.*?)$#$1#;
193 print(STDERR "$File:$call_info[2] $$ $Txt\n");
194 return("");
195 # }}}
196 } # D()
198 __END__
200 # Plain Old Documentation (POD) {{{
202 =pod
204 =head1 NAME
208 =head1 SYNOPSIS
210 [options] [file [files [...]]]
212 =head1 DESCRIPTION
216 =head1 OPTIONS
218 =over 4
220 =item B<-h>, B<--help>
222 Print a brief help summary.
224 =item B<-v>, B<--verbose>
226 Increase level of verbosity. Can be repeated.
228 =item B<--version>
230 Print version information.
232 =item B<--debug>
234 Print debugging messages.
236 =back
238 =head1 BUGS
242 =head1 AUTHOR
244 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
246 =head1 COPYRIGHT
248 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
249 This is free software; see the file F<COPYING> for legalese stuff.
251 =head1 LICENCE
253 This program is free software: you can redistribute it and/or modify it
254 under the terms of the GNU General Public License as published by the
255 Free Software Foundation, either version 3 of the License, or (at your
256 option) any later version.
258 This program is distributed in the hope that it will be useful, but
259 WITHOUT ANY WARRANTY; without even the implied warranty of
260 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
261 See the GNU General Public License for more details.
263 You should have received a copy of the GNU General Public License along
264 with this program.
265 If not, see L<http://www.gnu.org/licenses/>.
267 =head1 SEE ALSO
269 =cut
271 # }}}
273 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :