Index: /trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh	(revision 1012)
+++ /trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh	(revision 1013)
@@ -217,10 +217,33 @@
 function IGCM_sys_RshArchive {
   IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
+  typeset ergonCount gayaCount
   DEBUG_sys=false IGCM_sys_IsFileArchived "$@"
   if [ $? = 0 ] ; then
+    status=0
+    #special case for the find command. Only used together with RshArchive to find tared restart
+    if [ "X$( echo $@ | grep ^find )" != "X" ] ; then
+      # Ergon first
+      rsh ${STOREHOST} exec /bin/ksh <<-EOF > ergonList.txt
+    ${@}
+EOF
+      (( status=status + $? ))
+      # Gaya turn
+      rsh gaya exec /bin/ksh <<-EOF > gayaList.txt
+    ${@}
+EOF
+      (( status=status + $? ))
+
+      # the more the better
+      ergonCount=$( cat ergonList.txt | wc -l )
+      gayaCount=$(  cat gayaList.txt | wc -l  )
+
+      [ ${ergonCount} -ge ${gayaCount} ] && cat ergonList.txt || cat gayaList.txt
+      rm -f ergonList.txt gayaList.txt
+    else
     rsh ${STOREHOST} exec /bin/ksh <<-EOF
     ${@}
 EOF
     status=$?
+    fi
   else
     /bin/ksh <<-EOF
@@ -511,20 +534,38 @@
 #D-* Examples:
 #D-
+#function IGCM_sys_TestFileArchive {
+#  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
+#  typeset ExistFlag TempCommandFile
+#  TempCommandFile="[ -f $1 ] && echo 0 || echo 1"
+#  #Command depends on targeted file system
+#  #We want it quiet
+#  DEBUG_sys=false IGCM_sys_IsFileArchived $1
+#  if [ $? = 0 ] ; then
+#    ExistFlag=$( IGCM_sys_RshArchive ${TempCommandFile} )
+#  else
+#    ExistFlag=$( ${TempCommandFile} )
+#  fi
+#  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
+#
+#  return ${ExistFlag}
+#}
+
+#D-#==================================================
+#D-function IGCM_sys_TestFileArchive
+#D-* Purpose: Test file that must NOT EXISTS on Archive
+#D-* Examples:
+#D-
 function IGCM_sys_TestFileArchive {
   IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
-  typeset ExistFlag TempCommandFile
-  TempCommandFile="[ -f $1 ] && echo 0 || echo 1"
-  #Command depends on targeted file system
-  #We want it quiet
-  DEBUG_sys=false IGCM_sys_IsFileArchived $1
-  if [ $? = 0 ] ; then
-    ExistFlag=$( IGCM_sys_RshArchive ${TempCommandFile} )
-  else
-    ExistFlag=$( ${TempCommandFile} )
-  fi
+  typeset ExistFlag finalPosition
+
+  finalPosition=$( mfls $1 | wc -l )
+  [ ${finalPosition} -eq 8 ] && ExistFlag=1 || ExistFlag=0
+
   IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
 
   return ${ExistFlag}
 }
+
 
 #D-#==================================================
@@ -542,4 +583,26 @@
 }
 
+##D-#==================================================
+##D-function IGCM_sys_CountFileArchive
+##D-* Purpose: Count files on Archive filesystem
+##D-* Examples:
+##D-
+#function IGCM_sys_CountFileArchive {
+#  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
+#  #Command depends on targeted file system
+#  DEBUG_sys=false IGCM_sys_IsFileArchived $1
+#  if [ $? = 0 ] ; then
+#    IGCM_sys_RshArchive "ls ${@} 2>/dev/null | wc -l"
+#    status=$?
+#  else
+#    ls ${@} 2>/dev/null | wc -l
+#    status=$?
+#  fi
+#  if [ ${status} -gt 0 ] ; then
+#    echo "IGCM_sys_CountFileArchive : erreur."
+#  fi
+#  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
+#}
+
 #D-#==================================================
 #D-function IGCM_sys_CountFileArchive
@@ -549,9 +612,25 @@
 function IGCM_sys_CountFileArchive {
   IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
+  typeset status gayaPosition ergonPosition finalPosition gayaCount ergonCount
   #Command depends on targeted file system
   DEBUG_sys=false IGCM_sys_IsFileArchived $1
   if [ $? = 0 ] ; then
-    IGCM_sys_RshArchive "ls ${@} 2>/dev/null | wc -l"
-    status=$?
+    status=0
+    gayaPosition=$(  mfls ${@} | grep -n "++ Gaya"  | awk -F\: {'print $1'} )
+    (( status=status + $? ))
+    ergonPosition=$( mfls ${@} | grep -n "++ Ergon" | awk -F\: {'print $1'} )
+    (( status=status + $? ))
+    finalPosition=$( mfls ${@} | wc -l )
+    (( status=status + $? ))
+
+    (( gayaCount  = ergonPosition - gayaPosition - 4 ))
+    (( ergonCount = finalPosition - ergonPosition - 2 ))
+
+    # return number of files found. greater the better
+    [ ${ergonCount} -ge ${gayaCount} ] && echo ${ergonCount} || echo ${gayaCount}
+
+    # "Ergon only" case
+    #IGCM_sys_RshArchive "ls ${@} 2>/dev/null | wc -l"
+    #status=$?
   else
     ls ${@} 2>/dev/null | wc -l
