Index: branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting.sh
===================================================================
--- branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting.sh	(revision 5485)
+++ branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting.sh	(revision 5509)
@@ -6,5 +6,5 @@
 NEMO_TRUS=$( pwd $( dirname $0 ) )
 DEBUG=0; PUBLISH=0
-STATUS='FAILED'; STEP='' # 'FAILED' by default
+ST='FAILED'; ERR=0 # 'FAILED' by default
 
 # Get options for replacing some initials settings
@@ -64,5 +64,5 @@
 cd ${DIR_XIOS}
 #./make_xios --full --arch $ARCH -job $NPROC >& /dev/null
-[ ! -e ${DIR_XIOS}/lib/libxios.a ] && get_out $STATUS $STEP
+[ ! -e ${DIR_XIOS}/lib/libxios.a ] && get_out $ST ERR=1
 
 # NEMO config compiled from scratch
@@ -72,5 +72,5 @@
 #[ -d ${TEST_CONF} ] && ./makenemo -n ${TEST_CONF} clean
 ./makenemo -n ${TEST_CONF} -r ${REFE_CONF} -m $ARCH -j $NPROC >& /dev/null
-[ ! -e ${TEST_CONF}/BLD/bin/nemo.exe ] && get_out $STATUS $STEP
+[ ! -e ${TEST_CONF}/BLD/bin/nemo.exe ] && get_out $ST ERR=2
 
 # Get namelists, xml & forced files for running
@@ -80,5 +80,5 @@
 find ${NEMO_CONF}/${TEST_CONF}/EXP00 -regex '.*\(cfg\|opa\|ref\|xml\)' -exec cp {} . \;
 get_inputs
-[ $? -ne 0 ] && get_out $STATUS $STEP
+[ $? -ne 0 ] && get_out $ST ERR=3
 [ $( find . -name '*.gz' -print -quit ) ] && gunzip *.gz
 
@@ -92,5 +92,5 @@
 print_step 'Submitting job'
 JOB_ID=$( eval ${JOB_SUBM} )
-[ $? -ne 0 ] && get_out $STATUS $STEP
+[ $? -ne 0 ] && get_out $ST ERR=4
 print_step 'Holding-Running job'
 job_pending
@@ -102,5 +102,5 @@
 if   [[ ! -e time.step || $( grep -q 'E R R O R' ocean.output ) ]]; then
     comments 'E R R O R'
-    get_out $STATUS $STEP
+    get_out $ST ERR=5
 else
     # Get time computation
@@ -110,10 +110,10 @@
 fi
 
-STATUS='OK' # 'OK' by default
+ST='OK' # 'OK' by default
 # Inspect output text files
 #---------------------------------------------------
 print_step 'Test ASCII output files diff'
 diff_textfiles
-[ "$STATUS" == 'FAILED' ] && get_out $STATUS $STEP
+[ "$ST" == 'FAILED' ] && get_out $ST ERR=8
 
 # Inspect output NetCDF files
@@ -121,5 +121,5 @@
 print_step 'Test last restart NetCDF files diff'
 diff_restart
-[ "$STATUS" == 'FAILED' ] && get_out $STATUS $STEP
+[ "$ST" == 'FAILED' ] && get_out $ST ERR=10
 
 # Get comments (ocean.output & diff model.log)
@@ -129,4 +129,4 @@
 # End
 #---------------------------------------------------
-[ "$STATUS" == 'OK' ] && STEP='Code is reliable'
-get_out $STATUS $STEP
+[ "$ST" == 'OK' ] && ERR='Code is reliable'
+get_out $ST $ERR
Index: branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting_func.sh
===================================================================
--- branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting_func.sh	(revision 5485)
+++ branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting_func.sh	(revision 5509)
@@ -3,13 +3,9 @@
 
 comments() {
-    state=$1
+    state=$1; LAST_TIME_STEP=0
 
     if [ "$state" == 'E R R O R' ]; then
-	if [ -e time.step ]; then
-	    last_time_step=$( cat time.step | tr -d [:space:] )
-	    STEP='nemo.exe crashed at '${last_time_step} && export STEP
-	else
-	    STEP='nemo.exe crashed at initialization'    && export STEP
-	fi
+	[ -e time.step ] && LAST_TIME_STEP=$( cat time.step | tr -d [:space:] )
+	export ${LAST_TIME_STEP} ERR=1
     fi
 
@@ -22,9 +18,9 @@
 }
 
+
 diff_inputs() {
     mesg='Same'
-
     for file in inputs_list.txt $( ls namelist_* ) $( ls *.xml ); do
-	diff $file ${REFE_DIR}/$file
+	diff -q $file ${REFE_DIR}/$file
 	[ $? -ne 0 ] && mesg='Different'
     done
@@ -33,22 +29,22 @@
 }
 
+diff_results() {
+    for file in ocean.output $( ls *.stat ); do
+	[ ! -e ${REFE_DIR}/$file ] && export ST='FAILED' && get_out $ST ERR=7
+	diff -q $file ${REFE_DIR}/$file
+	[ $? -ne 0 ] && export ST='FAILED'
+    done
+}
+
 diff_restart() {
-
-    if   [ ! -e  ${REFE_DIR}/time.step ]                 ; then
-	echo "Seems that there is no restart files for comparison: no time.step in ${REFE_DIR}"
-	return
-    elif [ $( diff -q time.step ${REFE_DIR}/time.step ) ]; then
-	printf "Seems that the trusting test ends at a different time step: "
-	printf "${TEST_DIR} $( cat ${TEST_DIR}/time.step | tr -d [:space:] ) != "
-	printf "${REFE_DIR} $( cat ${REFE_DIR}/time.step | tr -d [:space:] )  \n"
-	return
-    fi
-
-    last_time_step=$( cat ${REFE_DIR}/time.step | tr -d [:space:] )
-    echo 'Last time step of standard run: '${last_time_step}
-
-    if [ $( find -name "*${last_time_step}_restart*.nc" -print -quit ) ]; then
-	base_name=$( find -name "*${last_time_step}_restart*.nc" -print -quit | awk -F/ '{print $NF}' \
-	             | sed "s/^\(.*\)$last_time_step\_restart.*/\1$last_time_step\_/"                  )
+    [ ! -e  ${REFE_DIR}/time.step ] && export ST='FAILED' && get_out $ST ERR=9
+
+    export LAST_TIME_STEP=$( cat ${REFE_DIR}/time.step | tr -d [:space:] )
+    echo 'Last time step of standard run: '${LAST_TIME_STEP}
+
+    if [    $( find -name "*${LAST_TIME_STEP}_restart*.nc" -print -quit ) \
+	 && $( diff -q     time.step ${REFE_DIR}/time.step              )  ]; then
+	base_name=$( find -name "*${LAST_TIME_STEP}_restart*.nc" -print -quit | awk -F/ '{print $NF}' \
+	             | sed "s/^\(.*\)$LAST_TIME_STEP\_restart.*/\1$LAST_TIME_STEP\_/"                  )
 
 	for comp in restart restart_ice restart_trc; do
@@ -66,5 +62,5 @@
 
 		if [ ! -z "${nc_diff}" ]; then
-		    export STATUS='FAILED' STEP="$file.nc different"
+		    export ST='FAILED'
 		    printf "$CDO ${nc_diff}\n"
 		else
@@ -73,5 +69,5 @@
 
 	    else
-		printf "No previous $file.nc found for comparison\n"
+		export ST='FAILED'
 	    fi
 
@@ -79,21 +75,7 @@
 
     else
-	export STATUS='FAILED'; STEP='No restart files found at last time step'
-	printf "No $file.nc found for comparison\n"
-    fi
-
-}
-
-diff_textfiles() {
-    for file in ocean.output $( ls *.stat ); do
-
-	if [ -e ${REFE_DIR}/$file ]; then
-	    diff $file ${REFE_DIR}/$file
-	    [ $? -ne 0 ] && export STATUS='FAILED' STEP="$file different"
-	else
-	    printf "No previous $file found for comparison\n"
-	fi
-
-    done
+	export ST='FAILED'
+    fi
+
 }
 
@@ -116,6 +98,6 @@
 get_soft_rel() {
     for rel in $CDO $COMPILER $MPI $NETCDF; do
-                                 arch_rel=$( echo $LOADEDMODULES | sed  "s#.*$rel/\([^:]*\).*#\1#" )
-	[ -z "${arch_rel}"  ] && arch_rel=$( echo $PATH          | sed  "s#.*$rel/\([^/]*\).*#\1#" )
+                                     arch_rel=$( echo $LOADEDMODULES | sed  "s#.*$rel/\([^:]*\).*#\1#" )
+	[ -z "${arch_rel}"  ]     && arch_rel=$( echo $PATH          | sed  "s#.*$rel/\([^/]*\).*#\1#" )
 	[ "$rel" == "$COMPILER" ] && arch_rel=$( $rel --version      | grep -m1 -o ' [0-9.]* '         )
 	echo $rel ${arch_rel} >> model.log
@@ -133,5 +115,5 @@
     if [[    $( echo ${NEMO_VERS} | grep  "HEAD\|up\|update"   ) \
 	  || $( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' )  ]]; then
-	rev=$( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' ) || rev='HEAD'
+	 rev=$( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' ) || rev='HEAD'
 	svn_cmd='svn update -r '$rev 
     else
@@ -161,5 +143,4 @@
 
     echo   'NEMOGCM '$rev   >> model.log
-#   printf "NEMOGCM rev.\n$rev\n" >  mesg_04_nemogcm_${CFG_USER}_${CFG_ARCH}.txt
     printf "NEMOGCM rev.\n" >  mesg_04_nemogcm_${CFG_USER}_${CFG_ARCH}.txt
     printf "<a href=\"https://forge.ipsl.jussieu.fr/nemo/changeset/$rev\" target=\"_blank\">$rev</a>" \
@@ -181,5 +162,5 @@
 
   # Send mail only when FAILED
-  if [[ ! -z $EMAIL && "$STATUS" == 'FAILED' ]]; then
+  if [[ ! -z $EMAIL && "$ST" == 'FAILED' ]]; then
       cat << END_MAIL > trusting.mail
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@@ -194,9 +175,9 @@
 
 END_MAIL
-#`tail -n 1 ${TEST_DIR}/mesg_03_step_${CFG_USER}_${CFG_ARCH}.txt`
+#`tail -n 1 ${TEST_DIR}/mesg_03_error_${CFG_USER}_${CFG_ARCH}.txt`
       if [ -e ${TEST_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt ]; then
 	  cat ${TEST_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt  >> trusting.mail
       fi
-      mail -s "[trusting ${REFE_CONF}] $STATUS $STEP" $EMAIL  <  trusting.mail
+      mail -s "[trusting ${REFE_CONF}] $ST $ERR" $EMAIL  <  trusting.mail
   fi
 
@@ -204,12 +185,11 @@
 }
 
-print_step() {
-    [ ! -z "$1" ] && STEP=$1
-    export STEP && printf "Step.....\n$STEP\n"
-}
+print_step() { printf "Step.....\n$1\n"; }
 
 get_out() {
+    printf "Status\n$ST\n"  > mesg_02_status_${CFG_USER}_${CFG_ARCH}.txt
+
     # Save tested configuration if trusting failed
-    if [ "$STATUS" == 'FAILED' ]; then
+    if [ "$ST" == 'FAILED' ]; then
 	cd ${TEST_DIR}
 	printf "Input files\n\n"   > mesg_09_inputfiles_${CFG_USER}_${CFG_ARCH}.txt
@@ -220,11 +200,26 @@
 	fi
 
+        # Error identification
+	case ERR in
+	    # Compilation
+	    1) ERR='XIOS compilation failed'	         ;;  2) ERR='NEMO compilation failed'            ;;
+	    # Submission
+	    3) ERR='Missing input files'                 ;;  4) ERR='Job submission error'               ;;
+	    # Running
+	    5) ERR='nemo.exe crashed at '${LAST_TIME_ERR};;  6) ERR='Exceeded time limit '${TIME_LIMI}'h';;
+	    # Results
+	    7) ERR='Missing previous outputs '           ;;  8) ERR='New outputs  differ/missing'        ;;
+	    9) ERR='Missing previous restarts'           ;; 10) ERR='New restarts differ/missing'        ;;
+	    # Undefined
+	    *) ERR='Unknown error'                       ;;
+	esac
+
 	#tar -czf ${REFE_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.tar.gz *
     fi
 
-    printf "Status\n$STATUS\n"  > mesg_02_status_${CFG_USER}_${CFG_ARCH}.txt
-    printf "Step.....\n$STEP\n" > mesg_03_step_${CFG_USER}_${CFG_ARCH}.txt
-
-    mesg_make; mesg_publish
+    printf "Result.....\n$ERR\n" > mesg_03_result_${CFG_USER}_${CFG_ARCH}.txt
+
+    mesg_make
+    mesg_publish
 
     exit 1
@@ -233,21 +228,19 @@
 job_pending() {
     time_elapsed=0; time_increment=30
+
     sleep ${time_increment}
-
     while [[ $( ${JOB_LIST} | grep ${JOB_ID} ) && ${time_elapsed} -lt ${TIME_LIMI} ]]; do
 	printf "\n####################################################" >> computation.log
 	${JOB_INFO} ${JOB_ID}                                           >> computation.log
 	sleep ${time_increment}
-	let time_elapsed+=${time_increment}
-    done
-
+#	let time_elapsed+=${time_increment}
+	time_elapsed=$(( ${time_elapsed} + ${time_increment} ))
+    done
     sleep ${time_increment}
 
     if [ ${time_elapsed} -eq ${TIME_LIMI} ]; then
-	STEP='Exceeded time limit'
-	[ $( ${JOB_LIST} | grep ${JOB_ID} ) ] && STEP='Job not finished on time: '$(( ${TIME_LIMI}/3600 ))'h'
-	print_step
 	${JOB_DELE} ${JOB_ID} &> /dev/null
-	get_out $STATUS $STEP
-    fi
-}
+	TIME_LIMIT=$(( ${TIME_LIMI} / 3600 ))
+	export ${TIME_LIMIT}
+	get_out $ST ERR=6
+}
