#!/usr/bin/perl

# average.pl
# Read STDIN and output average of each X samples to STDOUT

# Copyright 2001 John Ackermann   Version: 15 July 2001
# May be freely used provided these notices are retained, and a copy
# of any modified version that's distributed to third persons is sent
# to jra@febo.com

$Value = 0.0;
$SumOfValues = 0.0;
$Counter = 0;
$SamplesToAverage = 100;

while ($reading=<STDIN>) {
	$Counter = $Counter + 1;
	$Value = $reading;
	$SumOfValues = $SumOfValues + $Value;
	if ($Counter == $SamplesToAverage) {
		print $SumOfValues/$SamplesToAverage,"\n";
		$Counter = 0;
		$SumOfValues = 0;
	}
	endif;	
};

sub round {
	my($number) = shift;
	return int($number +.5 * ($number <=> 0) );
	};
