Index: LMDZ6/trunk/libf/phylmd/surf_land_bucket_mod.F90
===================================================================
--- LMDZ6/trunk/libf/phylmd/surf_land_bucket_mod.F90	(revision 3974)
+++ LMDZ6/trunk/libf/phylmd/surf_land_bucket_mod.F90	(revision 5022)
@@ -16,5 +16,11 @@
        snow, qsol, agesno, tsoil, &
        qsurf, z0_new, alb1_new, alb2_new, evap, &
-       fluxsens, fluxlat, tsurf_new, dflux_s, dflux_l)
+       fluxsens, fluxlat, tsurf_new, dflux_s, dflux_l &
+#ifdef ISO
+       ,xtprecip_rain, xtprecip_snow,xtspechum, &
+       xtsnow, xtsol,xtevap,h1, &
+       runoff_diag,xtrunoff_diag,Rland_ice &
+#endif           
+            )
 
     USE limit_read_mod
@@ -28,4 +34,14 @@
     USE mod_phys_lmdz_para
     USE indice_sol_mod
+#ifdef ISO
+    use infotrac_phy, ONLY: ntiso,niso
+    USE isotopes_mod, ONLY: iso_eau, iso_HDO, iso_O18, iso_O17, &
+        ridicule_qsol
+    USE isotopes_routines_mod, ONLY: calcul_iso_surf_ter_vectall
+#ifdef ISOVERIF
+    USE isotopes_verif_mod, ONLY: errmax,errmaxrel,iso_verif_noNaN, &
+        iso_verif_aberrant_o17,iso_verif_egalite_choix,iso_verif_egalite
+#endif
+#endif
 !****************************************************************************************
 ! Bucket calculations for surface. 
@@ -52,4 +68,8 @@
     REAL, DIMENSION(klon), INTENT(IN)       :: rugoro
     REAL, DIMENSION(klon), INTENT(IN)       :: swnet, lwnet
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(IN) :: xtprecip_rain, xtprecip_snow
+    REAL, DIMENSION(ntiso,klon), INTENT(IN) :: xtspechum    
+#endif
 
 ! In/Output variables
@@ -58,4 +78,7 @@
     REAL, DIMENSION(klon), INTENT(INOUT)          :: agesno
     REAL, DIMENSION(klon, nsoilmx), INTENT(INOUT) :: tsoil
+#ifdef ISO
+    REAL, DIMENSION(niso,klon), INTENT(INOUT)       :: xtsnow,xtsol
+#endif
 
 ! Output variables
@@ -67,4 +90,11 @@
     REAL, DIMENSION(klon), INTENT(OUT)       :: tsurf_new
     REAL, DIMENSION(klon), INTENT(OUT)       :: dflux_s, dflux_l      
+#ifdef ISO
+    REAL, DIMENSION(ntiso,klon), INTENT(OUT) :: xtevap
+    REAL, DIMENSION(klon),       INTENT(OUT) :: h1
+    REAL, DIMENSION(niso,klon),  INTENT(OUT) :: xtrunoff_diag
+    REAL, DIMENSION(klon),       INTENT(OUT) :: runoff_diag
+    REAL, DIMENSION(niso,klon),  INTENT(IN)  :: Rland_ice
+#endif
 
 ! Local variables
@@ -78,7 +108,43 @@
     REAL, DIMENSION(klon) :: dummy_riverflow,dummy_coastalflow 
     INTEGER               :: i
-!
-!****************************************************************************************
-
+#ifdef ISO
+    INTEGER               :: ixt
+    REAL, DIMENSION(niso,klon) :: xtsnow_prec,xtsol_prec
+    REAL, DIMENSION(klon) :: snow_prec,qsol_prec
+    REAL, PARAMETER       :: t_coup = 273.15
+    REAL, DIMENSION(klon) :: fq_fonte_diag
+    REAL, DIMENSION(klon) :: fqfonte_diag
+    REAL, DIMENSION(klon) :: snow_evap_diag 
+    REAL, DIMENSION(klon) :: fqcalving_diag 
+    REAL                  :: max_eau_sol_diag  
+    REAL, DIMENSION(klon) :: run_off_lic_diag 
+    REAL :: coeff_rel_diag
+#endif 
+!
+!****************************************************************************************
+
+#ifdef ISO
+#ifdef ISOVERIF
+        !write(*,*) 'surf_land_bucket 152'
+        DO i=1,knon
+          IF (iso_eau > 0) THEN
+            CALL iso_verif_egalite_choix(precip_snow(i), &
+     &                                   xtprecip_snow(iso_eau,i),'surf_land_bucket 131', &
+     &                                   errmax,errmaxrel)
+            CALL iso_verif_egalite_choix(qsol(i), &
+     &                                   xtsol(iso_eau,i),'surf_land_bucket 134', &
+     &                                   errmax,errmaxrel)
+          ENDIF
+        ENDDO
+#endif 
+#ifdef ISOVERIF
+        DO i=1,knon
+          DO ixt=1,niso
+            CALL iso_verif_noNaN(xtsol(ixt,i),'surf_land_mod_bucket 142')
+          ENDDO !do ixt=1,niso
+        ENDDO !do i=1,knon
+        !write(*,*) 'surf_land_bucket 152'
+#endif
+#endif
 
 !
@@ -131,4 +197,41 @@
          tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
     
+#ifdef ISO
+   ! verif
+#ifdef ISOVERIF
+    !write(*,*) 'surf_land_bucket 211'
+    DO i=1,knon
+      IF (iso_eau > 0) THEN
+        CALL iso_verif_egalite_choix(xtsnow(iso_eau,i), &
+     &           snow(i),'surf_land_bucket 522', &
+     &           errmax,errmaxrel) 
+      ENDIF !IF (iso_eau > 0) then
+    ENDDO !DO i=1,knon 
+#endif
+   ! end verif
+#endif         
+#ifdef ISO
+    DO i=1,knon
+      snow_prec(i)=snow(i)
+      qsol_prec(i)=qsol(i)
+      DO ixt=1,niso
+        xtsnow_prec(ixt,i)=xtsnow(ixt,i)
+        xtsol_prec(ixt,i) =xtsol(ixt,i)
+      ENDDO !DO ixt=1,niso
+      ! initialisation:
+      fqfonte_diag(i)  =0.0
+      fq_fonte_diag(i) =0.0
+      snow_evap_diag(i)=0.0
+    ENDDO !DO i=1,knon 
+#ifdef ISOVERIF
+    ! write(*,*) 'surf_land_bucket 235'
+    DO i=1,knon  
+      IF (iso_eau > 0) THEN
+        CALL iso_verif_egalite(qsol_prec(i),xtsol_prec(iso_eau,i), &
+    &                              'surf_land_bucket 141')
+      ENDIF
+    ENDDO !DO i=1,knon
+#endif    
+#endif    
 !
 !* Calculate snow height, run_off, age of snow
@@ -136,5 +239,64 @@
     CALL fonte_neige( knon, is_ter, knindex, dtime, &
          tsurf, precip_rain, precip_snow, &
-         snow, qsol, tsurf_new, evap)
+         snow, qsol, tsurf_new, evap &
+#ifdef ISO    
+     & ,fq_fonte_diag,fqfonte_diag,snow_evap_diag,fqcalving_diag   &
+     & ,max_eau_sol_diag,runoff_diag,run_off_lic_diag,coeff_rel_diag   &
+#endif
+     &   )
+
+#ifdef ISO
+#ifdef ISOVERIF
+        DO i=1,knon
+          DO ixt=1,niso
+            CALL iso_verif_noNaN(xtsol_prec(ixt,i),'surf_land_burcket 237')
+          ENDDO
+        ENDDO
+#endif
+#ifdef ISOVERIF
+        !write(*,*) 'surf_land_bucket 235'
+        DO i=1,knon
+          IF (iso_eau > 0) THEN
+            CALL iso_verif_egalite_choix(qsol_prec(i), &
+     &                                   xtsol_prec(iso_eau,i),'surf_land_bucket 628', &
+     &                                   errmax,errmaxrel)
+            CALL iso_verif_egalite_choix(precip_snow(i), &
+     &                                   xtprecip_snow(iso_eau,i),'surf_land_bucket 227', &
+     &                                   errmax,errmaxrel)
+             ! attention, dans fonte_neige, on modifie snow sans modifier
+             ! xtsnow
+             ! c'est fait plus tard dans gestion_neige
+!            write(*,*) 'surf_land_bucket 287: i=',i
+!            write(*,*) 'snow(i)=',snow(i)
+            CALL iso_verif_egalite_choix(xtsnow(iso_eau,i), &
+     &                                   snow_prec(i),'surf_land_bucket 245', &
+     &                                   errmax,errmaxrel) 
+          ENDIF  
+          IF ((iso_O17 > 0).AND.(iso_O18 > 0)) THEN
+              IF (qsol_prec(i) > ridicule_qsol) THEN
+                CALL iso_verif_aberrant_o17(xtsol_prec(iso_O17,i)/qsol_prec(i) &
+     &                                     ,xtsol_prec(iso_O18,i)/qsol_prec(i) &
+     &                                     ,'surf_land_bucket 642')
+              ENDIF !IF ((qsol_prec(i) > ridicule_qsol) &
+          ENDIF !IF ((iso_O17 > 0).AND.(iso_O18 > 0)) THEN
+        ENDDO  !DO i=1,knon 
+        !write(*,*) 'surf_land_mod 291'
+        !write(*,*) 'snow_evap_diag(1)=',snow_evap_diag(1)
+#endif          
+        CALL calcul_iso_surf_ter_vectall(klon,knon, &
+     &           evap,snow_evap_diag,snow, &
+     &           fq_fonte_diag,fqfonte_diag,dtime,precip_rain,xtprecip_rain, &
+     &           precip_snow,xtprecip_snow, snow_prec,xtsnow_prec, &
+     &           tsurf_new,xtspechum,pref,spechum,t_coup,u1_lay,v1_lay,p1lay, &
+     &           qsol,xtsol,qsol_prec,xtsol_prec, &
+     &           max_eau_sol_diag, &
+     &           xtevap,xtsnow,h1,runoff_diag,xtrunoff_diag,fqcalving_diag, &
+     &           knindex,is_ter,run_off_lic_diag,coeff_rel_diag,Rland_ice &
+     &   )
+!#ifdef ISOVERIF
+!        write(*,*) 'surf_land_bucket 303'
+!#endif
+#endif
+
 !
 !* Calculate the age of snow
