#!/bin/bash

# Compile
(cd ./sources/amip-forcing/src/fortran && make clean)
(cd ./sources/amip-forcing/src/fortran && make oasis)
(cd ./sources/amip-forcing/src/fortran && make)

cd ./tests
./run_example.sh fortran 4
./run_example.sh python 4

echo '*****************************************************************'
echo "Retrieving IFS_mock outputs..."
cat ./work_fortran_4_1/IFS_mock.out_* > ./work_fortran_4_1/IFS_mock__all.out
cat ./work_python_4_1/IFS_mock.out_* > ./work_python_4_1/IFS_mock__all.out

echo '*****************************************************************'
echo "Checking results..."

diff ./work_fortran_4_1/IFS_mock__all.out ./work_python_4_1/IFS_mock__all.out && echo "Test PASSED" || ( echo "Test ERROR"; exit 1 )

echo "AMIP_sic_AMIPFORC_01 diff:"
cdo -s diff ./work_fortran_4_1/AMIP_sic_AMIPFORC_01.nc ./work_python_4_1/AMIP_sic_AMIPFORC_01.nc
echo "AMIP_sst_AMIPFORC_01 diff:"
cdo -s diff ./work_fortran_4_1/AMIP_sst_AMIPFORC_01.nc ./work_python_4_1/AMIP_sst_AMIPFORC_01.nc

echo "A_Ice_frac_IFS_MOCK_01 diff:"
cdo -s diff ./work_fortran_4_1/A_Ice_frac_IFS_MOCK_01.nc ./work_python_4_1/A_Ice_frac_IFS_MOCK_01.nc
echo "A_SST_IFS_MOCK_01 diff:"
cdo -s diff ./work_fortran_4_1/A_SST_IFS_MOCK_01.nc ./work_python_4_1/A_SST_IFS_MOCK_01.nc
