gpst: Legger inn en Postgres-patch som har med en imginfo-funksjon å gjøre. Uferdig.
[gpstools.git] / vg
blob80d7c9eef050422a31e881736e16bfeffe1b6adf
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # $Id$
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 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 BEGIN {
15 our @version_array;
18 use strict;
19 use Getopt::Long;
21 $| = 1;
23 our $Debug = 0;
25 our %Std = (
27 'label-file' => "$ENV{'HOME'}/gps/poi/labels.gnuplot",
28 'with' => 'l',
32 our %Opt = (
34 '2d' => 0,
35 'debug' => 0,
36 'help' => 0,
37 'label-file' => "$Std{'label-file'}",
38 'time' => 0,
39 'verbose' => 0,
40 'version' => 0,
41 'with' => $Std{'with'},
45 our $progname = $0;
46 $progname =~ s/^.*\/(.*?)$/$1/;
48 my $rcs_id = '$Id$';
49 my $id_date = $rcs_id;
50 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
52 push(@main::version_array, $rcs_id);
53 my @cmdl = @ARGV;
55 Getopt::Long::Configure("bundling");
56 GetOptions(
58 "2d|2" => \$Opt{'2d'},
59 "debug" => \$Opt{'debug'},
60 "help|h" => \$Opt{'help'},
61 "label-file|l=s" => \$Opt{'label-file'},
62 "time|t" => \$Opt{'time'},
63 "verbose|v+" => \$Opt{'verbose'},
64 "version" => \$Opt{'version'},
65 "with|w=s" => \$Opt{'with'},
67 ) || die("$progname: Option error. Use -h for help.\n");
69 $Opt{'debug'} && ($Debug = 1);
70 $Opt{'help'} && usage(0);
71 if ($Opt{'version'}) {
72 print_version();
73 exit(0);
76 ($Opt{'2d'} && $Opt{'time'}) && die("$progname: Cannot mix --2d and --time options\n");
77 ($Opt{'with'} =~ /^(d|l|lp|p)$/) || die("$progname: $Opt{'with'}: Invalid value of --with option, see $progname -h for help\n");
79 my $cmdl_str = join(" ", @cmdl);
81 if ($Opt{'time'}) {
82 my $dat_file = "/tmp/vg-t.tmp";
83 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
84 my @gpst_array = ("gpst", "-o", "csv", "-rt", "-e", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
85 print(FP `@gpst_array`);
86 close(FP);
87 my $cmd_file = "/tmp/vg-t-cmd.tmp";
88 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
89 print(FP <<END);
90 set mouse
91 load "$Opt{'label-file'}"
92 set zdata time
93 # set timefmt "%Y-%m-%dT%H:%M:%SZ"
94 set timefmt "%s"
95 splot "$dat_file" using 2:3:1 w $Opt{'with'} palette
96 pause -1 "Trykk Enter..."
97 END
98 close(FP);
99 system("gnuplot -persist $cmd_file");
100 } elsif ($Opt{'2d'}) {
101 my $dat_file = "/tmp/vg-2.tmp";
102 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
103 my @gpst_array = ("gpst", "-o", "clean", "-rp", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
104 print(FP `@gpst_array`);
105 close(FP);
106 my $cmd_file = "/tmp/vg-2-cmd.tmp";
107 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
108 print(FP <<END);
109 set mouse
110 load "$Opt{'label-file'}"
111 plot "$dat_file" using 1:2 w $Opt{'with'}
112 pause -1 "Trykk Enter..."
114 close(FP);
115 system("gnuplot -persist $cmd_file");
116 } else {
117 my $dat_file = "/tmp/vg.tmp";
118 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
119 my @gpst_array = ("gpst", "-o", "clean", "-ret", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
120 print(FP `@gpst_array`);
121 close(FP);
122 my $cmd_file = "/tmp/vg-cmd.tmp";
123 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
124 print(FP <<END);
125 set mouse
126 load "$Opt{'label-file'}"
127 splot "$dat_file" w $Opt{'with'} palette
128 pause -1 "Trykk Enter..."
130 close(FP);
131 system("gnuplot -persist $cmd_file");
134 sub print_version {
135 # Print program version {{{
136 for (@main::version_array) {
137 print("$_\n");
139 # }}}
140 } # print_version()
142 sub usage {
143 # Send the help message to stdout {{{
144 my $Retval = shift;
146 if ($Opt{'verbose'}) {
147 print("\n");
148 print_version();
150 print(<<END);
152 Usage: $progname [options] [file [files [...]]]
154 Options:
156 -2, --2d
157 Create 2D plot instead of 3D. Bigger window by default in gnuplot,
158 and it’s faster when plotting lots of data.
159 -h, --help
160 Show this help.
161 -l X, --label-file X
162 Use X as label file.
163 Default: $Std{'label-file'}
164 -t, --time
165 Use time as Z axis instead of elevation.
166 -v, --verbose
167 Increase level of verbosity. Can be repeated.
168 -w X, --with X
169 Use line type X:
170 d - dots
171 l - lines
172 p - points
173 lp - lines with points
174 Default: $Std{'with'}
175 --version
176 Print version information.
177 --debug
178 Print debugging messages.
181 exit($Retval);
182 # }}}
183 } # usage()
185 sub msg {
186 # Print a status message to stderr based on verbosity level {{{
187 my ($verbose_level, $Txt) = @_;
189 if ($Opt{'verbose'} >= $verbose_level) {
190 print(STDERR "$progname: $Txt\n");
192 # }}}
193 } # msg()
195 sub D {
196 # Print a debugging message {{{
197 $Debug || return;
198 my @call_info = caller;
199 chomp(my $Txt = shift);
200 my $File = $call_info[1];
201 $File =~ s#\\#/#g;
202 $File =~ s#^.*/(.*?)$#$1#;
203 print(STDERR "$File:$call_info[2] $$ $Txt\n");
204 return("");
205 # }}}
206 } # D()
208 __END__
210 # Plain Old Documentation (POD) {{{
212 =pod
214 =head1 NAME
218 =head1 REVISION
220 $Id$
222 =head1 SYNOPSIS
224 [options] [file [files [...]]]
226 =head1 DESCRIPTION
230 =head1 OPTIONS
232 =over 4
234 =item B<-h>, B<--help>
236 Print a brief help summary.
238 =item B<-v>, B<--verbose>
240 Increase level of verbosity. Can be repeated.
242 =item B<--version>
244 Print version information.
246 =item B<--debug>
248 Print debugging messages.
250 =back
252 =head1 BUGS
256 =head1 AUTHOR
258 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
260 =head1 COPYRIGHT
262 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
263 This is free software; see the file F<COPYING> for legalese stuff.
265 =head1 LICENCE
267 This program is free software; you can redistribute it and/or modify it
268 under the terms of the GNU General Public License as published by the
269 Free Software Foundation; either version 2 of the License, or (at your
270 option) any later version.
272 This program is distributed in the hope that it will be useful, but
273 WITHOUT ANY WARRANTY; without even the implied warranty of
274 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
275 See the GNU General Public License for more details.
277 You should have received a copy of the GNU General Public License along
278 with this program; if not, write to the Free Software Foundation, Inc.,
279 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
281 =head1 SEE ALSO
283 =cut
285 # }}}
287 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
288 # End of file $Id$