#!/bin/sh

#job
#PBS -N runReindexing-2011_10_26_19_26_15-440

#user
#PBS -P jkarr:jkarr

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

#resources
#PBS -l walltime=1:00:00
#PBS -l nodes=1:ppn=4
#PBS -l mem=20gb
#PBS -l vmem=20gb

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

#schedule
#PBS -W depend=afterany:18491

#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/runReindexing/
#PBS -W stagein=/state/partition1/$PBS_JOBID/@covertlab:/home/projects/WholeCell/simulation/output/runSimulation/2011_10_26_19_26_15/440/
##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
rm -f 440/{*.sh,*.xml,*.log}
mkdir 2011_10_26_19_26_15
mv 440 2011_10_26_19_26_15/440

#job
./run_runReindexing.sh /usr/local/bin/MATLAB/MATLAB_Compiler_Runtime/v714 2011_10_26_19_26_15/440

#set permissions, store data
rm -rf 2011_10_26_19_26_15/440/state-[0-9]*.mat
rm -rf 2011_10_26_19_26_15/440/{fittedConstants,metadata,options,parameters,randStreamStates,summary}.mat
chmod -R 775 2011_10_26_19_26_15/
cp -R 2011_10_26_19_26_15/440 /home/projects/WholeCell/simulation/output/runSimulation/2011_10_26_19_26_15

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

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

#status
if [[ -f "2011_10_26_19_26_15/440/err.reindexing.log" ]]
then
  exit 1
fi
exit 0