Index: branches/LMDZ_WRFmeas_develop/README
===================================================================
--- branches/LMDZ_WRFmeas_develop/README	(revision 148)
+++ branches/LMDZ_WRFmeas_develop/README	(revision 149)
@@ -1,3 +1,3 @@
-**** Coupling WRF and LMDZ with the WRFmeas modifications
+**** Coupling WRF and LMDZ with the WRFmeas modifications and checking outputs
 * L.Fita, Laboratoire de Meteorologie Dynamique, CNRS, UPMC-Jussieu, Paris, FRANCE
 * July 2014
@@ -11,5 +11,5 @@
 
 1.- Extraction of the source code:
-  $ svn co http://svn.lmd.jussieu.fr/LMDZ_WRF/branches/LMDZ_WRFmeas LMDZ_WRFmeas
+  $ svn co http://svn.lmd.jussieu.fr/LMDZ_WRF/branches/LMDZ_WRFmeas_develop LMDZ_WRFmeas_develop
 
 2.- Copy (not int the repository folder...) folder 'WRFV3' to the desired spatial resolution (F77 legacy). As example one for 80x90x39
Index: branches/LMDZ_WRFmeas_develop/WRFV3/lmdz/physiq.F90
===================================================================
--- branches/LMDZ_WRFmeas_develop/WRFV3/lmdz/physiq.F90	(revision 148)
+++ branches/LMDZ_WRFmeas_develop/WRFV3/lmdz/physiq.F90	(revision 149)
@@ -1303,4 +1303,13 @@
       llp = 644
 
+! L. Fita, LMD August 2014
+      CHARACTER(LEN=50)                                  :: errmsg, fname, varname
+      LOGICAL                                            :: found
+      REAL                                               :: largest
+
+      fname = 'diagphy'
+      errmsg = 'ERROR -- error -- ERROR -- error'
+      largest = 10.e4
+
 !c======================================================================
 ! Gestion calendrier : mise a jour du module phys_cal_mod
@@ -3813,4 +3822,8 @@
       END IF 
       PRINT *,'  Lluis 10 d_h_vcol: ',d_h_vcol,' d_h_vcol_phy: ',d_h_vcol_phy
+      fname = '10 d_h_vcol'
+      varname = 't_seri'
+      CALL check_var3D(fname, varname, t_seri, klon, klev, largest, .FALSE.)
+
 !c
 !c
@@ -3925,4 +3938,7 @@
 !c Accumuler les variables a stocker dans les fichiers histoire:
 !c
+      fname = 'after phytrac'
+      varname = 't_seri'
+      CALL check_var3D(fname, varname, t_seri, klon, klev, largest, .FALSE.)
 
 !================================================================
@@ -3937,4 +3953,10 @@
        &        zmasse,exner,d_t_ec)
       t_seri(:,:)=t_seri(:,:)+d_t_ec(:,:)
+
+      fname = 'after ener_conserv'
+      varname = 't_seri'
+      CALL check_var3D(fname, varname, t_seri, klon, klev, largest, .FALSE.)
+      varname = 'd_t_ec'
+      CALL check_var3D(fname, varname, d_t_ec, klon, klev, largest, .FALSE.)
 
 !IM
@@ -4349,2 +4371,129 @@
       RETURN
       END SUBROUTINE gr_fi_ecrit
+
+SUBROUTINE check_var(funcn, varn, var, sizev, bigvalue, stoprun)
+!  Subroutine to check the consistency of a variable
+!    * NaN value: by definition is variable /= variable
+!    * bigvalue: threshold for the variable
+
+  IMPLICIT NONE
+
+#include "dimensions.h"
+
+  INTEGER, INTENT(IN)                                    :: sizev
+  CHARACTER(LEN=50), INTENT(IN)                          :: funcn, varn
+  REAL, DIMENSION(sizev), INTENT(IN)                     :: var
+  REAL, INTENT(IN)                                       :: bigvalue
+  LOGICAL, INTENT(IN)                                    :: stoprun
+
+! Local
+  INTEGER                                                :: i, wrongi, xpt, ypt
+  CHARACTER(LEN=50)                                      :: errmsg
+  LOGICAL                                                :: found
+  REAL, DIMENSION(sizev)                                 :: wrongvalues
+  INTEGER, DIMENSION(sizev)                              :: wronggridpt
+
+!!!!!!! Variables
+! funcn: at which functino of part of the program variable is checked
+! varn: name of the variable
+! var: variable to check
+! sizev: size of the variable
+! bigvalue: biggest attenaible value for the variable
+! stoprun: Should the run stop if it founds a problem?
+
+  errmsg = 'ERROR -- error -- ERROR -- error'
+
+  found = .FALSE.
+  wrongi = 0
+  DO i=1,sizev
+    IF (var(i) /= var(i) .OR. ABS(var(i)) > bigvalue ) THEN
+      IF (wrongi == 0) found = .TRUE.
+      wrongi = wrongi + 1
+      wrongvalues(wrongi) = var(i)
+      wronggridpt(wrongi) = i
+    END IF
+  END DO
+
+  IF (found) THEN
+    PRINT *,TRIM(errmsg)
+    PRINT *,"  at '" // TRIM(funcn) // "' variable '" //TRIM(varn)//                 &
+      "' is wrong in Nvalues= ",wrongi,' at i (x, y) value___'
+    DO i=1,wrongi
+       ypt = INT(wronggridpt(i)/wiim) + 1
+       xpt = wronggridpt(i) - (ypt-1)*wiim
+      PRINT *,wronggridpt(i), '(',xpt,', ',ypt,')', wrongvalues(i)
+    END DO
+    IF (stoprun) THEN
+      STOP
+    END IF
+  END IF
+
+  RETURN
+
+END SUBROUTINE check_var
+
+SUBROUTINE check_var3D(funcn, varn, var, sizev, zsize, bigvalue, stoprun)
+!  Subroutine to check the consistency of a 3D LMDSZ - variable (klon, klev) !
+!    * NaN value: by definition is variable /= variable
+!    * bigvalue: threshold for the variable
+
+  IMPLICIT NONE
+
+#include "dimensions.h"
+
+  INTEGER, INTENT(IN)                                    :: sizev, zsize
+  CHARACTER(LEN=50), INTENT(IN)                          :: funcn, varn
+  REAL, DIMENSION(sizev,zsize), INTENT(IN)               :: var
+  REAL, INTENT(IN)                                       :: bigvalue
+  LOGICAL, INTENT(IN)                                    :: stoprun
+
+! Local
+  INTEGER                                                :: i, k, wrongi, xpt, ypt
+  CHARACTER(LEN=50)                                      :: errmsg
+  LOGICAL                                                :: found
+  REAL, DIMENSION(sizev*zsize)                           :: wrongvalues
+  INTEGER, DIMENSION(sizev*zsize,2)                      :: wronggridpt
+
+!!!!!!! Variables
+! funcn: at which functino of part of the program variable is checked
+! varn: name of the variable
+! var: variable to check
+! sizev: size of the variable
+! zsize: vertical size of the variable
+! bigvalue: biggest attenaible value for the variable
+! stoprun: Should the run stop if it founds a problem?
+
+  errmsg = 'ERROR -- error -- ERROR -- error'
+
+  found = .FALSE.
+  wrongi = 0
+  DO i=1,sizev
+    DO k=1,zsize
+      IF (var(i,k) /= var(i,k) .OR. ABS(var(i,k)) > bigvalue ) THEN
+        IF (wrongi == 0) found = .TRUE.
+        wrongi = wrongi + 1
+        wrongvalues(wrongi) = var(i,k)
+        wronggridpt(wrongi,1) = i
+        wronggridpt(wrongi,2) = k
+      END IF
+    END DO
+  END DO
+
+  IF (found) THEN
+    PRINT *,TRIM(errmsg)
+    PRINT *,"  at '" // TRIM(funcn) // "' variable '" //TRIM(varn)//                 &
+      "' is wrong in Nvalues= ",wrongi,' at i (x,y) k value___'
+    DO i=1,wrongi
+       ypt = INT(wronggridpt(i,1)/wiim) + 1
+       xpt = wronggridpt(i,1) - (ypt-1)*wiim
+      PRINT *,wronggridpt(i,1), '(',xpt,', ',ypt,')', wronggridpt(i,2), wrongvalues(i)
+    END DO
+    IF (stoprun) THEN
+      STOP
+    END IF
+  END IF
+
+  RETURN
+
+END SUBROUTINE check_var3D
+
