#!/bin/ksh
#-----------------------------------------------------------------
function ATM_Initialize
{
    IGCM_debug_PushStack "ATM_Initialize"

    RESOL_ATM=${RESOL}
 
   [ -f ${SUBMIT_DIR}/../.resol ] && eval $(grep RESOL_ATM_3D ${SUBMIT_DIR}/../.resol) || RESOL_ATM_3D=96x95x19
    RESOL_ATM_Z=$( echo $RESOL_ATM_3D | awk "-Fx" '{print $3}' )

    ##- Parameter files directory
    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices PARAM
    PARAM=${lmdz_UserChoices_PARAM}
    echo Parameter files directory : ${PARAM}

    IGCM_debug_PopStack "ATM_Initialize"
}

#-----------------------------------------------------------------
function ATM_Update
{
    IGCM_debug_PushStack "ATM_Update"

    ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def
    if [ ${CumulPeriod} -eq 1 ] ; then
	RAZ_DATE=1
    else
	RAZ_DATE=0
    fi

    ## Mise en forme du fichier run.def
    sed -e "s/_dayref_/${InitDay}/"          \
	-e "s/_anneeref_/${InitYear}/"       \
	-e "s/_nday_/${PeriodLengthInDays}/" \
	-e "s/_raz_date_/${RAZ_DATE}/"       \
	-e "s/_adjust_/n/"                   \
	run.def > run.def.tmp
    IGCM_sys_Mv run.def.tmp run.def


    ## Mise en forme du fichier physiq.def
    sed -e "s/_ok_instan_/n/"                \
	-e "s/_ok_journe_/n/"                \
	-e "s/_ok_mensuel_/n/"               \
	-e "s/_ok_hf_/n/"                    \
	physiq.def > physiq.def.tmp
    IGCM_sys_Mv physiq.def.tmp physiq.def

    ## Mise en forme du fichier gcm.def
    sed -e "s/_day_step_/240/"               \
	gcm.def > gcm.def.tmp
    IGCM_sys_Mv gcm.def.tmp gcm.def


    IGCM_debug_PopStack "ATM_Update"
}

#-----------------------------------
function ATM_Finalize
{
    IGCM_debug_PushStack "ATM_Finalize"

    echo FINALIZE ATM !

    IGCM_debug_PopStack "ATM_Finalize"
}
