Index: branches/libIGCM_MPI_OpenMP/libIGCM_sys/libIGCM_sys_vargas.ksh
===================================================================
--- branches/libIGCM_MPI_OpenMP/libIGCM_sys/libIGCM_sys_vargas.ksh	(revision 558)
+++ branches/libIGCM_MPI_OpenMP/libIGCM_sys/libIGCM_sys_vargas.ksh	(revision 571)
@@ -81,5 +81,5 @@
 typeset -r RSYNC_opt="-va"
 # ie storage filesystem
-typeset -r RHOST=gaya.idris.fr
+typeset -r STOREHOST=gaya.idris.fr
 typeset -r REMOTE_RSYNC=/u/rech/ces/rces452/RSYNC/bin/rsync
 
@@ -118,4 +118,8 @@
 #- OUT
 typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
+
+#====================================================
+#- R_BUF  Buffer to pack files
+typeset -r R_BUF=${WORKDIR}/BUFFER_IGCM
 
 #====================================================
@@ -149,4 +153,43 @@
 
 #D-#==================================================
+#D-function IGCM_sys_RshMaster
+#D-* Purpose: Connection to frontend machine.
+#D-* Examples:
+#D-
+(( RshMNum = 0 ))
+function IGCM_sys_RshMaster {
+    IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
+
+    typeset THEFILE OUTFILE ERR
+
+    RshDIR=${WORKDIR}/RUN_DIR/${config_UserChoices_TagName}/${config_UserChoices_JobName}.${$}
+    if [ ! -d ${RshDIR} ] ; then
+	IGCM_sys_Mkdir ${RshDIR}
+    fi
+    THEFILE=${RshDIR}/file_sys_RshMaster_$$_${RshMNum}
+    echo '#!/bin/ksh' > ${THEFILE}
+    echo "export libIGCM=${libIGCM} > /dev/null 2>&1" >> ${THEFILE}
+    echo "export DEBUG_debug=${DEBUG_debug} > /dev/null 2>&1" >> ${THEFILE}
+    echo ". ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh > /dev/null 2>&1" >> ${THEFILE}
+    echo ". ${libIGCM}/libIGCM_card/libIGCM_card.ksh > /dev/null 2>&1" >> ${THEFILE}
+    echo "${@} " >> ${THEFILE}
+
+    # No frontend queue on brodie : just rsh the job on the frontend with submission.
+    sed -e "s@IGCM_sys_Qsub\(.*\)@\1@" ${THEFILE} > ${THEFILE}_
+
+    chmod u+x  ${THEFILE}_
+
+    OUTFILE=${RshDIR}/out_RshMaster.$$.${RshMNum}
+    (( RshMNum = RshMNum + 1 ))
+
+    rsh ${MASTER} 'bash -c "nohup '${THEFILE}'_ > '${OUTFILE}' 2>&1 &"'
+    if [ $? -gt 0 ] ; then
+	echo "IGCM_sys_RshMaster : erreur."
+	IGCM_debug_Exit "IGCM_sys_RshMaster"
+    fi
+    IGCM_debug_PopStack "IGCM_sys_RshMaster"
+}
+
+#D-#==================================================
 #D-function IGCM_sys_RshArchive
 #D-* Purpose: Archive rsh command
@@ -155,5 +198,5 @@
 function IGCM_sys_RshArchive {
     IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
-    rsh gaya exec /bin/ksh <<-EOF
+    rsh ${STOREHOST} exec /bin/ksh <<-EOF
     ${@}
 EOF
@@ -177,10 +220,10 @@
 
     # keep standard input to keep it for postpone if ulam don't answer
-    cat >/tmp/tmp_IGCM_sys_RshPost_$$
+    cat >/tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
 
     ## Add submission for old postponed files only if command is a Qsub
     ##
     ISITQSUB=0
-    grep Qsub /tmp/tmp_IGCM_sys_RshPost_$$ >/dev/null 2>&1 && ISITQSUB=1
+    grep Qsub /tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME} >/dev/null 2>&1 && ISITQSUB=1
     if  ( [ ${ISITQSUB} -gt 0 ] ) ; then 
       if [ -d ${SUBMIT_DIR}/POSTPONE ] ; then
@@ -201,12 +244,14 @@
     RETURN=0
     # rsh ulam command
-    rsh ulam exec /bin/ksh </tmp/tmp_IGCM_sys_RshPost_$$
+    rsh ulam exec /bin/ksh </tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
     RETURN=$?
 
     # keep standard input for postpone if ulam don't answer
     if ( [ ${RETURN} -gt 0 ] ) ; then
-        IGCM_debug_Print 2 "Postpone tmp_IGCM_sys_RshPost_$$"
+        IGCM_debug_Print 2 "Postpone tmp_IGCM_sys_RshPost_$$_${LOGNAME}"
         [ -d ${SUBMIT_DIR}/POSTPONE ] || mkdir ${SUBMIT_DIR}/POSTPONE
-        mv /tmp/tmp_IGCM_sys_RshPost_$$ ${SUBMIT_DIR}/POSTPONE
+        mv /tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME} ${SUBMIT_DIR}/POSTPONE
+    else
+        IGCM_sys_Rm /tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
     fi
     IGCM_debug_PopStack "IGCM_sys_RshPost"
@@ -290,5 +335,5 @@
     fi
     #- creation de repertoire sur le serveur fichier
-    rsh gaya -n mkdir -p $1
+    rsh ${STOREHOST} -n mkdir -p $1
 
     if [ $? -gt 0 ] ; then
@@ -413,4 +458,22 @@
 
 #D-#==================================================
+#D-function IGCM_sys_IsFileArchived
+#D-* Purpose: Test file that must NOT EXISTS on Archive
+#D-* always true on vargas.
+#D-* Examples:
+#D-
+function IGCM_sys_IsFileArchived {
+  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
+  if ( $DEBUG_sys ) ; then
+    echo "IGCM_sys_IsFileArchived :" $@
+  fi
+  typeset IsArchivedFlag
+  IsArchivedFlag=$( echo 0 )
+  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
+
+  return ${IsArchivedFlag}
+}
+
+#D-#==================================================
 #D-function IGCM_sys_TestFileArchive
 #D-* Purpose: Test file that must NOT EXISTS on Archive
@@ -427,4 +490,18 @@
 
 #D-#==================================================
+#D-function IGCM_sys_TestFileBuffer
+#D-* Purpose: Test file that must NOT EXISTS on Buffer
+#D-* Examples:
+#D-
+function IGCM_sys_TestFileBuffer {
+  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
+  typeset ExistFlag
+  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
+  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
+
+  return ${ExistFlag}
+}
+
+#D-#==================================================
 #D-function IGCM_sys_CountFileArchive
 #D-* Purpose: Count files on Archive filesystem
@@ -441,4 +518,18 @@
 
 #D-#==================================================
+#D-function IGCM_sys_CountFileBuffer
+#D-* Purpose: Count files on Scratch filesystem
+#D-* Examples:
+#D-
+function IGCM_sys_CountFileBuffer {
+  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
+  ls ${@} 2>/dev/null | wc -l
+  if [ $? -gt 0 ] ; then
+    echo "IGCM_sys_CountFileBuffer : erreur."
+  fi
+  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
+}
+
+#D-#==================================================
 #D-function IGCM_sys_Tree
 #D-* Purpose: Tree directories with files on ${ARCHIVE}
@@ -466,11 +557,9 @@
 	echo "IGCM_sys_Tar :" $@
     fi
-    \tar cvf $@
+    \tar cf $@
     if [ $? -gt 0 ] ; then
 	echo "IGCM_sys_Tar : erreur."
 	IGCM_debug_Exit "IGCM_sys_Tar"
     fi
-    \tar tvf $1
-
     IGCM_debug_PopStack "IGCM_sys_Tar"
 }
@@ -532,4 +621,5 @@
     fi
     cd ${POST_DIR}
+    echo MAF QsubPost vargas
     /opt/ibmll/LoadL/full/bin/llsubmit ${libIGCM_POST}/$1.job
     cd -
@@ -742,4 +832,6 @@
 	cat out_rsync
 	IGCM_debug_Exit "IGCM_sys_Cp"
+     else
+	 \rm out_rsync
     fi
     IGCM_debug_PopStack "IGCM_sys_Cp"
@@ -784,4 +876,6 @@
             cat out_rsync
             IGCM_debug_Exit "IGCM_sys_Mv"
+	else
+	    \rm out_rsync
         fi
     else
@@ -815,5 +909,5 @@
 	#
 	#USUAL WAY
-	rcp -r $1 gaya:$2 > out_rsync 2>&1
+	rcp -r $1 ${STOREHOST}:$2 > out_rsync 2>&1
   	RET=$?
 
@@ -822,4 +916,6 @@
 	    cat out_rsync
 	    IGCM_debug_Exit "IGCM_sys_Put_Dir"
+	else
+	    \rm out_rsync
 	fi
     else
@@ -849,5 +945,5 @@
 
 	#USUAL WAY
-	rcp -rp gaya:$1 $2 > out_rsync 2>&1
+	rcp -rp ${STOREHOST}:$1 $2 > out_rsync 2>&1
   	RET=$?
 
@@ -894,6 +990,6 @@
 
 # 	#RSYNC WITH NETWORK RSH CALL
-# 	echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
-# 	${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
+# 	echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
+# 	${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
 
 #  	#RSYNC WITH NFS USE
@@ -911,4 +1007,6 @@
 	    cat out_rsync
 	    IGCM_debug_Exit "IGCM_sys_Put_Rest"
+	else
+	    \rm out_rsync
 	fi
     else
@@ -916,4 +1014,45 @@
     fi
     IGCM_debug_PopStack "IGCM_sys_Put_Rest"
+}
+
+#D-#==================================================
+#D-function IGCM_sys_PutBuffer_Rest
+#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
+#D-           File and target directory must exist.
+#D-* Examples:
+#D-
+function IGCM_sys_PutBuffer_Rest {
+  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
+  if ( $DEBUG_sys ) ; then
+    echo "IGCM_sys_PutBuffer_Rest :" $@
+  fi
+  if [ $DRYRUN = 0 ]; then
+    if [ ! -f ${1} ] ; then
+      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
+      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
+    fi
+
+    typeset RET
+    #
+    if [ X${JobType} = XRUN ] ; then
+      IGCM_sys_Chmod 444 ${1}
+    fi
+
+    #
+    # USUAL WAY
+    \cp $1 $2 > out_rsync 2>&1
+    RET=$?
+
+    if [ ${RET} -gt 0 ] ; then
+      echo "IGCM_sys_PutBuffer_Rest : error."
+      cat out_rsync
+      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
+    else
+      \rm out_rsync
+    fi
+  else
+    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
+  fi
+  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
 }
 
@@ -951,6 +1090,6 @@
 
 # 	#RSYNC WITH NETWORK RSH CALL
-# 	echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
-# 	${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
+# 	echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
+# 	${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
 
 #  	#RSYNC WITH NFS USE
@@ -968,4 +1107,6 @@
 	    cat out_rsync
 	    IGCM_debug_Exit "IGCM_sys_Put_Out"
+	else
+	    \rm out_rsync
 	fi
 	IGCM_sys_Rm out_rsync
@@ -975,4 +1116,49 @@
     IGCM_debug_PopStack "IGCM_sys_Put_Out"
     return 0
+}
+
+#D-#==================================================
+#D-function IGCM_sys_PutBuffer_Out
+#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
+#D-* Examples:
+#D-
+function IGCM_sys_PutBuffer_Out {
+  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
+  if ( $DEBUG_sys ) ; then
+    echo "IGCM_sys_PutBuffer_Out :" $@
+  fi
+  if [ $DRYRUN = 0 ]; then
+    if [ ! -f ${1} ] ; then
+      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
+      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
+      return 1
+    fi
+    #
+    IGCM_sys_Mkdir $( dirname $2 )
+    #
+    typeset RET
+
+    if [ X${JobType} = XRUN ] ; then
+      if [ X${3} = X ] ; then
+        IGCM_sys_Chmod 444 ${1}
+      fi
+    fi
+    #
+    # USUAL WAY
+    \cp $1 $2 > out_rsync 2>&1
+    RET=$?
+
+    if [ ${RET} -gt 0 ] ; then
+      echo "IGCM_sys_PutBuffer_Out : error."
+      cat out_rsync
+      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
+    else
+      \rm out_rsync
+    fi
+  else
+    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
+  fi
+  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
+  return 0
 }
 
@@ -1025,6 +1211,6 @@
 
 # 	#RSYNC WITH NETWORK RSH CALL
-# 	echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
-# 	${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
+# 	echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
+# 	${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
 
 #  	#RSYNC WITH NFS USE
@@ -1042,4 +1228,6 @@
 	    cat out_rsync
 	    IGCM_debug_Exit "IGCM_sys_Get"
+	else
+	    \rm out_rsync
 	fi
     else
@@ -1047,4 +1235,52 @@
     fi
     IGCM_debug_PopStack "IGCM_sys_Get"
+}
+
+#D-#==================================================
+#D-function IGCM_sys_GetBuffer
+#D-* Purpose: Get a file from ${SCRATCHDIR}
+#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
+#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
+function IGCM_sys_GetBuffer {
+  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
+
+  typeset DEST RET buf_liste ifile target file_work
+
+  if ( $DEBUG_sys ) ; then
+    echo "IGCM_sys_GetBuffer :" $@
+  fi
+  if [ $DRYRUN -le 2 ]; then
+    if [ X${1} = X'/l' ] ; then
+      # test if the first file is present in the old computation :
+      eval set +A buf_liste \${${2}}
+    else
+      eval set +A buf_liste ${1}
+    fi
+    eval DEST=\${${#}}
+
+    #USUAL WAY
+    if [ X${1} = X'/l' ] ; then
+      (( RET=0 ))
+      for target in ${buf_liste[*]} ; do
+        local_file=$( basename ${target} )
+        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
+        (( RET = RET + $? ))
+      done
+    else
+      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
+      RET=$?
+    fi
+
+    if [ ${RET} -gt 0 ] ; then
+      echo "IGCM_sys_GetBuffer : copy error."
+      cat out_rsync
+      IGCM_debug_Exit "IGCM_sys_GetBuffer"
+    else
+      \rm out_rsync
+    fi
+  else
+    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
+  fi
+  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
 }
 
@@ -1061,4 +1297,8 @@
 	echo "IGCM_sys_GetDate_FichWork :" $@
     fi
+    typeset dateF
+    set +A dateF -- $( rsh ${MASTER} -n /opt/freeware/bin/ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
+    eval ${2}=${dateF[5]}
+
     # donne la date filesys d'un fichier sur la machine work
     IGCM_debug_PopStack "IGCM_sys_FichWork"
@@ -1075,4 +1315,8 @@
 	echo "IGCM_sys_GetDate_FichArchive :" $@
     fi
+    typeset dateF
+    set +A dateF -- $( rsh ${STOREHOST} -n ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
+    eval ${2}=${dateF[5]}
+
     IGCM_debug_PopStack "IGCM_sys_FichArchive"
 }
