#! /bin/bash
## note that nodes must be equal to 1, i.e., nodes=1. Max cpus is 24 on Ares.
#PBS -l nodes=1:ppn=24
#PBS -l walltime=2:00:00
#PBS -l mem=58gb

inPath="'"$1"'"
outPath=$2
inPrefix="'"$3"'"
outPrefix="'"$4"'"
expNumIn=$5
startSlice=$6
numSlices=$7

if [ $8 == 11 ]; then
   inputfile=tif2bin_11
elif [ $8 == 6 ]; then
   inputfile=tif2bin_06
fi

# place log files
#logLoc=$outPath
#logLoc+=/matlab_$expNumIn.log
logE=$outPath
logE+=/matlab_e_$expNumIn.log
logO=$outPath
logO+=/matlab_o_$expNumIn.log

logE=matlab_e_$expNumIn.log
logO=matlab_o_$expNumIn.log

outPath="'"$outPath"'"


###########################################################################################
cd $PBS_O_WORKDIR

#echo $inputfile
#echo $inPath
#echo $outPath
#echo $inPrefix
#echo $outPrefix


#/shared/matlab/R2015b/bin/matlab -nosplash -nodisplay -nodesktop -r "$inputfile($inPath,$outPath,$inPrefix,$outPrefix,$PBS_NUM_PPN); exit" > $logE  > $logO

#/home/olk335/matlab/r2017a/bin/matlab -nosplash -nodisplay -nodesktop -r "batch($inputfile($inPath,$outPath,$inPrefix,$outPrefix,$startSlice,$numSlices,$PBS_NUM_PPN)); exit" > $logE  > $logO

matlab -nosplash -nodisplay -nodesktop -r "batch($inputfile($inPath,$outPath,$inPrefix,$outPrefix,$startSlice,$numSlices,$PBS_NUM_PPN)); exit" > $logE  > $logO
