
#.... JR 2011-04-30;  target for RANGER
set XHOME=/share/home/00461

if ( "$TARGETHOST" == "none" ) then
   set TARGETHOST="tg457370\@login4.ranger.tacc.utexas.edu"
endif

if ( "$TARGETPREP" == "none" ) then
   set TARGETPREP="GFORTRAN_UNBUFFERED_PRECONNECTED=y ; export GFORTRAN_UNBUFFERED_PRECONNECTED; module load autotools/1.0; module load gcc/4.4.1; module swap mvapich mvapich2 "
endif

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

if ( "$MPIF77_FLAGS" == "none" ) then
   set MPIF77_FLAGS=" -O3 -v -w -mcmodel=medium  "
endif

if ( "$MPIF90_FLAGS" == "none" ) then
   set MPIF90_FLAGS="-g -O  -mcmodel=medium  "
endif

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

set CORES=`echo $TOTNODES | awk '{print 16*(int(($1-1)/16+1));}'`
cat >> tmp.submit << EOF
echo === Preparing batch file for run $RUN on $TOTNODES nodes. Target: remote-tacc-ranger
echo === Location: \$USER@`hostname -f`:\$PWD Target: remote-tacc-ranger

mv openggcm $RUN.exe
#...... we want to run everything in the pp directory, which is supposed to be on a large file system
mkdir -p $XHOME/${TUSER}/pp/$RUN
/bin/cp -au ./* $XHOME/${TUSER}/pp/$RUN
cd $XHOME/${TUSER}/pp/$RUN
if [ -f $RUN.exe ]; then
    echo $RUN.exe exists, proceeding with job submission
else
    echo the file $RUN.exe does not exist, bailing out in $0
fi

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

cat > $RUN.qsub <<XEOF
#!/bin/csh
#
#\$ -V
#\$ -cwd
#\$ -N ${RUN}
#\$ -j y
#\$ -o $XHOME/${TUSER}/pp/$RUN/$RUN.joblog
#\$ -pe 16way $CORES
#\$ -q ${CLASS}
#\$ -l h_rt=${RUNTIME}
#\$ -M J.Raeder@unh.edu  

module load autotools/1.0
module swap pgi gcc/4.4.1
module swap mvapich mvapich2
cd $XHOME/${TUSER}/pp/$RUN
pwd
/bin/ls -al
setenv GFORTRAN_UNBUFFERED_PRECONNECTED y

ibrun $XHOME/${TUSER}/pp/$RUN/$RUN.exe >&!  $XHOME/${TUSER}/pp/$RUN/$RUN.log

XEOF

echo === Submitting job $RUN.qsub  Target: remote-tacc-ranger
cat $RUN.qsub 
qsub $RUN.qsub
EOF
