#!/usr/bin/perl -w
#compare_NGD.pl

#################################################################
#### in_file's textform :                                     ###
####           "n val"                                        ###
####           "A NGD_AA NGD_AB ///"                          ### 
####           "B NGD_BA NGD_BB ///"                          ### 
####                      ///                                 ###
#################################################################

####################################
### insert in_file's information ###
####################################

open(G,"out_r_for_g.txt");
#open(G,"sample_g.txt");

while(<G>){
    @s = <G>;
}

$n = 0;
$i = 0;
foreach $line(@s){
    chomp($line);
    @str = split(/\s/,$line,);

#    print"$str[0] $str[1]\n";

    if($n == 0){
	$n = $str[1];     # n : number of word
    }else{
	for($j=0;$j<=$n;$j++){
	    $g_matrix[$i][$j] = $str[$j];
	}
	$i++;
    }
}

open(Y,"out_r_for_y.txt");
#open(Y,"sample_y.txt");

while(<Y>){
    @s = <Y>;
}

$n = 0;
$i = 0;
foreach $line(@s){
    chomp($line);
    @str = split(/\s/,$line,);
    if($n == 0){
	$n = $str[1];     # n : number of word
    }else{
	for($j=0;$j<=$n;$j++){
	    $y_matrix[$i][$j] = $str[$j];
	}
	$i++;
    }
}

#print"x_NGD_matrix\n";
#for($i=0;$i<$n;$i++){
#    for($j=0;$j<=$n;$j++){
#	print sprintf("%6s ",$x_matrix[$i][$j]);
#    }
#    print"\n";
#}
#print"y_NGD_matrix\n";
#for($i=0;$i<$n;$i++){
#    for($j=0;$j<=$n;$j++){
#	print sprintf("%6s ",$y_matrix[$i][$j]);
#    }
#    print"\n";
#}



$g_val =0;
$y_val =0;

for($i=0;$i<$n;$i++){
    for($j=0;$j<=$n;$j++){
	if($j==0){
	    $new_matrix[$i][$j] = $g_matrix[$i][$j];
	}else{
	    if($y_matrix[$i][$j]==0){
		if($g_matrix[$i][$j]==0){
		    $new_matrix[$i][$j] = 0;
		}else{
		    $new_matrix[$i][$j] = -1;
		}
	    }else{
		$tmp1 = $g_matrix[$i][$j] / $y_matrix[$i][$j];
		$tmp2 = $y_matrix[$i][$j] / $g_matrix[$i][$j];
		$y_val += $tmp1; 
#		$new_matrix[$i][$j] = $tmp1 - 1;
#		    print"y_point:$tmp1-1\n";
		$g_val += $tmp2;
#		$new_matrix[$i][$j] = $tmp2 - 1;
#		    print"g_point:$tmp2-1\n";
		
#		    if($tmp2 > 10){
#			printf"$g_matrix[$i][$j]:$y_matrix[$i][$j]::$tmp2\n";
#		    }
		
		
	    }
	}
    }
}


#print "NGD comparison\n";
#for($i=0;$i<$n;$i++){
#    for($j=0;$j<=$n;$j++){
#	if($j==0){
#	    print sprintf("%5s ",$new_matrix[$i][$j]);
#	}else{
#	    print sprintf("%1.4f ",$new_matrix[$i][$j]);
#	}
#    }
#    print"\n";
#}

print"sum_g_val:$g_val\n";
print"sum_y_val:$y_val\n";
