3 #=======================================================================
5 # File ID: d16a06e8-6138-11df-8aac-90e6ba3022ac
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 #=======================================================================
31 $progname =~ s/^.*\/(.*?)$/$1/;
32 our $VERSION = "0.00";
34 Getopt
::Long
::Configure
("bundling");
37 "debug" => \
$Opt{'debug'},
38 "help|h" => \
$Opt{'help'},
39 "verbose|v+" => \
$Opt{'verbose'},
40 "version" => \
$Opt{'version'},
42 ) || die("$progname: Option error. Use -h for help.\n");
44 $Opt{'debug'} && ($Debug = 1);
45 $Opt{'help'} && usage
(0);
46 if ($Opt{'version'}) {
52 if (/(.*?<(?:trkpt|rtept|wpt)\s+.*?)"(.*?)"(.*?)"(.*?)"(.*)$/) {
53 my ($num1, $num2) = (trunc_number
($2, 6), trunc_number
($4, 6));
54 print("$1\"$num1\"$3\"$num2\"$5\n");
55 } elsif (/^(.*?<ele>)(-?[\d\.]+)(<\/ele
>.*)$/) {
56 my $ele = trunc_number
($2, 3);
64 # Convert scientific notation to decimal notation {{{
66 length($Retval) || return("");
67 if ($Retval =~ /^(.*)e([-+]?)(.*)$/) {
68 my ($num, $sign, $exp) = ($1, $2, $3);
69 my $sig = $sign eq '-' ?
"." . ($exp - 1 + length $num) : '';
70 $Retval = sprintf("%${sig}f", $Retval);
73 my $minus = ($Retval =~ s/^-//) ?
"-" : "";
74 if ($Retval =~ /\.\d/) {
77 $Retval =~ s/^0([1-9]+)\./$1./;
82 length($Retval) || ($Retval = 0);
83 $Retval = $Retval ?
"$minus$Retval" : 0;
89 # Truncate decimals of floating point number {{{
90 my ($num, $scale) = @_;
91 $num = int($num * (10**$scale)) / 10**$scale;
92 return(num_expand
($num));
97 # Print program version {{{
98 print("$progname v$VERSION\n");
103 # Send the help message to stdout {{{
106 if ($Opt{'verbose'}) {
112 Usage: $progname [options] [file [files [...]]]
119 Increase level of verbosity. Can be repeated.
121 Print version information.
123 Print debugging messages.
131 # Print a status message to stderr based on verbosity level {{{
132 my ($verbose_level, $Txt) = @_;
134 if ($Opt{'verbose'} >= $verbose_level) {
135 print(STDERR
"$progname: $Txt\n");
141 # Print a debugging message {{{
143 my @call_info = caller;
144 chomp(my $Txt = shift);
145 my $File = $call_info[1];
147 $File =~ s
#^.*/(.*?)$#$1#;
148 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
155 # Plain Old Documentation (POD) {{{
165 [options] [file [files [...]]]
175 =item B<-h>, B<--help>
177 Print a brief help summary.
179 =item B<-v>, B<--verbose>
181 Increase level of verbosity. Can be repeated.
185 Print version information.
189 Print debugging messages.
199 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
203 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
204 This is free software; see the file F<COPYING> for legalese stuff.
208 This program is free software: you can redistribute it and/or modify it
209 under the terms of the GNU General Public License as published by the
210 Free Software Foundation, either version 3 of the License, or (at your
211 option) any later version.
213 This program is distributed in the hope that it will be useful, but
214 WITHOUT ANY WARRANTY; without even the implied warranty of
215 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
216 See the GNU General Public License for more details.
218 You should have received a copy of the GNU General Public License along
220 If not, see L<http://www.gnu.org/licenses/>.
228 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :