-
Notifications
You must be signed in to change notification settings - Fork 3
/
wkjoin
executable file
·129 lines (100 loc) · 2.46 KB
/
wkjoin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl -w
#
# Copyright (c) 2008 Rainer Clasen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms described in the file LICENSE included in this
# distribution.
#
use strict;
use warnings;
use Workout;
use Getopt::Long;
use I18N::Langinfo qw(langinfo CODESET);
my $charset = langinfo(CODESET);
binmode STDIN, ":encoding($charset)";
binmode STDOUT, ":encoding($charset)";
binmode STDERR, ":encoding($charset)";
# TODO: pod
# concatenate multiple workouts
my $itype;
my $otype;
my $opt_verbose;
my $debug;
my $needhelp;
my $wanthelp;
if( ! GetOptions(
"debug!" => \$debug,
"help!" => \$wanthelp,
"itype=s" => \$itype,
"otype=s" => \$otype,
"verbose|v!" => \$opt_verbose,
)){
$needhelp++;
}
if( $wanthelp ){
print <<EOF;
$0 [opt] <output file> <intput file1> ...
concatenate workout files of same type.
Input files must not overlap. They're ordered by time automatically. All
files have to use the same type and recording intervall as the first
specified input file. Meta information (Note, Slope, ...) is taken from
the last input file.
Options:
--itype=<type> input file type
--otype=<type> output file type
--debug enable debuging output
--help this help
EOF
exit 0;
}
if( @ARGV <= 2 ){
print STDERR "in- and output filename required\n";
$needhelp++;
}
if( $needhelp ){
print STDERR "use --help for usage info\n";
exit 1;
}
my $ofname = shift;
my @sources;
foreach my $fname ( @ARGV ){
$opt_verbose && print "reading ", $fname,"... \n";
push @sources, Workout::file_read( $fname, {
ftype => $itype,
debug => $debug,
});
}
$otype ||= Workout::file_type_name( $ofname );
$otype ||= ($sources[0]->filetypes)[0];
my $recint = $sources[0]->recint;
my $dst = Workout::file_new( {
ftype => $otype,
recint => $recint,
debug => $debug,
});
if( $recint && ! $dst->cap_block ){
my $mod = $sources[0]->time_start % $recint;
foreach my $in ( @sources ){
if( $mod != ( $in->time_start % $recint ) ){
print STDERR "block start time doesn't fit n*recint: ",
$in->time_start, "\n";
exit 1;
}
}
}
my @sorted = sort {
$a->time_start <=> $b->time_start;
} @sources;
my $iter = Workout::filter('Concat', shift @sorted, {
debug => $debug,
sources => \@sorted,
});
$iter = Workout::filter('Join', $iter, {
debug => $debug,
recint => $recint,
}) if ! $dst->cap_block;
$dst->from( $iter );
$opt_verbose && print "writing ", $ofname ,"... \n";
$dst->meta_prune;
$dst->write( $ofname );