#!perl/

use File::Copy;
use File::Path;
use Getopt::Long;

my $tag;
GetOptions ( 'tag=s' => \$tag );


print "ClusterMangle 1.0: Run a tgz collection of VECT files through mangle.\n";

unless (defined $tag) {

    die("Needs option --tag=\"tag\" to identify runs\n");

}

print "Removing old ~/Jason/unfinished\n\t".`rm -fr ~/Jason/unfinished*`."\n";

print "./data/unfinished.tar.gz -> ~/Jason/unfinished.tgz\n";

copy("./data/unfinished.tar.gz","/home/us/Jason/unfinished.tgz") or die("Couldn't copy");

print "Expanding unfinished...\n";

chdir("/home/us/Jason/");

`tar -xzf unfinished.tgz`;

unless (-d "/home/us/Jason/unfinished/") { die("Couldn't untar /home/us/Jason/unfinished.\n"); }

chdir("/home/us/Jason/unfinished") or die("Couldn't chdir to unfinished.\n");

print "Loading perl scripts into unfinished.\n";

`cp /home/us/Jason/prl/* /home/us/Jason/unfinished/`;

unless (-f "/home/us/Jason/unfinished/setupMangleRun.pl") { die("Couldn't move pl scripts."); }

print "Setting up mangle run with tag $tag...\n";

`perl setupMangleRun.pl --tag=$tag`;

print "Generating condor files...\n";

`perl generateMangleCondorFiles.prl`;

print "Submitting condor files...\n";

`perl submitCondorFiles.prl`;

print "Done!\n";
    

