#!/usr/bin/perl -w

foreach $l(`find ../results -name '*.log'`) {
    chomp $l;
    $t = $l;
    $t =~ s/.log$/.txt/;
    system("./mdfconv $l > $t");

    my %hist = ();
    open(my $fh, '<', $t);
    while (<$fh>) {
	next if /^#/;
	chomp;
	@l1 = split / /, $_;
	$_ = <$fh>;
	chomp;
	@l2 = split / /, $_;

	$time10us = $l2[14]-$l1[14];
# 	if (exists $hist{$time10us}) {
	    $hist{$time10us} += 1;
# 	} else {
# 	    $hist{$time10us} = 1;
# 	}
    }
    $cum = 0;
    foreach $t(reverse(sort {$a <=> $b} keys(%hist))) {
	$cum += $hist{$t};
	$hist{$t} = $cum;
    }

    $h=$t;
    $h =~ s/.txt$/-hist.txt/;
    open(my $fhout, '>', $h);
    print "$h\n";
    foreach $t(sort {$a <=> $b} keys(%hist)) {
	printf $fhout "%g %d\n", $t/100.0, $hist{$t};
    }
}
exit 0
