#コミュニケーション回数（出次数，入次数など）を計算するプログラム

$filename = "output20061208.net";


&countAll();
exit;


sub countAll() {
	my %countFrom;		#出次数
	my %countTo;		#入次数
	my %countAll;		#次数
	
	open LOG, "$filename" or die "file open error : $filename.";
		while($line = <LOG>) {
			chomp $line;
			if($line eq "*Arcs") {
				last;
			}
		}
		
		while($line = <LOG>) {
			chomp $line;
			my($from, $to, $num) = split / /, $line;
			$countFrom{$from} += $num;
			$countTo{$to} += $num;
			$countAll{$from} += $num;
			$countAll{$to} += $num;
		}
	close LOG;
	
	open FROM, ">countFrom_$filename.txt" or die "file open error : countFrom_$filename.txt";
	foreach $no (sort {$countFrom{$b} <=> $countFrom{$a}} keys %countFrom)  {
    	print FROM "$no\t$countFrom{$no}\n";
	}
	close FROM;
	
	open TO, ">countTo_$filename.txt" or die "file open error : countTo_$filename.txt";
	foreach $no (sort {$countTo{$b} <=> $countTo{$a}} keys %countTo)  {
    	print TO "$no\t$countTo{$no}\n";
	}
	close TO;
	
	open ALL, ">countAll_$filename.txt" or die "file open error : countAll_$filename.txt";
	foreach $no (sort {$countAll{$b} <=> $countAll{$a}} keys %countAll)  {
    	print ALL "$no\t$countAll{$no}\n";
	}
	close ALL;
	
}


