#! /bin/bash
# Script to submit matlab jobs that convert tif stacks to
# binary images and .mat files. --Orion, July 2017
basePath="/home/projects/APS/xctRecon/2017_11"
startSlice=15
numSlices=2088
#===========================================
# RANGE
# comment list lines and uncomment to do a range
reconStart=205
reconFinish=205
for  ((i=$reconStart; i<=$reconFinish; i++))

#===========================================
# LIST
# comment range lines and uncomment to do a set list
#reconList=(25)
#reconFinish=${reconList[${#reconList[@]}-1]}
#for i in ${reconList[@]}

#===========================================
# main body of loop. Do not edit below this.
do
    expNum=${i}
    expNumIn=$(printf %03d $expNum)
    projNum=$(printf %04d $expNum)
    # Make the paths and a directory to place the output in
    inPath="${basePath}/Exp$expNumIn/8bit" # recon_proj_${projNum}"
    outPath="${basePath}/Exp$expNumIn/matBin"
    if [ ! -e "$outPath" ]; then mkdir "${outPath}"; fi
    inPrefix="Exp${expNumIn}_" #"recon_proj_${projNum}__"
    outPrefix="Exp${expNumIn}_"

    # Run the job
    qsub -N tif2bin_exp$expNumIn -F "$inPath $outPath $inPrefix $outPrefix $expNumIn $startSlice $numSlices 11" /home/projects/APS/xctRecon/makeBin/run_matlab_batch.sh
    # Pause slightly before submitting the next job
    if [ "$expNum" -ne "$reconFinish" ]; then sleep 1; fi
done	
exit 0	
