#!/usr/local/bin/perl -w

my $usage = "Usage: $0 runid [execdir [datadir [testdir]]]\n" .
  "  runid\t\tID of current run (e.g. 085)\n" .
  "  execdir\tDirectory in which executables reside (default curdir/exec)\n" .
  "  datadir\tDirectory in which data resides (default curdir/data)\n" .
  "  testdir\tDirectory in which test.main resides (default curdir/data)\n\n";

my $runid = shift or die $usage;
die $usage if $runid eq '-h';
chomp(my $pwd = `pwd`);
my $execpath = shift || "$pwd/exec/";
my $datapath = shift || "$pwd/data/";
my $testpath = shift || "$pwd/data/";
print STDERR $execpath, "\n", $datapath, "\n", $testpath, "\n";

die "Can't find executable funcTest in $execpath, aborting" 
	if !-e "$execpath/funcTest";
die "Can't find data directory $datapath, aborting" 
	if !-d $datapath;
die "Can't find data directory $testpath, aborting" 
	if !-d $testpath;
mkdir "$datapath/PStatInfo"
	if !-d "$datapath/PStatInfo";

print STDERR "Making run $runid\n";

my $inputfile = (qw(test.main test.main-map test.main-edges test.main-dup
			test.final test.final-map test.final-edges
			test.final-dup))[0];

system ("time $execpath/funcTest $datapath $testpath$inputfile > ${testpath}res$runid.output");

rename "$datapath/PStatInfo/pStat.txt", "$testpath/res$runid";
rename "$datapath/funcerr.txt", "$testpath/res$runid.errs.txt";
