#!/bin/bash
#SBATCH -J script_art435
#SBATCH -N 1 
#SBATCH -n 1 
#SBATCH --threads-per-core=1
#SBATCH --cpus-per-task=18
#SBATCH --time=100:00:00

ulimit -a
ulimit -s unlimited
ulimit -a
source /opt/intel/compilers_and_libraries_2018.3.222/linux/bin/compilervars.sh intel64

set -x
free
make clean
make
workdir=${SLURM_SUBMIT_DIR}/JOB_${SLURM_JOBID}
mkdir ${workdir} 
cd ${workdir}

#lfs setstripe -c 1 .

cp $0 .
export OMP_NUM_THREADS=${SLURM_CPUS_PER_TASK}
MKL_NUM_THREADS=$OMP_NUM_THREADS 
export KMP_STACKSIZE=1000000000
export KMP_MONITOR_STACKSIZE=1000000000


cp ../cst_labv7_FS_2017 .
cp ../param_seq_29nov2018_EOS_30mn .
mkdir results
cp param_seq_29nov2018_EOS_30mn param_2018_EOS_tempo

NINDEX=0               #indice de boucle  1ere heure


while [ $NINDEX -le 0 ]         #on decide jusqu'a va la boucle    
 
do
        let NSTART=40*$NINDEX+1    #indice de depart
	Nfich=$(printf "%04d" $NINDEX)
	echo $Nfich
        echo "New execution: starting frame $NSTART"
        cp param_seq_29nov2018_EOS_30mn param_2018_EOS_tempo #on copie le fichier de parametre de depart dans un temporaire
        echo "ip_start=$NSTART # numero de la plaque de demarrage">> param_2018_EOS_tempo  #on ajoute une ligne
sed -i 's#param_seq_29nov2018_EOS_30mn#param_2018_EOS_tempo#g' param_2018_EOS_tempo
srun -N 1 -n 1 -c $OMP_NUM_THREADS cst_labv7_FS_2017 < param_2018_EOS_tempo  >> output_${SLURM_JOBID}.log

     #liste des fichiers a renommer
	echo ${workdir}
	mv ${workdir}/results/div1b ${workdir}/results/div_b_$Nfich
	mv ${workdir}/results/div1h ${workdir}/results/div_h_$Nfich
	mv ${workdir}/results/div1k ${workdir}/results/div_k_$Nfich
	mv ${workdir}/results/div1l ${workdir}/results/div_l_$Nfich
	mv ${workdir}/results/div1m ${workdir}/results/div_m_$Nfich
	mv ${workdir}/results/err1b ${workdir}/results/err_b_$Nfich
	mv ${workdir}/results/err1h ${workdir}/results/err_h_$Nfich
	mv ${workdir}/results/err1k ${workdir}/results/err_k_$Nfich
	mv ${workdir}/results/err1l ${workdir}/results/err_l_$Nfich
	mv ${workdir}/results/err1m ${workdir}/results/err_m_$Nfich
	mv ${workdir}/results/rot1b ${workdir}/results/rot_b_$Nfich
	mv ${workdir}/results/rot1h ${workdir}/results/rot_h_$Nfich
	mv ${workdir}/results/rot1k ${workdir}/results/rot_k_$Nfich
	mv ${workdir}/results/rot1l ${workdir}/results/rot_l_$Nfich
	mv ${workdir}/results/rot1m ${workdir}/results/rot_m_$Nfich
	mv ${workdir}/results/ux1b ${workdir}/results/ux_b_$Nfich
	mv ${workdir}/results/ux1h ${workdir}/results/ux_h_$Nfich
	mv ${workdir}/results/ux1k ${workdir}/results/ux_k_$Nfich
	mv ${workdir}/results/ux1l ${workdir}/results/ux_l_$Nfich
	mv ${workdir}/results/ux1m ${workdir}/results/ux_m_$Nfich
	mv ${workdir}/results/uy1b ${workdir}/results/uy_b_$Nfich
	mv ${workdir}/results/uy1h ${workdir}/results/uy_h_$Nfich
	mv ${workdir}/results/uy1k ${workdir}/results/uy_k_$Nfich
	mv ${workdir}/results/uy1l ${workdir}/results/uy_l_$Nfich
	mv ${workdir}/results/uy1m ${workdir}/results/uy_m_$Nfich
	mv ${workdir}/results/nb_gran ${workdir}/results/nb_gran_$Nfich
	mv ${workdir}/results/param_2018_EOS_tempo ${workdir}/results/param_2018_EOS_tempo_$Nfich
	mv ${workdir}/results/traject1_11 ${workdir}/results/traject_11_$Nfich

	let NINDEX=NINDEX+1 #on augmente l'indice de la boucle de 1
rm param_2018_EOS_tempo #on vire le fichier temporaire

done


