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

cd $PBS_O_WORKDIR/72056-0

# This is the master job for runid, runid-light, runid-0.
# Subjobs must be submitted separatedly.

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


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

rm job.id job.host
