Index: /trunk/libIGCM/AA_RunChecker
===================================================================
--- /trunk/libIGCM/AA_RunChecker	(revision 951)
+++ /trunk/libIGCM/AA_RunChecker	(revision 952)
@@ -16,259 +16,4 @@
 
 
-function ChangeUsr {
-
-  CurrentGrp=$( groups $CurrentUsr | gawk '{print $3}' )
-  TargetGrp=$( groups $TargetUsr | gawk '{print $3}' )
-
-  echo $1 | sed -e "s/${CurrentUsr}/${TargetUsr}/" \
-                -e "s/${CurrentGrp}/${TargetGrp}/"
-
-}
-
-
-function SearchCatalog {
-
-  typeset num
-  unset SUBMIT_DIR
-
-  fg_new=false
-
-  if [ ! X${JobName} == X ] ; then
-    NbOcc=$( gawk -v JobName=${JobName} \
-             'BEGIN {x=0}  $1 ~ JobName {++x} END {print x}' ${SimuCatalog} )
-  else
-    NbOcc=0
-  fi
-
-  if ( [ ${NbOcc} -eq 0 ] && ( ${fg_path} ) ) ; then
-    set -A FileList $( ls ${ConfigPath}/Job_* )
-    if [ X$FileList == X ] ; then
-      NbOcc=0
-    else
-      NbOcc=${#FileList[@]}
-      fg_new=true
-    fi
-  fi
-
-  if ( [ ${NbOcc} -eq 0 ] && ( ${fg_search} ) ) ; then
-    SEARCH_DIR=${WORKDIR}
-    if [ ${TargetUsr} != ${CurrentUsr} ] ; then
-      SEARCH_DIR=$( ChangeUsr ${SEARCH_DIR})
-    fi
-    echo "${JobName} not in Catalog, we'll try to find it in ${SEARCH_DIR}"
-
-    set -A FileList $( find ${SEARCH_DIR}/ \
-                            -path ${SEARCH_DIR}/IGCM_OUT -prune -o \
-                            -name Job_${JobName} -print )
-    if [ X$FileList == X ] ; then
-      NbOcc=0
-    else
-      NbOcc=${#FileList[@]}
-      fg_new=true
-    fi
-  fi
-
-  if [ ${NbOcc} -gt 1 ] ; then
-    echo "More than one job"
-    ind=0
-    while [ ${ind} -lt ${NbOcc} ] ; do
-      printf '%2i) %-30s\n' ${ind} ${FileList[${ind}]}
-      (( ind = ind + 1 ))
-    done
-    echo "Give your choice number or 'q' to quit : "
-    read Choice
-    if [ X${Choice} == Xq ] ; then
-      exit
-    else
-      fg_new=true
-      FileList=${FileList[${Choice}]}
-      NbOcc=1
-    fi
-  fi
-
-  case ${NbOcc} in
-    0)
-      echo "${JobName} not found."
-      echo "You can try : *) '-s' option to automatically search your \$WORKDIR ; "
-      echo "              *) '-p' option to provide the directory (absolute path) "
-      echo "                      containing the config.card ; "
-      echo "              *)  manually editing your ${SimuCatalog}."
-      exit ;;
-    1)
-      if ( ${fg_new} ) ; then
-        JobName=${JobName:=$( basename ${FileList} | gawk -F"_" '{ print $2 }' )}
-        SUBMIT_DIR=$( dirname ${FileList} )
-        echo "${JobName} ${TargetUsr} ${HostName} ${SUBMIT_DIR}"
-        echo "${JobName} ${TargetUsr} ${HostName} ${SUBMIT_DIR}" >> ${SimuCatalog}
-        sort -u ${SimuCatalog} > ${SimuCatalog}.tmp
-        mv ${SimuCatalog}.tmp ${SimuCatalog}
-      elif ( [ ${TargetUsr} == $( gawk -v JobName=${JobName} \
-                                      '$1 ~ JobName {print $2}' \
-                                      ${SimuCatalog} ) ] \
-          && [ ${HostName}  == $( gawk -v JobName=${JobName} \
-                                      '$1 ~ JobName {print $3}' \
-                                      ${SimuCatalog} ) ] ) ; then
-        JobName=$( gawk -v JobName=${JobName} '$1 ~ JobName {print $1}' ${SimuCatalog} )
-        SUBMIT_DIR=$( gawk -v JobName=${JobName} '$1 ~ JobName {print $4}' ${SimuCatalog} )
-      else
-        echo "${JobName} not in Catalog."
-        exit
-      fi
-      ;;
-    *)
-      break ;;
-  esac
-
-  return
-
-}
-
-
-function AffichResult {
-
-  fg_first=false
-  fg_last=false
-  fg_job=false
-
-  while [ $# -ne 0 ] ; do
-    case ${1} in
-      -f|--first)
-        fg_first=true
-        shift 1 ;;
-      -l|--last)
-        fg_last=true
-        shift 1 ;;
-      -j|--job)
-        fg_job=true
-        shift 1 ;;
-      -*)
-        echo "usage: ${0}"
-        echo "       options = -f; -l"
-        exit ;;
-      *)
-        break ;;
-    esac
-  done
-
-
-  # Define colors
-  # =============
-  ColEsc="\033["
-  ColNon="${ColEsc}0m"       # Return to normal
-  ColExp="${ColEsc}1m"       # Blanc - gras
-  ColFat="${ColEsc}1;31m"    # Fatal
-  ColCpl="${ColEsc}1;32m"    # Completed
-  ColAtt="${ColEsc}1;30m"    # Waiting
-  ColDef="${ColEsc}1;34m"    # Default
-  ColRbl="${ColEsc}31m"      # Rebuild
-
-
-
-  #Â Print header
-  # ============
-  if ( ${fg_first} ) ; then
-    Dum=""
-    (( len = 67 - ${#JobName} ))
-    echo "|===========================================================================================================|"
-    printf "| JobName = ${ColExp}%-${#JobName}s${ColNon}" ${JobName}
-    printf "%-${len}s" ${Dum}
-    printf "run.card : ${ColExp}%-18s${ColNon}|\n" "${LastWrite}"
-    echo "|-------------------------|-------------|-------------------------|-------------|-----:----------:----------|"
-    echo "|                         |             |                         |             |     Pending Rebuilds      |"
-    echo "| Date Begin - DateEnd    | PeriodState | Current Period          | CumulPeriod | Nb  : from     : to       |"
-    echo "|-------------------------|-------------|-------------------------|-------------|-----:----------:----------|"
-
-    printf "| %-10s - %-10s | " \
-           $DateBegin $DateEnd
-
-    case $PeriodState in
-      Fatal)
-        Color=${ColFat}
-        ;;
-      Completed)
-        Color=${ColCpl}
-        ;;
-      Waiting|OnQueue)
-        Color=${ColAtt}
-        ;;
-      *)
-        Color=${ColDef}
-        ;;
-    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
-
-    if [ ${NbLines} -gt 0 ] ; then
-      printf "|-----------------------------------------------------------------------------------------------------------|\n"
-      printf "|                                                      Last                                                 |\n"
-      printf "|     Rebuild      |   Pack_Output    |   Pack_Restart   |    Pack_Debug    |  Monitoring  |     Atlas      |\n"
-      printf "|------------------|------------------|------------------|------------------|--------------|----------------|\n"
-    fi
-
-    return
-  fi
-
-  # 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}]}
-      eval Nb=\${${JobType}_Nb[${ind}]}
-
-      if [ X${Status} == XOK  ] ; then
-        Color=${ColCpl}
-      else
-        Color=${ColFat}
-      fi
-      printf "  ${Color}%-8s${ColNon} : %3s  |" ${Date} ${Nb}
-    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}"
-    return
-  fi
-
-}
 
 #======================================================================#
@@ -364,4 +109,5 @@
 #-------
 . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
+. ${libIGCM}/libIGCM_check/libIGCM_check.ksh
 . ${libIGCM}/libIGCM_config/libIGCM_config.ksh
 #-------
@@ -370,4 +116,5 @@
 ( ${DEBUG_debug} ) && IGCM_date_Check
 
+
 JobName=$1
 
@@ -376,7 +123,6 @@
 fi
 
-echo "Target user = ${TargetUsr}"
-
 # Define the catalog in which the known simulations are stored
+# ============================================================
 SimuCatalog="${HOME}/.simucatalog.dat"
 if [ ! -s ${SimuCatalog} ] ; then
@@ -384,14 +130,10 @@
 fi
 
-# Date format
-DateFormat="%d/%m/%y %R:%S"
-
 # Find SUBMIT_DIR in catalog
 # ==========================
-SearchCatalog
+IGCM_check_SearchCatalog
 
 if [ ! X${SUBMIT_DIR} == X ] ; then
 
-  echo "Submit:  >${SUBMIT_DIR}<"
   IGCM_sys_Cd $SUBMIT_DIR
 
@@ -404,4 +146,5 @@
 
   IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card
+  IGCM_check_CommonDef
 
 
@@ -445,179 +188,28 @@
   POST_DIR=${R_BUFR}/Out
   CWORK_DIR=${R_FIGR}
-  if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
-    RebuildJob="rebuild_fromArchive"
-  else
-    RebuildJob="rebuild_fromWorkdir"
-  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}<"
-  echo "Post:    >${POST_DIR}<"
-  echo "Work:    >${CWORK_DIR}<"
-
-  # Are packs activated or not ?
-  # ============================
-  if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && \
-       [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
-    Pack=true
-  else
-    Pack=false
-  fi
-
+    DATA_DIR=$( IGCM_check_ChangeUsr ${DATA_DIR} )
+    POST_DIR=$( IGCM_check_ChangeUsr ${POST_DIR} )
+    CWORK_DIR=$( IGCM_check_ChangeUsr ${CWORK_DIR} )
+    REBUILD_DIR=$( IGCM_check_ChangeUsr ${REBUILD_DIR} )
+  fi
 
   if [ $PeriodState != "Waiting" ] ; then
-
-    # Check pending rebuilds
+    # Check pending REBUILDS
     # ======================
-
-    set -A RebuildList $( find ${REBUILD_DIR}/ -name "REBUILD_*" | sort )
-    if [ ${#RebuildList[*]} -gt 0 ] ; then
-      NbRebuild=$( IGCM_sys_CountFileArchive ${REBUILD_DIR} )
-
-      FirstRebuild=$( basename ${RebuildList[0]} | cut -f2 -d\_ )
-      LastRebuild=$( basename ${RebuildList[ (( NbRebuild=${NbRebuild}-1 )) ]} | cut -f2 -d\_ )
-    else
-      NbRebuild="."
-
-      FirstRebuild="."
-      LastRebuild="."
-    fi
-  else
-    NbRebuild="."
-
-    FirstRebuild="."
-    LastRebuild="."
-  fi
-
-
-  if [ $PeriodState != "Waiting" ] ; then
+    IGCM_check_CheckPendingRebuild
 
     # 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"
-      typeset    name3="${JobType}_Activ"
-      if [ X${JobType} == X${RebuildJob} ] ; then
-        if ( ${Pack} ) ; then
-          eval ${name1}=IGCM_sys_PutBuffer_Out
-        else
-          eval ${name1}=IGCM_sys_Put_Out
-        fi
-        eval ${name2}=4
-        eval ${name3}=true
-      else
-        eval ${name1}=IGCM_sys_Put_Out
-        eval ${name2}=3
-        if ( ${Pack} ) ; then
-          eval ${name3}=true
-        else
-          eval ${name3}=false
-        fi
-      fi
-    done
-
-    #Â Check jobs
-    # ----------
-    NbLines=0
-    for JobType in ${JobType_list[*]} ; do
-      eval String=\${${JobType}_String}
-      eval Field=\${${JobType}_Field}
-      eval Activ=\${${JobType}_Activ}
-
-      if ( ${Activ} ) ; then
-
-        set -A FileList $( ls ${POST_DIR}/${JobType}.*.out | tail -n ${NbHisto} )
-
-        if [ ${#FileList[*]} -gt ${NbLines} ] ; then
-          NbLines=${#FileList[*]}
-        fi
-
-        (( ind = 0 ))
-        for FileName in ${FileList[*]} ; do
-          LastDate=""
-          LastDate=$( basename ${FileName} | gawk -F"." '{ print $(NF-1) }' )
-
-          set -- $( gawk -v String=${String} \
-                         'BEGIN { nb_ok = 0 ; nb_ko = 0 } \
-                         ($1 ~ String) { \
-                           if ($3 !~ /error./) { \
-                             nb_ok = nb_ok + 1 \
-                           } else { \
-                             nb_ko = nb_ko + 1 \
-                           } \
-                         } \
-                         END { print nb_ok " " nb_ko }' \
-                         ${POST_DIR}/${JobType}.${LastDate}.out )
-          Match=$1
-          Error=$2
-
-          (( Nb = ${Match} - ${Error} ))
-
-          if ( [ ${Error} -eq 0 ] && [ ${Nb} -gt 0 ] ) ; then
-            Status=OK
-          else
-            Status=KO
-          fi
-
-          eval ${JobType}_Date[$ind]=${LastDate}
-          eval ${JobType}_Status[$ind]=${Status}
-          eval ${JobType}_Nb[$ind]=${Nb}
-
-          (( ind = ind + 1 ))
-        done
-
-      else
-
-          eval ${JobType}_Date[0]=""
-          eval ${JobType}_Status[0]=""
-          eval ${JobType}_Nb[0]=""
-
-      fi
-
-    done
+    IGCM_check_CheckRebPackJobs
 
     # Check last MONITORING jobs
     # ==========================
-    LastDate=""
-    JobType=monitoring
-    IGCM_sys_TestDirArchive ${CWORK_DIR}/MONITORING
-    RC=$?
-    if [ $RC == 0 ] ; then
-      FileTmp=$( IGCM_sys_RshArchive "ls ${CWORK_DIR}/MONITORING/files/*.nc | head -n 1" )
-      IGCM_sys_GetDate_Monitoring ${FileTmp} LastDate
-      eval ${JobType}_Date=${LastDate}
-    fi
+    IGCM_check_CheckMonitoring
 
     # Check last ATLAS jobs
     # =====================
-    JobType=atlas
-    IGCM_sys_TestDirArchive ${CWORK_DIR}/ATLAS
-    RC=$?
-    if [ $RC == 0 ] ; then
-      set -A FileList $( IGCM_sys_RshArchive "ls ${CWORK_DIR}/ATLAS | tail -n ${NbHisto}" )
-
-      if [ ${#FileList[*]} -gt ${NbLines} ] ; then
-        NbLines=${#FileList[*]}
-      fi
-
-      (( ind = 0 ))
-      for FileName in ${FileList[*]} ; do
-        eval ${JobType}_Date[$ind]=${FileName}
-        (( ind = ind + 1 ))
-      done
-    fi
-
+    IGCM_check_CheckAtlas
 
     # Time of last write on run.card
@@ -627,4 +219,8 @@
   else
 
+    NbRebuild="."
+    FirstRebuild="."
+    LastRebuild="."
+
     NbLines=0
 
@@ -634,11 +230,11 @@
   # Print results
   # =============
-  AffichResult -f
+  IGCM_check_PrintHeader
   ind=0
   while [ $ind -lt $NbLines ] ; do
-    AffichResult -j
+    IGCM_check_PrintJob
     (( ind = ind + 1 ))
   done
-  AffichResult -l
-
-fi
+  IGCM_check_PrintFooter
+
+fi
Index: /trunk/libIGCM/libIGCM_check/libIGCM_tools.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_check/libIGCM_tools.ksh	(revision 952)
+++ /trunk/libIGCM/libIGCM_check/libIGCM_tools.ksh	(revision 952)
@@ -0,0 +1,476 @@
+#!/bin/ksh
+
+#**************************************************************
+# Author: Sebastien Denvil, Martial Mancip
+# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr Martial.Mancip__at__ipsl.jussieu.fr
+# $Revision:: 939                                      $ Revision of last commit
+# $Author:: sdipsl                                     $ Author of last commit
+# $Date:: 2013-08-23 11:38:24 +0200 (Fri, 23 Aug 2013) $ Date of last commit
+# IPSL (2006)
+#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
+#
+#**************************************************************
+
+#===================================
+function IGCM_check_CommonDef
+{
+
+  IGCM_debug_PushStack "IGCM_check_CommonDef" $@
+
+  # Define colors
+  # -------------
+  ColEsc="\033["
+  ColNon="${ColEsc}0m"       # Return to normal
+  ColExp="${ColEsc}1m"       # Blanc - gras
+  ColFat="${ColEsc}1;31m"    # Fatal
+  ColCpl="${ColEsc}1;32m"    # Completed
+  ColAtt="${ColEsc}1;30m"    # Waiting
+  ColDef="${ColEsc}1;34m"    # Default
+  ColRbl="${ColEsc}31m"      # Rebuild
+
+  # Define date format
+  # ------------------
+  DateFormat="%d/%m/%y %R:%S"
+
+
+  # What kind of rebuild ?
+  # ----------------------
+  if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
+    RebuildJob="rebuild_fromArchive"
+    IGCM_sys_TestDirArchive ${REBUILD_DIR}
+    RebuildExists=$?
+  else
+    RebuildJob="rebuild_fromWorkdir"
+    IGCM_sys_TestDir ${REBUILD_DIR}
+    RebuildExists=$?
+  fi
+
+  # Are packs activated or not ?
+  # ----------------------------
+  if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && \
+       [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
+    Pack=true
+  else
+    Pack=false
+  fi
+
+
+  # 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"
+    typeset    name3="${JobType}_Activ"
+    if [ X${JobType} == X${RebuildJob} ] ; then
+      if ( ${Pack} ) ; then
+        eval ${name1}=IGCM_sys_PutBuffer_Out
+      else
+        eval ${name1}=IGCM_sys_Put_Out
+      fi
+      eval ${name2}=4
+      eval ${name3}=true
+    else
+      eval ${name1}=IGCM_sys_Put_Out
+      eval ${name2}=3
+      if ( ${Pack} ) ; then
+        eval ${name3}=true
+      else
+        eval ${name3}=false
+      fi
+    fi
+  done
+
+  IGCM_debug_PopStack "IGCM_check_CommonDef"
+
+}
+
+#===================================
+function IGCM_check_ChangeUsr
+{
+
+  IGCM_debug_PushStack "IGCM_check_ChangeUsr" $@
+
+  CurrentGrp=$( groups $CurrentUsr | gawk '{print $3}' )
+  TargetGrp=$( groups $TargetUsr | gawk '{print $3}' )
+
+  echo $1 | sed -e "s/${CurrentUsr}/${TargetUsr}/" \
+                -e "s/${CurrentGrp}/${TargetGrp}/"
+
+  IGCM_debug_PopStack "IGCM_check_ChangeUsr"
+
+}
+
+
+
+#===================================
+function IGCM_check_SearchCatalog
+{
+
+  IGCM_debug_PushStack "IGCM_check_SearchCatalog" $@
+
+  typeset num
+  unset SUBMIT_DIR
+
+  fg_new=false
+
+  if [ ! X${JobName} == X ] ; then
+    NbOcc=$( gawk -v JobName=${JobName} \
+             'BEGIN {x=0}  $1 ~ JobName {++x} END {print x}' ${SimuCatalog} )
+  else
+    NbOcc=0
+  fi
+
+  if ( [ ${NbOcc} -eq 0 ] && ( ${fg_path} ) ) ; then
+    set -A FileList $( ls ${ConfigPath}/Job_* )
+    if [ X$FileList == X ] ; then
+      NbOcc=0
+    else
+      NbOcc=${#FileList[@]}
+      fg_new=true
+    fi
+  fi
+
+  if ( [ ${NbOcc} -eq 0 ] && ( ${fg_search} ) ) ; then
+    SEARCH_DIR=${WORKDIR}
+    if [ ${TargetUsr} != ${CurrentUsr} ] ; then
+      echo $SEARCH_DIR
+      SEARCH_DIR=$( IGCM_check_ChangeUsr ${SEARCH_DIR} )
+      echo $SEARCH_DIR
+    fi
+    echo "${JobName} not in Catalog, we'll try to find it in ${SEARCH_DIR}"
+
+    set -A FileList $( find ${SEARCH_DIR}/ \
+                            -path ${SEARCH_DIR}/IGCM_OUT -prune -o \
+                            -name Job_${JobName} -print )
+    if [ X$FileList == X ] ; then
+      NbOcc=0
+    else
+      NbOcc=${#FileList[@]}
+      fg_new=true
+    fi
+  fi
+
+  if [ ${NbOcc} -gt 1 ] ; then
+    echo "More than one job"
+    ind=0
+    while [ ${ind} -lt ${NbOcc} ] ; do
+      printf '%2i) %-30s\n' ${ind} ${FileList[${ind}]}
+      (( ind = ind + 1 ))
+    done
+    echo "Give your choice number or 'q' to quit : "
+    read Choice
+    if [ X${Choice} == Xq ] ; then
+      exit
+    else
+      fg_new=true
+      FileList=${FileList[${Choice}]}
+      NbOcc=1
+    fi
+  fi
+
+  case ${NbOcc} in
+    0)
+      echo "${JobName} not found."
+      echo "You can try : *) '-s' option to automatically search your \$WORKDIR ; "
+      echo "              *) '-p' option to provide the directory (absolute path) "
+      echo "                      containing the config.card ; "
+      echo "              *)  manually editing your ${SimuCatalog}."
+      exit ;;
+    1)
+      if ( ${fg_new} ) ; then
+        JobName=${JobName:=$( basename ${FileList} | gawk -F"_" '{ print $2 }' )}
+        SUBMIT_DIR=$( dirname ${FileList} )
+        echo "${JobName} ${TargetUsr} ${HostName} ${SUBMIT_DIR}"
+        echo "${JobName} ${TargetUsr} ${HostName} ${SUBMIT_DIR}" >> ${SimuCatalog}
+        sort -u ${SimuCatalog} > ${SimuCatalog}.tmp
+        mv ${SimuCatalog}.tmp ${SimuCatalog}
+      elif ( [ ${TargetUsr} == $( gawk -v JobName=${JobName} \
+                                      '$1 ~ JobName {print $2}' \
+                                      ${SimuCatalog} ) ] \
+          && [ ${HostName}  == $( gawk -v JobName=${JobName} \
+                                      '$1 ~ JobName {print $3}' \
+                                      ${SimuCatalog} ) ] ) ; then
+        JobName=$( gawk -v JobName=${JobName} '$1 ~ JobName {print $1}' ${SimuCatalog} )
+        SUBMIT_DIR=$( gawk -v JobName=${JobName} '$1 ~ JobName {print $4}' ${SimuCatalog} )
+      else
+        echo "${JobName} not in Catalog."
+        exit
+      fi
+      ;;
+    *)
+      break ;;
+  esac
+
+  IGCM_debug_PopStack "IGCM_check_SearchCatalog"
+
+}
+
+#===================================
+function IGCM_check_PrintHeader
+{
+
+  IGCM_debug_PushStack "IGCM_check_PrintHeader" $@
+
+  echo "|===========================================================================================================|"
+  printf "| JobName = ${ColExp}%-71.71s${ColNon}date : ${ColExp}%-18s${ColNon}|\n" \
+         ${JobName} "$( date +"${DateFormat}" )"
+
+  printf "| User    = ${ColExp}%-56.56s${ColNon}last run.card write : ${ColExp}%-18s${ColNon}|\n" \
+         ${TargetUsr} "${LastWrite}"
+
+  printf "|-----------------------------------------------------------------------------------------------------------|\n"
+
+  printf "| Submit  | ${ColExp}%-95.95s${ColNon} |\n" ${SUBMIT_DIR}
+  printf "| Data    | ${ColExp}%-95.95s${ColNon} |\n" ${DATA_DIR}
+  printf "| Rebuild | ${ColExp}%-95.95s${ColNon} |\n" ${REBUILD_DIR}
+  printf "| Post    | ${ColExp}%-95.95s${ColNon} |\n" ${POST_DIR}
+  printf "| Work    | ${ColExp}%-95.95s${ColNon} |\n" ${CWORK_DIR}
+
+  echo "|-------------------------|-------------|-------------------------|-------------|-----:----------:----------|"
+  echo "|                         |             |                         |             |     Pending Rebuilds      |"
+  echo "| Date Begin - DateEnd    | PeriodState | Current Period          | CumulPeriod | Nb  : from     : to       |"
+  echo "|-------------------------|-------------|-------------------------|-------------|-----:----------:----------|"
+
+  printf "| %-10s - %-10s | " \
+         $DateBegin $DateEnd
+
+  case $PeriodState in
+    Fatal)
+      Color=${ColFat}
+      ;;
+    Completed)
+      Color=${ColCpl}
+      ;;
+    Waiting|OnQueue)
+      Color=${ColAtt}
+      ;;
+    *)
+      Color=${ColDef}
+      ;;
+  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
+
+  if [ ${NbLines} -gt 0 ] ; then
+    printf "|-----------------------------------------------------------------------------------------------------------|\n"
+    printf "|                                                      Last                                                 |\n"
+    printf "|     Rebuild      |   Pack_Output    |   Pack_Restart   |    Pack_Debug    |  Monitoring  |     Atlas      |\n"
+    printf "|------------------|------------------|------------------|------------------|--------------|----------------|\n"
+  fi
+
+  IGCM_debug_PopStack "IGCM_check_PrintHeader"
+
+}
+
+#===================================
+function IGCM_check_PrintJob
+{
+
+  IGCM_debug_PushStack "IGCM_check_PrintJob" $@
+
+  printf "|"
+
+  #Â Print rebuild and pack jobs
+  #Â ---------------------------
+  for JobType in ${JobType_list[*]} ; do 
+    eval Date=\${${JobType}_Date[${ind}]}
+    eval Status=\${${JobType}_Status[${ind}]}
+    eval Nb=\${${JobType}_Nb[${ind}]}
+
+    if [ X${Status} == XOK  ] ; then
+      Color=${ColCpl}
+    else
+      Color=${ColFat}
+    fi
+    printf "  ${Color}%-8s${ColNon} : %3s  |" ${Date} ${Nb}
+  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"
+
+  IGCM_debug_PopStack "IGCM_check_PrintJob"
+
+}
+
+#===================================
+function IGCM_check_PrintFooter
+{
+
+  IGCM_debug_PushStack "IGCM_check_PrintFooter" $@
+
+  printf "|===========================================================================================================|\n"
+  #date +"${DateFormat}"
+
+  IGCM_debug_PopStack "IGCM_check_PrintFooter"
+
+}
+
+#===================================
+function IGCM_check_CheckPendingRebuild
+{
+
+  IGCM_debug_PushStack "IGCM_check_PendingRebuild" $@
+
+  NbRebuild="."
+  FirstRebuild="."
+  LastRebuild="."
+
+  if [ ${RebuildExists} == 0 ] ; then
+    set -A RebuildList $( find ${REBUILD_DIR}/ -name "REBUILD_*" | sort )
+    if [ ${#RebuildList[*]} -gt 0 ] ; then
+      NbRebuild=$( IGCM_sys_CountFileArchive ${REBUILD_DIR} )
+
+      FirstRebuild=$( basename ${RebuildList[0]} | cut -f2 -d\_ )
+      LastRebuild=$( basename ${RebuildList[ (( NbRebuild=${NbRebuild}-1 )) ]} | cut -f2 -d\_ )
+    fi
+  fi
+
+  IGCM_debug_PopStack "IGCM_check_PendingRebuild"
+
+}
+
+#===================================
+function IGCM_check_CheckRebPackJobs
+{
+
+  IGCM_debug_PushStack "IGCM_check_CheckRebPackJobs" $@
+
+  NbLines=0
+  for JobType in ${JobType_list[*]} ; do
+    eval String=\${${JobType}_String}
+    eval Field=\${${JobType}_Field}
+    eval Activ=\${${JobType}_Activ}
+
+    if ( ${Activ} ) ; then
+
+      set -A FileList $( ls ${POST_DIR}/${JobType}.*.out | tail -n ${NbHisto} )
+
+      if [ ${#FileList[*]} -gt ${NbLines} ] ; then
+        NbLines=${#FileList[*]}
+      fi
+
+      (( ind = 0 ))
+      for FileName in ${FileList[*]} ; do
+        LastDate=""
+        LastDate=$( basename ${FileName} | gawk -F"." '{ print $(NF-1) }' )
+
+        set -- $( gawk -v String=${String} \
+                       'BEGIN { nb_ok = 0 ; nb_ko = 0 } \
+                       ($1 ~ String) { \
+                         if ($3 !~ /error./) { \
+                           nb_ok = nb_ok + 1 \
+                         } else { \
+                           nb_ko = nb_ko + 1 \
+                         } \
+                       } \
+                       END { print nb_ok " " nb_ko }' \
+                       ${POST_DIR}/${JobType}.${LastDate}.out )
+        Match=$1
+        Error=$2
+
+        (( Nb = ${Match} - ${Error} ))
+
+        if ( [ ${Error} -eq 0 ] && [ ${Nb} -gt 0 ] ) ; then
+          Status=OK
+        else
+          Status=KO
+        fi
+
+        eval ${JobType}_Date[$ind]=${LastDate}
+        eval ${JobType}_Status[$ind]=${Status}
+        eval ${JobType}_Nb[$ind]=${Nb}
+
+        (( ind = ind + 1 ))
+      done
+
+    else
+
+        eval ${JobType}_Date[0]=""
+        eval ${JobType}_Status[0]=""
+        eval ${JobType}_Nb[0]=""
+
+    fi
+
+  done
+
+  IGCM_debug_PopStack "IGCM_check_CheckRebPackJobs"
+
+}
+
+#===================================
+function IGCM_check_CheckMonitoring
+{
+
+  IGCM_debug_PushStack "IGCM_check_CheckMonitoring" $@
+
+    LastDate=""
+    JobType=monitoring
+    IGCM_sys_TestDirArchive ${CWORK_DIR}/MONITORING
+    RC=$?
+    if [ $RC == 0 ] ; then
+      FileTmp=$( IGCM_sys_RshArchive "ls ${CWORK_DIR}/MONITORING/files/*.nc | head -n 1" )
+      IGCM_sys_GetDate_Monitoring ${FileTmp} LastDate
+      eval ${JobType}_Date=${LastDate}
+    fi
+
+  IGCM_debug_PopStack "IGCM_check_CheckMonitoring"
+
+}
+
+#===================================
+function IGCM_check_CheckAtlas
+{
+
+  IGCM_debug_PushStack "IGCM_check_CheckAtlas" $@
+
+  JobType=atlas
+  IGCM_sys_TestDirArchive ${CWORK_DIR}/ATLAS
+  RC=$?
+  if [ $RC == 0 ] ; then
+    set -A FileList $( IGCM_sys_RshArchive "ls ${CWORK_DIR}/ATLAS | tail -n ${NbHisto}" )
+
+    if [ ${#FileList[*]} -gt ${NbLines} ] ; then
+      NbLines=${#FileList[*]}
+    fi
+
+    (( ind = 0 ))
+    for FileName in ${FileList[*]} ; do
+      eval ${JobType}_Date[$ind]=${FileName}
+      (( ind = ind + 1 ))
+    done
+  fi
+
+  IGCM_debug_PopStack "IGCM_check_CheckAtlas"
+
+}
+
+#===================================
