Index: trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh
===================================================================
--- trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh	(revision 1068)
+++ trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh	(revision 1069)
@@ -945,4 +945,115 @@
 
 #=======================================================================
+function IGCM_comp_modifyDefFile
+{
+#
+# syntax:     IGCM_comp_modifyDefFile  type  filein  key  [value]
+#
+# For example : IGCM_comp_modifyDefFile blocker run.def day_step 1200
+#
+# This function is used to modify a parameter file for a specific variable.
+# The file must be a ".def" file, i.e. with IOIPSL parameter file syntax. 
+# This function can be used in the comp.driver files for the components. 
+#
+# Arguments: 
+# - type   : first argument must be blocker or nonblocker. 
+#            For "blocker" case, the variable must be attributed the keyworld AUTO 
+#            otherwise this function will exit.
+#            For "nonblocker" case, the user can remove or modify the variable. For 
+#            this case, as long as AUTO is not set, no modification will be done. 
+# - filein : the file in run directory of .def type in which the variable should be set
+# - key    : the variable to modify
+# - value  : the value to set the key equal to, optional. If value is not set or if 
+#            value=DEFAULT, then a default value must be given in filein using syntax :
+#            key= AUTO : DEFAULT=def_value
+#
+    IGCM_debug_PushStack "IGCM_comp_modifyDefFile"
+    
+    # Set local variables and test the arguments
+    if [ $# = 4 ] ; then
+	# Normal case with 4 arguments
+	type=$1 ; filein=$2 ; key=$3 ; value=$4
+    elif [ $# = 3 ] ; then
+	# Normal case with 3 arguments
+	type=$1 ; filein=$2 ;	key=$3; value="DEFAULT"
+    else
+	IGCM_debug_Exit "IGCM_comp_modifyDefFile: Bad number of arguments."
+	return
+    fi
+    IGCM_debug_Print 1 "Entering IGCM_comp_modifyDefFile with arguments: $type $filein $key $value"
+
+    # Test if first argument is correct
+    if [ $type != blocker ] && [ $type != nonblocker ] ; then
+	IGCM_debug_Exit "IGCM_comp_modifyDefFile: Error in first argument must be blocker or nonblocker"
+	return
+    fi
+
+    # Test if the file exist
+    if [ ! -f ${filein} ] ; then
+	IGCM_debug_Exit "IGCM_comp_modifyDefFile: $filein does not exist."
+	return
+    fi
+
+    # Define list of files to test using all files with suffix .def
+    filelist=$( ls *def )
+
+    # Count number of occurances for the key in all files
+    nb_occ=$( grep -w $key $filelist |grep -v "#"  |wc -l )
+
+    # Test if key is set several times
+    if [ $nb_occ -gt 1 ] ; then
+        IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in $filein: Variable=$key is set ${nb_occ} times"
+	return
+    fi
+
+    # Treatement according to different cases
+    if [ $nb_occ -eq 0 ] && [ $type = blocker ] ; then
+        # Stop if the key is never set and the function is blocker
+        IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in $filein: Variable=$key has been removed but this function is blocker. "
+	IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: restore $filein for variable $key."
+    elif [ $nb_occ -eq 0 ] && [ $type = nonblocker ] ; then
+	# The key is not set but it is a nonblocker call so nothing is done.
+	IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key is not set in $filein. This is a nonblocker call so nothing is done."
+	IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: Default value for $key from the model will be used."
+    elif [ $( grep $key $filein | grep -v "\#"  |wc -l ) = 0 ] ; then
+	# Variable key is not set in filein, stop. 
+	IGCM_debug_Exit "IGCM_comp_modifyDefFile : Variable $key is not set in correct file. It should be set in $filein."
+    else
+	# Read the value of key from filein
+	if [ X"$( grep $key $filein | grep -v "\#" | grep AUTO )" = "X" ] ; then
+	    # The key variable is not set to AUTO 
+	    if [ $type = blocker ] ; then
+		# Stop because this is a blocker call
+		IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable $key cannot be modified. It should be set to AUTO."
+	    else
+		# Do nothing. Suppose that the user did set the variable correct
+		IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key is set by the user. Nothing done."
+	    fi
+	else
+	    # The variable key is set to AUTO.
+
+	    # For option DEFAULT, read default value from file.
+	    if [ X"$value" = XDEFAULT ] || [ X"$value" = X ] ; then
+		# Case to set DEFAULT value
+		# Read default value from filein
+		value=$( grep $key $filein | grep -v "\#" | awk  -F"DEFAULT *=" '{print $2}')
+
+		if [ X"$value" = X ] ; then
+		    IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable $key needs a DEFAULT value in $filein."
+		    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: The syntax in $filein should be:"
+		    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key=_AUTO_:DEFAULT=def_value"
+		    return
+		fi
+	    fi
+
+	    # Now change key in filein
+	    sed -e "s/^${key}\ *=.*/${key}= ${value}/" $filein > $filein.tmp
+	    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: In $filein set $key=$value"
+	    \mv $filein.tmp $filein
+	fi
+    fi	
+}
+
+#=======================================================================
 function IGCM_comp_Update
 {
