Index: /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting.sh
===================================================================
--- /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting.sh	(revision 5688)
+++ /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting.sh	(revision 5689)
@@ -8,5 +8,5 @@
 NEMO_TRUS=$PWD
 DEBUG=0; PUBLISH=0; TIME_STEP=0
-I_MODULE=0; ST='FAILED' ## No 'module' command & 'FAILED' status
+IMOD=0; ST='FAILED' ## No 'module' command & 'FAILED' status
 xios_full='--full'; stderr_redir='>&' ## DEBUG options
 
@@ -50,25 +50,23 @@
 ## Summary of trusting test context
 ##---------------------------------------------------
-printf "\n\
-NEMO Trusting test:\n\
--------------------\n\
-Testing ${TEST_CONF} based on ${REFE_CONF} from ${NEMO_BRAN}\n\
-NEMO installation: ${NEMO_USER}\n\
-Computing architecture: ${NEMO_HPCC}\n\
-Trusting SVN version: $( svn info | awk '(NR == 9) {print $NF}' )\n"
+echo 'NEMO Trusting test:'
+echo '-------------------'
+echo 'Testing '${TEST_CONF}' based on '${REFE_CONF}' from '${NEMO_BRAN}
+echo 'NEMO installation: '${NEMO_USER}
+echo 'Computing architecture: '${NEMO_HPCC}
+echo 'Trusting SVN version: '$( svn info | awk '(NR == 9) {print $NF}' )
 
 
 ## Making timestamped directory with messenger files
 ##---------------------------------------------------
-print_step 'Time-stamp generation & testing directory creation'
-mkdir -p ${TEST_DIR} ${REFE_DIR}
-echo ${TEST_DIR} && cd ${TEST_DIR}
-init_files && get_date
+cd ${TEST_DIR}
+
+print_step 'Create timestamped testing directory'
+echo ${TEST_DIR} && init_files && get_date
 
 
 ## SVN action on XIOS & NEMO essentials directories
 ##---------------------------------------------------
-print_step 'SVN command on NEMO directories:'
-get_nemo_rev
+print_step 'SVN command on NEMO directories:'; get_nemo_rev
 
 
@@ -76,14 +74,16 @@
 ##---------------------------------------------------
 print_step 'Get softwares releases'
+
 [ -e ${ARCH_ENV} ] && . ${ARCH_ENV} > /dev/null
-(( $? == 0  )) && export I_MODULE=1
-get_soft_rel
-cat model.log
+[ $? -eq 0 ] && export IMOD=1
+
+get_soft_rel; cat model.log
 
 
 ## XIOS compiling
 ##---------------------------------------------------
+cd ${DIR_XIOS}
+
 print_step 'Compile XIOS'
-cd ${DIR_XIOS}
 [ $DEBUG -eq 1 ] && xios_full='' && stderr_redir='>'
 eval ./make_xios ${xios_full} --arch ${NEMO_HPCC} --job $NPROC \
@@ -93,9 +93,10 @@
 ## NEMO config compiled from scratch
 ##---------------------------------------------------
-print_step "Compile ${REFE_CONF} configuration"
 cd ${NEMO_CONF}
 
+print_step "Compile ${REFE_CONF} configuration"
+
 if [[ -d ${TEST_CONF} && $DEBUG -eq 0 ]]; then
-    eval ./makenemo -n ${TEST_CONF} clean_config > /dev/null <<EOF
+    ./makenemo -n ${TEST_CONF} clean_config > /dev/null <<EOF
 y
 EOF
@@ -103,5 +104,5 @@
 
 eval ./makenemo -n ${TEST_CONF} -r ${REFE_CONF} -m ${NEMO_HPCC} -j $NPROC \
-                ${KEYS_ADD} ${KEYS_DEL}                                   \
+                   ${KEYS_ADD} ${KEYS_DEL}                                \
     ${stderr_redir} /dev/null
 [ ! -e ${TEST_CONF}/BLD/bin/nemo.exe ] && get_out 2
@@ -110,10 +111,12 @@
 ## Get namelists, xml & forcing files for running
 ##---------------------------------------------------
+cd ${TEST_DIR}
+
 print_step 'Set job (copying & extracting input files)'
-cd ${TEST_DIR}
 cp ${NEMO_CONF}/${TEST_CONF}/cpp_* .
 find ${NEMO_CONF}/${TEST_CONF}/EXP00 -regex '.*\(_cfg\|.in\|opa\|_ref\|.xml\)' -exec cp {} . \;
+
 get_inputs
-(( $? != 0 )) && get_out 3
+[ $? -ne 0 ] && get_out 3
 [ $( find . -name '*.gz' -print -quit ) ] && find . -name '*.gz' -exec gunzip {} \;
 
@@ -121,53 +124,37 @@
 ## Check input files in all cases
 ##---------------------------------------------------
-print_step 'Compare with standard input files list'
-diff_inputs
+print_step 'Compare with benchmark input files list'; diff_inputs
 
 
 ## Job submission & computing
 ##---------------------------------------------------
-print_step 'Submit job'
-JOB_ID=$( eval ${JOB_SUBM} )
-(( $? != 0 )) && get_out 4
-print_step 'Pending job'
-job_pending
+print_step 'Submit job'; JOB_ID=$( eval ${JOB_SUBM} )
+[ $? -ne 0 ] && get_out 4
+
+print_step 'Pending job'; job_pending
+
 print_step 'Job finished'
 
 
-## Job state
+## Job state & get time computation if succeeded
 ##---------------------------------------------------
 print_step 'Test job state'
 
-if   [[ ! -e time.step || $( grep -q 'E R R O R' ocean.output ) ]]; then
-    echo 'Error'
-    comments 'E R R O R'
+if   [[ ! -e time.step || $( grep 'E R R O R' ocean.output ) ]]; then
+    echo 'Failure'
     get_out 5
 else
-    echo 'Good'
-    ## Get time computation
-    ##---------------------------------------------------
-    print_step 'Get real CPU time'
-    get_cpu_time
+    echo 'Success'
 fi
 
+print_step 'Get real CPU time'; get_cpu_time
+
+
+## Inspect outputs
+##---------------------------------------------------
 ST='OK' ## 'OK' by default
 
-
-## Inspect output text files
-##---------------------------------------------------
-print_step 'Test output files diff'
-diff_results
-
-
-## Inspect output NetCDF files
-##---------------------------------------------------
-print_step 'Test last restart files diff'
-diff_restart
+print_step 'Compare new outputs to benchmark files'; diff_results; diff_restart
 [ $ST == 'FAILED' ] && get_out 8
-
-
-## Get comments (ocean.output & diff model.log)
-##---------------------------------------------------
-comments 'W A R N I N G'
 
 
Index: /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting_func.sh
===================================================================
--- /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting_func.sh	(revision 5688)
+++ /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting_func.sh	(revision 5689)
@@ -1,4 +1,6 @@
 #!/bin/bash
 
+
+mkdir -p ${TEST_DIR} ${REFE_DIR}
 
 ## Messenger filenames
@@ -26,5 +28,8 @@
 
     # 'Failed' status with 'Unknown error' by default
-    echo $ST             >> ${FILE_STAT}; echo 'Unknown error'    >> ${FILE_RESU}
+    echo $ST             \
+	>> ${FILE_STAT}
+    echo 'Unknown error' \
+	>> ${FILE_RESU}
 }
 
@@ -33,5 +38,6 @@
     local dat=$( date -ud ${DATE} +"%F %R %Z" )
 
-    echo $dat >> ${FILE_DATE}
+    echo $dat          \
+	>> ${FILE_DATE}
 }
 
@@ -60,5 +66,6 @@
 	if [ $dir == ${DIR_XIOS} ]; then
 	    rev_loc=$( svn info $dir | awk '(NR == 9) {print $NF}' )
-	    echo 'XIOS '${rev_loc} >> model.log
+	    echo 'XIOS '${rev_loc} \
+		>> model.log
 	    echo "<a href=\"https://forge.ipsl.jussieu.fr/ioserver/changeset/${rev_loc}\" target=\"_blank\">${rev_loc}</a>" \
 		>> ${FILE_XIOS}
@@ -69,8 +76,9 @@
 	${svn_cmd} $dir
 	rev_loc=$( svn info $dir | awk '(NR == 9) {print $NF}' )
-	(( ${rev_loc} >= $rev )) && rev=${rev_loc}
-    done
-
-    echo 'NEMOGCM '$rev   >> model.log
+	[ ${rev_loc} -gt $rev ] && rev=${rev_loc}
+    done
+
+    echo 'NEMOGCM '$rev \
+	>> model.log
     echo "<a href=\"https://forge.ipsl.jussieu.fr/nemo/changeset/$rev\" target=\"_blank\">$rev</a>" \
 	>> ${FILE_NEMO}
@@ -84,5 +92,5 @@
 	soft_rel=''
 
-        if (( ${I_MODULE} == 1 )); then
+        if [ $IMOD -eq 1 ]; then
 	    soft_rel=$( echo $LOADEDMODULES | sed "s/.*$soft\/\([0-9.a-z_]*\).*/\1/i" )
 	else
@@ -93,9 +101,14 @@
 	## Cleaning characters string to display proper soft name
 	soft=$( echo $soft | sed 's#\\##g; s#[/-]$##' )
-	echo $soft ${soft_rel} >> model.log
-    done
-
-    sed -n 4p model.log >> ${FILE_COMP}; sed -n 5p model.log >> ${FILE_MPIN}
-    sed -n 6p model.log >> ${FILE_NCDF}
+	echo $soft ${soft_rel} \
+	    >> model.log
+    done
+
+    sed -n 4p model.log \
+	>> ${FILE_COMP}
+    sed -n 5p model.log \
+	>> ${FILE_MPIN}
+    sed -n 6p model.log \
+	>> ${FILE_NCDF}
 }
 
@@ -113,19 +126,13 @@
     local files_list='' mesg='Same' 
 
-    for file in inputs_list.txt namelist_* *.xml cpp_*; do
+    for file in 'inputs_list.txt' *namelist_* *.xml cpp_*; do
 	dif=''
-
-	if [ -e ${REFE_DIR}/$file ]; then
-	    dif=$( diff -q $file ${REFE_DIR}/$file )
-	else dif=0; fi
-
-	if [ -n "$dif" ]; then
-	    mesg='Different'
-	    [ "$dif" != '0' ] && echo $dif && files_list+=$file' '
-	fi
-
-    done
-
-    echo $mesg | tee -a ${FILE_INPT}
+	if [ -e ${REFE_DIR}/$file ]; then dif=$( diff -q $file ${REFE_DIR}/$file ); else dif=0; fi
+	if [ -n "$dif" ]; then mesg='Different'; [ "$dif" != '0' ] && echo $dif && files_list+=$file' '; fi
+    done
+
+    [ $mesg == 'Same' ] && echo $mesg
+    echo $mesg         \
+	>> ${FILE_INPT}
     [ -n "${files_list}" ] && echo 'Inputs  : '${files_list}'differ<br>' \
 	>> temp_${FILE_COMM}
@@ -139,6 +146,8 @@
 
     while [[ $( ${JOB_LIST} | grep ${JOB_ID} ) && ${time_elapsed} -lt ${TIME_LIMI} ]]; do
-	printf "\n%s\n" ${outline// /#} >> computation.log
-	${JOB_INFO} ${JOB_ID}           >> computation.log
+	printf "\n%s\n" ${outline// /#} \
+	    >> computation.log
+	${JOB_INFO} ${JOB_ID}           \
+	    >> computation.log
 	sleep ${time_increment}
 	time_elapsed=$(( ${time_elapsed} + ${time_increment} ))
@@ -147,8 +156,7 @@
     sleep ${time_increment}
 
-    if (( ${time_elapsed} == ${TIME_LIMI} )); then
+    if [ ${time_elapsed} -eq ${TIME_LIMI} ]; then
 	${JOB_DELE} ${JOB_ID} &> /dev/null
-	let TIME_LIMIT/=3600
-	export ${TIME_LIMIT}
+	export TIME_LIMIT/=3600
 	get_out 6
     fi
@@ -159,8 +167,8 @@
     local files_list=''
 
-    for file in ocean.output *.stat; do
+    for file in 'ocean.output' *.stat; do
 	[ ! -e ${REFE_DIR}/$file ] && export ST='FAILED' && get_out 7
 	diff -q $file ${REFE_DIR}/$file
-	(( $? != 0 )) && export ST='FAILED' && files_list+=$file' '
+	[ $? -ne 0 ] && export ST='FAILED' && files_list+=$file' '
     done
 
@@ -192,13 +200,13 @@
 		nb_dom=$( find -name "${file}_[0-9]*.nc" | wc -l | awk '{ print $1 }' )
 
-		if   (( ${nb_dom} >  1 )); then
+		if   [ ${nb_dom} -gt 1 ]; then
 		    ${NEMO_TRBD}/rebuild_nemo -t $NPROC $file ${nb_dom} > /dev/null
 		    [ $? -eq 0 ] && rm -f ${file}_[0-9]*.nc             > /dev/null
-		elif (( ${nb_dom} == 0 )); then
+		elif [ ${nb_dom} -eq 0 ]; then
 		    export ST='FAILED' && get_out 8
 		fi
 
 		## Compare restart files at same time step
-		if (( $tmsp == ${TIME_STEP} )); then
+		if [ $tmsp -eq ${TIME_STEP} ]; then
 		    if [ -e ${REFE_DIR}/$file.nc ]; then
 	                ## UNIX `cmp` not suitable (timestamp in .nc file)
@@ -206,5 +214,5 @@
 			       | awk '/records/ {print $0}' | sed '2 s/^/,/' | tr -d '\n'  )
 
-			if [[ -n "$dif" && (( $( echo $dif | awk '{print $1}' ) -ne 0 )) ]]; then
+			if [[ -n "$dif" && $( echo $dif | awk '{print $1}' ) -ne 0 ]]; then
 			    export ST='FAILED' && files_list+=$file' '
 			    let dift+=$( echo $dif | awk '{print $1}' )
@@ -212,17 +220,24 @@
 			fi
 
-		    else export ST='FAILED' && get_out 7; fi
-
-		else continue; fi
+		    else
+			export ST='FAILED' && get_out 7
+		    fi
+
+		else
+		    continue
+		fi
 
 	    done
 	done
 
-	if (( $dift != 0 )); then
-	    echo 'Restarts: '${files_list}$dift' record(s) differ<br>' \
-		>> temp_${FILE_COMM}
-	else echo 'No restart differ'; fi
-
-    else export ST='FAILED'; fi
+	if [ $dift -ne 0 ]; then
+	    echo 'Restarts: '${files_list}$dift' record(s) differ<br>' | tee -a temp_${FILE_COMM}
+	else 
+	    echo 'No restart differ'
+	fi
+
+    else
+	export ST='FAILED'
+    fi
 
 }
@@ -247,5 +262,6 @@
 
     echo   $line
-    printf "$line<br>" >> temp_${FILE_COMM}
+    printf "$line<br>"      \
+	>> temp_${FILE_COMM}
 }
 
@@ -267,5 +283,6 @@
 	if [ -f ${REFE_DIR}/trusting_$PATTERNAME.txt ]; then cmd='tail -1'; else cmd='cat'; fi
 
-	$cmd ${FILE_TRUS} >> ${REFE_DIR}/trusting_$PATTERNAME.txt
+	$cmd ${FILE_TRUS}                           \
+	    >> ${REFE_DIR}/trusting_$PATTERNAME.txt
 
   ## Send mail only when FAILED
@@ -285,6 +302,4 @@
 `cat ${TEST_DIR}/${FILE_TRUS}`
 END_MAIL
-#	    cat ${TEST_DIR}/${FILE_TRUS}                  \
-#		>> trusting.mail
 	    mail -s "[NEMO Trusting ${NEMO_HPCC} ${REFE_CONF} ${NEMO_BRAN}] $ST $ERR" $EMAIL \
 		<  trusting.mail
@@ -319,5 +334,5 @@
     fi
 
-    sed -i "2 s/.*/$ST/"  ${FILE_STAT} && sed -i "2 s/.*/$ERR/" ${FILE_RESU}
+    sed -i "2 s/.*/$ST/" ${FILE_STAT} && sed -i "2 s/.*/$ERR/" ${FILE_RESU}
 
     ## Save tested configuration if trusting failed
@@ -328,6 +343,11 @@
     fi
 
-    mesg_make
-    mesg_publish
+    if [ $ERR -eq 5 ]; then
+	print_step 'Comments'; comments 'E R R O R'
+    else
+	print_step 'Comments'; comments 'W A R N I N G'
+    fi
+
+    print_step 'Trusting outcome'; mesg_make; mesg_publish
 
     exit 0
