Index: /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting.sh
===================================================================
--- /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting.sh	(revision 5437)
+++ /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting.sh	(revision 5438)
@@ -11,5 +11,5 @@
 #---------------------------------------------------
 NEMO_TRUS=$( pwd $( dirname $0 ) )
-SVN_CMD='svn status'
+SVN_OPT='status'
 DEBUG=0; PUBLISH=0; status='OK'
 
@@ -27,7 +27,4 @@
     esac
 done
-
-#export DEBUG PUBLISH
-
 
 # Initialization (super-computer & user environment)
@@ -47,10 +44,5 @@
 fi
 
-# If -v|--version option has been set, modify svn command
-[ $( echo ${NEMO_VERS} | grep  "up\|update"         ) ] && SVN_CMD='svn update'
-[ $( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' ) ] && SVN_CMD='svn update -r '$( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' )
-
 . ./trusting_func.sh
-
 
 # 
@@ -59,39 +51,30 @@
 echo ${TEST_DIR} && cd ${TEST_DIR}
 datestr1=$( LC_ALL=C date -d"${DATE_STR}" +%Y-%m-%dT%H:%M )
-printf "Date\n%s\n"       $datestr1 > mesg_01_date_${CFG_USER}_${CFG_ARCH}.txt
+printf "Date\n$datestr1\n" > mesg_01_date_${CFG_USER}_${CFG_ARCH}.txt
 # Only at end status will change to OK
-printf "Status\nFAILED\n"           > mesg_03_status_${CFG_USER}_${CFG_ARCH}.txt
+status='FAILED'
 
-
-# Check softwares versions
+# Check softwares versions (source arch environment)
 #---------------------------------------------------
-printf "Step......................\nGet softwares release\n"                     | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
-. ${ARCH_ENV} > /dev/null    # Sourcing architecture environment
+pstep 'Get softwares release'
+. ${ARCH_ENV} > /dev/null
 get_soft_rel
-sed -n 2p model.log | sed 'i\Fortran compiler' | tee mesg_05_compiler_${CFG_USER}_${CFG_ARCH}.txt
-sed -n 3p model.log | sed 'i\MPI libraries   ' | tee mesg_06_mpi_${CFG_USER}_${CFG_ARCH}.txt
-sed -n 4p model.log | sed 'i\NetCDF libraries' | tee mesg_07_netcdf_${CFG_USER}_${CFG_ARCH}.txt
-
 
 # SVN action on XIOS & NEMO essentials directories
 #---------------------------------------------------
-printf "Step......................\nGet NEMO SVN revision with: ${SVN_CMD}\n"    | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
+pstep "Get NEMO SVN state with: ${SVN_OPT}"
 get_nemo_rev
-sed -n 6p model.log | sed 'i\NEMO revision'    | tee  mesg_02_nemo_${CFG_USER}_${CFG_ARCH}.txt
-
-
+exit 0
 # NEMO config compiled from scratch
 #---------------------------------------------------
-printf "Step......................\nCompiling ${CONF_REF} configuration\n"       | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
+pstep "Compiling ${CONF_REF} configuration"
 cd ${NEMO_CONF}
 #[ -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
-
+[ ! -e ${TEST_CONF}/BLD/bin/nemo.exe ] && get_out $step $status
 
 # Get namelists, xml & forced files for running
 #---------------------------------------------------
-cd ${TEST_DIR}
-printf "Step......................\nPreparing job\n"                             | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
+pstep 'Preparing job'
 find ${NEMO_CONF}/${TEST_CONF}/EXP00 -regex '.*\(cfg\|opa\|ref\|xml\)' -exec cp {} . \;
 
@@ -103,13 +86,17 @@
 
 ${cmd_iol} > inputs_list.txt && ${cmd_iof} > /dev/null
-[ $? -ne 0 ] && get_out
+[ $? -ne 0 ] && get_out $step $status
 [ $( find . -name '*.gz' -print -quit ) ] && gunzip *.gz
-exit 0
+
+# Check input files in all cases
+#---------------------------------------------------
+pstep 'Test input files difference'
+diff_inputs
 
 # Job submission & computing
 #---------------------------------------------------
-printf "Step......................\nRunning\n"                                   | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt; echo ${JOB_SUBM}
+pstep 'Running'
 job_num=$( ${JOB_SUBM} | awk '{print $NF}' )
-[ $? -ne 0 ] && get_out
+[ $? -ne 0 ] && get_out $step $status
 
 time_elapsed=0; time_increment=30
@@ -125,62 +112,40 @@
 # Eventual crash during computing
 #---------------------------------------------------
-printf "Step......................\nTest if ASCII output files exist\n"          | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
-if   [ ! -f ocean.output                  ]; then
-    printf "Step......................\nOpa crashed at initialization\n"         | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
+pstep 'Test if ASCII output files exist'
+if   [[ ! -f ocean.output || $( grep 'E R R O R' ocean.output ) ]]; then
+    ${JOB_DELE} ${job_num} &> /dev/null
+    [ ! -f ocean.output                  ] && step='nemo.exe crashed at initialization'
+    [ $( grep 'E R R O R' ocean.output ) ] && step='nemo.exe crashed'
+    comments('E R R O R')
     ${JOB_DELE} ${job_num} >/dev/null 2>&1
     status='FAILED'
-elif [ $( grep 'E R R O R' ocean.output ) ]; then
-    printf "Step......................\nOpa crashed\n"                           | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
-    grep 'E R R O R'       ocean.output | tee    mesg_10_comments_${CFG_USER}_${CFG_ARCH}.txt
-    sed 's/^/Time step :/' time.step    | tee -a mesg_10_comments_${CFG_USER}_${CFG_ARCH}.txt
-    ${JOB_DELE} ${job_num} >/dev/null 2>&1
-    status='FAILED'
+    get_out $step $status
+else
+    status='OK'
+
+    # Inspect output text files
+    #---------------------------------------------------
+    pstep 'Test ASCII output files diff'
+    for file in ocean.output solver.stat tracer.stat; do
+	diff $file ${REFE_DIR}/$file
+	[ $? -ne 0 ] && status='FAILED'
+    done
+
+    # Inspect output NetCDF files
+    #---------------------------------------------------
+    pstep 'Test last restart NetCDF files diff'
+    diff_restart #2> /dev/null
+    [ $? -ne 0 ] && status='FAILED'
+
+    # Get computation duration
+    #---------------------------------------------------
+    pstep 'Get real CPU time'
+    get_cpu_time
+
+    comments('W A R N I N G')
 fi
-
-
-# Inspect output text files
-#---------------------------------------------------
-printf "Step......................\nTest ASCII output files difference\n"        | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
-for file in ocean.output solver.stat tracer.stat; do
-    diff $file ${REFE_DIR}/$file
-    [ $? -ne 0 ] && status='FAILED'
-done
-
-
-# Inspect output NetCDF files
-#---------------------------------------------------
-printf "Step......................\nTest last restart NetCDF files difference\n" | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
-diff_restart 2>/dev/null
-[ $? -ne 0 ] && status='FAILED'
-
-
-# Finals tests
-#---------------------------------------------------
-if [ $status != 'FAILED' ]; then
-
-    # Comments
-    #---------------------------------------------------
-    echo 'Comments'                    | tee    mesg_10_comments_${CFG_USER}_${CFG_ARCH}.txt
-    grep 'W A R N I N G:' ocean.output | tee -a mesg_10_comments_${CFG_USER}_${CFG_ARCH}.txt
-
-    # Portability !
-    printf "Step......................\nGet real CPU time\n"                     | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
-    real_cpu_time=$( ${JOB_VIEW} ${job_num} | awk 'END{print $9}' )
-    printf "Real CPU time\n%s\n" ${real_cpu_time} | tee mesg_08_realcputime_${CFG_USER}_${CFG_ARCH}.txt
-    printf "Input files\nNA"                      | tee mesg_09_inputfiles_${CFG_USER}_${CFG_ARCH}.txt
-else
-    printf "Step......................\nTest input files difference\n"           | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
-    diff_inputs
-    get_out
-fi
-
-
-# So far, everything is good
-#---------------------------------------------------
-printf "Status\nOK\n" > mesg_03_status_${CFG_USER}_${CFG_ARCH}.txt
-printf "Step......................\nCode is reliable\n"                          | tee mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
-
 
 # End
 #---------------------------------------------------
-get_out
+if [ $status == 'FAILED' ]; then step='Test outputs difference'; else step='Code is reliable'; fi
+get_out $step $status
Index: /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting_func.sh
===================================================================
--- /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting_func.sh	(revision 5437)
+++ /branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting_func.sh	(revision 5438)
@@ -2,53 +2,52 @@
 
 
+comments() {
+    echo 'Comments'      | tee    mesg_10_comments_${CFG_USER}_${CFG_ARCH}.txt
+    grep $1 ocean.output | tee -a mesg_10_comments_${CFG_USER}_${CFG_ARCH}.txt
+}
+
+get_cpu_time() {
+    # Portability !
+    real_cpu_time=$( ${JOB_VIEW} ${job_num} | awk 'END{print $9}' )
+    printf "Real CPU time\n%s\n" ${real_cpu_time} | tee mesg_08_realcputime_${CFG_USER}_${CFG_ARCH}.txt
+}
+
 diff_inputs() {
+    mesg='Same'
+
     for file in inputs_list.txt $( ls namelist_* ) iodef.xml; do
 	diff $file ${REFE_DIR}/$file
-
-	if [ $? -ne 0 ]; then
-	    printf "Input files\nDifferent" | tee mesg_09_inputfiles_${CFG_USER}_${CFG_ARCH}.txt
-	    get_out
-	fi
-
+	[ $? -ne 0 ] && mesg='Different'
     done
 
-    printf "Input files\nSame"              | tee mesg_09_inputfiles_${CFG_USER}_${CFG_ARCH}.txt
+    printf "Input files\n$mesg" | tee mesg_09_inputfiles_${CFG_USER}_${CFG_ARCH}.txt
 }
 
-diff_nc() {
-    stat=100; file1=$1; file2=$2
-
-    $CDO diffv $file1 $file2 > out_tmp
-    ( [ $? -ne 0 ] && stat=100 ) || stat=$( grep -m 1 'records differ' out_tmp | awk -Fof '{print $1}' )
-    [ -f out_tmp ] && rm out_tmp
-
-    return $stat
-} 
-
 diff_restart() {
-    result=0
     last_time_step=$( cat ${REFE_DIR}/time.step | tr -d [:space:] )
-    echo 'Last time step: '${last_time_step}
+    echo 'Last time step of standard run: '${last_time_step}
 
     if [ $( find ${TEST_DIR} -name "*${last_time_step}_restart*.nc" -print -quit ) ]; then
-	basename=$( find ${TEST_DIR} -name "*${last_time_step}_restart*.nc" -print -quit \
-	             | sed "s/^\(.*\)$last_time_step\_.*/\1$last_time_step/"               )
+	base_name=$( find ${TEST_DIR} -name "*${last_time_step}_restart*.nc" -print -quit           \
+	             | awk -F/ '{print $NF}' | sed "s/^\(.*\)$last_time_step\_.*/\1$last_time_step/" )
 
 	for comp in restart restart_ice restart_trc; do
-	    printf "${TEST_DIR}/${basename}_${comp}*.nc: "
+	    printf "${base_name}_${comp}.nc: "
 
-	    nb_dom=$( find ${TEST_DIR} -name "${basename}_${comp}_[0-9]*.nc" | wc -l | awk '{print $1}' )
+	    nb_dom=$( find ${TEST_DIR} -name "${base_name}_${comp}_[0-9]*.nc" | wc -l | awk '{print $1}' )
 	    if [ ${nb_dom} -gt 1 ]; then
-		${NEMO_TRBD}/rebuild_nemo -t $NPROC ${basename}_$comp ${nb_dom} >/dev/null
+		${NEMO_TRBD}/rebuild_nemo -t $NPROC ${base_name}_$comp ${nb_dom} > /dev/null
 	    fi
 
-	    cmp ${TEST_DIR}/${basename}_$comp.nc ${REFE_DIR}/${basename}_$comp.nc
+	    cmp ${TEST_DIR}/${base_name}_$comp.nc ${REFE_DIR}/${base_name}_$comp.nc
 	    if [ $? -ne 0 ]; then
-		result=$( diff_nc ${TEST_DIR}/${basename}_$comp.nc ${REFE_DIR}/${basename}_$comp.nc )
-		printf "$CDO diffv $result\n"
+		status='FAILED'
+		printf "$CDO diffn\n"
+		$CDO diffn ${TEST_DIR}/${base_name}_$comp.nc ${REFE_DIR}/${base_name}_$comp.nc 2> /dev/null
 	    else
 		printf "identical\n"
 	    fi
-#	    \rm *${last_time_step}_${comp}_[0-9]*.nc
+
+	    \rm  ${TEST_DIR}/${base_name}_${comp}_[0-9]*.nc
 	done
 
@@ -60,9 +59,13 @@
 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#" )
-	[ $rel == $COMPILER ] && arch_rel=$( $rel --version | grep -m1 -o ' [0-9.]* ' )
+                                 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
     done
+
+    sed -n 2p model.log | sed 'i\Compiler'    | tee mesg_05_compiler_${CFG_USER}_${CFG_ARCH}.txt
+    sed -n 3p model.log | sed 'i\MPI libs'    | tee mesg_06_mpi_${CFG_USER}_${CFG_ARCH}.txt
+    sed -n 4p model.log | sed 'i\NetCDF libs' | tee mesg_07_netcdf_${CFG_USER}_${CFG_ARCH}.txt
 }
 
@@ -70,9 +73,28 @@
     rev=0
 
+    # If -v|--version option has been set, modify svn command
+    if   [ $( echo ${NEMO_VERS} | grep  "up\|update"         ) ]; then SVN_OPT='update'
+    elif [ $( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' ) ]; then SVN_OPT='checkout'
+	rev=$( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' )
+    fi
+
     for dir in ${DIR_XIOS}  ${NEMO_ARCH} ${NEMO_CONF} ${NEMO_ENGI} ${NEMO_EIOI} \
 	       ${NEMO_EFCM} ${NEMO_TRUS} ${NEMO_TCMP} ${NEMO_TRBD}               ; do
+
 	# For time being, just get revision number from XIOS
-	[ $dir == ${DIR_XIOS} ] && echo 'XIOS '$( svn info $dir | awk '(NR == 9) {print $NF}' ) >> model.log && continue
-	${SVN_CMD} $dir
+	if [ $dir == ${DIR_XIOS} ]; then
+	    echo 'XIOS '$( svn info $dir | awk '(NR == 9) {print $NF}' ) >> model.log
+	    continue
+	fi
+
+	# 
+	if [ $( echo ${SVN_OPT} | grep 'checkout' ) ]; then
+	    cd ../$dir 
+	    url=$( svn info $dir | grep URL | awk '{print $NF}' )
+	    svn ${SVN_OPT} $url -r $rev $dir && cd -
+	else
+	    svn ${SVN_OPT} $dir
+	fi
+
 	rev_loc=$( svn info $dir | awk '(NR == 5) {print $NF}' )
 	(( ${rev_loc} >= $rev )) && rev=${rev_loc}
@@ -80,9 +102,10 @@
 
     echo 'NEMO '$rev >> model.log
+    sed -n 6p model.log | sed 'i\NEMOGCM rev.' | tee mesg_02_nemo_${CFG_USER}_${CFG_ARCH}.txt
 }
 
 mesg_make() {
     paste -d ';' mesg_*_${CFG_USER}_${CFG_ARCH}.txt > trusting_${DATE_STR}_${CFG_USER}_${CFG_ARCH}.txt
-    cat trusting_${DATE_STR}_${CFG_USER}_${CFG_ARCH}.txt
+    cat                                               trusting_${DATE_STR}_${CFG_USER}_${CFG_ARCH}.txt
 }
 
@@ -115,14 +138,23 @@
 }
 
+pstep() {
+    printf "Step.....\n$1\n"
+}
+
 get_out() {
+    step=$1; status=$2
     mesg_make; mesg_publish
 
     # Save tested configuration if trusting failed
     if [ $status == 'FAILED' ]; then
+	touch mesg_08_realcputime_${CFG_USER}_${CFG_ARCH}.txt mesg_10_comments_${CFG_USER}_${CFG_ARCH}.txt
 	cd ${REFE_DIR}
 	tar -czf trusting_${DATE_STR}_${CFG_USER}_${CFG_ARCH}.tar.gz ${TEST_DIR}/*
 	cd -
     fi
-	
+
+    printf "Status\n$status\n"  > mesg_03_status_${CFG_USER}_${CFG_ARCH}.txt
+    printf "Step.....\n$step\n" > mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt
+
     exit 1
 }
