Index: /trunk/libIGCM/AA_RunChecker
===================================================================
--- /trunk/libIGCM/AA_RunChecker	(revision 767)
+++ /trunk/libIGCM/AA_RunChecker	(revision 768)
@@ -18,4 +18,7 @@
 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}/"
@@ -32,5 +35,5 @@
 
   if [ ! X${JobName} == X ] ; then
-    NbOcc=$( awk -v JobName=${JobName} \
+    NbOcc=$( gawk -v JobName=${JobName} \
              'BEGIN {x=0}  $1 ~ JobName {++x} END {print x}' ${SimuCatalog} )
   else
@@ -93,5 +96,5 @@
     1)
       if ( ${fg_new} ) ; then
-        JobName=${JobName:=$( basename ${FileList} | awk -F"_" '{ print $2 }' )}
+        JobName=${JobName:=$( basename ${FileList} | gawk -F"_" '{ print $2 }' )}
         SUBMIT_DIR=$( dirname ${FileList} )
         echo "${JobName} ${TargetUsr} ${HostName} ${SUBMIT_DIR}"
@@ -99,12 +102,12 @@
         sort -u ${SimuCatalog} > ${SimuCatalog}.tmp
         mv ${SimuCatalog}.tmp ${SimuCatalog}
-      elif ( [ ${TargetUsr} == $( awk -v JobName=${JobName} \
+      elif ( [ ${TargetUsr} == $( gawk -v JobName=${JobName} \
                                       '$1 ~ JobName {print $2}' \
                                       ${SimuCatalog} ) ] \
-          && [ ${HostName}  == $( awk -v JobName=${JobName} \
+          && [ ${HostName}  == $( gawk -v JobName=${JobName} \
                                       '$1 ~ JobName {print $3}' \
                                       ${SimuCatalog} ) ] ) ; then
-        JobName=$( awk -v JobName=${JobName} '$1 ~ JobName {print $1}' ${SimuCatalog} )
-        SUBMIT_DIR=$( awk -v JobName=${JobName} '$1 ~ JobName {print $4}' ${SimuCatalog} )
+        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."
@@ -275,5 +278,4 @@
 
 CurrentUsr=$( whoami )
-CurrentGrp=$( groups $CurrentUsr | awk '{print $3}' )
 
 if ( [ $# -eq 0 ] ) ; then
@@ -375,8 +377,6 @@
 echo "Target user = ${TargetUsr}"
 
-TargetGrp=$( groups $TargetUsr | awk '{print $3}' )
-
 # Define the catalog in which the known simulations are stored
-SimuCatalog="$( ccc_home )/.simucatalog.dat"
+SimuCatalog="${HOME}/.simucatalog.dat"
 if [ ! -s ${SimuCatalog} ] ; then
   touch ${SimuCatalog}
@@ -413,5 +413,6 @@
 
   if ( [ X${PeriodState} == XRunning ] || [ X${PeriodState} == XOnQueue ] ) ; then
-    NbRun=$( ccc_mstat -f | grep -c ${JobName} )
+    #NbRun=$( ccc_mstat -f | grep -c ${JobName} )
+    IGCM_sys_CountJobInQueue ${JobName} NbRun
 
     if [ ${NbRun} -eq 0 ] ; then
@@ -430,5 +431,5 @@
     IGCM_card_DefineVariableFromOption ${RunFile} Configuration PeriodDateBegin
     IGCM_card_DefineVariableFromOption ${RunFile} Configuration PeriodDateEnd
-  IGCM_card_DefineVariableFromOption ${RunFile} Configuration CumulPeriod
+    IGCM_card_DefineVariableFromOption ${RunFile} Configuration CumulPeriod
     PeriodDateBegin=${run_Configuration_PeriodDateBegin}
     PeriodDateEnd=${run_Configuration_PeriodDateEnd}
@@ -523,11 +524,11 @@
       (( ind = 0 ))
       for FileName in ${FileList[*]} ; do
-        LastDate=$( basename ${FileName} | awk -F"." '{ print $(NF-1) }' )
-
-        Error=$( awk -v String=${String} \
+        LastDate=$( basename ${FileName} | gawk -F"." '{ print $(NF-1) }' )
+
+        Error=$( gawk -v String=${String} \
                      'BEGIN { x=0 } ($1~String) && ($3~"error.") { x=x+1 } END { print x }' \
                      ${POST_DIR}/${JobType}.${LastDate}.out )
 
-        Match=$( awk -v String=${String} \
+        Match=$( gawk -v String=${String} \
                      'BEGIN { x=0 } ($1~String) && ($3!~"error.") { x=x+1 } END { print x }' \
                      ${POST_DIR}/${JobType}.${LastDate}.out )
@@ -553,5 +554,5 @@
     if [ -d ${CWORK_DIR}/MONITORING ] ; then
       LastDate=$( cdo showyear ${CWORK_DIR}/MONITORING/files/ATM_bils_global_ave.nc 2> /dev/null | \
-                      awk '{ print $NF }' )
+                      gawk '{ print $NF }' )
       eval ${JobType}_Date=${LastDate}
     fi
@@ -577,5 +578,5 @@
     # Time of last write on run.card
     # ==============================
-    LastWrite=$( ls -l --time-style=+"${DateFormat}" ${SUBMIT_DIR}/run.card | awk '{print $6 " " $7}' )
+    LastWrite=$( ls -l --time-style=+"${DateFormat}" ${SUBMIT_DIR}/run.card | gawk '{print $6 " " $7}' )
 
   else
Index: /trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh	(revision 767)
+++ /trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh	(revision 768)
@@ -2643,2 +2643,26 @@
   IGCM_debug_PopStack "IGCM_sys_cdo"
 }
+
+#D-#==================================================
+#D-function IGCM_sys_CountJobInQueue
+#D-* Purpose: Check if job_name is currently 
+#D-  running or in queue
+#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
+#D-
+
+function IGCM_sys_CountJobInQueue {
+  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
+  if ( $DEBUG_sys ) ; then
+    echo "IGCM_sys_CountJobInQueue"
+  fi
+
+  #NbRun=$( ccc_mstat -f | grep -c ${JobName} )
+
+  # With -f option, the full job name is given in the last column
+  NbRun=$( ccc_mstat -f | gawk -v JobName=$1 'BEGIN { x=0 } ($NF~String) { x=x+1 } END { print x }' )
+
+  eval ${2}=${NbRun}
+
+  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
+}
+
Index: /trunk/libIGCM/libIGCM_sys/libIGCM_sys_titane.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_sys/libIGCM_sys_titane.ksh	(revision 767)
+++ /trunk/libIGCM/libIGCM_sys/libIGCM_sys_titane.ksh	(revision 768)
@@ -2969,2 +2969,26 @@
   IGCM_debug_PopStack "IGCM_sys_cdo"
 }
+
+#D-#==================================================
+#D-function IGCM_sys_CountJobInQueue
+#D-* Purpose: Check if job_name is currently 
+#D-  running or in queue
+#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
+#D-
+
+function IGCM_sys_CountJobInQueue {
+  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
+  if ( $DEBUG_sys ) ; then
+    echo "IGCM_sys_CountJobInQueue"
+  fi
+
+  #NbRun=$( ccc_mstat -f | grep -c ${JobName} )
+
+  # With -f option, the full job name is given in the last column
+  NbRun=$( ccc_mstat -f | gawk -v JobName=$1 'BEGIN { x=0 } ($NF~String) { x=x+1 } END { print x }' )
+
+  eval ${2}=${NbRun}
+
+  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
+}
+
Index: /trunk/libIGCM/libIGCM_sys/libIGCM_sys_vargas.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_sys/libIGCM_sys_vargas.ksh	(revision 767)
+++ /trunk/libIGCM/libIGCM_sys/libIGCM_sys_vargas.ksh	(revision 768)
@@ -1681,2 +1681,23 @@
   IGCM_debug_PopStack "IGCM_sys_check_quota"
 }
+
+#D-#==================================================
+#D-function IGCM_sys_CountJobInQueue
+#D-* Purpose: Check if job_name is currently 
+#D-  running or in queue
+#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
+#D-
+
+function IGCM_sys_CountJobInQueue {
+  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
+  if ( $DEBUG_sys ) ; then
+    echo "IGCM_sys_CountJobInQueue"
+  fi
+
+  # Print only the full (-W) JobName (%jn)
+  NbRun=$( llq -W -f %jn | grep -c "$1" )
+
+  eval ${2}=${NbRun}
+
+  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
+}
