#!/pkg/bin/perl -w

$infile = "$ARGV[0]";
open IN, $infile;
close(IN);

$infile =~ m/data(.*)\.txt/;
$i = 1;

$goutprefix = "$ARGV[1]";
chomp ($goutprefix);

$goutfile = $goutprefix . '.' . $i;
open (OUTG, ">$goutfile");


open (OUTTI, '>title');

$eo2 = 0;
$nhom = 0;

$infile = "$ARGV[0]";
open IN, $infile;

while(<IN>) {
	$line = $_;
	chomp $line;
	
	if($eo2 == 0) {
		#$title = $line;
		print OUTTI "1\n";	
		$eo2 = 1;
	} else {	
		if ($line =~ /^[012]+$/) {
			$genoline = "";
			$linelength = length($line);
     						
     			@arr1 =  split(//, $line);
     			
			for ($j = 0; $j < $linelength; $j++) {
				$genoline = $genoline . "$arr1[$j] "; 
			}
			$homarray[$nhom++] = $genoline;
			$eo2 = 0; 		
		} 
	}
}
close(IN);

print OUTG "$nhom $linelength\n";
$j = 0;
until ($j == $nhom) {
	print OUTG "$homarray[$j]\n";
	$j++;
}

close (OUTG);
close (OUTTI);