#!/bin/ksh

#-----------------------------------
CPL_Initialize ()
{

    IGCM_debug_PushStack "CPL_Initialize"
 
    echo INITIALIZE CPL !!!

    #D- Default number of processor for lmdz and oasis
    NUM_PROC_ATM=1 ; (( NUM_PROC_OASIS = NUM_PROC_ATM + 2 ))
    #D- Number of processors used for lmdz and oasis coupler computed from PBS variable
    [ -z "${PBS_NUM_PROC_TOT}" ] || { (( NUM_PROC_ATM = PBS_NUM_PROC_TOT - 1 )) ; (( NUM_PROC_OASIS = PBS_NUM_PROC_TOT + 1 )) ; }

    echo PBS_NUM_PROC_TOT=${PBS_NUM_PROC_TOT}
    echo NUM_PROC_ATM=${NUM_PROC_ATM}
    echo NUM_PROC_OASIS=${NUM_PROC_OASIS}

    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/<nproc_atm>/${NUM_PROC_ATM}/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"

}
