#!/bin/bash

cp -n  ../context_grid_dynamico.xml ./
cp -n ../dynamico_grid.nc ./


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}minimum${NC} reduce..." >> report.txt 
echo " " >> report.txt

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) 

if [$machine_name == irene]
then
    ccc_mprun -n $nb_proc ../../../build_prod/bin/generic_testcase.exe
else
    mpirun -np $nb_proc ../../../build_prod/bin/generic_testcase.exe
fi

python sub_check.py

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

done
