#!/bin/bash

usage() {
>&2 cat << EOF
Usage: $0
   [ -h | --help ]
   [ --start-temp input ]
   [ --end-temp input ] 
   [ --points input ]
   [ --samples input ]
   [ --array input ]
   [ --time input ]
   [ --account input (required) ]
EOF
exit 1
}

# Defaults
start_temp=2.1
end_temp=2.4
points_temp=40
samples=1000000
array_arg=20
time_arg="0-00:30:00"
account=""

VALID_ARGS=$(getopt -o h --long help,start-temp:,end-temp:,points:,samples:,array:,time:,account: -- "$@")
if [[ $? -ne 0 ]]; then
    usage
fi

eval set -- ${VALID_ARGS}
while : 
do
    case "$1" in
        -h | --help)
            usage
            shift
            ;;
        --start-temp)
            start_temp=$2
            shift 2
            ;;
        --end-temp)
            end_temp=$2
            shift 2
            ;;
        --points)
            points=$2
            shift 2
            ;;
        --samples)
            samples=$2
            shift 2
            ;;
        --array)
            array_arg=$(echo "${2// /}")
            shift 2
            ;;
        --time)
            time_arg=$2
            shift 2
            ;;
        --account)
            account=$2
            shift 2
            ;;
        --) shift; break ;;
    esac
done

if [ -z "$account" ]; then
    usage
fi

sbatch --array=$array_arg --time=$time_arg --account=$account ./slurm_scripts/pt.script $start_temp $end_temp $points_temp $samples
