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

cd $PBS_O_WORKDIR/72182-2/

#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 72182 > 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 72182 -o run72182-2.h5 --geom-out 72182-2.geom --bl 2 --nproc $NCPUS  --min-spots=0 --clen=193.000000  --rayonix-root="/xustrg0/2019A8088/"  --type=2 2>&1 >> cheetah.log

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

rm job.id job.host
