#!/bin/bash

mkdir ./logs

rootpath="$(pwd)/../.."
rootpath=$(builtin cd $rootpath; pwd)

for subj in $(seq 1 33); do
	# if ica has not been performed yet
	if [ ! -f ${rootpath}/data/outputs/eeg/sub-$(printf "%03d" ${subj})*_ica.mat ]; then
		echo "ICA not performed yet for this subject"
		echo "#!/bin/bash"                    			> job.slurm
		echo "#SBATCH --job-name eegmp_ica_${subj}" 	>> job.slurm
		echo "#SBATCH --cpus-per-task 8"				>> job.slurm
		echo "#SBATCH --mem 8gb" 						>> job.slurm
		echo "#SBATCH --time 24:00:00" 					>> job.slurm
		echo "#SBATCH --output ./logs/eegmp_ica_${subj}.out"			>> job.slurm
		echo "#SBATCH --workdir ." 										>> job.slurm
		echo "./a3_ica_run.sh /opt/matlab/R2016b ${subj} ${rootpath}" 	>> job.slurm
		sbatch job.slurm
		rm -f job.slurm
	fi
done