Index: /trunk/LMDZ.MARS/README
===================================================================
--- /trunk/LMDZ.MARS/README	(revision 172)
+++ /trunk/LMDZ.MARS/README	(revision 173)
@@ -754,2 +754,7 @@
 - minor correction to callradite.F (to enable compilation in debug mode
   with ifort when there is only one tracer).
+
+== 17/06/2011 == AC
+- Added maximum vertical velocity and heat flux output from thermals
+- Added buoyancy diagnostics
+- Minor modifications in thermals routines 
Index: /trunk/LMDZ.MARS/libf/phymars/calltherm_interface.F90
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/calltherm_interface.F90	(revision 172)
+++ /trunk/LMDZ.MARS/libf/phymars/calltherm_interface.F90	(revision 173)
@@ -6,5 +6,5 @@
      & ptimestep,pu,pv,pt,pq,pdu,pdv,pdt,pdq,q2, &
      & pplay,pplev,pphi,nq,zpopsk, &
-     & pdu_th,pdv_th,pdt_th,pdq_th,lmax_th,pbl_dtke)
+     & pdu_th,pdv_th,pdt_th,pdq_th,lmax_th,pbl_dtke,hfmax,wmax)
 
        USE ioipsl_getincom
@@ -67,4 +67,5 @@
       REAL buoyancyOut(ngrid,nlayer)
       REAL buoyancyEst(ngrid,nlayer)
+      REAL hfmax(ngrid),wmax(ngrid)
 
 !---------------------------------------------------------
@@ -137,5 +138,5 @@
      &      ,zw2,fraca &
      &      ,zpopsk,ztla,heatFlux,heatFlux_down &
-     &      ,buoyancyOut,buoyancyEst)
+     &      ,buoyancyOut,buoyancyEst,hfmax,wmax)
 
 
@@ -185,8 +186,4 @@
         call WRITEDIAGFI(ngrid,'d_t_th',  &
      &         'tendance temp TH','K',1,d_t_ajs)
-        call WRITEDIAGFI(ngrid,'d_q_ajs',  &
-     &         'tendance q updraft','kg/kg',1,d_q_ajs(:,:,nq))
-        call WRITEDIAGFI(ngrid,'d_q_tke',  &
-     &         'tendance q updraft','q2/q2',1,pbl_dtke*ptimestep)
       else
 
Index: /trunk/LMDZ.MARS/libf/phymars/calltherm_mars.F90
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/calltherm_mars.F90	(revision 172)
+++ /trunk/LMDZ.MARS/libf/phymars/calltherm_mars.F90	(revision 173)
@@ -8,5 +8,5 @@
      &      ,fm_therm,entr_therm,detr_therm,lmax,&
      &   zw2,fraca,zpopsk,ztla,heatFlux,heatFlux_down,&
-     &     buoyancyOut,buoyancyEst)
+     &     buoyancyOut,buoyancyEst,hfmax,wmax)
 
        USE thermcell, only : nsplit_thermals,r_aspect_thermals
@@ -43,16 +43,8 @@
 !********************************************************
 !     declarations
-      LOGICAL flag_bidouille_stratocu
-      real fmc_therm(ngrid,nlayer+1)
-      real zqla(ngrid,nlayer)
-      real zqta(ngrid,nlayer)
       real zpopsk(ngrid,nlayer)
       real ztla(ngrid,nlayer)
-      real wmax_sec(ngrid)
-      real zmax_sec(ngrid)
-      real f_sec(ngrid)
-      real detrc_therm(ngrid,nlayer)
-      real zw_sec(ngrid,nlayer+1)
-      integer lmix_sec(ngrid)
+      real wmax(ngrid)
+      real hfmax(ngrid)
       integer lmax(ngrid)
 
@@ -160,9 +152,9 @@
      &       +zheatFlux(:,:)*fact
             heatFlux_down(:,:)=heatFlux_down(:,:) &
-             +zheatFlux_down(:,:)*fact
+     &       +zheatFlux_down(:,:)*fact
             buoyancyOut(:,:)=buoyancyOut(:,:) &
      &       +zbuoyancyOut(:,:)*fact
             buoyancyEst(:,:)=buoyancyEst(:,:) &
-                 &       +zbuoyancyEst(:,:)*fact
+     &       +zbuoyancyEst(:,:)*fact
 
             zw2(:,:)=zw2(:,:) + zzw2(:,:)*fact
@@ -194,5 +186,10 @@
 !             enddo
 !          enddo
-
+        
+          DO i=1,ngrid
+            hfmax(i)=MAXVAL(heatFlux(i,:)+heatFlux_down(i,:))
+            wmax(i)=MAXVAL(zw2(i,:))
+          ENDDO
+ 
       return
 
Index: /trunk/LMDZ.MARS/libf/phymars/meso_physiq.F
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/meso_physiq.F	(revision 172)
+++ /trunk/LMDZ.MARS/libf/phymars/meso_physiq.F	(revision 173)
@@ -366,5 +366,5 @@
       INTEGER lmax_th(ngrid)
       REAL dtke_th(ngrid,nlayer+1)
-      REAL dummycol(ngrid)
+      REAL wmax_th(ngrid),hfmax_th(ngrid)
 c=======================================================================
 #ifdef MESOSCALE
@@ -1013,5 +1013,5 @@
      $ ptimestep,pu,pv,pt,pq,pdu,pdv,pdt,pdq,q2,
      $ pplay,pplev,pphi,nq,zpopsk,
-     $ pdu_th,pdv_th,pdt_th,pdq_th,lmax_th,dtke_th)
+     $ pdu_th,pdv_th,pdt_th,pdq_th,lmax_th,dtke_th,hfmax_th,wmax_th)
  
          DO l=1,nlayer
Index: /trunk/LMDZ.MARS/libf/phymars/physiq.F
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/physiq.F	(revision 172)
+++ /trunk/LMDZ.MARS/libf/phymars/physiq.F	(revision 173)
@@ -303,4 +303,5 @@
 
       REAL lmax_th_out(ngrid)
+      REAL wmax_th(ngrid),hfmax_th(ngrid)
       REAL pdu_th(ngrid,nlayer),pdv_th(ngrid,nlayer)
       REAL pdt_th(ngrid,nlayer),pdq_th(ngrid,nlayer,nq)
@@ -308,4 +309,6 @@
       REAL dtke_th(ngrid,nlayer+1)
       REAL dummycol(ngrid)
+      REAL hfx(ngrid)
+
 c=======================================================================
 
@@ -631,4 +634,5 @@
      &        zdqdif,zdqsdif)
 
+          hfx(:) = zflubid(:)-capcal(:)*zdtsdif(:)
 
          DO l=1,nlayer
@@ -680,5 +684,5 @@
      $ ptimestep,pu,pv,pt,pq,pdu,pdv,pdt,pdq,q2,
      $ pplay,pplev,pphi,nq,zpopsk,
-     $ pdu_th,pdv_th,pdt_th,pdq_th,lmax_th,dtke_th)
+     $ pdu_th,pdv_th,pdt_th,pdq_th,lmax_th,dtke_th,hfmax_th,wmax_th)
  
          DO l=1,nlayer
@@ -1457,5 +1461,5 @@
 c        Outputs of thermals
 c        ----------------------------------------------------------
-
+         if (calltherm) then
 
 !        call WRITEDIAGFI(ngrid,'dtke',
@@ -1476,4 +1480,21 @@
 !        endif
 
+        lmax_th_out(:)=real(lmax_th(:))
+
+        call WRITEDIAGFI(ngridmx,'hfx',
+     &              'sensible heat flux','W.m-2',
+     &                         2,hfx)
+
+        call WRITEDIAGFI(ngridmx,'lmax_th',
+     &              'hauteur du thermique','K',
+     &                         2,lmax_th_out)
+        call WRITEDIAGFI(ngridmx,'hfmax_th',
+     &              'maximum TH heat flux','K.m/s',
+     &                         2,hfmax_th)
+        call WRITEDIAGFI(ngridmx,'wmax_th',
+     &              'maximum TH vertical velocity','m/s',
+     &                         2,wmax_th)
+
+         endif
 
 c        ----------------------------------------------------------
@@ -1512,19 +1533,22 @@
 
 ! THERMALS STUFF 1D
+
+        call WRITEDIAGFI(ngridmx,'hfx',
+     &              'sensible heat flux','W.m-2',
+     &                         0,hfx)
          if(calltherm) then
 
         lmax_th_out(:)=real(lmax_th(:))
 
-      if (ngridmx .eq. 1) then
         call WRITEDIAGFI(ngridmx,'lmax_th',
-     &              'hauteur du thermique','K',
+     &              'hauteur du thermique','point',
      &                         0,lmax_th_out)
-
-       else
-        call WRITEDIAGFI(ngridmx,'lmax_th',
-     &              'hauteur du thermique','K',
-     &                         2,lmax_th_out)
-
-       endif
+        call WRITEDIAGFI(ngridmx,'hfmax_th',
+     &              'maximum TH heat flux','K.m/s',
+     &                         0,hfmax_th)
+        call WRITEDIAGFI(ngridmx,'wmax_th',
+     &              'maximum TH vertical velocity','m/s',
+     &                         0,wmax_th)
+
 
          co2col(:)=0.
Index: /trunk/LMDZ.MARS/libf/phymars/thermcell_main_mars.F90
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/thermcell_main_mars.F90	(revision 172)
+++ /trunk/LMDZ.MARS/libf/phymars/thermcell_main_mars.F90	(revision 173)
@@ -303,5 +303,5 @@
       ztva_est(:,:)=ztva(:,:)
       ztla(:,:)=0.
-
+      zdz=0.
       zbuoy(:,:)=0.
       w_est(:,:)=0.
@@ -332,5 +332,5 @@
        do l=2,nlay-1
          do ig=1,ngrid
-            if (ztv(ig,l)>(ztv(ig,l+1)+0.5) .and. ztv(ig,1)>=ztv(ig,l) .and. ztv(ig,l-1)>(ztv(ig,l))) then
+            if (ztv(ig,l)>(ztv(ig,l+1)+0.5) .and. ztv(ig,1)>=ztv(ig,l) .and. (alim_star(ig,l-1) .ne. 0.)) then
                alim_star(ig,l)=MAX((ztv(ig,l)-ztv(ig,l+1)),0.)  &
      &                       *sqrt(zlev(ig,l+1))
