#!/usr/bin/perl -w

$curdir = "D:/data/TreeTests.BayesFactor/cdp12";
for($i=1;$i<10;$i++){# directories 01 to 09 (inclusive)
	chdir "$curdir/0$i/" || die "can't cd to $curdir/0$i/: $!";
	print "\nNow doing Tree 0$i:\n";
	open(LOGFILE,"d_alpha.out") || die "\ncould not open $curdir/0$i/ infile... $!\n";
	open(DATAFILE,">$curdir/data0$i.txt") || die "\ncould not open $curdir/0$i/ outfile... $!\n";
	while(<LOGFILE>){
		chomp;
		($idx,$loglkl,$rest) = split(/	/);
		if($loglkl<0){ # this is to get rid of the 1st line (headers)
			print DATAFILE "$loglkl\n";
		}
	}
}
for($i=0;$i<6;$i++){# directories 10 to 15 (inclusive)
	chdir "$curdir/1$i/" || die "can't cd to $curdir/1$i/: $!";
	print "\nNow doing Tree 1$i:\n";
	open(LOGFILE,"d_alpha.out") || die "\ncould not open $curdir/0$i/ infile... $!\n";
	open(DATAFILE,">$curdir/data1$i.txt") || die "\ncould not open $curdir/0$i/ outfile... $!\n";
	while(<LOGFILE>){
		chomp;
		($idx,$loglkl,$rest) = split(/	/);
		if($loglkl<0){ print DATAFILE "$loglkl\n";}
	}
}
print "\a\n\nNormal end of script!\n\n";
