#!/bin/bash

rm -f sub_config1.py
rm -f sub_config2.py
rm -f sub_check.py
rm -f default_param.py

cp -n ../user_config.py sub_config1.py
cp -n ../config.py sub_config2.py
cp -n ../check.py sub_check.py
cp -n ../default_param.py default_param.py


# Black        0;30     Dark Gray     1;30
# Red          0;31     Light Red     1;31
# Green        0;32     Light Green   1;32
# Brown/Orange 0;33     Yellow        1;33
# Blue         0;34     Light Blue    1;34
# Purple       0;35     Light Purple  1;35
# Cyan         0;36     Light Cyan    1;36
# Light Gray   0;37     White         1;37



Color='\033[0;36m'
NC='\033[0m' # No Color

touch report.txt
> report.txt
echo " " >> report.txt
echo " " >> report.txt
echo -e "testing ${Color}axis${NC} algorithms..." >> report.txt
echo " " >> report.txt

touch report.html
> report.html
echo "<br> " >> report.html
echo "<br> " >> report.html
echo "<br> " >> report.html
echo "<p>testing  <font color="blue">axis</font> algorithms...</p>" >> report.html 
echo "<br> " >> report.html

nb_config=$(python sub_config1.py 2>&1)                                                                                                                    


counter=0
while [ $counter -lt $nb_config ]
do

rm -f user_param.py

cp user_param.py.$counter user_param.py

((counter++))

nb_proc=$(python sub_config2.py 2>&1) 
nb_jz=$(($nb_proc-1))

if [[ ($machine_name == irene) ]]
then
    ccc_mprun -n $nb_proc ../../build_prod/bin/generic_testcase.exe
elif [[($machine_name == ada)]]
then
    echo "Testing on ADA"
    mpirun -np $nb_proc ../../build_prod/bin/generic_testcase.exe
elif [[($machine_name == jeanzay)]]
then
    echo "Testing on Jean-Zay" 
    # touch srun.conf
    # > srun.conf
    # echo "0-"$nb_jz " ../../build_prod/bin/generic_testcase.exe">> srun.conf
    # srun --mpi=pmi2 -K1 --multi-prog -m cyclic ./srun.conf 
    srun -n $nb_proc --mpi=pmi2 ../../build_prod/bin/generic_testcase.exe
else
    echo "other machine"
fi

python sub_check.py

rm -f iodef.xml
mv iodef.xml.bkp iodef.xml

done
