#!/usr/bin/perl

#   This is for execution on IBM Blue Gene, using mpirun as kickoff.
#   It is clearly just a template file, to get you started...

# Path to binary. Change as appropriate
$binary="/FS/gamess/gamess.old-01.x";

# Path to bg/l mpirun. Change as appropriate
$mpirun="/bgl/BlueLight/ppcfloor/bglsys/bin/mpirun";

$cpucount=$ARGV[1];
if ($cpucount == "")
{
	$cpucount = "32";
}
# Options to pass to mpirun such as shape and number of processors or partition information
#$mpirun_opts="-shape 8x8x8 -connect torus";
#$mpirun_opts="-np 32 -partition R000_J104_32";
$mpirun_opts="-np $cpucount -partition R000_J104_32";

# Path to store input files and output files. 
# Keep the pathnames short since there is a 1024 character environment limit.
$runpath="/FS/scratch/";

### End of things to be changed ###

$input=$ARGV[0];
if($input eq "")
{
	print "You must specify an input file. For example to use 'exam01.inp', specify exam01\n";
	exit(1);
}
system("rm -f $runpath/$input.*");
if(-e "$input.inp")
{
   system("cp $input.inp $runpath/$input.F05");
}
if(!(-e "$runpath/$input.F05"))
{
   if(!(-e "$runpath/$input.inp"))
   {
      print "Couldn't find $runpath/$input.F05 or $runpath/$input.inp\n";
      exit;
   }
   system("cp $runpath/$input.inp $runpath/$input.F05");
}

# make sure no old run files are still around.
system("rm -f $runpath/$input.dat");
system("rm -f $runpath/$input.F08*");
system("rm -f $runpath/$input.F10");
#
# add -verbose 4 for lots debugging output
#
$string="$mpirun $mpirun_opts -exe $binary -cwd $runpath -env \"ERICFMT=$runpath/ericfmt.dat ORDINT=$runpath/$input.F24 EFPIND=$runpath/$input.F24 SOINTY=$runpath/$input.F32 SOINTZ=$runpath/$input.F33 SOINTX=$runpath/$input.F31 IRCDATA=$runpath/$input.irc CSFSAVE=$runpath/$input.F17 INPUT=$runpath/$input.F05 PUNCH=$runpath/$input.dat AOINTS=$runpath/$input.F08 MOINTS=$runpath/$input.F09 DICTNRY=$runpath/$input.F10 DRTFILE=$runpath/$input.F11 CIVECTR=$runpath/$input.F12 CASINTS=$runpath/$input.F13 JKFILE=$runpath/$input.F23 DAFL30=$runpath/$input.F30 CIINTS=$runpath/$input.F14 FOCKDER=$runpath/$input.F18 DASORT=$runpath/$input.F20 WORK15=$runpath/$input.F15 SOCCDAT=$runpath/$input.F40 WORK16=$runpath/$input.F16\"";
print "Executing: $string\n";
print "String is ".length($string)." chars\n";
system($string);

