#引数の番号の人の次数推移を表示するプログラム

#ファイル名一覧を書いたファイル
$filename = "degreecount.txt";


if($#ARGV < 0) {
	print "need more arguments : @ARGV\n";
}

&transform();
exit;


sub transform() {
	my $countFrom;		#出次数
	my $countTo;		#入次数
	my $countAll;		#次数
	
	open LIST, "$filename" or die "file open error : $filename.";
		@list = <LIST>;
	close LIST;
	
	print "Date\tOut-deg\tIn-deg\tAll-deg\n";
	
	foreach $file (@list) {
		$countFrom = 0;
		$countTo = 0;
		$countAll = 0;
		
		chomp $file;
		open LOG, "$file" or die "file open error : $file.";
			while($line = <LOG>) {
				chomp $line;
				if($line =~ /^\*Arcs/) {
					last;
				}
			}
			
			while($line = <LOG>) {
				chomp $line;
				my($from, $to, $num) = split / /, $line;
				if($from == $ARGV[0]) {
					$countFrom += $num;
					$countAll += $num;
				}
				if($to == $ARGV[0]) {
					$countTo += $num;
					$countAll += $num;
				}
			}
			$file =~ s/(\d{6,6}).*/$1/g;
			print "$file\t$countFrom\t$countTo\t$countAll\n";
		close LOG;
	}
	
}


