if ( "$TARGETHOST" == "none" ) then
  set TARGETHOST="plasma.unh.edu"
endif

if ( "$TARGETPREP" == "none" ) then
  set TARGETPREP=" module load hdf5; module list"
endif

if ( "$RUNTIME" == "none" ) then
  set RUNTIME="24:00:00"
endif

if ( "$MPIF77" == "mpif77" ) then
   set MPIF77="mpif77"
endif

if ( "$MPIF77_FLAGS" == "none" ) then
  set MPIF77_FLAGS="-g -O2"
endif

if ( "$MPIF90" == "mpif90" ) then
   set MPIF90="mpif90"
endif

if ( "$MPIF90_FLAGS" == "none" ) then
  set MPIF90_FLAGS="-g -O2"
endif

if ( "$MPICC" == "mpicc" ) then
   set MPICC="mpicc"
endif

if ( "$MPICC_FLAGS" == "none" ) then
  set MPICC_FLAGS="-g -O2"
endif

if ( "$MPICXX" == "mpicxx" ) then
   set MPICXX="mpicxx"
endif

if ( "$MPICXX_FLAGS" == "none" ) then
  set MPICXX_FLAGS="-g -O2"
endif

cat >> tmp.submit << EOF
echo === Preparing batch file for run $RUN on $TOTNODES cores.
echo === Location: \$USER@`hostname -f`:\$PWD

PPN=128
NODES=\$(( ($TOTNODES + \$PPN - 1) / \$PPN))
CORES=\$(( \$NODES * \$PPN ))

mv openggcm $RUN.exe

cat > $RUN.sbatch <<XEOF
#! /bin/bash
#SBATCH --ntasks \$TOTNODES
#SBATCH --time=$RUNTIME

cd \$PWD

export GFORTRAN_UNBUFFERED_ALL=1
export TMPDIR=\$HOME/tmp
mpirun -np $TOTNODES ./$RUN.exe &> $RUN.log

XEOF

echo === Submitting job $RUN.sbatch
cd \$PWD && sbatch $RUN.sbatch
EOF

