Index: CONFIG/UNIFORM/v6/LMDZOR_v6/GENERAL/DRIVER/orchidee.driver
===================================================================
--- CONFIG/UNIFORM/v6/LMDZOR_v6/GENERAL/DRIVER/orchidee.driver	(revision 2582)
+++ CONFIG/UNIFORM/v6/LMDZOR_v6/GENERAL/DRIVER/orchidee.driver	(revision 2595)
@@ -5,12 +5,4 @@
 {
     IGCM_debug_PushStack "SRF_Initialize"
-
-    RESOL_SRF=ALL
-
-    for frequency in ${config_SRF_WriteFrequency} ; do
-        case ${frequency} in
-            HF|hf) SRF_ok_hf=y ;;
-        esac
-    done
 
     ##- Define variable DefSuffix set in orchidee.card
@@ -33,56 +25,65 @@
     # Activate STOMATE if the compontent SBG=stomate is set in config.card
     if [ X${config_ListOfComponents_SBG} = Xstomate ] ; then
+	# Activate stomate in orchidee.def
         IGCM_comp_modifyDefFile blocker orchidee.def STOMATE_OK_STOMATE y
     else
+	# Deactivate stomate in orchidee.def
         IGCM_comp_modifyDefFile blocker orchidee.def STOMATE_OK_STOMATE n
+	# Deactivate output files for stomate
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 enabled .FALSE.
+        IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 enabled .FALSE.
     fi
 
-    # Default init : files are desactivated
-    IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 enabled .FALSE.
-    IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba2 enabled .FALSE.
+    # Set default values for sechiba1_enabled, sechiba1_freq and sechiba2_enabled.
+    sechiba1_enabled=.FALSE.
+    sechiba2_enabled=.FALSE.
+    sechiba1_freq=0s
 
-    SRF_WriteFrequency=$( echo ${config_SRF_WriteFrequency} | sed -e 's/\([0-9]*[yYmMdDs]\).*/\1/' )
-    case ${SRF_WriteFrequency} in
-        *Y|*y)
-            WriteInYears=$( echo ${SRF_WriteFrequency} | awk -F '[yY]' '{print $1}' )
-            PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | awk -F '[yY]' '{print $1}' )
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 enabled .TRUE.
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 output_freq ${WriteInYears}y
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 name sechiba_history
-            ;;
-        *M|*m)
-            WriteInMonths=$( echo ${SRF_WriteFrequency} | awk -F '[mM]' '{print $1}' )
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 enabled .TRUE.
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 output_freq ${WriteInMonths}mo
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 name sechiba_history
-            ;;
-        5D|5d)
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 enabled .TRUE.
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 output_freq 5d
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 name sechiba_history
-            ;;
-        1D|1d)
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 enabled .TRUE.
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 output_freq 1d
-            IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba1 name sechiba_history
-            ;;
-        *s)
-            WriteInSeconds=$( echo ${SRF_WriteFrequency} | awk -F '[s]' '{print $1}' )
-            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_debug_Exit "SRF_Update " ${SRF_WriteFrequency} " invalid WriteFrequency : choose in 1Y, 1M, 5D, 1D."
-            IGCM_debug_Verif_Exit ;;
-    esac
+    # Get WriteFrenquecies from config.card for SECHIBA
+    # Note that it is only possible to have one HF and one other option. 
+    # If more options are set in config.card only the latest will be used.
+    for frequency in ${config_SRF_WriteFrequency} ; do
+	case ${frequency} in
+	    *Y|*y) 
+		NbYears=$( echo ${frequency} | awk -F '[yY]' '{print $1}' )
+		NbDaysYear=$( IGCM_date_DaysInYear ${year} )
+		sechiba1_enabled=.TRUE.
+		sechiba1_freq=${NbYears}y
+	    *M|*m)
+		NbMonths=$( echo ${frequency} | awk -F '[mM]' '{print $1}' )
+		sechiba1_enabled=.TRUE.
+		sechiba1_freq=${NbMonths}mo
+	    *D|*d)
+		NbDayss=$( echo ${frequency} | awk -F '[dD]' '{print $1}' )
+		sechiba1_enabled=.TRUE.
+		sechiba1_freq=${NbDays}d
+	    *s)
+		WriteInSeconds=$( echo ${frequency} | awk -F '[s]' '{print $1}' )
+		sechiba1_enabled=.TRUE.
+		sechiba1_freq=${WriteInSeconds}s
+            HF|hf) 
+		SRF_ok_hf=y 
+		sechiba2_enabled=.TRUE. ;;
+	    *) 
+		IGCM_debug_Exit "SRF_Update " ${frequency} " invalid WriteFrequency : choose in xY, xM, xD, xs and HF" 
+		IGCM_debug_Verif_Exit ;;
+	esac
+    done
 
-    # Outputs HF in HISTFILE2 if required. Output frequency is 3 hours by default.
-    if [ X${SRF_ok_hf} = Xy ] ; then
-        IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba2 enabled .TRUE.
-        IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba2 output_freq 10800s
-        IGCM_comp_modifyXmlFile force file_def_orchidee.xml sechiba2 name sechiba_out_2
-    fi
+    # Do the modifications in file_def_orchidee.xml
+    IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba1 enabled ${sechiba1_enabled}
+    IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba1 output_freq ${sechiba1_freq}
+    IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba2 enabled ${sechiba2_enabled}
 
+    # Add include of orchidee context in iodef.xml
+    # In iodef.xml add on next line after "COMPONENT CONTEXT"
+    #  <context id="orchidee" src="./context_orchidee.xml"/>
+    echo '<context id="orchidee" src="./context_orchidee.xml"/>' > add.tmp
+    cp iodef.xml iodef.xml.tmp
+    sed -e "/COMPONENT CONTEXT/r add.tmp" iodef.xml.tmp > iodef.xml
+    rm iodef.xml.tmp add.tmp
+
+
+    # Define in orchidee.def if restart file should be used
     if ( [ ${CumulPeriod} -ne 1 ] || [ "${config_SRF_Restart}" != "n" ] ) ; then
         IGCM_comp_modifyDefFile blocker orchidee.def SECHIBA_restart_in sechiba_rest_in.nc
@@ -103,18 +104,4 @@
     fi
 
-    #IGCM_sys_Cp ${RUN_DIR}/orchidee.def ${RUN_DIR}/run.def
-    #IGCM_sys_Put_Out ${RUN_DIR}/run.def ${R_SAVE}/${PREFIX}_run.def
-
-    #Temporary way to fix bug on cimean variable
-    IGCM_comp_modifyXmlFile force field_def_orchidee.xml cimean enabled .FALSE.
-
-    # Add include of orchidee context in iodef.xml
-    # In iodef.xml add on next line after "COMPONENT CONTEXT"
-    #  <context id="orchidee" src="./context_orchidee.xml"/>
-    echo '<context id="orchidee" src="./context_orchidee.xml"/>' > add.tmp
-    cp iodef.xml iodef.xml.tmp
-    sed -e "/COMPONENT CONTEXT/r add.tmp" iodef.xml.tmp > iodef.xml
-    rm iodef.xml.tmp add.tmp
-
     IGCM_debug_PopStack "SRF_Update"
 }
@@ -125,8 +112,4 @@
     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"
 }
