Index: /LMDZ6/trunk/DefLists/field_def_lmdz.xml
===================================================================
--- /LMDZ6/trunk/DefLists/field_def_lmdz.xml	(revision 4886)
+++ /LMDZ6/trunk/DefLists/field_def_lmdz.xml	(revision 4887)
@@ -311,4 +311,5 @@
 	<field id="prsw"   long_name="Precipitable solid water"  unit="kg/m2" />
 	<field id="prbsw"   long_name="Precipitable blowing snow"  unit="kg/m2" />
+	<field id="water_budget"   long_name="Residual non-conservation water budget from physics"  unit="kg/m2" />
         <field id="s_pblh"    long_name="Boundary Layer Height"    unit="m" />
         <field id="s_pblt"    long_name="t at Boundary Layer Height"    unit="K" />
Index: /LMDZ6/trunk/DefLists/field_def_lmdz_cospv2.xml
===================================================================
--- /LMDZ6/trunk/DefLists/field_def_lmdz_cospv2.xml	(revision 4886)
+++ /LMDZ6/trunk/DefLists/field_def_lmdz_cospv2.xml	(revision 4887)
@@ -265,4 +265,5 @@
         <field id="prlw"   long_name="Precipitable liquid water"  unit="kg/m2" />
         <field id="prsw"   long_name="Precipitable solid water"  unit="kg/m2" />
+	<field id="water_budget"   long_name="Residual non-conservation water budget from physics"  unit="kg/m2" />
         <field id="s_pblh"    long_name="Boundary Layer Height"    unit="m" />
         <field id="s_pblt"    long_name="t at Boundary Layer Height"    unit="K" />
Index: /LMDZ6/trunk/DefLists/file_def_histmth_lmdz.xml
===================================================================
--- /LMDZ6/trunk/DefLists/file_def_histmth_lmdz.xml	(revision 4886)
+++ /LMDZ6/trunk/DefLists/file_def_histmth_lmdz.xml	(revision 4887)
@@ -254,4 +254,5 @@
                 <field field_ref="prlw" level="1" />
                 <field field_ref="prsw" level="1" />
+                <field field_ref="water_budget" level="1" />
                 <field field_ref="s_pblh" level="1" />
                 <field field_ref="s_pblt" level="1" />
Index: /LMDZ6/trunk/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 4886)
+++ /LMDZ6/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 4887)
@@ -319,6 +319,6 @@
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: JrNt
 !$OMP THREADPRIVATE(JrNt)
-      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: dthmin, evap, snowerosion, fder, plcl, plfc, prw, prlw, prsw, prbsw
-!$OMP THREADPRIVATE(dthmin, evap, snowerosion, fder, plcl, plfc, prw, prlw, prsw, prbsw)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: dthmin, evap, snowerosion, fder, plcl, plfc, prw, prlw, prsw, prbsw, water_budget
+!$OMP THREADPRIVATE(dthmin, evap, snowerosion, fder, plcl, plfc, prw, prlw, prsw, prbsw, water_budget)
       REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: zustar, zu10m, zv10m, rh2m
 !$OMP THREADPRIVATE(zustar, zu10m, zv10m, rh2m)
@@ -829,5 +829,5 @@
       ALLOCATE(JrNt(klon))
       ALLOCATE(dthmin(klon), evap(klon), snowerosion(klon), fder(klon), plcl(klon), plfc(klon))
-      ALLOCATE(prw(klon), prlw(klon), prsw(klon), prbsw(klon), zustar(klon), zu10m(klon), zv10m(klon), rh2m(klon))
+      ALLOCATE(prw(klon), prlw(klon), prsw(klon), prbsw(klon), water_budget(klon), zustar(klon), zu10m(klon), zv10m(klon), rh2m(klon))
       ALLOCATE(s_lcl(klon))
       ALLOCATE(s_pblh(klon), s_pblt(klon), s_therm(klon))
@@ -1163,5 +1163,5 @@
       DEALLOCATE(JrNt)
       DEALLOCATE(dthmin, evap, snowerosion, fder, plcl, plfc)
-      DEALLOCATE(prw, prlw, prsw, prbsw, zustar, zu10m, zv10m, rh2m, s_lcl)
+      DEALLOCATE(prw, prlw, prsw, prbsw, water_budget, zustar, zu10m, zv10m, rh2m, s_lcl)
       DEALLOCATE(s_pblh, s_pblt, s_therm)
 !
Index: /LMDZ6/trunk/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4886)
+++ /LMDZ6/trunk/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 4887)
@@ -833,4 +833,6 @@
   TYPE(ctrl_out), SAVE :: o_prbsw = ctrl_out((/ 10, 10, 10, 10, 10, 10, 11, 11, 11, 11/), &
     'prbsw', 'Precipitable blowing snow', 'kg/m2', (/ ('', i=1, 10) /))
+  TYPE(ctrl_out), SAVE :: o_water_budget = ctrl_out((/ 1, 1, 10, 10, 10, 10, 11, 11, 11, 11/), &
+    'water_budget', 'Water budget', 'kg/m2', (/ ('', i=1, 10) /))
   TYPE(ctrl_out), SAVE :: o_s_pblh = ctrl_out((/ 1, 10, 10, 10, 10, 10, 11, 11, 11, 11/), &
     's_pblh', 'Boundary Layer Height', 'm', (/ ('', i=1, 10) /))
Index: /LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 4886)
+++ /LMDZ6/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 4887)
@@ -83,5 +83,5 @@
          o_Mipsh, o_Ma, &
          o_dnwd, o_dnwd0, o_ftime_deepcv, o_ftime_con, o_mc, &
-         o_prw, o_prlw, o_prsw, o_prbsw, o_s_pblh, o_s_pblt, o_s_lcl, &
+         o_prw, o_prlw, o_prsw, o_prbsw, o_water_budget, o_s_pblh, o_s_pblt, o_s_lcl, &
          o_s_therm, o_uSTDlevs, o_vSTDlevs, &
          o_wSTDlevs, o_zSTDlevs, o_qSTDlevs, &
@@ -324,5 +324,5 @@
          uwat, vwat, &
          rneb_seri, d_rneb_dyn, &
-         plcl, plfc, wbeff, convoccur, upwd, dnwd, dnwd0, prw, prlw, prsw,prbsw, &
+         plcl, plfc, wbeff, convoccur, upwd, dnwd, dnwd0, prw, prlw, prsw, prbsw, water_budget, &
          s_pblh, s_pblt, s_lcl, s_therm, uwriteSTD, &
          vwriteSTD, wwriteSTD, phiwriteSTD, qwriteSTD, &
@@ -1400,4 +1400,5 @@
        CALL histwrite_phy(o_prbsw, prbsw)
        ENDIF
+       CALL histwrite_phy(o_water_budget, water_budget)
        CALL histwrite_phy(o_s_pblh, s_pblh)
        CALL histwrite_phy(o_s_pblt, s_pblt)
Index: /LMDZ6/trunk/libf/phylmd/physiq_mod.F90
===================================================================
--- /LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4886)
+++ /LMDZ6/trunk/libf/phylmd/physiq_mod.F90	(revision 4887)
@@ -259,5 +259,5 @@
        JrNt,                             &
        dthmin, evap, snowerosion,fder, plcl, plfc,   &
-       prw, prlw, prsw, prbsw,                  &
+       prw, prlw, prsw, prbsw, water_budget,         &
        s_lcl, s_pblh, s_pblt, s_therm,   &
        cdragm, cdragh,                   &
@@ -2464,5 +2464,11 @@
     qql1(:)=0.0
     DO k = 1, klev
-      qql1(:)=qql1(:)+(q_seri(:,k)+ql_seri(:,k)+qs_seri(:,k)+qbs_seri(:,k))*zmasse(:,k)
+      qql1(:)=qql1(:)+(q_seri(:,k)+ql_seri(:,k))*zmasse(:,k)
+      IF (nqo >= 3) THEN
+        qql1(:)=qql1(:)+qs_seri(:,k)*zmasse(:,k)
+      ENDIF
+      IF (ok_bs) THEN
+        qql1(:)=qql1(:)+qbs_seri(:,k)*zmasse(:,k)
+      ENDIF
     ENDDO
     ENDIF
@@ -5465,34 +5471,100 @@
     t_seri(:,:)=t_seri(:,:)+d_t_ec(:,:)
 
-    !=======================================================================
-    !   SORTIES
-    !=======================================================================
-    !
-    !IM initialisation + calculs divers diag AMIP2
-    !
-    include "calcul_divers.h"
-    !
-    !IM Interpolation sur les niveaux de pression du NMC
-    !   -------------------------------------------------
-    !
-    include "calcul_STDlev.h"
-    !
-    ! slp sea level pressure derived from Arpege-IFS : CALL ctstar + CALL pppmer
-    CALL diag_slp(klon,t_seri,paprs,pplay,pphis,ptstar,pt0,slp)
-    !
+    !==================================================================
+    !--OB water mass fixer for the physics
+    !--water profiles are corrected to force mass conservation of water
+    !--currently flag is turned off
+    !==================================================================
+    IF (mass_fixer) THEN
+    qql2(:)=0.0
+    DO k = 1, klev
+      qql2(:)=qql2(:)+(q_seri(:,k)+ql_seri(:,k))*zmasse(:,k)
+      IF (nqo >= 3) THEN
+        qql2(:)=qql2(:)+qs_seri(:,k)*zmasse(:,k)
+      ENDIF
+      IF (ok_bs) THEN
+        qql2(:)=qql2(:)+qbs_seri(:,k)*zmasse(:,k)
+      ENDIF
+    ENDDO
+
+#ifdef CPP_StratAer
+    IF (ok_qemiss) THEN
+       DO k = 1, klev
+          qql1(:) = qql1(:)+d_q_emiss(:,k)*zmasse(:,k)
+       ENDDO
+    ENDIF
+#endif
+    IF (ok_qch4) THEN
+       DO k = 1, klev
+          qql1(:) = qql1(:)+d_q_ch4_dtime(:,k)*zmasse(:,k)
+       ENDDO
+    ENDIF
+    
+    DO i = 1, klon
+      !--compute ratio of what q+ql should be with conservation to what it is
+      IF (ok_bs) THEN
+        corrqql=(qql1(i)+(evap(i)-rain_fall(i)-snow_fall(i)-bs_fall(i))*pdtphys)/qql2(i)
+      ELSE
+        corrqql=(qql1(i)+(evap(i)-rain_fall(i)-snow_fall(i))*pdtphys)/qql2(i)
+      ENDIF
+      DO k = 1, klev
+        q_seri(i,k) =q_seri(i,k)*corrqql
+        ql_seri(i,k)=ql_seri(i,k)*corrqql
+        IF (nqo >= 3) THEN
+          qs_seri(i,k)=qs_seri(i,k)*corrqql
+        ENDIF
+        IF (ok_bs) THEN
+          qbs_seri(i,k)=qbs_seri(i,k)*corrqql
+        ENDIF
+      ENDDO
+    ENDDO
+    ENDIF
+    !--fin mass fixer
+
     !cc prw  = eau precipitable
     !   prlw = colonne eau liquide 
     !   prlw = colonne eau solide
     !   prbsw = colonne neige soufflee
+    !   water_budget = non-conservation residual from the LMDZ physics
+    !                  (should be equal to machine precision if mass fixer is activated)
     prw(:) = 0.
     prlw(:) = 0.
     prsw(:) = 0.
     prbsw(:) = 0.
+    water_budget(:) = 0.0
     DO k = 1, klev
        prw(:)  = prw(:)  + q_seri(:,k)*zmasse(:,k)
        prlw(:) = prlw(:) + ql_seri(:,k)*zmasse(:,k)
-       prsw(:) = prsw(:) + qs_seri(:,k)*zmasse(:,k)
-       prbsw(:)= prbsw(:) + qbs_seri(:,k)*zmasse(:,k)
+       water_budget(:) = water_budget(:) + (q_seri(:,k)-qx(:,k,ivap)+ql_seri(:,k)-qx(:,k,iliq))*zmasse(:,k)
+       IF (nqo >= 3) THEN
+         prsw(:) = prsw(:) + qs_seri(:,k)*zmasse(:,k)
+         water_budget(:) = water_budget(:) + (qs_seri(:,k)-qx(:,k,isol))*zmasse(:,k)
+       ENDIF
+       IF (nqo >= 4 .AND. ok_bs) THEN
+         prbsw(:)= prbsw(:) + qbs_seri(:,k)*zmasse(:,k)
+         water_budget(:) = water_budget(:) + (qbs_seri(:,k)-qx(:,k,ibs))*zmasse(:,k)
+       ENDIF
     ENDDO
+    water_budget(:)=water_budget(:)+(rain_fall(:)+snow_fall(:)-evap(:))*pdtphys
+    IF (ok_bs) THEN
+      water_budget(:)=water_budget(:)+bs_fall(:)*pdtphys
+    ENDIF
+
+    !=======================================================================
+    !   SORTIES
+    !=======================================================================
+    !
+    !IM initialisation + calculs divers diag AMIP2
+    !
+    include "calcul_divers.h"
+    !
+    !IM Interpolation sur les niveaux de pression du NMC
+    !   -------------------------------------------------
+    !
+    include "calcul_STDlev.h"
+    !
+    ! slp sea level pressure derived from Arpege-IFS : CALL ctstar + CALL pppmer
+    CALL diag_slp(klon,t_seri,paprs,pplay,pphis,ptstar,pt0,slp)
+    !
     !
     IF (ANY(type_trac == ['inca','inco'])) THEN
@@ -5579,39 +5651,4 @@
     !IM global posePB      include "write_bilKP_ave.h"
     !
-
-    !--OB mass fixer 
-    !--profile is corrected to force mass conservation of water
-    IF (mass_fixer) THEN
-    qql2(:)=0.0
-    DO k = 1, klev
-      qql2(:)=qql2(:)+(q_seri(:,k)+ql_seri(:,k)+qs_seri(:,k)+qbs_seri(:,k))*zmasse(:,k)
-    ENDDO
-
-#ifdef CPP_StratAer
-    IF (ok_qemiss) THEN
-       DO k = 1, klev
-          qql1(:) = qql1(:)+d_q_emiss(:,k)*zmasse(:,k)
-       ENDDO
-    ENDIF
-#endif
-    IF (ok_qch4) THEN
-       DO k = 1, klev
-          qql1(:) = qql1(:)+d_q_ch4_dtime(:,k)*zmasse(:,k)
-       ENDDO
-    ENDIF
-    
-    DO i = 1, klon
-      !--compute ratio of what q+ql should be with conservation to what it is
-      corrqql=(qql1(i)+(evap(i)-rain_fall(i)-snow_fall(i))*pdtphys)/qql2(i)
-      DO k = 1, klev
-        q_seri(i,k) =q_seri(i,k)*corrqql
-        ql_seri(i,k)=ql_seri(i,k)*corrqql
-        qs_seri(i,k)=qs_seri(i,k)*corrqql
-        qbs_seri(i,k)=qbs_seri(i,k)*corrqql
-      ENDDO
-    ENDDO
-    ENDIF
-    !--fin mass fixer
-
     ! Sauvegarder les valeurs de t et q a la fin de la physique:
     !
