#!/bin/perl

open (GOOD, "< usedrun_805days.out");

$livetime = 0;
while (<GOOD>) {
    @line = split;

    $key = "$line[0]-$line[1]";
    $totallive = $line[2] - $line[3];
    $run{$key} = $totallive;
}

close GOOD;
    
foreach $i (</net/sukul1/atmpd1/fdufour/log/event/pcevent_2_4_024*.log>) {
    open (FILE, "< $i");
    while (<FILE>) {
	$run = substr($_, 8, 8) + 0;
	$sub = substr($_, 16, 8) + 0;
	$key = "$run-$sub";
    
	if ($run{$key} > 0) {
	    $num{$key}++;
#	    print "$key $run{$key} $num{$key}\n";
	}
    }
    close FILE;
}

open (GOOD, "< usedrun_805days.out");

$livetime = 0;
while (<GOOD>) {
    @line = split;

    $key = "$line[0]-$line[1]";
    $liveday = $run{$key} / 86400;

    print " $line[0] $line[1] $liveday $num{$key}\n";
}

close GOOD;
