#!/bin/bash
#PBS -l nodes=1:ppn=14
#PBS -e 72166-1/cheetah.stderr
#PBS -o 72166-1/cheetah.stdout
#PBS -N 72166-1
#PBS -q serial

cd $PBS_O_WORKDIR/72166-1/

#if [ -e job.id ]; then
#   exit
#fi

echo "#PBS_JOBID=$PBS_JOBID
#hostname=`hostname`"
echo $PBS_JOBID > job.id
hostname > job.host
source /home/sacla_sfx_app/setup.sh
ShowRunInfo -b 2 -r 72166 > run.info

/home/sacla_sfx_app/packages/rayonix/dials-v1-10-2/build/bin/dials.python /work/jkern/2019A8088/xrd/data_allhits/cheetah-sacla-api-rayonix/cheetah_marccd.py --run 72166 -o run72166-1.h5 --geom-out 72166-1.geom --bl 2 --nproc $NCPUS  --min-spots=0 --clen=193.000000  --rayonix-root="/xustrg0/2019A8088/"  --type=1 2>&1 >> cheetah.log

# th 100 gr 5000000 for > 10 keV
/home/sacla_sfx_app/local/bin/indexamajig -g 72166-1.geom --indexing=dirax --peaks=zaef --threshold=400 --min-gradient=10000 --min-snr=5 --int-radius=3,4,7 -o 72166-1.stream -j 14 -i -  -indexing=none  <<EOF
run72166-1.h5
EOF
rm -fr indexamajig.*
grep Cell 72166-1.stream | wc -l > indexed.cnt
ruby /home/sacla_sfx_app/packages/tools/parse_stream.rb < 72166-1.stream > 72166-1.csv

rm job.id job.host
