Index: CONFIG/UNIFORM/v6/LMDZORINCAREPR_v6/GENERAL/DRIVER/orchidee.driver
===================================================================
--- CONFIG/UNIFORM/v6/LMDZORINCAREPR_v6/GENERAL/DRIVER/orchidee.driver	(revision 3559)
+++ CONFIG/UNIFORM/v6/LMDZORINCAREPR_v6/GENERAL/DRIVER/orchidee.driver	(revision 4208)
@@ -34,6 +34,8 @@
 	# Deactivate output files for stomate
 	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 enabled .FALSE.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 output_level 0
 	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 output_freq 1mo
         IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 enabled .FALSE.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 output_level 0
 	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 output_freq 1mo
     fi
@@ -46,9 +48,32 @@
     fi
 
+    # Set VEGET_UPDATE=1Y in orchidee.def if VEGET_UPDATE_at_start=y in orchidee.card and if it is the first cumul periond (start of new simulation)
+    if [ X${orchidee_UserChoices_VEGET_UPDATE_at_start} = Xy ] && [ ${CumulPeriod} -eq 1 ] ; then
+        IGCM_comp_modifyDefFile nonblocker orchidee.def VEGET_UPDATE   1Y
+    fi
+
     # Modify in orchidee.def VEGET_UPDATE if it is set in orchidee.card section UserChoices
+    # Note: if the variable has been set by VEGET_UPDATE_at_start, this section will not overwrite it.
     if [ ! X${orchidee_UserChoices_VEGET_UPDATE} = X ] ; then
         IGCM_comp_modifyDefFile nonblocker orchidee.def VEGET_UPDATE   ${orchidee_UserChoices_VEGET_UPDATE}
     else
         IGCM_comp_modifyDefFile nonblocker orchidee.def VEGET_UPDATE 0Y
+    fi
+
+    # Set LAI_MAP in orchidee.def acording to value set in orchidee.card section UserChoices
+    # If LAI_MAP is not definded in orchidee.card, set default value n
+    # Note: this option is only read by ORCHIDEE if starting without restart files
+    if [ ! X${orchidee_UserChoices_LAI_MAP} = X ] ; then
+        IGCM_comp_modifyDefFile nonblocker orchidee.def LAI_MAP   ${orchidee_UserChoices_LAI_MAP}
+    else
+        IGCM_comp_modifyDefFile nonblocker orchidee.def LAI_MAP   DEFAULT
+    fi
+
+    # Set DO_WOOD_HARVEST in orchidee.def acording to value set in orchidee.card section UserChoices
+    # If DO_WOOD_HARVEST is not definded in orchidee.card, set default value y
+    if [ ! X${orchidee_UserChoices_DO_WOOD_HARVEST} = X ] ; then
+        IGCM_comp_modifyDefFile nonblocker orchidee.def DO_WOOD_HARVEST   ${orchidee_UserChoices_DO_WOOD_HARVEST}
+    else
+        IGCM_comp_modifyDefFile nonblocker orchidee.def DO_WOOD_HARVEST   DEFAULT
     fi
 
@@ -62,69 +87,46 @@
 
     ## 2. Mangement of output and modifications of related xml files
-
-    # Set default values for sechiba1_enabled and sechiba1_freq.
-    # These variables are used only to modify file_def_orchidee.xml
-    sechiba1_enabled=.FALSE.
-    sechiba2_enabled=.FALSE.
-    sechiba1_freq=0s
-    sechiba2_freq=0s
-
-
-    # Get WriteFrenquecy for SRF (SECHIBA) from config.card
-    # 1 or 2 frequencies can be set in WriteFrenquecy for SRF
-    # The first frequency will always be used for the sechiba_history file and the 
-    # second frequency will be used for the sechiba_out_2.nc file. 
-    # The files are activated only if its corresponding frequency is set in WriteFrequency
-    ifreq=0
-    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} )
-		file_enabled=.TRUE.
-		file_freq=${NbYears}y ;;
-	    *M|*m)
-		NbMonths=$( echo ${frequency} | awk -F '[mM]' '{print $1}' )
-		file_enabled=.TRUE.
-		file_freq=${NbMonths}mo ;;
-	    *D|*d)
-		NbDays=$( echo ${frequency} | awk -F '[dD]' '{print $1}' )
-		file_enabled=.TRUE.
-		file_freq=${NbDays}d ;;
-	    *s)
-		WriteInSeconds=$( echo ${frequency} | awk -F '[s]' '{print $1}' )
-		file_enabled=.TRUE.
-		file_freq=${WriteInSeconds}s ;;
-            HF|hf) 
-		file_enabled=.TRUE. 
-		file_freq=10800s ;;
-	    *) 
-		IGCM_debug_Exit "SRF_Update " ${frequency} " invalid WriteFrequency : choose in xY, xM, xD, xs and HF" 
-		IGCM_debug_Verif_Exit ;;
-	esac
-
-	(( ifreq = ifreq + 1 ))
-	case ${ifreq} in
-	    1)
-		sechiba1_enabled=${file_enabled}
-		sechiba1_freq=${file_freq} ;;
-	    2)
-		sechiba2_enabled=${file_enabled}
-		sechiba2_freq=${file_freq} ;;
-        *)
-		IGCM_debug_Exit "SRF_Update: It is not possible to set more than 2 output files for sechiba from config.card"
-		IGCM_debug_Exit "You must correct WriteFrequancy in SRF secion in config.card."
-		IGCM_debug_Exit "Adapt file_def_orchidee.xml directly if you want more output files"
-		IGCM_debug_Verif_Exit ;;
-	esac
-    done
-
-
-    # Modify file_def_orchidee.xml file
-    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}
-    IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba2 output_freq ${sechiba2_freq}
+    # Modify file_def_orchidee.xml file using settings from orchidee.card
+    # We here suppose that for each file, in orchidee.card UserChoices section, if the parameter 
+    # output_level_filename is set, then also output_freq_filename must be set. The existance of output_freq_filename will not be checked. 
+    # If output_level_filename=NONE or if it is not set, the corresponding file will be deactivated.
+    # Settings in config.card WriteFrequency are not used any more.
     
+    if [ X${orchidee_UserChoices_output_level_sechiba_history} = X ] || [ X${orchidee_UserChoices_output_level_sechiba_history} = XNONE ] ; then
+	# output_level_sechiba_history is not set in orchidee.card or it is set to NONE.
+	# Deactivate the file.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba1 enabled .FALSE.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba1 output_level 0
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba1 output_freq 1mo
+    else
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba1 enabled      .TRUE.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba1 output_level ${orchidee_UserChoices_output_level_sechiba_history}
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba1 output_freq  ${orchidee_UserChoices_output_freq_sechiba_history}
+    fi
+    
+    if [ X${orchidee_UserChoices_output_level_sechiba_out_2} = X ] || [ X${orchidee_UserChoices_output_level_sechiba_out_2} = XNONE ] ; then
+	# output_level_sechiba_out_2 is not set in orchidee.card or it is set to NONE.
+	# Deactivate the file.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba2 enabled .FALSE.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba2 output_level 0
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba2 output_freq 1mo
+    else
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba2 enabled      .TRUE.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba2 output_level ${orchidee_UserChoices_output_level_sechiba_out_2}
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba2 output_freq  ${orchidee_UserChoices_output_freq_sechiba_out_2}
+    fi
+    
+    if [ X${orchidee_UserChoices_output_level_sechiba_history_4dim} = X ] || [ X${orchidee_UserChoices_output_level_sechiba_history_4dim} = XNONE ] ; then
+	# output_level_sechiba_history_4dim is not set in orchidee.card or it is set to NONE.
+	# Deactivate the file.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba3 enabled .FALSE.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba3 output_level 0
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba3 output_freq 1mo
+    else
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba3 enabled      .TRUE.
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba3 output_level ${orchidee_UserChoices_output_level_sechiba_history_4dim}
+	IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml sechiba3 output_freq  ${orchidee_UserChoices_output_freq_sechiba_history_4dim}
+    fi
+        
 
     # Add include of orchidee context in iodef.xml
@@ -132,4 +134,8 @@
     #  <context id="orchidee" src="./context_orchidee.xml"/>
     echo '<context id="orchidee" src="./context_orchidee.xml"/>' > add.tmp
+    if [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] ; then
+	echo '<context id="orchidee" src="./ping_orchidee.xml"/>' >> add.tmp
+	echo '<context id="orchidee" src="./dr2xml_orchidee.xml"/>' >> add.tmp
+    fi
     cp iodef.xml iodef.xml.tmp
     sed -e "/COMPONENT CONTEXT/r add.tmp" iodef.xml.tmp > iodef.xml
