#!/usr/athena/bin/perl

open (FI, "$ARGV[0]");
				# 
if($#ARGV > 0) {		# 
    if($ARGV[1]=~/av/) {
	$avgmode = 1;
    }
    if ($ARGV[1]=~/tal/) {
	$tally = 1;
}# 
    if ($ARGV[1]=~/cal/) {
	$cal = 1;
	}
}				# 
# 
while (<FI>) {
    if(/\d+\s/) {
	if($tally) {
	    split;
	    foreach $t (@_) {
		$tots[$t]++;
		if($tots[$t] > $max) {$max =$tots[$t]; }
		if($t > $mh) {$mh = $t;}
	    }
	}
	else {
	($hour, $amount) = split;
	if($avgmode) {	# 
	    $tots[$hour] = ($nt[$hour]*$tots[$hour])+$amount;
	    $nt[$hour]++;	# 
	    $tots[$hour] = $tots[$hour] / $nt[$hour]; 
	}			# 
	else {		# 
	    $tots[$hour] = $tots[$hour] + $amount; 
	}			# 
	print"$amount.";	# 
	$gtot = $gtot + $amount;
	if($tots[$hour] > $max){ $max = $tots[$hour];}
	if($hour>$mh) { $mh = $hour;} # 
    }
    }	
    
}
$scale = 70/$max;
print "\n\n\n";		# 
foreach $h (0..$mh) {	# 
$val = int($tots[$h]);
if($val > 0){
    print"$h";		# 
    $long = $tots[$h] * $scale;
    $length = int $long;
    if($h<10){print"  ";}
	else{print" ";}
    print "-" x $length;
    $val = int($tots[$h]);
    print " $val%";
    print "\n";
}
}				# 

    
