#!/bin/sh

#Set the main dir (no capital letters as it is best practice not to mess up with system variables
main_dir=/home/lhcb/kopecna/B2KstarMuMu/code/ewp-Bplus2Kstmumu-AngAna/FCNCfitter/condor

# Used to clean up the mess condor created by default
for CondorID in {500..650}
do
	mkdir $main_dir/error/$CondorID
	mkdir $main_dir/output/$CondorID

	#Delete empty error messages
	find $main_dir/error/toys_$CondorID* -size 0 -exec rm {} \;
	find $main_dir/Folding0/error/toys_$CondorID* -size 0 -exec rm {} \;
	find $main_dir/Folding1/error/toys_$CondorID* -size 0 -exec rm {} \;
	find $main_dir/Folding2/error/toys_$CondorID* -size 0 -exec rm {} \;
	find $main_dir/Folding3/error/toys_$CondorID* -size 0 -exec rm {} \;
	find $main_dir/Folding4/error/toys_$CondorID* -size 0 -exec rm {} \;
	
	#Move the error messages into a subfolder
	mv "$main_dir/error/toys_$CondorID"* "$main_dir/error/$CondorID/"
	mv "$main_dir/Folding0/error/toys_$CondorID"* "$main_dir/error/$CondorID/"
	mv "$main_dir/Folding1/error/toys_$CondorID"* "$main_dir/error/$CondorID/"
	mv "$main_dir/Folding2/error/toys_$CondorID"* "$main_dir/error/$CondorID/"
	mv "$main_dir/Folding3/error/toys_$CondorID"* "$main_dir/error/$CondorID/"
	mv "$main_dir/Folding4/error/toys_$CondorID"* "$main_dir/error/$CondorID/"
	#rm "$MAIN_DIR/error/toys_$CondorID"*

	#Move the output file into a subfodler
	mv "$main_dir/output/toys_$CondorID"* "$main_dir/output/$CondorID/"
	mv "$main_dir/Folding0/output/toys_$CondorID"* "$main_dir/output/$CondorID/"
	mv "$main_dir/Folding1/output/toys_$CondorID"* "$main_dir/output/$CondorID/"
	mv "$main_dir/Folding2/output/toys_$CondorID"* "$main_dir/output/$CondorID/"
	mv "$main_dir/Folding3/output/toys_$CondorID"* "$main_dir/output/$CondorID/"
	mv "$main_dir/Folding4/output/toys_$CondorID"* "$main_dir/output/$CondorID/"
	
	#Move the log from the folding folder
	
	mv "$main_dir/Folding0/log/toys_$CondorID"* "$main_dir/log/"
	mv "$main_dir/Folding1/log/toys_$CondorID"* "$main_dir/log/"
	mv "$main_dir/Folding2/log/toys_$CondorID"* "$main_dir/log/"
	mv "$main_dir/Folding3/log/toys_$CondorID"* "$main_dir/log/"
	mv "$main_dir/Folding4/log/toys_$CondorID"* "$main_dir/log/"

	#Echo we are done :)
	echo "Cleaned."
done

