#!/usr/local/bin/perl -w

open (SHELLNUMS, "thirdCAshell.txt")||die "could not open num file";
open (SHELLDATA, "shellpercentreport.txt")||die "couldnt open %data";
open (RESULT, ">windowdata.txt")|| die "couldn't create result";


while (<SHELLNUMS>){
	$targetshellnum=$_;
	print $_;
	if (/\d+.*/){
	    print "in if";
	    #print $targetshellnum;
	    $_=<SHELLDATA>;

	    #print $_;
	    /(.*?)\s+-1\s+(.*)/;
	    #print $1;
	    @shelldata=split(/\t/,$2);

	    $startpadding=0;
	    $endpadding=0;

	    $start=$targetshellnum-3;
	    if ($start<0){
		$startpadding=-1*$start;
		$start=0;}

	    $end=$targetshellnum+3; 
	    if ($end>$#shelldata) {
		$endpadding=$end-$#shelldata;
		$end=$#shelldata;}

	    print RESULT $1."\t";

	    #print start padding too keep windows aligned
	    #use a different invalid value to keep seperate from null data 	
	    for ($index=0;$index<$startpadding;$index++){
		print RESULT "-2\t";
	    }

	    for ($index=$start;$index<=$end;$index++){
		print RESULT $shelldata[$index]."\t";
	    }
	    print RESULT "\n";
	} #end if this number line has data
	    else{
		# go past this entryt if it's a blank line
		<SHELLDATA>;
	    }
}

close SHELLNUMS;
close SHELLDATA;
close RESULT;
