#- $Id: inca.driver 119 2007-07-31 13:56:33Z acosce $
#!/bin/ksh

#D- Driver du script pour INCA
#-----------------------------------------------------------------
function INCA_sed_replace
{
    IGCM_debug_PushStack "INCA_sed_replace"

    sed -e "s/${2}/${3}/" ${1} > ${1}.tmp
    RET=$?
    echo "INCA_sed : ${1} ${2} ${3}"
    \mv ${1}.tmp ${1}

    IGCM_debug_PopStack "INCA_sed_replace"
    return $RET
}
function INCA_sed_complete
{
    IGCM_debug_PushStack "INCA_sed_complete"

    sed -e "s/^${2}\ *=.*/${2}= ${3}/" ${1} > ${1}.tmp
    RET=$?
    echo "INCA_sed : ${1} ${2} ${3}"
    \mv ${1}.tmp ${1}

    IGCM_debug_PopStack "INCA_sed_complete"
    return $RET
}

#-----------------------------------------------------------------
function CHM_Initialize
{
    IGCM_debug_PushStack "CHM_Initialize"

    RESOL_CHM=$( echo $RESOL | awk "-Fx" '{print $2}' | awk "-FD" '{print $2}')

    [ -f ${SUBMIT_DIR}/../.resol ] && eval $(grep RESOL_ATM_3D ${SUBMIT_DIR}/../.resol) || RESOL_ATM_3D=96x95x19
    RESOL_CHM_Z=$( echo ${RESOL_ATM_3D} | awk "-Fx" '{print $3}' | awk "-F-" '{print $1}')
    echo 'resol chimie', $RESOL_CHM

    [ -f ${SUBMIT_DIR}/../.chimie ] && eval $(grep CHEM ${SUBMIT_DIR}/../.chimie) 
    INCA_sed_replace ${SUBMIT_DIR}/config.card \${CHEM} ${CHEM}
    echo "INCA Tag : LMDZ-INCA" ${config_UserChoices_TagName}

    IGCM_debug_PopStack "CHM_Initialize"
}

#-----------------------------------------------------------------
function CHM_Update
{
    IGCM_debug_PushStack "CHM_Update"

    case ${CHEM} in 
	AER)
	INCA_sed_complete run.def config_inca aero
	;;
	NMHC) 
	INCA_sed_complete run.def config_inca chem
	;;
	NMHC_AER)
	INCA_sed_complete run.def config_inca aero
	;;
	CH4)
	INCA_sed_complete run.def config_inca chem
	;;
	CH4_AER)
	INCA_sed_complete run.def config_inca aero
	;;
	GES)
	INCA_sed_complete run.def config_inca chem
	esac

    IGCM_debug_PopStack "CHM_Update"
}

#-----------------------------------------------------------------
function CHM_Finalize
{
    IGCM_debug_PushStack "CHM_Finalize"

    echo FINALIZE CHM !!!
#
#    IGCM_sys_Mkdir ${R_OUT_EXE}
#    cd ${MODIPSL}
#    tar cf src_${config_UserChoices_JobName}.tar  modeles
#    IGCM_sys_Mv src_${config_UserChoices_JobName}.tar ${R_OUT_EXE}/.
#    cd -
#

    IGCM_debug_PopStack "CHM_Finalize"
}
