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