Repack testfile.tar.gz without volume label for portability
[gpstools.git] / roundgpx
blob5b58a49c38b84c6f6f3b6206ce51f343d06dc7d0
1 #!/usr/bin/env perl
3 #=======================================================================
4 # roundgpx
5 # File ID: d16a06e8-6138-11df-8aac-90e6ba3022ac
6 # [Description]
8 # Character set: UTF-8
9 # ©opyleft 2010– Ø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 warnings;
16 use Getopt::Long;
18 $| = 1;
20 our $Debug = 0;
22 our %Opt = (
24 'debug' => 0,
25 'help' => 0,
26 'verbose' => 0,
27 'version' => 0,
31 our $progname = $0;
32 $progname =~ s/^.*\/(.*?)$/$1/;
33 our $VERSION = "0.00";
35 Getopt::Long::Configure("bundling");
36 GetOptions(
38 "debug" => \$Opt{'debug'},
39 "help|h" => \$Opt{'help'},
40 "verbose|v+" => \$Opt{'verbose'},
41 "version" => \$Opt{'version'},
43 ) || die("$progname: Option error. Use -h for help.\n");
45 $Opt{'debug'} && ($Debug = 1);
46 $Opt{'help'} && usage(0);
47 if ($Opt{'version'}) {
48 print_version();
49 exit(0);
52 while (<>) {
53 if (/(.*?<(?:trkpt|rtept|wpt)\s+.*?)"(.*?)"(.*?)"(.*?)"(.*)$/) {
54 my ($num1, $num2) = (sprintf("%.6f", $2), sprintf("%.6f", $4));
55 print("$1\"" . num_expand($num1) . "\"$3\"" . num_expand($num2) . "\"$5\n");
56 } elsif (/^(.*?<ele>)(-?[\d\.]+)(<\/ele>.*)$/) {
57 my $ele = sprintf("%.3f", $2);
58 print($1 . num_expand($ele) . "$3\n");
59 } else {
60 print;
64 sub num_expand {
65 # Convert scientific notation to decimal notation {{{
66 my $Retval = shift;
67 length($Retval) || return("");
68 if ($Retval =~ /^(.*)e([-+]?)(.*)$/) {
69 my ($num, $sign, $exp) = ($1, $2, $3);
70 my $sig = $sign eq '-' ? "." . ($exp - 1 + length $num) : '';
71 $Retval = sprintf("%${sig}f", $Retval);
73 $Retval =~ s/^\+//;
74 my $minus = ($Retval =~ s/^-//) ? "-" : "";
75 if ($Retval =~ /\.\d/) {
76 $Retval =~ s/0+$//;
77 $Retval =~ s/^0+/0/;
78 $Retval =~ s/^0([1-9]+)\./$1./;
79 $Retval =~ s/\.$//;
80 } else {
81 $Retval =~ s/^0+//;
83 length($Retval) || ($Retval = 0);
84 $Retval = $Retval ? "$minus$Retval" : 0;
85 return($Retval);
86 # }}}
87 } # num_expand()
89 sub print_version {
90 # Print program version {{{
91 print("$progname v$VERSION\n");
92 # }}}
93 } # print_version()
95 sub usage {
96 # Send the help message to stdout {{{
97 my $Retval = shift;
99 if ($Opt{'verbose'}) {
100 print("\n");
101 print_version();
103 print(<<END);
105 Usage: $progname [options] [file [files [...]]]
107 Options:
109 -h, --help
110 Show this help.
111 -v, --verbose
112 Increase level of verbosity. Can be repeated.
113 --version
114 Print version information.
115 --debug
116 Print debugging messages.
119 exit($Retval);
120 # }}}
121 } # usage()
123 sub msg {
124 # Print a status message to stderr based on verbosity level {{{
125 my ($verbose_level, $Txt) = @_;
127 if ($Opt{'verbose'} >= $verbose_level) {
128 print(STDERR "$progname: $Txt\n");
130 # }}}
131 } # msg()
133 sub D {
134 # Print a debugging message {{{
135 $Debug || return;
136 my @call_info = caller;
137 chomp(my $Txt = shift);
138 my $File = $call_info[1];
139 $File =~ s#\\#/#g;
140 $File =~ s#^.*/(.*?)$#$1#;
141 print(STDERR "$File:$call_info[2] $$ $Txt\n");
142 return("");
143 # }}}
144 } # D()
146 __END__
148 # Plain Old Documentation (POD) {{{
150 =pod
152 =head1 NAME
156 =head1 SYNOPSIS
158 [options] [file [files [...]]]
160 =head1 DESCRIPTION
164 =head1 OPTIONS
166 =over 4
168 =item B<-h>, B<--help>
170 Print a brief help summary.
172 =item B<-v>, B<--verbose>
174 Increase level of verbosity. Can be repeated.
176 =item B<--version>
178 Print version information.
180 =item B<--debug>
182 Print debugging messages.
184 =back
186 =head1 BUGS
190 =head1 AUTHOR
192 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
194 =head1 COPYRIGHT
196 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
197 This is free software; see the file F<COPYING> for legalese stuff.
199 =head1 LICENCE
201 This program is free software: you can redistribute it and/or modify it
202 under the terms of the GNU General Public License as published by the
203 Free Software Foundation, either version 3 of the License, or (at your
204 option) any later version.
206 This program is distributed in the hope that it will be useful, but
207 WITHOUT ANY WARRANTY; without even the implied warranty of
208 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
209 See the GNU General Public License for more details.
211 You should have received a copy of the GNU General Public License along
212 with this program.
213 If not, see L<http://www.gnu.org/licenses/>.
215 =head1 SEE ALSO
217 =cut
219 # }}}
221 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :