#!/usr/bin/perl # 10us-wrap.pl # Filter a series of data values and scale to keep in a 0 - 10 range. # Algorithm shamelessly stolen from Tom Van Baak (tvb@leapsecond.com) # 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; $PreviousValue = 5.0; $Base = 0.0; $OutVal = 0.0; while ($reading=) { $Value = round($reading * 100)/100; if ($PreviousValue > 6.0 && $Value < 2.0) { $Base = $Base + 10.0; } elsif ($PreviousValue < 2.0 && $Value > 6.0) { $Base = $Base - 10.0; } endif; $PreviousValue = $Value; $OutVal = $Value + $Base; print($OutVal,"\n"); }; sub round { my($number) = shift; return int($number +.5 * ($number <=> 0) ); };