#!/usr/athena/bin/perl

while(<>){
    chop;
    if($_ > 0){
	$nstate =1;
    }
    else{
	$nstate =0;
    }
    if($nstate == $state){
	$ct++;
    }
    else{
#	print "Switch $state -> $nstate\n";
	$bits = int(($ct+2)/10);
	$bigbits .= $state x $bits;
	if(($ct%10 > 3) && ($ct%10 <8)){
#	    print "-----------> $bits ($ct) $state 's\n";
	}
#	print "$bits ($ct) $state 's ($nstate)\n";
	$ct=1;
    }
    $state = $nstate;
    &process if(length($bigbits > 4000));
}
&process;

sub process {

@ary = split(//, $bigbits);
#print $bigbits;
for ($x=$leftoff;$x< ($#ary-10);$x++) {
#    print "\n$x\n";
    if($ary[$x] eq "1" && $ary[$x+9] eq "0"){
	$bword = $ary[$x+1].$ary[$x+2].$ary[$x+3].$ary[$x+4].$ary[$x+5].$ary[$x+6].$ary[$x+7].$ary[$x+8];
	$bword =~ s/1/x/g;
	$bword =~ s/0/1/g;
	$bword =~ s/x/0/g;
#	print "$ary[$x] $bword ", $ary[$x+9], "\n";
	$x = $x+9;
	print pack("b*", $bword);
    }

}
$bigbits = substr($bigbits,$x);
}
