#!/bin/sh

#job
#PBS -N runSimulation-2011_10_26_19_26_15-415

#user
#PBS -P jkarr:jkarr

#notification
#PBS -M wholecell+pbs@lists.stanford.edu
#PBS -m a

#resources
#PBS -l walltime=72:00:00
#PBS -l nodes=1:ppn=1
#PBS -l mem=1300mb
#PBS -l vmem=3gb

#log
#PBS -o /home/projects/WholeCell/simulation/output/runSimulation/2011_10_26_19_26_15/415/out.log
#PBS -e /home/projects/WholeCell/simulation/output/runSimulation/2011_10_26_19_26_15/415/err.log
#PBS -W umask=002

#staging
#PBS -v TMPDIR=/state/partition1
#PBS -W stagein=/state/partition1/$PBS_JOBID/@covertlab:/home/projects/WholeCell/simulation/output/runSimulation/2011_10_26_19_26_15/bin/runSimulation/
#PBS -W stagein=/state/partition1/$PBS_JOBID/conditions.xml@covertlab:/home/projects/WholeCell/simulation/output/runSimulation/2011_10_26_19_26_15/415/conditions.xml
##PBS -W stageout=/state/partition1/$PBS_JOBID/2011_10_26_19_26_15@covertlab:/home/projects/WholeCell/simulation/output/runSimulation

#set environment
export MATLAB_PREFDIR=/tmp/emptydir
export MCR_CACHE_ROOT=/tmp/mcr_cache_$PBS_JOBID
mkdir -p $MCR_CACHE_ROOT

#setup
cd /state/partition1/$PBS_JOBID
mkdir 2011_10_26_19_26_15
mkdir 2011_10_26_19_26_15/415
mv conditions.xml 2011_10_26_19_26_15/415

#job
./run_runSimulation.sh /usr/local/bin/MATLAB/MATLAB_Compiler_Runtime/v714 2011_10_26_19_26_15/415 true

#set permissions, store data
rm -f 2011_10_26_19_26_15/415/conditions.xml
chmod -R 775 2011_10_26_19_26_15/
cp -R 2011_10_26_19_26_15/415 /home/projects/WholeCell/simulation/output/runSimulation/2011_10_26_19_26_15

#cleanup
rm -rf 2011_10_26_19_26_15/415/
rm -rf $MCR_CACHE_ROOT/*

#resources
echo ""
echo "=============="
echo "=== status ==="
echo "=============="
qstat -f $PBS_JOBID

#status
if [[ -f "2011_10_26_19_26_15/415/err.mat" ]]
then
  exit 1
fi
exit 0
