Index: CONFIG/UNIFORM/v6/LMDZORINCA_v6/GENERAL/DRIVER/stomate.driver
===================================================================
--- CONFIG/UNIFORM/v6/LMDZORINCA_v6/GENERAL/DRIVER/stomate.driver	(revision 2346)
+++ CONFIG/UNIFORM/v6/LMDZORINCA_v6/GENERAL/DRIVER/stomate.driver	(revision 2694)
@@ -1,5 +1,5 @@
 #!/bin/ksh
 
-#D- Driver du script pour ORCHIDEE
+#D- Driver pour ORCHIDEE stomate component
 
 #-----------------------------------------------------------------
@@ -8,6 +8,4 @@
     IGCM_debug_PushStack "SBG_Initialize"
 
-    RESOL_SBG=ALL
-    
     IGCM_debug_PopStack "SBG_Initialize"
 }
@@ -17,131 +15,47 @@
 {
     IGCM_debug_PushStack "SBG_Update"
+    
+    # Output management
 
-    typeset STOMATE_WRITE_STEP
+    # Set default values for stomate output files.
+    stomate_enabled=.FALSE.
+    stomate_freq=0s
 
-    if [ X${orchidee_UserChoices_XIOS} = Xy ] ; then
-	IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 enabled .FALSE. 
-	IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 enabled .FALSE. 
-    fi   
-    case ${config_SBG_WriteFrequency} in
-	*Y|*y) 
-	    WriteInYears=$( echo ${config_SBG_WriteFrequency} | awk -F '[yY]' '{print $1}' )
-	    PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | awk -F '[yY]' '{print $1}' )
-	    (( STOMATE_WRITE_STEP = PeriodLengthInDays * WriteInYears / PeriodLengthInYears )) 
-	    if [ X${orchidee_UserChoices_XIOS} = Xy ] ; then
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 output_freq ${WriteInYears}y
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 name stomate_history 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 output_freq ${WriteInYears}y
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 name stomate_ipcc_history 
+    # Read WriteFrequency set in config.card section SBG. 
+    # Only one choice can be set as WriteFrequency. The same choice will be used for 
+    # both stomate_history and stomate_ipcc_history files. 
+    for frequency in ${config_SBG_WriteFrequency} ; do
+	case ${frequency} in
+	    *Y|*y) 
+		NbYears=$( echo ${frequency} | awk -F '[yY]' '{print $1}' )
+		NbDaysYear=$( IGCM_date_DaysInYear ${year} )
+		stomate_enabled=.TRUE.
+		stomate_freq=${NbYears}y ;;
+	    *M|*m) 
+		NbMonths=$( echo ${frequency} | awk -F '[mM]' '{print $1}' )
+		stomate_enabled=.TRUE.
+		stomate_freq=${NbMonths}mo ;;
+	    *D|*d)
+		NbDays=$( echo ${frequency} | awk -F '[dD]' '{print $1}' )
+		stomate_enabled=.TRUE.
+		stomate_freq=${NbDays}d ;;
+	    *) 
+		IGCM_debug_Exit "SBG WriteFrequency=${frequency} is invalid. Choose between xY, xM and xD for Stomate." ;;
+	esac
+    done
 
-	    fi
-	    ;;
-	1M|1m) 
-	    if [ X${orchidee_UserChoices_XIOS} = Xy ] ; then
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 output_freq 1mo
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 name stomate_history 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 output_freq 1mo
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 name stomate_ipcc_history 
-	    fi
-	    case ${config_UserChoices_PeriodLength} in
-	    *Y|*y)
-		STOMATE_WRITE_STEP=-1.
-		;;
-	    *M|*m)
-		STOMATE_WRITE_STEP=-1.
-		;;
-	    *)
-		(( STOMATE_WRITE_STEP = $( IGCM_date_DaysInMonth $year $month ) )) ;;
-	    esac
-	    ;;
-	*M|*m) 
-	    WriteInMonths=$( echo ${config_SBG_WriteFrequency} | awk -F '[mM]' '{print $1}' )
-	    if [ X${orchidee_UserChoices_XIOS} = Xy ] ; then
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 output_freq ${WriteInMonths}mo
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 name stomate_history 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 output_freq ${WriteInMonths}mo
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 name stomate_ipcc_history 
-	    fi
-	    case ${config_UserChoices_PeriodLength} in
-	    *Y|*y)
-		PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | awk -F '[yY]' '{print $1}' )
-		(( STOMATE_WRITE_STEP = 30 ))
-		;;
-	    *M|*m)
-		PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | awk -F '[mM]' '{print $1}' )
-		(( STOMATE_WRITE_STEP = PeriodLengthInDays * WriteInMonths / PeriodLengthInMonths ))
-		;;
-	    *)
-		(( STOMATE_WRITE_STEP = $( IGCM_date_DaysInMonth $year $month ) )) 
-		if [ X${orchidee_UserChoices_XIOS} = Xy ] ; then
-		    IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 enabled .TRUE. 
-		    IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 output_freq ${STOMATE_WRITE_STEP}s
-		    IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 name stomate_history
-		    IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 enabled .TRUE. 
-		    IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 output_freq ${STOMATE_WRITE_STEP}s
-		    IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 name stomate_ipcc_history
-		fi
-		;;
-	    esac
-	    ;;
-	5D|5d) 
-	    (( STOMATE_WRITE_STEP = 5 ))
-	    if [ X${orchidee_UserChoices_XIOS} = Xy ] ; then
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 output_freq 5d
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 name stomate_history 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 output_freq 5d
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 name stomate_ipcc_history 
-	    fi
-	    ;;
-	1D|1d) 
-	    (( STOMATE_WRITE_STEP = 1 )) 
-	    if [ X${orchidee_UserChoices_XIOS} = Xy ] ; then
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 output_freq 1d
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate1 name stomate_history 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 output_freq 1d
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 name stomate_ipcc_history 
-	    fi
-	    ;;
-	*s)
-	    WriteInSeconds=$( echo ${config_SBG_WriteFrequency} | awk -F '[s]' '{print $1}' )
-	    if [ X${orchidee_UserChoices_XIOS} = Xy ] ; then
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 output_freq ${WriteInSeconds}s
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 name sechiba_history 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 enabled .TRUE. 
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 output_freq ${WriteInSeconds}s
-		IGCM_comp_modifyXmlFile force file_def_orchidee.xml stomate2 name stomate_ipcc_history 
-	    fi
-	    (( STOMATE_WRITE_STEP = 1 )) ;;
-	*) 
-	    IGCM_debug_Exit "SBG_Update " ${config_SBG_WriteFrequency} " invalid WriteFrequency : choose in 1Y, 1M, 5D, 1D." 
-	    IGCM_debug_Verif_Exit ;;
-    esac
+    # Modify file_def_orchidee.xml
+    IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 enabled ${stomate_enabled}
+    IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 output_freq ${stomate_freq}
+    IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 enabled ${stomate_enabled}
+    IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 output_freq ${stomate_freq}
+    
 
-
-#Use of XIOS library only
-
-    if [ X${orchidee_UserChoices_XIOS} = Xy ] ; then
-	(( STOMATE_WRITE_STEP = 0 ))
-    fi
-
-    IGCM_comp_modifyDefFile nonblocker orchidee.def STOMATE_HIST_DT ${STOMATE_WRITE_STEP}
-    IGCM_comp_modifyDefFile nonblocker orchidee.def STOMATE_HISTLEVEL ${stomate_UserChoices_stomate_LEVEL}
-
+    # Define in orchidee.def if restart file should be used
     if ( [ ${CumulPeriod} -eq 1 ] && [ "${config_SBG_Restart}" = "n" ] ) ; then
-	echo "STOMATE : without restart"
-	IGCM_comp_modifyDefFile blocker orchidee.def STOMATE_RESTART_FILEIN NONE
+        echo "STOMATE : without restart"
+        IGCM_comp_modifyDefFile blocker orchidee.def STOMATE_RESTART_FILEIN NONE
     else
-	IGCM_comp_modifyDefFile blocker orchidee.def STOMATE_RESTART_FILEIN stomate_rest_in.nc
+        IGCM_comp_modifyDefFile blocker orchidee.def STOMATE_RESTART_FILEIN stomate_rest_in.nc
     fi
 
@@ -152,14 +66,6 @@
 function SBG_Finalize
 {
-#set -vx
     IGCM_debug_PushStack "SBG_Finalize"
-
-    if [ $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${year}1230 ) -ge 0 ] ; then
-	IGCM_sys_Put_Out stomate_Cforcing.nc ${R_OUT_SBG_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_stomate_Cforcing.nc
-	IGCM_sys_Put_Out stomate_forcing.nc  ${R_OUT_SBG_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_stomate_forcing.nc
-# 	rm -f stomate_Cforcing.nc
-# 	rm -f stomate_forcing.nc
-    fi
-
+    
     IGCM_debug_PopStack "SBG_Finalize"
 }
