Index: /trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh	(revision 671)
+++ /trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh	(revision 672)
@@ -661,4 +661,6 @@
       if [ "${do_start}" = "y" ] ; then
 
+        # Restore Restarts files
+        #-----------------------
 	if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
 	  eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
@@ -668,5 +670,4 @@
 	    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
@@ -675,29 +676,76 @@
 	    eval Date_tmp=\${config_${comp}_RestartDate}
 	    Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} )
-	    eval Path_r=\${config_${comp}_RestartPath}/\${config_${comp}_RestartJobName}/${CompOldName}/Restart
-	    eval file_in_Name=\${config_${comp}_RestartJobName}_${Date_r}_${file_in}
-
-	    generic_restart_file_name_in=$( basename ${file_in_Name} .nc )
-	    generic_restart_file_name_out=$( basename ${file_out} .nc )
+            # will be re-use
+            eval RestartPath=\${config_${comp}_RestartPath}
+            eval RestartJobName=\${config_${comp}_RestartJobName}
+            #
+	    Path_r=${RestartPath}/${RestartJobName}/${CompOldName}/Restart
+	    file_in_Name=${RestartJobName}_${Date_r}_${file_in}
+
+	    extension_in=$( echo ${file_in_Name##*.} )
+	    extension_out=$( echo ${file_out##*.} )
+
+	    generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
+	    generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
 	    
-	    eval Path_OUT=\${Path_r}/${generic_restart_file_name_in}
-	    nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.nc)
-
-	    if [ ${nb_restart_file} -gt 1 ] ; then
+	    Path_OUT=${Path_r}/${generic_restart_file_name_in}
+
+            if [ $( IGCM_sys_TestFileBuffer ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
+	      IGCM_debug_Print 3 "Buffered restart"
+	      Buffered=true
+	      Archived=false
+	      Tared=false
+	      nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_OUT}_????.${extension_in})
+            elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
+	      IGCM_debug_Print 3 "Archived restart"
+	      Buffered=false
+	      Archived=true
+	      Tared=false
+	      nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
+            else
+              IGCM_debug_Print 3 "Tared restart"
+	      Buffered=false
+	      Archived=false
+	      Tared=true
+              # Look after the tar file we want if we did not found it already
+	      if [ X${IsMatching} = X ] ; then
+	        for PotentialTarFile in $( find ${RestartPath}/${RestartJobName}/RESTART -name "${RestartJobName}_*_restart.tar" -print ) ; do
+		  IsMatching=$( echo ${PotentialTarFile##*/} | sed "s:^${RestartJobName}_::" | sed "s:\.restart\.tar$::" | gawk -F_ -v restartdate=${Date_r} '{if (($1 < restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
+		  if [ ! X${IsMatching} = X ] ; then
+		    TarFileFound=${PotentialTarFile}
+		    break
+		  fi
+	        done
+	      fi
+              IGCM_debug_Print 1 "tar xvf ${TarFileFound} ${comp}_${generic_restart_file_name_in}*.${extension_in}"
+	      tar xvf ${TarFileFound} ${comp}_${generic_restart_file_name_in}*.${extension_in}
+	      nb_restart_file=$( IGCM_sys_CountFileBuffer ${comp}_${generic_restart_file_name_in}_????.${extension_in} )
+	    fi
+
+            if [ ${nb_restart_file} -gt 1 ] ; then
 	      j=0
 	      until [ $j -ge $nb_restart_file ]; do
-		j4=${j}
-		eval IGCM_sys_Get ${Path_r}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
-		#IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc
-		#eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1
-		(( j=j+1 ))
+	        j4=${j}
+	        if [ X${Buffered} = Xtrue ] ; then
+		  IGCM_sys_GetBuffer ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
+	        elif [ X${Archived} = Xtrue ] ; then
+		  IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
+	        elif [ X${Tared} = Xtrue ] ; then
+		  IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
+	        fi
+	        (( j=j+1 ))
 	      done
 	    else
-	      eval IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}  
-	      #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out}
-	    fi
-	    
+	      if [ X${Buffered} = Xtrue ] ; then
+	        IGCM_sys_GetBuffer ${Path_r}/${file_in_Name} ${file_out}
+	      elif [ X${Archived} = Xtrue ] ; then
+	        IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out}
+	      elif [ X${Tared} = Xtrue ] ; then
+	        IGCM_sys_Mv ${comp}_${file_in_Name} ${file_out}
+	      fi
+	    fi
 	    (( i=i+3 ))
 	  done
+
 	else
 	  if [ X${FileName0} != XNONE ] ; then
@@ -725,10 +773,8 @@
 	  
 	  file_in_Name=${run_Configuration_OldPrefix}_${file_in}
-
 	  
 	  extension_in=$( echo ${file_in_Name##*.} )
 	  extension_out=$( echo ${file_out##*.} )
 
-
 	  generic_restart_file_name_in=$( basename ${file_in_Name} .${extension_in} )
 	  generic_restart_file_name_out=$( basename ${file_out} .${extension_out} )
@@ -737,5 +783,4 @@
 	  eval Path_OUT=\${R_OUT_${comp}_R}/${generic_restart_file_name_in}
 
-	  #if [ -f ${Path_BUF}*.nc ] ; then
           if [ $( IGCM_sys_TestFileBuffer ${Path_BUF}*.${extension_in} ; echo $? ) = 0 ] ; then
 	    IGCM_debug_Print 3 "Buffered restart"
@@ -744,11 +789,10 @@
 	    Tared=false
 	    nb_restart_file=$(IGCM_sys_CountFileBuffer ${Path_BUF}_????.${extension_in})
-	  #elif [ -f ${Path_OUT}*.nc ] ; then
-          elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_out} ; echo $? ) = 0 ] ; then
+          elif [ $( IGCM_sys_TestFileArchive ${Path_OUT}*.${extension_in} ; echo $? ) = 0 ] ; then
 	    IGCM_debug_Print 3 "Archived restart"
 	    Buffered=false
 	    Archived=true
 	    Tared=false
-	    nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_out})
+	    nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_OUT}_????.${extension_in})
 	  else
 	    IGCM_debug_Print 3 "Tared restart"
@@ -777,5 +821,5 @@
 		IGCM_sys_GetBuffer ${Path_BUF}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
 	      elif [ X${Archived} = Xtrue ] ; then
-		IGCM_sys_Get ${Path_OUT}_${j4}.${extension_out} ${generic_restart_file_name_out}_${j4}.${extension_out}
+		IGCM_sys_Get ${Path_OUT}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
 	      elif [ X${Tared} = Xtrue ] ; then
 		IGCM_sys_Mv ${comp}_${generic_restart_file_name_in}_${j4}.${extension_in} ${generic_restart_file_name_out}_${j4}.${extension_out}
