#!/usr/local/bin/perl


my $old = shift @ARGV;
my $new = shift @ARGV;

	open IN, $old or die "Can't read source file $old: $!\n";
	open OUT, "> $new" or die "Can't write to file $new: $!\n";

	my ($opens, $shorts, $noisy);
	my @oldlines=<IN>;
	my $tally = 0;
	
	$oldlines[0] =~s///g;
	$old =~s/_report.txt/_pulser.000\n/g;

	open INN, $old or die "Can't read source file $old: $!\n";
	
	my @olderlines=<INN>;
	foreach(@olderlines){$_=~s///g;
			++$tally};

	print OUT $oldlines[0];
	
 	my $search = "@oldlines";

	$search =~ m/(The detected opens are:)/g;
	$o2 = pos($search);

	$search =~ m/(The detected shorts are:)/g;
	$s2=pos($search);
	$s1= $s2 -length($1);

	$search =~ m/(Channels with too much or too little noise:)/g;
	$p2=pos($search);
	$p1= $p2 - length($1);

	$search =~ EOF;
	$n2=pos($search);
	$n1= $n2 - length($1);

	$opens = substr($search, $o2, $s1-$o2);
	$shorts = substr($search, $s2, $p1-$s2);
	$noisy = substr($search, $p2, $n2);

	$opens=~s///g;
	$shorts=~s///g;
	$noisy=~s///g;

		print OUT "opens:";
			if(length($opens)==2){
				print OUT "\nnull\n";
			}
			else{
				print OUT $opens;
			}	
		print OUT "shorts:";
			if(length($shorts)==2){
				print OUT "\nnull\n";
			}
		else{
				print OUT $shorts;
			}
		if ($n1==$n2){print OUT "noisy:\nnull\n";}
			else{print OUT "noisy:$noisy";}
		if ($tally<513){print OUT "4_Chip\n";}
			else{print OUT "6_Chip\n";}


		foreach (@olderlines){$a=substr($_,0,-2);
			print OUT "$a\n";
};
close OUT;











 


