#!/bin/sh

# submit jobs to the que with this script using the following command:
# qsub -N jobname -v in=name rng16_66
# rng16_66 is this script
# jobname is a name you will see in the qstat command
# name is the actual file minus .com etc it is passed into this script as ${in}

# batch processing commands
#PBS -l walltime=119:59:00
#PBS -lselect=1:ncpus=20:mem=100000MB
#PBS -j oe
#PBS -q pqph

# load modules
#
  module load gaussian/g16-c01-avx
#
# check for a checkpoint file
# variable PBS_O_WORKDIR=directory from which the job was sumbited.
   test -r $PBS_O_WORKDIR/${in}.chk
   if [ $? -eq 0 ]
   then
     echo "located $PBS_O_WORKDIR/${in}.chk"
     cp $PBS_O_WORKDIR/${in}.chk $EPHEMERAL/.
   else
     echo "no checkpoint file $PBS_O_WORKDIR/${in}.chk"
   fi   
#
# run gaussian
#
  cd $EPHEMERAL
  g09 $PBS_O_WORKDIR/${in}.com
#
# job has ended copy back the checkpoint file
# check to see if there are other external files like .wfn or .mos and copy these as well
#
  cp $EPHEMERAL/${in}.chk /$PBS_O_WORKDIR/.
  cp $EPHEMERAL/${in}.log /$PBS_O_WORKDIR/.
  test -r $EPHEMERAL/${in}.wfn
  if [ $? -eq 0 ]
  then
    cp $EPHEMERAL/${in}.wfn /$PBS_O_WORKDIR/${in}.wfn
  fi
  test -r $EPHEMERAL/fort.7
  if [ $? -eq 0 ]
  then
    cp $EPHEMERAL/fort.7 /$PBS_O_WORKDIR/${in}.mos
  fi
# exit
