# Cluster Batch Script
#PBS -N columbus
#PBS -j oe 
#PBS -m ae
#PBS -M srb@osc.edu
#PBS -l cput=159:55:00
#PBS -l walltime=159:56:00
#PBS -l nodes=1:ppn=1
##PBS -l mem=64Mw
# default mem is 490Mb
#PBS -S /bin/sh
#
# Perform argos, cidrt, tran, ciuft, cisrt, ciudg.
# $INPUT contains argosin, cidrtky, mocoef, cisrtin, ciudgin.
# Copy argosls, cidrtls, tranls, ciuftls, cisrtls, ciudgls, civout, civfl
# to $OUTPUT.
#
# adjustable parameters:
# MEMSIZE = workspace memory size; the argument to each programs -m option.
# EXECUTABLES = path of the Columbus programs.
# INPUT = path of the input files.
# RESULT = subdirectory name for this calculation.
# OUTPUT = $INPUT/$RESULT = path of the output files.
# TMP = working directory; use $TMPDIR because batch queue handles cleanup.
#
set -xv
pwd
#set
MEMSIZE=56000000
# 56000000 -> 224Mb in top
#
#EXECUTABLES=$COLUMBUS
EXECUTABLES=/usr/local/Columbus/current
INPUT=$HOME/ciinput
RESULT=bigci
if [ ! -d $INPUT/$RESULT ]; then mkdir $INPUT/$RESULT; fi
OUTPUT=$INPUT/$RESULT
TMP=$TMPDIR
cd $TMP
mkdir $RESULT
cd $RESULT
if [ -f argos.aoints ]
then
   mv argos.aoints aoints
   mv argos.aoints2 aoints2
else
   if  [ -f $INPUT/aoints ]
   then
      cp $INPUT/aoints .
      cp $INPUT/aoints2 .
   else
      cp $INPUT/argosin .
      $EXECUTABLES/argos.x -m $MEMSIZE
      cp argosls $OUTPUT
   fi
fi
if [ ! -f aoints ]; then exit 19; fi
#
# no cnvrt
#
# no scfpq
#
# no mcscf
#
cp $INPUT/cidrtky cidrtin
$EXECUTABLES/cidrt.x -m $MEMSIZE cidrtls
exit_status=$?
cp cidrtls $OUTPUT
if [ $exit_status -ne 0 ]
then
   ls -ls 1>&2
   date
   exit 3
fi
#
if [ ! -f mocoef ]
then
   cp $INPUT/mocoef mocoef
fi
# use cidrtfl for tran input
$EXECUTABLES/tran.x -m $MEMSIZE
exit_status=$?
cp tranls $OUTPUT
mv aoints argos.aoints
mv aoints2 argos.aoints2
if [ $exit_status -ne 0 ]
then
   ls -ls 1>&2
   date
   exit 4
fi
#
$EXECUTABLES/ciuft.x -m $MEMSIZE
exit_status=$?
cp ciuftls $OUTPUT
if [ $exit_status -ne 0 ]
then
   ls -ls 1>&2
   date
   exit 5
fi
#
cp $INPUT/cisrtin cisrtin
$EXECUTABLES/cisrt.x -m $MEMSIZE
exit_status=$?
cp cisrtls $OUTPUT
if [ $exit_status -ne 0 ]
then
   ls -ls 1>&2
   date
   exit 6
fi
#
cp $INPUT/civout .
cp $INPUT/civfl .
cp $INPUT/ciudgin ciudgin
ls -ls 1>&2
df
# copy ciudg.x to avoid potential network problems for long running jobs.
cp $EXECUTABLES/ciudg.x .
./ciudg.x -m $MEMSIZE
exit_status=$?
cp ciudgls $OUTPUT
cp civout $OUTPUT
cp civfl $OUTPUT
if [ $exit_status -ne 0 ]
then
   ls -ls 1>&2
   date
   exit 7
fi
#
# cleanup
#
# $TMPDIR is automatically removed by the batch queue
ls -ls 1>&2
date
df