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

if ( "$TARGETPREP" == "none" ) then
   set TARGETPREP="module purge; module load gmp/4.2.4 mpfr/2.3.2 gcc/4.3.2 openmpi/1.4.2/gcc-4.3.2 phdf5/1.8.1; module list"
endif

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

if ( "$MPIF77_FLAGS" == "none" ) then
   set MPIF77_FLAGS="-g -O3 -ffast-math"
endif

if ( "$MPIF90_FLAGS" == "none" ) then
   set MPIF90_FLAGS="-g -O3 -ffast-math"
endif

if ( "$MPICC_FLAGS" == "none" ) then
   set MPICC_FLAGS="-g -O3 -ffast-math"
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:myri
#PBS -l walltime=$RUNTIME

cd \$PWD

export GFORTRAN_UNBUFFERED_ALL=1
mpirun ./$RUN.exe >$RUN.log 2>&1

XEOF

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