#!/usr/bin/perl

# prefilter.pl
# Do some preprocessing to remove non-numeric values, and data outliers.

# 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;
$LastGood = 0.0;
$PreviousValue = 0.0;
$First = 1;

while ($Value=<STDIN>) {
	chomp($Value);
	if ($First) {
		$LastGood = $Value;
		$First = 0;
		}
	$tmp1 = abs($Value - $LastGood);
	if ($tmp1 > 0.4) {
		print "Bad reading: ",$Value," (LastGood: $LastGood)\n";
		}
	else {
		print $Value,"\n";
		$LastGood = $Value;
	};
}

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