#!/bin/ksh

#D- Driver du script pour ORCHIDEE_OL (off-line)

#-----------------------------------------------------------------
function SRF_Initialize
{
    IGCM_debug_PushStack "SRF_Initialize"

    RESOL_SRF=$( echo $RESOL | awk "-Fx" '{print $2}' | awk "-F-" '{print $1}' )

    ##--Variables used by ORCHIDEE --
    PAT_WRI_STEP=$(     grep 'WRITE_STEP='   ${SUBMIT_DIR}/PARAM/orchidee.def )

    IGCM_debug_PopStack "SRF_Initialize"
}

#-----------------------------------------------------------------
function SRF_Update
{
    IGCM_debug_PushStack "SRF_Update"

    (( SECH_WRI_STEP=PeriodLengthInDays * 86400 ))

    if ( [ ${CumulPeriod} -eq 1 ] && [ "${config_SRF_Restart}" = "n" ] ) ; then
	sed -e "s/_start_sech_/default/" \
	    -e "s/${PAT_WRI_STEP}/WRITE_STEP=${SECH_WRI_STEP}/" \
	    orchidee.def > orchidee.def.tmp
    else
	sed -e "s/_start_sech_/start_sech.nc/" \
	    -e "s/${PAT_WRI_STEP}/WRITE_STEP=${SECH_WRI_STEP}/" \
	    orchidee.def > orchidee.def.tmp
    fi

    IGCM_sys_Mv orchidee.def.tmp orchidee.def

    #IGCM_sys_Cp ${RUN_DIR}/orchidee.def ${RUN_DIR}/run.def
    #IGCM_sys_Put_Out ${RUN_DIR}/run.def ${R_SAVE}/${PREFIX}_run.def

    IGCM_debug_PopStack "SRF_Update"
}

#-----------------------------------------------------------------
function SRF_Finalize
{
    IGCM_debug_PushStack "SRF_Finalize"

    #IGCM_sys_Put_Out ${RUN_DIR}/used_run.def ${R_SAVE}/${PREFIX}_used_run.def

    echo FINALIZE SRF !!!

    IGCM_debug_PopStack "SRF_Finalize"
}
