#
#
#NOT IN USE BECAUSE IN 'sending to cluter.py' we already did this by not coping it when cluster brasil is set
#* removing all interpolated data file from replicas because to heavy to send to cluster Brazil (cluster brasil has a copy of interpolated data already)
#for i in `ls -d */`;do rm $i\inter_i56_f108_d200.npz;done
#
#
#
#* making bash file to run all jobs (it starts empty):
echo "" > send_all_jobs.sh
s=5 # seting sleeping time (in second) betwen sending jobs (to make sure the entropy calls (random generator seeds) are far apart in time)  
#
#* seting cluster Brazil header comands:
#---> editi the node info to change node or comment with an extra '#' to set all nodes availables
echo "#!/bin/bash" > slurm_headerTMP.txt
echo "" >> slurm_headerTMP.txt
if [ $1 -eq 101 ]  # 630h for 1000k OPT loops --> 126h for 200k OPT loops (~5 days and 6h)
then
	echo "#SBATCH -w node101 #quando tem dois ## é comentário se tiver um #SBATCH, tá valendo" >> slurm_headerTMP.txt
elif [ $1 -eq 105 ] # 615h for 1000k OPT loops --> 123h for 200k OPT loops (~5 days and 1h)
then
	echo "#SBATCH -w node105 #quando tem dois ## é comentário se tiver um #SBATCH, tá valendo" >> slurm_headerTMP.txt
elif [ $1 -eq 106 ] # 630h for 1000k OPT loops --> 126h for 200k OPT loops (~5 days and 6h)
then
	echo "#SBATCH -w node106 #quando tem dois ## é comentário se tiver um #SBATCH, tá valendo" >> slurm_headerTMP.txt
fi
echo "#SBATCH --qos qos_long # QOS" >> slurm_headerTMP.txt
echo "#SBATCH --partition long # partition" >> slurm_headerTMP.txt
echo "# Comandos de execução do seu programa:" >> slurm_headerTMP.txt
echo "" >> slurm_headerTMP.txt
#
#* making the jobs files of each replica:
c0="run_sequential_PAULO -n PAULO" # string to replace from cluster run chile
#c1="python" # cluster brasil new string
c1="python3" # cluster brasil new string
a=1 # number of each jobs
for i in `ls -d cR_*/`;do cp slurm_headerTMP.txt job$a.sh; echo cd $i >> job$a.sh; b=$(head $i\run_jobs.sh); echo ${b/$c0/$c1} >> job$a.sh; echo cd ../ >> job$a.sh; echo  >> job$a.sh; chmod +x job$a.sh; echo "sbatch job$a.sh ; sleep $s" >> send_all_jobs.sh; a=$((a+1));done
chmod +x send_all_jobs.sh
rm slurm_headerTMP.txt
#
#
#
#* Old lines, not in use:
#for i in `seq 1 1 10`;do cp sub_slurm_header.txt job$i.sh; tail -20 sub_slurm.txt | awk -v nl="$i" 'NR==nl{print $0}' >> job$i.sh;done
#cp sub_slurm.txt allJobs.sh                                     
#chmod +x allJobs.sh                                             
#for i in `seq 1 1 20`;do chmod +x job$i.sh;done                 
#for i in `seq 1 1 20`;do head job$i.sh;done 