
if ( "$TARGETHOST" == "none" ) then
   set TARGETHOST="fca041"
endif

if ( "$TARGETPREP" == "none" ) then
   set TARGETPREP="module purge; module load openmpi-ppc; module list"
endif

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

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

mv openggcm $RUN.exe

PPN=2
NODES=\$(( ($TOTNODES + \$PPN - 1) / \$PPN))

cat > $RUN.qsub <<XEOF
#! /bin/bash
#PBS -l nodes=\$NODES:ppn=\$PPN:compute
#PBS -l walltime=$RUNTIME

cd \$PWD

export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib64
export GFORTRAN_UNBUFFERED_ALL=1
/usr/lib64/openmpi/bin/mpirun ./$RUN.exe &> $RUN.log

XEOF

echo You can now submit the job with 
echo "cd \$PWD && qsub $RUN.qsub"
EOF
