Index: /trunk/libIGCM/AA_RunChecker
===================================================================
--- /trunk/libIGCM/AA_RunChecker	(revision 752)
+++ /trunk/libIGCM/AA_RunChecker	(revision 753)
@@ -1,6 +1,4 @@
 #!/bin/ksh
 
-# Created by: S. Labetoulle
-# Date:       May 19th 2010
 #**************************************************************
 # Author: Sonia Labetoulle
@@ -17,4 +15,13 @@
 
 # Display a report on how a simulation is faring.
+
+function ChangeUsr {
+
+#  echo ">$1<"
+
+  echo $1 | sed -e "s/${CurrentUsr}/${TargetUsr}/" \
+                -e "s/${CurrentGrp}/${TargetGrp}/"
+
+}
 
 
@@ -49,7 +56,7 @@
     if [ ${NbOcc} -eq 1 ] ; then
 
-      if ( [ ${UserName} == $( awk -v JobName=${JobName} '$1 ~ JobName {print $2}' ${SimuCatalog} ) ] && [ ${HostName} == $( awk -v JobName=${JobName} '$1 ~ JobName {print $3}' ${SimuCatalog} ) ] ) ; then
+      if ( [ ${TargetUsr} == $( awk -v JobName=${JobName} '$1 ~ JobName {print $2}' ${SimuCatalog} ) ] && [ ${HostName} == $( awk -v JobName=${JobName} '$1 ~ JobName {print $3}' ${SimuCatalog} ) ] ) ; then
         JobName=$( awk -v JobName=${JobName} '$1 ~ JobName {print $1}' ${SimuCatalog} )
-        UserName=$( awk -v JobName=${JobName} '$1 ~ JobName {print $2}' ${SimuCatalog} )
+        TargetUsr=$( awk -v JobName=${JobName} '$1 ~ JobName {print $2}' ${SimuCatalog} )
         HostName=$( awk -v JobName=${JobName} '$1 ~ JobName {print $3}' ${SimuCatalog} )
         SUBMIT_DIR=$( awk -v JobName=${JobName} '$1 ~ JobName {print $4}' ${SimuCatalog} )
@@ -191,4 +198,8 @@
 #D- Task type (computing or post-processing)
 TaskType=post-processing
+typeset -i Verbosity=0
+
+CurrentUsr=$( whoami )
+CurrentGrp=$( groups $CurrentUsr | awk '{print $3}' )
 
 libIGCM=${libIGCM:=::modipsl::/libIGCM}
@@ -202,4 +213,5 @@
 #-------
 . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
+. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
 
 if ( [ $# -eq 0 ] ) ; then
@@ -209,5 +221,5 @@
 
 # Default argument values
-UserName=$( whoami )
+TargetUsr=${CurrentUsr}
 HostName=$( hostname | sed -e "s/[0-9].*//" )
 
@@ -215,4 +227,5 @@
 fg_new=".false."
 fg_quiet=".false."
+(( NbHisto = 1 ))
 
 # Get arguments from command line
@@ -220,5 +233,5 @@
   case $1 in
     -h|--help|-help)
-      echo "usage: $0 [-u UserName] JobName"
+      echo "usage: $0 [-u TargetUsr] JobName"
       exit ;;
     -b|--nocolor)
@@ -235,5 +248,5 @@
       shift 2 ;;
     -u|--user)
-      UserName="$2"
+      TargetUsr="$2"
       shift 2 ;;
     -*)
@@ -247,13 +260,8 @@
 JobName=$1
 
-echo "UserName = ${UserName}"
+echo "TargetUsr = ${TargetUsr}"
 echo "HostName = ${HostName}"
 
-# Define useful directories
-SCRAT_DIR=$( ccc_home -s -u ${UserName} )
-STORE_DIR=$( ccc_home -A -u ${UserName} )
-CWORK_DIR=$( ccc_home -W -u ${UserName} )
-WORK_DIR=$( ccc_home -w -u ${UserName} )
-
+TargetGrp=$( groups $TargetUsr | awk '{print $3}' )
 
 # Define the catalog in which the known simulations are stored
@@ -277,8 +285,11 @@
 
 
-# Extract usefull information from run.card and config.card
+  # Extract usefull information from run.card and config.card
 
   RunFile="${SUBMIT_DIR}/run.card"
   ConfFile="${SUBMIT_DIR}/config.card"
+
+  IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card
+
 
   if [ -s ${RunFile} ] ; then
@@ -297,9 +308,4 @@
   fi
 
-  IGCM_card_DefineVariableFromOption ${ConfFile} UserChoices DateBegin
-  IGCM_card_DefineVariableFromOption ${ConfFile} UserChoices DateEnd
-  IGCM_card_DefineVariableFromOption ${ConfFile} UserChoices TagName
-  IGCM_card_DefineVariableFromOption ${ConfFile} UserChoices ExperimentName
-  IGCM_card_DefineVariableFromOption ${ConfFile} UserChoices SpaceName
   DateBegin=${config_UserChoices_DateBegin}
   DateEnd=${config_UserChoices_DateEnd}
@@ -321,14 +327,20 @@
   fi
 
-  if [ ! X${ExperimentName} == X ] ; then
-    EXP_DIR=IGCM_OUT/${TagName}/${SpaceName}/${ExperimentName}/${JobName}
-  else
-    EXP_DIR=IGCM_OUT/${TagName}/${JobName}
-  fi
-
-  DATA_DIR=${STORE_DIR}/${EXP_DIR}
-  POST_DIR=${SCRAT_DIR}/${EXP_DIR}/Out
-  CWORK_DIR=${CWORK_DIR}/${EXP_DIR}
-  REBUILD_DIR=${SCRAT_DIR}/REBUILD/${TagName}/${JobName}
+  DATA_DIR=${R_SAVE}
+  POST_DIR=${R_BUFR}/Out
+  CWORK_DIR=${R_FIGR}
+  if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
+    REBUILD_DIR=${R_SAVE}/TMP
+  else
+    REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
+  fi
+
+  if [ ${TargetUsr} != ${CurrentUsr} ] ; then
+    DATA_DIR=$( ChangeUsr ${DATA_DIR})
+    POST_DIR=$( ChangeUsr ${POST_DIR} )
+    CWORK_DIR=$( ChangeUsr ${CWORK_DIR} )
+    REBUILD_DIR=$( ChangeUsr ${REBUILD_DIR} )
+  fi
+
   echo "Data:    >${DATA_DIR}<"
   echo "Rebuild: >${REBUILD_DIR}<"
@@ -336,5 +348,4 @@
   echo "Work:    >${CWORK_DIR}<"
 
-
   if [ $PeriodState != "Waiting" ] ; then
 
@@ -364,27 +375,28 @@
   # Check last REBUILD
   FileType=rebuild_*
-  (( num = 1 ))
-  LastDate[$num]=$( ls ${POST_DIR}/${FileType}.*.out | tail -n 1 | awk -F"." '{ print $2 }' )
-
-  dum=$( basename $( grep ^IGCM_sys_PutBuffer_Out ${POST_DIR}/${FileType}.${LastDate[$num]}.out | tail -1 | awk '{ print $4 }' ) | awk -F"_" '{ print $3 }' )
-
-  if [[ ${dum} == ${LastDate[$num]} ]] ; then
-    Result[$num]=OK
-  else
-    Result[$num]=KO
+  (( ind = 1 ))
+
+  LastDate[$ind]=$( ls ${POST_DIR}/${FileType}.*.out | tail -n ${NbHisto} | awk -F"." '{ print $2 }' )
+
+  dum=$( basename $( grep ^IGCM_sys_PutBuffer_Out ${POST_DIR}/${FileType}.${LastDate[$ind]}.out | tail -1 | awk '{ print $4 }' ) | awk -F"_" '{ print $3 }' )
+
+  if [[ ${dum} == ${LastDate[$ind]} ]] ; then
+    Result[$ind]=OK
+  else
+    Result[$ind]=KO
   fi
 
   # Check last PACK jobs
   for FileType in pack_output pack_restart pack_debug ; do
-    (( num = num + 1 ))
-
-    LastDate[$num]=$( ls ${POST_DIR}/${FileType}.*.out | tail -n 1 | awk -F"." '{ print $2 }' )
-
-    dum=$( basename $( grep ^IGCM_sys_Put_Out ${POST_DIR}/${FileType}.${LastDate[$num]}.out | tail -1 | awk '{ print $3 }' ) | awk -F"_" '{ print $3 }' )
-
-    if [[ ${dum} == ${LastDate[$num]} ]] ; then
-      Result[$num]=OK
+    (( ind = ind + 1 ))
+
+    LastDate[$ind]=$( ls ${POST_DIR}/${FileType}.*.out | tail -n ${NbHisto} | awk -F"." '{ print $2 }' )
+
+    dum=$( basename $( grep ^IGCM_sys_Put_Out ${POST_DIR}/${FileType}.${LastDate[$ind]}.out | tail -1 | awk '{ print $3 }' ) | awk -F"_" '{ print $3 }' )
+
+    if [[ ${dum} == ${LastDate[$ind]} ]] ; then
+      Result[$ind]=OK
     else
-      Result[$num]=KO
+      Result[$ind]=KO
     fi
   done
@@ -396,14 +408,14 @@
 
   FileType=monitoring
-  (( num = num + 1 ))
-
-  LastDate[$num]=$( cdo showyear ${CWORK_DIR}/MONITORING/files/ATM_bils_global_ave.nc 2> /dev/null | awk '{ print $NF }' )
+  (( ind = ind + 1 ))
+
+  LastDate[$ind]=$( cdo showyear ${CWORK_DIR}/MONITORING/files/ATM_bils_global_ave.nc 2> /dev/null | awk '{ print $NF }' )
 
   # Check last ATLAS jobs
 
   FileType=atlas
-  (( num = num + 1 ))
-
-  LastDate[$num]=$( ls ${CWORK_DIR}/ATLAS | tail -1 )
+  (( ind = ind + 1 ))
+
+  LastDate[$ind]=$( ls ${CWORK_DIR}/ATLAS | tail -n ${NbHisto} )
 
 
