* /trunk/vg
[gpstools.git] / vg
blobe6ebb0e5e98d19173a6378424920c554c66fe618
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 %Opt = (
27 'debug' => 0,
28 'help' => 0,
29 'time' => 0,
30 'verbose' => 0,
31 'version' => 0,
35 our $progname = $0;
36 $progname =~ s/^.*\/(.*?)$/$1/;
38 my $rcs_id = '$Id$';
39 my $id_date = $rcs_id;
40 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
42 push(@main::version_array, $rcs_id);
43 my @cmdl = @ARGV;
45 Getopt::Long::Configure("bundling");
46 GetOptions(
48 "debug" => \$Opt{'debug'},
49 "help|h" => \$Opt{'help'},
50 "time|t" => \$Opt{'time'},
51 "verbose|v+" => \$Opt{'verbose'},
52 "version" => \$Opt{'version'},
54 ) || die("$progname: Option error. Use -h for help.\n");
56 $Opt{'debug'} && ($Debug = 1);
57 $Opt{'help'} && usage(0);
58 if ($Opt{'version'}) {
59 print_version();
60 exit(0);
63 my $cmdl_str = join(" ", @cmdl);
65 if ($Opt{'time'}) {
66 my $dat_file = "/tmp/vg-t.tmp";
67 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
68 my @gpst_array = ("gpst", "-o", "csv", "-rt", "-e", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
69 print(FP `@gpst_array`);
70 close(FP);
71 my $cmd_file = "/tmp/vg-t-cmd.tmp";
72 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
73 print(FP <<END);
74 set mouse
75 # load "/tmp/label.gnuplot"
76 set zdata time
77 # set timefmt "%Y-%m-%dT%H:%M:%SZ"
78 set timefmt "%s"
79 splot "$dat_file" using 2:3:1 w l palette
80 pause -1 "Trykk Enter..."
81 END
82 close(FP);
83 system("gnuplot -persist $cmd_file");
84 } else {
85 my $dat_file = "/tmp/vg.tmp";
86 open(FP, ">$dat_file") || die("$progname: $dat_file: Cannot open file for write: $!\n");
87 my @gpst_array = ("gpst", "-o", "clean", "-ret", "-d", "-t", @ARGV, "|", "rmspcall", "|", "uniq");
88 print(FP `@gpst_array`);
89 close(FP);
90 my $cmd_file = "/tmp/vg-cmd.tmp";
91 open(FP, ">$cmd_file") || die("$progname: $cmd_file: Cannot open file for write: $!\n");
92 print(FP <<END);
93 set mouse
94 # load "/tmp/label.gnuplot"
95 splot "$dat_file" w l palette
96 pause -1 "Trykk Enter..."
97 END
98 close(FP);
99 system("gnuplot -persist $cmd_file");
102 sub print_version {
103 # Print program version {{{
104 for (@main::version_array) {
105 print("$_\n");
107 # }}}
108 } # print_version()
110 sub usage {
111 # Send the help message to stdout {{{
112 my $Retval = shift;
114 if ($Opt{'verbose'}) {
115 print("\n");
116 print_version();
118 print(<<END);
120 Usage: $progname [options] [file [files [...]]]
122 Options:
124 -h, --help
125 Show this help.
126 -t, --time
127 Use time as Z axis instead of elevation.
128 -v, --verbose
129 Increase level of verbosity. Can be repeated.
130 --version
131 Print version information.
132 --debug
133 Print debugging messages.
136 exit($Retval);
137 # }}}
138 } # usage()
140 sub msg {
141 # Print a status message to stderr based on verbosity level {{{
142 my ($verbose_level, $Txt) = @_;
144 if ($Opt{'verbose'} >= $verbose_level) {
145 print(STDERR "$progname: $Txt\n");
147 # }}}
148 } # msg()
150 sub D {
151 # Print a debugging message {{{
152 $Debug || return;
153 my @call_info = caller;
154 chomp(my $Txt = shift);
155 my $File = $call_info[1];
156 $File =~ s#\\#/#g;
157 $File =~ s#^.*/(.*?)$#$1#;
158 print(STDERR "$File:$call_info[2] $$ $Txt\n");
159 return("");
160 # }}}
161 } # D()
163 __END__
165 # Plain Old Documentation (POD) {{{
167 =pod
169 =head1 NAME
173 =head1 REVISION
175 $Id$
177 =head1 SYNOPSIS
179 [options] [file [files [...]]]
181 =head1 DESCRIPTION
185 =head1 OPTIONS
187 =over 4
189 =item B<-h>, B<--help>
191 Print a brief help summary.
193 =item B<-v>, B<--verbose>
195 Increase level of verbosity. Can be repeated.
197 =item B<--version>
199 Print version information.
201 =item B<--debug>
203 Print debugging messages.
205 =back
207 =head1 BUGS
211 =head1 AUTHOR
213 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
215 =head1 COPYRIGHT
217 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
218 This is free software; see the file F<COPYING> for legalese stuff.
220 =head1 LICENCE
222 This program is free software; you can redistribute it and/or modify it
223 under the terms of the GNU General Public License as published by the
224 Free Software Foundation; either version 2 of the License, or (at your
225 option) any later version.
227 This program is distributed in the hope that it will be useful, but
228 WITHOUT ANY WARRANTY; without even the implied warranty of
229 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
230 See the GNU General Public License for more details.
232 You should have received a copy of the GNU General Public License along
233 with this program; if not, write to the Free Software Foundation, Inc.,
234 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
236 =head1 SEE ALSO
238 =cut
240 # }}}
242 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
243 # End of file $Id$