#!/bin/bash
#SBATCH --partition=exfel
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --time=8:00:00
#SBATCH --job-name=pes2spec
#SBATCH -o slurm.%x.err.txt
#SBATCH -e slurm.%x.err.txt
#SBATCH --reservation=exfel_ml

optstring="d:"

DIR=results
while getopts ${optstring} arg; do
    case ${arg} in
        d)
            DIR=${OPTARG}
            S=$OPTIND
            ;;
        *)
            S=$((OPTIND))
            break
            ;;
    esac
done
OPTS="${@:$S}"
echo "Options: $OPTS"

source /usr/share/Modules/init/sh

module load exfel exfel_anaconda3

cd $HOME/scratch/karabo/devices/pes_to_spec
source env/bin/activate
pwd
export PYTHONPATH=$PYTHONPATH:$PWD

mkdir $DIR

do_it() {
    p=$1
    r=$2
    rt=$3
    output=$DIR/p${p}r${r}t${rt}
    mkdir -p $output
    echo "Proposal $p, run $r, test at run $rt"
    CMD=(./pes_to_spec/test/offline_analysis.py -p $p -r $r -t $rt -d $output ${@:4})
    echo "${CMD[*]}"
    ${CMD[*]} 2>&1 | tee $output/log.txt
}

do_it 900331  69 70 $OPTS

# train in run 2 and test in run 3
#do_it 3384  2  3 $OPTS

# new runs:
#for run in 2 4
#do
#    do_it 3384 $run $run $OPTS
#done

# train in run 4 and test in run 3
#do_it 3384  4  3 $OPTS

# old run
#do_it 2828 206 206 $OPTS
#do_it 2828 206 207 $OPTS

#do_it 2828 207 207 $OPTS

