Index: trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh
===================================================================
--- trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh	(revision 1603)
+++ trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh	(revision 1624)
@@ -752,4 +752,16 @@
             eval file_out=${file_out_}
 
+            (( i_ = i+2 ))
+            eval is_opt=\${${ListFilesName}[$i_]} > /dev/null 2>&1
+            if [ X${is_opt} = XOPTIONAL ] ; then
+                echo ${file_in} is optional
+                (( i=i+4 ))
+            else
+                is_opt="MANDATORY"
+                echo ${file_in} is mandatory
+                (( i=i+3 ))
+            fi
+            IGCM_debug_Print 3 "Now search for restart file ${file_in} which is ${is_opt} (in section do_start=y)"
+
             eval Date_tmp=\${config_${comp}_RestartDate}
             Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
@@ -810,15 +822,39 @@
                   IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
                   IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
-                  IGCM_debug_Exit "Please double check restart settings in config.card"
-                  IGCM_debug_Verif_Exit
+                  if [ ${is_opt} = 'OPTIONAL' ] ; then
+                    IGCM_debug_Print 3 "The restart file is optional. Now continue."
+                    nb_restart_file=0
+                    Tared=false
+                  else
+                    IGCM_debug_Exit "Please double check restart settings in config.card"
+                    IGCM_debug_Verif_Exit
+                  fi
+                fi	
+              fi
+
+	      if [ X${Tared} = Xtrue ] ; then
+                # The tar file exist but not sure all files are inside 
+                IGCM_sys_PrepareTaredRestart ${TarFileFound}
+                TarFileLocation=$( basename ${TarFileFound} )
+                nb_files=$( tar tvf ${TarFileLocation} | grep ${comp}_${generic_restart_file_name_in}*.${extension_in} | wc -l )
+                if [ ${nb_files} -gt 0 ] ; then
+                    IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
+                    tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
+                    nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
+                else
+                    # No file was found
+                    if [ ${is_opt} = 'OPTIONAL' ] ; then
+                        IGCM_debug_Print 3 "The restart file is not found in the tar file but it is optional. Now continue."
+                        nb_restart_file=0
+                        Tared=false
+                    else
+                        IGCM_debug_Print 3 "The restart file was not found in the tar file but it is mandatory."
+                        IGCM_debug_Exit "Please double check restart settings in config.card"
+                        IGCM_debug_Verif_Exit
+                    fi
                 fi
-              fi
-              IGCM_sys_PrepareTaredRestart ${TarFileFound}
-              TarFileLocation=$( basename ${TarFileFound} )
-              IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
-              tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
-              nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
+	      fi
             fi
-
+            
             if [ ${nb_restart_file} -gt 1 ] ; then
               j=0                                      # BASH LINE NOT NEEDED
@@ -849,8 +885,16 @@
                 IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}
               elif [ X${Tared} = Xtrue ] ; then
-                IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
+                if [ -f ${comp}_${file_in_Name} ] ; then
+                   # The file exixt
+                   IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
+                elif [ ${is_opt} = 'OPTIONAL' ] ; then
+                   IGCM_debug_Print 3 "The restart file is not found in the tar file but it is optional. Now continue."
+                else
+                   IGCM_debug_Print 3 "The restart file was not found in the tar file but it is mandatory."
+                   IGCM_debug_Exit "Please double check restart settings in config.card"
+                   IGCM_debug_Verif_Exit
+                fi
               fi
             fi
-            (( i=i+3 ))
           done
         else
@@ -874,7 +918,22 @@
           eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1
           eval file_in=${file_in_}
+
           (( i_ = i+1 ))
           eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
           eval file_out=${file_out_}
+
+          (( i_ = i+2 ))
+          eval is_opt=\${${ListFilesName}[$i_]} > /dev/null 2>&1
+          if [ X${is_opt} = XOPTIONAL ] ; then
+              # Read a forth argument
+              echo ${file_in} is optional
+              (( i=i+4 ))
+          else
+              is_opt="MANDATORY"
+              echo ${file_in} is mandatory
+              (( i=i+3 ))
+          fi
+
+          IGCM_debug_Print 3 "Now search for restart file ${file_in} which is ${is_opt} (in section do_start=n)"
 
           file_in_Name=${config_UserChoices_JobName}_${LastPeriodDateEnd}_${file_in}
@@ -922,12 +981,36 @@
               IGCM_debug_Print 3 "Restart files have been searched for in buffer and archive directory."
               IGCM_debug_Print 3 "They have been searched for in packed and unpacked format."
-              IGCM_debug_Exit "Please double check restart settings in config.card"
-              IGCM_debug_Verif_Exit
+              if [ ${is_opt} = 'OPTIONAL' ] ; then
+                 IGCM_debug_Print 3 "The restart file is optional. Now continue."
+                 nb_restart_file=0
+                 Tared=false
+              else
+                 IGCM_debug_Print 3 "The restart file is mandatory."
+                 IGCM_debug_Exit "Please double check restart settings in config.card"
+                 IGCM_debug_Verif_Exit
+              fi
+            else
+              # The tar file exist but not sure all files are inside 
+              IGCM_sys_PrepareTaredRestart ${TarFileFound}
+              TarFileLocation=$( basename ${TarFileFound} )
+              nb_files=$( tar tvf ${TarFileLocation} | grep ${comp}_${generic_restart_file_name_in}*.${extension_in} | wc -l )
+              if [ ${nb_files} -gt 0 ] ; then
+                IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
+                tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
+                nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
+              else
+                # No file was found
+                if [ ${is_opt} = 'OPTIONAL' ] ; then
+                  IGCM_debug_Print 3 "The restart file is not found in the tar file but it is optional. Now continue."
+                  nb_restart_file=0
+                  Tared=false
+                else
+                  IGCM_debug_Print 3 "The restart file was not found in the tar file but it is mandatory."
+                  IGCM_debug_Exit "Please double check restart settings in config.card"
+                  IGCM_debug_Verif_Exit
+                fi
+              fi
+
             fi
-            IGCM_sys_PrepareTaredRestart ${TarFileFound}
-            TarFileLocation=$( basename ${TarFileFound} )
-            IGCM_debug_Print 1 "tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
-            tar xvf ${TarFileLocation} ${comp}_${generic_restart_file_name_in}*.${extension_in}
-            nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
           fi
 
@@ -955,5 +1038,4 @@
             fi
           fi
-          (( i=i+3 ))
         done
       else
@@ -1732,8 +1814,7 @@
     ListFilesName=${compname}_RestartFiles_List
     eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
-
+    
     if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
       eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
-
       (( i=0 ))
       until [ $i -ge $NbFiles ]; do
@@ -1749,4 +1830,15 @@
         eval file_outin=${file_outin_}
 
+        (( i_ = i+3 ))
+	eval is_opt=\${${ListFilesName}[$i_]} > /dev/null 2>&1
+	if [ X${is_opt} = XOPTIONAL ] ; then
+	    echo ${file_in} is optional
+	    (( i=i+4 ))
+	else
+	    is_opt=""
+	    echo ${file_in} is mandatory
+	    (( i=i+3 ))
+	fi
+	
         generic_restart_file_name_in=$(    basename ${file_in} .nc )
         generic_restart_file_name_out=$(   basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc )
@@ -1760,33 +1852,46 @@
             j4=${j}                               # BASH LINE NOT NEEDED
             if [ X${Pack} = Xtrue ] ; then
-              eval IGCM_sys_PutBuffer_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_BUF_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
+              eval IGCM_sys_PutBuffer_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_BUF_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc ${is_opt}
             else
-              eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc
+              eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc ${is_opt}
             fi
-            if [ ! ${file_in} = ${file_outin} ] ; then
-              if ( ${ExitFlag} ) ; then
-                echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
-              else
-                IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
-              fi
-            fi
+
+	    if [ -f  ${generic_restart_file_name_in}_${j4}.nc ] ; then
+		if [ ! ${file_in} = ${file_outin} ] ; then
+		    if ( ${ExitFlag} ) ; then
+			echo "IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc not executed."
+		    else
+			IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc
+		    fi
+		fi
+	    else
+		# This is the case where the restart file no not exist.
+		# It has already been checked if the model should stop for this case.
+		IGCM_debug_Print 1 "Restart file does not exist, no move in RUN_DIR done :  ${generic_restart_file_name_in}_${j4}.nc"
+	    fi
             (( j=j+1 ))                           # BASH LINE NOT NEEDED
           done
         else
           if [ X${Pack} = Xtrue ] ; then
-            eval IGCM_sys_PutBuffer_Rest ${file_in} \${R_BUF_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
+            eval IGCM_sys_PutBuffer_Rest ${file_in} \${R_BUF_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} ${is_opt}
           else
-            eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out}
+            eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} ${is_opt}
           fi
-          if [ ! ${file_in} = ${file_outin} ] ; then
-            if ( ${ExitFlag} ) ; then
-              echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
-            else
-              IGCM_sys_Mv ${file_in} ${file_outin}
-            fi
-          fi
+
+	  if [ -f ${file_in} ] ; then
+	      if [ ! ${file_in} = ${file_outin} ] ; then
+		  if ( ${ExitFlag} ) ; then
+		      echo "IGCM_sys_Mv ${file_in} ${file_outin} not executed."
+		  else
+		      IGCM_sys_Mv ${file_in} ${file_outin}
+		  fi
+              fi
+	  else
+	      # This is the case where the restart file no not exist.
+	      # It has already been checked if the model should stop for this case.
+	      IGCM_debug_Print 1 "Restart file does not exist, no move in RUN_DIR done :   ${file_in}"
+	  fi
         fi
 
-        (( i=i+3 ))
       done
     else
