Index: branches/LMDZ_WRFmeas/WRFV3/lmdz/calltherm.F90
===================================================================
--- branches/LMDZ_WRFmeas/WRFV3/lmdz/calltherm.F90	(revision 69)
+++ branches/LMDZ_WRFmeas/WRFV3/lmdz/calltherm.F90	(revision 70)
@@ -121,4 +121,13 @@
 !$OMP THREADPRIVATE(first)
 !********************************************************
+
+! Lluis
+      INTEGER                                            :: llp
+      CHARACTER(LEN=50)                                  :: lvarname, lfname
+      REAL                                               :: largest
+
+      llp = 734
+      lfname = 'physiq'
+      largest = 10.e5
       if (first) then
         itap=0
@@ -133,4 +142,7 @@
 !         print*,'thermiques: WARNING on passe t au lieu de t_seri'
 
+      lfname='beginning calltherm'
+      lvarname = 't_seri'
+      CALL check_var3D(lfname, lvarname, t_seri, klon, klev, largest, .FALSE.)
 
 ! On prend comme valeur initiale des thermiques la valeur du pas
@@ -237,4 +249,5 @@
 
 !            print*,'THERM iflag_thermas_ed=',iflag_thermals_ed
+
             CALL thermcell_main(itap,klon,klev,zdt  &
      &      ,pplay,paprs,pphi,debut  &
@@ -270,4 +283,9 @@
 ! Ce serait bien de changer, mai en prenant le temps de vÃ©rifier que ca
 ! fait bien ce qu'on croit.
+      lfname='after thermcell_main'
+      lvarname = 't_seri'
+      CALL check_var3D(lfname, lvarname, t_seri, klon, klev, largest, .FALSE.)
+      lvarname = 'd_t_the'
+      CALL check_var3D(lfname, lvarname, d_t_the, klon, klev, largest, .FALSE.)
 
        flag_bidouille_stratocu=iflag_thermals<=12.or.iflag_thermals==14.or.iflag_thermals==16.or.iflag_thermals==18
@@ -301,4 +319,9 @@
        fm_therm(:,klev+1)=0.
 
+      lfname='after transforming from derivate to tendency'
+      lvarname = 't_seri'
+      CALL check_var3D(lfname, lvarname, t_seri, klon, klev, largest, .FALSE.)
+      lvarname = 'd_t_the'
+      CALL check_var3D(lfname, lvarname, d_t_the, klon, klev, largest, .FALSE.)
 
 
@@ -316,4 +339,9 @@
             q_seri(:,:) = q_seri(:,:) + d_q_the(:,:)
            if (prt_level.gt.10) write(lunout,*)'Apres apres thermcell_main OK'
+      lfname='after thermcell_main add tendencies'
+      lvarname = 't_seri'
+      CALL check_var3D(lfname, lvarname, t_seri, klon, klev, largest, .FALSE.)
+      lvarname = 'd_t_the'
+      CALL check_var3D(lfname, lvarname, d_t_the, klon, klev, largest, .FALSE.)
 
        DO i=1,klon
@@ -436,2 +464,129 @@
 
       end
+
+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
+
