Index: /trunk/libIGCM/AA_RunChecker
===================================================================
--- /trunk/libIGCM/AA_RunChecker	(revision 753)
+++ /trunk/libIGCM/AA_RunChecker	(revision 754)
@@ -13,6 +13,6 @@
 
 #======================================================================#
-
 # Display a report on how a simulation is faring.
+
 
 function ChangeUsr {
@@ -35,14 +35,14 @@
 
   if [ ${NbOcc} -eq 0 ] ; then
-    if [ X${fg_new} == X.true. ] ; then
-      echo "${JobName} not in Catalog, we'll try to find it in ${WORK_DIR}"
+    if ( ${fg_new} ) ; then
+      echo "${JobName} not in Catalog, we'll try to find it in ${WORKDIR}"
       
       set -A FileList
-      FileList=$( find ${WORK_DIR}/ -name "Job_${JobName}" )
+      FileList=$( find ${WORKDIR}/ -name "Job_${JobName}" )
       echo $FileList
       (( NbOcc = ${#FileList[@]} ))
     else
       echo "${JobName} not in Catalog."
-      echo "Use option -n / --new to look for it and add it to the catalog."
+      echo "Add job_name, user_name, host_name and submit_dir in ${SimuCatalog}"
       exit
     fi
@@ -73,14 +73,18 @@
 function AffichResult {
 
-  fg_first=".false."
-  fg_last=".false."
+  fg_first=false
+  fg_last=false
+  fg_job=false
 
   while [ $# -ne 0 ] ; do
     case ${1} in
       -f|--first)
-	fg_first=".true."
+	fg_first=true
 	shift 1 ;;
       -l|--last)
-	fg_last=".true."
+	fg_last=true
+	shift 1 ;;
+      -j|--job)
+	fg_job=true
 	shift 1 ;;
       -*)
@@ -95,4 +99,5 @@
 
   # Define colors
+  # =============
   ColEsc="\033["
   ColNon="${ColEsc}0m"       # Return to normal
@@ -106,5 +111,7 @@
 
   
-  if [ X${fg_first} == X.true. ] ; then
+  #Â Print header
+  # ============
+  if ( ${fg_first} ) ; then
     Dum=""
     (( len = 67 - ${#JobName} ))
@@ -117,8 +124,88 @@
     echo "| Date Begin - DateEnd    | PeriodState | Current Period          | CumulPeriod | Nb  : from     : to       |"
     echo "|-------------------------|-------------|-------------------------|-------------|-----:----------:----------|"
+
+    printf "| %-10s - %-10s | " \
+           $DateBegin $DateEnd 
+
+    case $PeriodState in
+      Fatal)
+        Color=${ColFat}
+        break ;;
+      Completed)
+        Color=${ColCpl}
+        break ;;
+      Waiting|OnQueue)
+        Color=${ColAtt}
+        break ;;
+      *)
+        Color=${ColDef}
+        break ;;
+    esac
+    printf "${Color}%-11s${ColNon} | " $PeriodState
+
+    printf "%-10s - %-10s | %11s | " \
+           $PeriodDateBegin $PeriodDateEnd $CumulPeriod
+
+    if ( [ X${NbRebuild} != X. ] && [ X${NbRebuild} != X0 ] ) ; then
+      printf "${ColRbl}%3s : %-8s : %-8s${ColNon} |\n" \
+             $NbRebuild $FirstRebuild $LastRebuild
+    else
+      printf "%3s : %-8s : %-8s |\n" \
+             $NbRebuild $FirstRebuild $LastRebuild
+    fi
+
+    printf "|-----------------------------------------------------------------------------------------------------------|\n"
+    printf "|                                                      Last                                                 |\n"
+    printf "|     Rebuild      |   Pack_Output    |   Pack_Restart   |    Pack_Debug    |  Monitoring  |     Atlas      |\n"
+    printf "|------------------|------------------|------------------|------------------|--------------|----------------|\n"
+
     return
   fi
 
-  if [ X${fg_last} == X.true. ] ; then
+  # Print Post-processing job status
+  # ================================
+  if ( ${fg_job} ) ; then
+    printf "|"
+
+    #Â Print rebuild and pack jobs
+    #Â ---------------------------
+    for JobType in ${JobType_list[*]} ; do 
+      eval Date=\${${JobType}_Date[${ind}]}
+      eval Status=\${${JobType}_Status[${ind}]}
+
+      if [ X${Status} == XOK  ] ; then
+        Color=${ColCpl}
+      else
+        Color=${ColFat}
+      fi
+      printf "     ${Color}%-8s${ColNon}     |" ${Date}
+    done
+
+    Color=${ColExp}
+
+    #Â Print monitoring jobs
+    #Â ---------------------
+    JobType=monitoring
+    if [ $ind -eq 0 ] ; then
+      eval Date=\${${JobType}_Date}
+    else
+      Date=""
+    fi
+    printf "     ${Color}%-4s${ColNon}     |" ${Date}
+
+    #Â Print atlas jobs
+    #Â ----------------
+    JobType=atlas
+    eval Date=\${${JobType}_Date[${ind}]}
+    printf "  ${Color}%-12s${ColNon}  |" ${Date}
+
+    printf "\n"
+
+    return
+  fi
+
+  #Â Print footer
+  #Â ============
+  if ( ${fg_last} ) ; then
     printf "|===========================================================================================================|\n"
     date +"${DateFormat}"
@@ -126,70 +213,4 @@
   fi
 
-  printf "| %-10s - %-10s | " \
-	 $DateBegin $DateEnd 
-
-  case $PeriodState in
-    Fatal)
-      Color=${ColFat}
-      break ;;
-    Completed)
-      Color=${ColCpl}
-      break ;;
-    Waiting|OnQueue)
-      Color=${ColAtt}
-      break ;;
-    *)
-      Color=${ColDef}
-      break ;;
-  esac
-  printf "${Color}%-11s${ColNon} | " $PeriodState
-
-  printf "%-10s - %-10s | %11s | " \
-	 $PeriodDateBegin $PeriodDateEnd $CumulPeriod
-
-  if ( [ X${NbRebuild} != X. ] && [ X${NbRebuild} != X0 ] ) ; then
-    printf "${ColRbl}%3s : %-8s : %-8s${ColNon} |\n" \
-	   $NbRebuild $FirstRebuild $LastRebuild
-  else
-    printf "%3s : %-8s : %-8s |\n" \
-	   $NbRebuild $FirstRebuild $LastRebuild
-  fi
-
-  printf "|-----------------------------------------------------------------------------------------------------------|\n"
-  printf "|                                                      Last                                                 |\n"
-  printf "|     Rebuild      |   Pack_Output    |   Pack_Restart   |    Pack_Debug    |  Monitoring  |     Atlas      |\n"
-  printf "|------------------|------------------|------------------|------------------|--------------|----------------|\n"
-
-  if [ X${Result[1]} == XOK  ] ; then
-    Color=${ColCpl}
-  else
-    Color=${ColFat}
-  fi
-  printf "|     ${Color}%-8s${ColNon}     |" ${LastDate[1]}
-
-  if [ X${Result[2]} == XOK  ] ; then
-    Color=${ColCpl}
-  else
-    Color=${ColFat}
-  fi
-  printf "     ${Color}%-8s${ColNon}     |" ${LastDate[2]}
-
-  if [ X${Result[3]} == XOK  ] ; then
-    Color=${ColCpl}
-  else
-    Color=${ColFat}
-  fi
-  printf "     ${Color}%-8s${ColNon}     |" ${LastDate[3]}
-
-  if [ X${Result[4]} == XOK  ] ; then
-    Color=${ColCpl}
-  else
-    Color=${ColFat}
-  fi
-  printf "     ${Color}%-8s${ColNon}     |" ${LastDate[4]}
-
-  Color=${ColExp}
-  printf "     ${Color}%-4s${ColNon}     |  ${Color}%-12s${ColNon}  |\n" \
-	 ${LastDate[5]} ${LastDate[6]}
 }
 
@@ -203,4 +224,62 @@
 CurrentGrp=$( groups $CurrentUsr | awk '{print $3}' )
 
+if ( [ $# -eq 0 ] ) ; then
+  $0 -h
+  exit
+fi
+
+# Arguments
+# =========
+# Default argument values
+#Â -----------------------
+TargetUsr=${CurrentUsr}
+HostName=$( hostname | sed -e "s/[0-9].*//" )
+
+fg_color=true
+fg_new=false
+fg_quiet=false
+NbHisto=10
+
+# Get arguments from command line
+# -------------------------------
+while [ $# -ne 0 ] ; do
+  case $1 in
+    -h|--help|-help)
+      echo "usage: $0 [-u TargetUsr] JobName"
+      exit ;;
+    -b|-nocolor)
+      fg_color=false
+      shift 1 ;;
+    -n|-new)
+      fg_new=true
+      shift 1 ;;
+    -q|-quiet)
+      fg_quiet=true
+      shift 1 ;;
+    -p|-config-path)
+      ConfigPath="$2"
+      shift 2 ;;
+    -j|-job-number)
+      NbHisto="$2"
+      shift 2 ;;
+    -u|-user)
+      TargetUsr="$2"
+      shift 2 ;;
+    -*)
+      $0 -h
+      exit ;;
+    *)
+      break ;;
+  esac
+done
+
+if [ $# -lt 1 ] ; then
+  $0 -h
+  exit
+fi
+
+
+# Load libIGCM library
+# ====================
 libIGCM=${libIGCM:=::modipsl::/libIGCM}
 
@@ -215,48 +294,10 @@
 . ${libIGCM}/libIGCM_config/libIGCM_config.ksh
 
-if ( [ $# -eq 0 ] ) ; then
-  $0 -h
-  exit
+
+JobName=$1
+
+if ( ${fg_quiet} ) ; then
+  NbHisto=1
 fi
-
-# Default argument values
-TargetUsr=${CurrentUsr}
-HostName=$( hostname | sed -e "s/[0-9].*//" )
-
-fg_color=".true."
-fg_new=".false."
-fg_quiet=".false."
-(( NbHisto = 1 ))
-
-# Get arguments from command line
-while [ $# -ne 0 ] ; do
-  case $1 in
-    -h|--help|-help)
-      echo "usage: $0 [-u TargetUsr] JobName"
-      exit ;;
-    -b|--nocolor)
-      fg_color=".false."
-      shift 1 ;;
-    -n|--new)
-      fg_new=".true."
-      shift 1 ;;
-    -q|--quiet)
-      fg_quiet=".true."
-      shift 1 ;;
-    -p|--config-path)
-      ConfigPath="$2"
-      shift 2 ;;
-    -u|--user)
-      TargetUsr="$2"
-      shift 2 ;;
-    -*)
-      $0 -h
-      exit ;;
-    *)
-      break ;;
-  esac
-done
-
-JobName=$1
 
 echo "TargetUsr = ${TargetUsr}"
@@ -274,9 +315,8 @@
 DateFormat="%d/%m/%y %R:%S"
 
-# Find SUBMIT_DIR from catalog
-
+# Find SUBMIT_DIR in catalog
+# ==========================
 SearchCatalog
 
-# Go to SUBMIT_DIR 
 if [ ! X${SUBMIT_DIR} == X ] ; then
 
@@ -286,4 +326,5 @@
 
   # Extract usefull information from run.card and config.card
+  # =========================================================
 
   RunFile="${SUBMIT_DIR}/run.card"
@@ -332,6 +373,8 @@
   if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
     REBUILD_DIR=${R_SAVE}/TMP
+    RebuildJob="rebuild_fromArchive"
   else
     REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
+    RebuildJob="rebuild_fromWorkdir"
   fi
 
@@ -350,5 +393,6 @@
   if [ $PeriodState != "Waiting" ] ; then
 
-    # Check missing rebuilds
+    # Check pending rebuilds
+    # ======================
 
     set -A RebuildList $( find ${REBUILD_DIR}/ -name "REBUILD_*" | sort )
@@ -371,60 +415,84 @@
   fi
 
-  typeset -A LastDate Result
-
-  # Check last REBUILD
-  FileType=rebuild_*
-  (( 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
+
+  # Check last REBUILD and PACK* jobs
+  # =================================
+  # Define input parameters
+  # -----------------------
+  set -A JobType_list "${RebuildJob}" "pack_output" "pack_restart" "pack_debug"
+
+  for JobType in ${JobType_list[*]} ; do 
+    typeset    name1="${JobType}_String"
+    typeset    name2="${JobType}_Field"
+    if [ X${JobType} == X${RebuildJob} ] ; then
+      eval ${name1}=IGCM_sys_PutBuffer_Out
+      eval ${name2}=4
+    else
+      eval ${name1}=IGCM_sys_Put_Out
+      eval ${name2}=3
+    fi
+  done
+
+  #Â Check jobs
+  # ----------
+  for JobType in ${JobType_list[*]} ; do 
+    eval String=\${${JobType}_String}
+    eval Field=\${${JobType}_Field}
+
+    FileList=$( ls ${POST_DIR}/${JobType}.*.out | tail -n ${NbHisto} )
+
+    (( ind = 0 ))
+    for FileName in ${FileList} ; do
+      LastDate=$( basename ${FileName} | awk -F"." '{ print $(NF-1) }' )
+
+      dum=$( basename $( grep ^${String} ${POST_DIR}/${JobType}.${LastDate}.out | \
+               tail -1 | awk -v Field=${Field} '{ print $( Field ) }' ) | \
+               awk -F"_" '{ print $3 }' )
+
+      if [[ X${dum} == X${LastDate} ]] ; then
+        Status=OK
+      else
+        Status=KO
+      fi
+
+      eval ${JobType}_Date[$ind]=${LastDate}
+      eval ${JobType}_Status[$ind]=${Status}
+      
+      (( ind = ind + 1 ))
+    done
+  done
+
+  # Check last MONITORING jobs
+  # ==========================
+  JobType=monitoring
+  LastDate=$( cdo showyear ${CWORK_DIR}/MONITORING/files/ATM_bils_global_ave.nc 2> /dev/null | \
+                  awk '{ print $NF }' )
+  eval ${JobType}_Date=${LastDate}
+
+  # Check last ATLAS jobs
+  # =====================
+  JobType=atlas
+  FileList=$( ls ${CWORK_DIR}/ATLAS | tail -n ${NbHisto} )
+
+  (( ind = 0 ))
+  for FileName in ${FileList} ; do
+    eval ${JobType}_Date[$ind]=${FileName}
     (( 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[$ind]=KO
-    fi
   done
 
 
-  # Check last MONITORING jobs
-
-  #set -vx
-
-  FileType=monitoring
-  (( 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
-  (( ind = ind + 1 ))
-
-  LastDate[$ind]=$( ls ${CWORK_DIR}/ATLAS | tail -n ${NbHisto} )
-
-
   # Time of last write on run.card
+  # ==============================
   LastWrite=$( ls -l --time-style=+"${DateFormat}" ${SUBMIT_DIR}/run.card | awk '{print $6 " " $7}' )
     
 
   # Print results
+  # =============
   AffichResult -f
-  AffichResult
+  ind=0
+  while [ $ind -lt $NbHisto ] ; do
+    AffichResult -j
+    (( ind = ind + 1 ))
+  done
   AffichResult -l
 
