~ubuntu-branches/ubuntu/quantal/ceph/quantal

« back to all changes in this revision

Viewing changes to src/script/smooth.pl

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-07-16 09:56:24 UTC
  • mfrom: (0.3.11)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: package-import@ubuntu.com-20120716095624-azr2w4hbhei1rxmx
Tags: upstream-0.48
ImportĀ upstreamĀ versionĀ 0.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
my $n = shift @ARGV || 2;
 
4
 
 
5
my %v;  # t -> [..]
 
6
while (<>) {
 
7
    chomp;
 
8
    my @l = split(/\t/,$_);
 
9
    my $t = shift @l;
 
10
    if (int $t) {
 
11
        $v{$t} = \@l;
 
12
    } else {
 
13
        print "$_\n";
 
14
    }
 
15
}
 
16
 
 
17
for my $t (sort {$a <=> $b} keys %v) {
 
18
    my $s = $t - $n/2;
 
19
    my @v;
 
20
    my $c = 0;
 
21
    for (my $a=0; $a < $n; $a++) {
 
22
        my $x = $t + $a;
 
23
        next unless ($v{$x});
 
24
        my @o = @{$v{$x}};
 
25
        #print "$t: $x o @o\n";
 
26
        if (@v) {
 
27
            for (my $y=0; $y<=$#o; $y++) {
 
28
                $v[$y] += $o[$y];
 
29
            }
 
30
        } else {
 
31
            @v = @o;
 
32
        }
 
33
        #print "$t: $x v @v\n";
 
34
        $c++;
 
35
    }
 
36
    print "$t";
 
37
    for my $sum (@v) {
 
38
        print "\t" . ($sum / $c);
 
39
    }
 
40
    print "\n";    
 
41
}