#!/bin/bash



cp ../context_grid_dynamico.xml ./
cp ../dynamico_grid.nc ./

cp ../config.py sub_config.py
cp ../check.py sub_check.py

cp ../default_param.py default_param.py

cp ../iodef.xml iodef.xml

# 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


mv iodef.xml iodef.xml.bkp

nb_proc=$(python sub_config.py 2>&1) 

machine_name=jeanzay

echo $nb_proc
if [[ ($machine_name == irene) ]]
then
    echo "Testing on Irene"
    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" 
    srun -n $nb_proc --mpi=pmi2 ../../build_prod/bin/generic_testcase.exe
    if [ $? -ne 0 ]
        then
            echo "execution failed"
            rm -f iodef.xml
            mv iodef.xml.bkp iodef.xml
            rm -f user_param.py
            rm -f default_param.py
            rm -f sub_config.py
            exit 1234
    fi
else
    echo "other machine"
    exit 1234
fi

python sub_check.py

rm -f iodef.xml
mv iodef.xml.bkp iodef.xml
rm -f user_param.py
rm -f default_param.py
rm -f sub_config.py
