#!/bin/ksh
#-----------------------------------
CPL_Initialize ()
{

    IGCM_debug_PushStack "CPL_Initialize"
 
    echo INITIALIZE CPL !!!

#D- MPI context used to launch the coupled model
LIBMPI=$(cat ${SUBMIT_DIR}/../.libmpi)
echo LIBMPI=${LIBMPI}

    IGCM_sys_build_run_file ${LIBMPI}

    IGCM_debug_PopStack "CPL_Initialize"

}

#-----------------------------------
CPL_Update ()
{

    IGCM_debug_PushStack "CPL_Update"

############ Update Time and Counters ##############
##-- Calcul de la duree du job (en secondes)
(( D_JOB_SEC = 3600 * 24 * PeriodLengthInDays ))

############ Update Other Parameters  ##############

############ Update Parameter Files   ##############
sed -e "s/<initial_date>/${PeriodDateBegin}/" \
    -e "s/<total_time>/${D_JOB_SEC}/" \
    -e "s/<lib_mpi>/${LIBMPI}/" \
    -e "s/<nproc_atm>/${NUM_PROC_ATM}/g" \
    -e "s/<nproc_oce>/${NUM_PROC_OCE}/g" \
	namcouple > namcouple.tmp

    IGCM_sys_Mv namcouple.tmp namcouple
    # Unused files we want to remove
    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=trace
    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=gweights
    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=mweights
    eval FileToBeDeleted[${#FileToBeDeleted[@]}]=anaisout

    IGCM_debug_PopStack "CPL_Update"
}

#-----------------------------------
CPL_Finalize ()
{

    IGCM_debug_PushStack "CPL_Finalize"

    echo FINALIZE CPL !!!

    IGCM_debug_PopStack "CPL_Finalize"

}
