source ~/.bashrc
conda activate dqc

# Filter
if [ -z "$1" ]
  then
    echo "No filter argument supplied"	
    exit
fi
TAG=$1

# Threads
if [ -z "$2" ]
  then
    echo "No number of threads argument supplied"	
    exit
fi
let NT=$2

cd /data/joan/c3s512-wp1-datachecker/dqc_wrapper
QAR_CONF_DIR="/data/joan/c3s512-wp1-datachecker/dqc_wrapper/QAR_dqc/conf"
QAR_RES_DIR="/shared/QAR_dqc/results"

let i=1
for check_tests in `ls -1 $QAR_CONF_DIR/$TAG*`
do
	zip=`basename $conf | sed s/.ini/.zip/g`

	# Avoid skipping + NT threads
	if [ ! -f $QAR_RES_DIR/$zip ]; then
       		# Fork
		touch $QAR_RES_DIR/$zip
        	cmd="python checker.py $conf"
        	$cmd &

        	# Wait for every NT threads
        	if (( $i%$NT == 0 ));
        	then
        	        wait
        	fi

        	# Increase counter
        	let i=i+1
	fi

done
