Index: /LMDZ5/trunk/libf/phylmd/concvl.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/concvl.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/concvl.F90	(revision 2481)
@@ -16,6 +16,7 @@
                   evap, ep, epmlmMm, eplaMm, &                       ! RomP
                   wdtrainA, wdtrainM, wght, qtc, sigt, &
-                  tau_cld_cv, coefw_cld_cv)                           ! RomP+RL, AJ
+                  tau_cld_cv, coefw_cld_cv, &                           ! RomP+RL, AJ
 !RomP <<<
+                  epmax_diag) ! epmax_cape
 ! **************************************************************
 ! *
@@ -148,4 +149,5 @@
   REAL zx_t, zdelta, zx_qs, zcor
   REAL tau_cld_cv, coefw_cld_cv
+  REAL epmax_diag(klon) ! epmax_cape
 
 !   INTEGER iflag_mix
@@ -388,5 +390,6 @@
                    da, phi, mp, phi2, d1a, dam, sij, clw, elij, &       !RomP
                    evap, ep, epmlmMm, eplaMm, &                         !RomP
-                   wdtrainA, wdtrainM)                                  !RomP
+                   wdtrainA, wdtrainM, &                                !RomP
+                   epmax_diag) ! epmax_cape
 !           print *, 'cv_driver ->'      !jyg
 
@@ -425,6 +428,7 @@
                     clw, elij, evap, ep, epmlmMm, eplaMm, &             ! RomP+RL
                     wdtrainA, wdtrainM, qtc, sigt, &
-                    tau_cld_cv, coefw_cld_cv)                           ! RomP,AJ
+                    tau_cld_cv, coefw_cld_cv, &                         ! RomP,AJ
 !AC!+!RomP+jyg
+                    epmax_diag) ! epmax_cape
   END IF
 ! ------------------------------------------------------------------
Index: /LMDZ5/trunk/libf/phylmd/conema3.h
===================================================================
--- /LMDZ5/trunk/libf/phylmd/conema3.h	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/conema3.h	(revision 2481)
@@ -4,4 +4,5 @@
 !
       real epmax             ! 0.993
+      real coef_epmax_cape             ! 0.993
 !jyg<
       REAL  cvl_comp_threshold     ! 0.
@@ -13,11 +14,11 @@
 
 !jyg<
-!!      common/comconema1/epmax,ok_adj_ema,iflag_clw,sig1feed,sig2feed
+!!      common/comconema1/epmax,coef_epmax_cape,ok_adj_ema,iflag_clw,sig1feed,sig2feed
 !!      common/comconema2/iflag_cvl_sigd
-      common/comconema1/epmax, cvl_comp_threshold, cvl_sig2feed
+      common/comconema1/epmax,coef_epmax_cape, cvl_comp_threshold, cvl_sig2feed
       common/comconema2/iflag_cvl_sigd, iflag_clw, ok_adj_ema
 !>jyg
 
-!      common/comconema/epmax,ok_adj_ema,iflag_clw
+!      common/comconema/epmax,coef_epmax_cape,ok_adj_ema,iflag_clw
 !$OMP THREADPRIVATE(/comconema1/)
 !$OMP THREADPRIVATE(/comconema2/)
Index: /LMDZ5/trunk/libf/phylmd/conf_phys_m.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/conf_phys_m.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/conf_phys_m.F90	(revision 2481)
@@ -155,4 +155,5 @@
     LOGICAL,SAVE :: ok_4xCO2atm_omp
     REAL,SAVE :: epmax_omp
+    REAL,SAVE :: coef_epmax_cape_omp
     LOGICAL,SAVE :: ok_adj_ema_omp
     INTEGER,SAVE :: iflag_clw_omp
@@ -812,4 +813,7 @@
     epmax_omp = .993
     call getin('epmax', epmax_omp)
+
+    coef_epmax_cape_omp = 0.0   
+    call getin('coef_epmax_cape', coef_epmax_cape_omp)        
     !
     !Config Key  = ok_adj_ema
@@ -1999,4 +2003,5 @@
 
     epmax = epmax_omp
+    coef_epmax_cape = coef_epmax_cape_omp
     ok_adj_ema = ok_adj_ema_omp
     iflag_clw = iflag_clw_omp
@@ -2303,4 +2308,5 @@
     write(lunout,*)'iflag_bergeron=',iflag_bergeron
     write(lunout,*)' epmax = ', epmax
+    write(lunout,*)' coef_epmax_cape = ', coef_epmax_cape
     write(lunout,*)' ok_adj_ema = ', ok_adj_ema
     write(lunout,*)' iflag_clw = ', iflag_clw
Index: /LMDZ5/trunk/libf/phylmd/cv30_routines.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/cv30_routines.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/cv30_routines.F90	(revision 2481)
@@ -839,4 +839,5 @@
     q, qs, gz, p, h, tv, lv, pbase, buoybase, plcl, inb, tp, tvp, clw, hp, &
     ep, sigp, buoy)
+    ! epmax_cape: ajout arguments
   IMPLICIT NONE
 
@@ -1242,5 +1243,4 @@
   REAL dtmin(nloc, nd), sigold(nloc, nd)
 
-
   ! -------------------------------------------------------
   ! -- Initialization
@@ -1348,5 +1348,4 @@
 
   ! the interval on which cape is computed starts at pbase :
-
   DO k = 1, nl
     DO i = 1, ncum
@@ -3146,8 +3145,8 @@
     vprecip, evap, ep, sig, w0, ft, fq, fu, fv, ftra, inb, ma, upwd, dnwd, &
     dnwd0, qcondc, wd, cape, da, phi, mp, phi2, d1a, dam, sij, elij, clw, &
-    epmlmmm, eplamm, wdtraina, wdtrainm, iflag1, precip1, vprecip1, evap1, &
+    epmlmmm, eplamm, wdtraina, wdtrainm,epmax_diag, iflag1, precip1, vprecip1, evap1, &
     ep1, sig1, w01, ft1, fq1, fu1, fv1, ftra1, inb1, ma1, upwd1, dnwd1, &
     dnwd01, qcondc1, wd1, cape1, da1, phi1, mp1, phi21, d1a1, dam1, sij1, &
-    elij1, clw1, epmlmmm1, eplamm1, wdtraina1, wdtrainm1)
+    elij1, clw1, epmlmmm1, eplamm1, wdtraina1, wdtrainm1,epmax_diag1) ! epmax_cape
   IMPLICIT NONE
 
@@ -3170,4 +3169,5 @@
   REAL wd(nloc), cape(nloc)
   REAL da(nloc, nd), phi(nloc, nd, nd), mp(nloc, nd)
+  REAL epmax_diag(nloc) ! epmax_cape
   ! RomP >>>
   REAL phi2(nloc, nd, nd)
@@ -3193,4 +3193,5 @@
   REAL wd1(nloc), cape1(nloc)
   REAL da1(nloc, nd), phi1(nloc, nd, nd), mp1(nloc, nd)
+  REAL epmax_diag1(len) ! epmax_cape
   ! RomP >>>
   REAL phi21(len, nd, nd)
@@ -3211,4 +3212,5 @@
     inb1(idcum(i)) = inb(i)
     cape1(idcum(i)) = cape(i)
+    epmax_diag1(idcum(i))=epmax_diag(i) ! epmax_cape
   END DO
 
@@ -3269,2 +3271,88 @@
 END SUBROUTINE cv30_uncompress
 
+        subroutine cv30_epmax_fn_cape(nloc,ncum,nd &
+                ,cape,ep,hp,icb,inb,clw,nk,t,h,lv &
+                ,epmax_diag)
+        implicit none
+
+        ! On fait varier epmax en fn de la cape
+        ! Il faut donc recalculer ep, et hp qui a déjà été calculé et
+        ! qui en dépend
+        ! Toutes les autres variables fn de ep sont calculées plus bas.
+
+#include "cvthermo.h"
+#include "cv30param.h"
+#include "conema3.h"
+
+! inputs:
+      integer ncum, nd, nloc
+      integer icb(nloc), inb(nloc)
+      real cape(nloc)
+      real clw(nloc,nd),lv(nloc,nd),t(nloc,nd),h(nloc,nd)
+      integer nk(nloc)
+! inouts:
+      real ep(nloc,nd)
+      real hp(nloc,nd)
+! outputs ou local
+      real epmax_diag(nloc)
+! locals
+      integer i,k    
+      real hp_bak(nloc,nd)
+
+        ! on recalcule ep et hp
+        
+        if (coef_epmax_cape.gt.1e-12) then
+        do i=1,ncum
+           epmax_diag(i)=epmax-coef_epmax_cape*sqrt(cape(i))
+           do k=1,nl
+                ep(i,k)=ep(i,k)/epmax*epmax_diag(i)
+                ep(i,k)=amax1(ep(i,k),0.0)
+                ep(i,k)=amin1(ep(i,k),epmax_diag(i))
+           enddo
+        enddo
+
+! On recalcule hp:
+      do k=1,nl
+        do i=1,ncum
+	  hp_bak(i,k)=hp(i,k)
+	enddo
+      enddo
+      do k=1,nlp
+        do i=1,ncum
+	  hp(i,k)=h(i,k)
+	enddo
+      enddo
+      do k=minorig+1,nl
+       do i=1,ncum
+        if((k.ge.icb(i)).and.(k.le.inb(i)))then
+          hp(i,k)=h(i,nk(i))+(lv(i,k)+(cpd-cpv)*t(i,k))*ep(i,k)*clw(i,k)
+        endif
+       enddo
+      enddo !do k=minorig+1,n
+!     write(*,*) 'cv30_routines 6218: hp(1,20)=',hp(1,20)
+      do i=1,ncum  
+       do k=1,nl
+        if (abs(hp_bak(i,k)-hp(i,k)).gt.0.01) then
+           write(*,*) 'i,k=',i,k
+           write(*,*) 'coef_epmax_cape=',coef_epmax_cape
+           write(*,*) 'epmax_diag(i)=',epmax_diag(i)
+           write(*,*) 'ep(i,k)=',ep(i,k)
+           write(*,*) 'hp(i,k)=',hp(i,k)
+           write(*,*) 'hp_bak(i,k)=',hp_bak(i,k)
+           write(*,*) 'h(i,k)=',h(i,k)
+           write(*,*) 'nk(i)=',nk(i)
+           write(*,*) 'h(i,nk(i))=',h(i,nk(i))
+           write(*,*) 'lv(i,k)=',lv(i,k)
+           write(*,*) 't(i,k)=',t(i,k)
+           write(*,*) 'clw(i,k)=',clw(i,k)
+           write(*,*) 'cpd,cpv=',cpd,cpv
+           stop
+        endif
+       enddo !do k=1,nl
+      enddo !do i=1,ncum  
+      endif !if (coef_epmax_cape.gt.1e-12) then
+
+      return
+      end subroutine cv30_epmax_fn_cape
+
+
Index: /LMDZ5/trunk/libf/phylmd/cv3_routines.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/cv3_routines.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/cv3_routines.F90	(revision 2481)
@@ -4142,8 +4142,10 @@
                           ft, fq, fu, fv, ftra, &
                           Ma, upwd, dnwd, dnwd0, qcondc, wd, cape, &
+                          epmax_diag, & ! epmax_cape
                           iflag1, &
                           precip1, sig1, w01, &
                           ft1, fq1, fu1, fv1, ftra1, &
-                          Ma1, upwd1, dnwd1, dnwd01, qcondc1, wd1, cape1)
+                          Ma1, upwd1, dnwd1, dnwd01, qcondc1, wd1, cape1, &
+                          epmax_diag1) ! epmax_cape
   IMPLICIT NONE
 
@@ -4162,4 +4164,5 @@
   REAL qcondc(nloc, nd)
   REAL wd(nloc), cape(nloc)
+  REAL epmax_diag(nloc)
 
 !outputs:
@@ -4173,4 +4176,5 @@
   REAL qcondc1(nloc, nd)
   REAL wd1(nloc), cape1(nloc)
+  REAL epmax_diag1(len) ! epmax_cape
 
 !local variables:
@@ -4182,4 +4186,5 @@
     wd1(idcum(i)) = wd(i)
     cape1(idcum(i)) = cape(i)
+    epmax_diag1(idcum(i))=epmax_diag(i) ! epmax_cape
   END DO
 
@@ -4216,2 +4221,148 @@
   RETURN
 END SUBROUTINE cv3_uncompress
+
+
+        subroutine cv3_epmax_fn_cape(nloc,ncum,nd &
+                 , ep,hp,icb,inb,clw,nk,t,h,hnk,lv,lf,frac &
+                 , pbase, p, ph, tv, buoy, sig, w0,iflag &
+                 , epmax_diag)
+        implicit none
+
+        ! On fait varier epmax en fn de la cape
+        ! Il faut donc recalculer ep, et hp qui a déjà été calculé et
+        ! qui en dépend
+        ! Toutes les autres variables fn de ep sont calculées plus bas.
+
+  include "cvthermo.h"
+  include "cv3param.h"  
+  include "conema3.h"
+  include "cvflag.h"
+
+! inputs:
+      INTEGER, INTENT (IN)                               :: ncum, nd, nloc
+      INTEGER, DIMENSION (nloc), INTENT (IN)             :: icb, inb, nk
+      REAL, DIMENSION (nloc), INTENT (IN)                :: hnk,pbase
+      REAL, DIMENSION (nloc, nd), INTENT (IN)            :: t, lv, lf, tv, h
+      REAL, DIMENSION (nloc, nd), INTENT (IN)            :: clw, buoy,frac
+      REAL, DIMENSION (nloc, nd), INTENT (IN)            :: sig,w0
+      INTEGER, DIMENSION (nloc), INTENT (IN)             :: iflag(nloc)
+      REAL, DIMENSION (nloc, nd), INTENT (IN)            :: p
+      REAL, DIMENSION (nloc, nd+1), INTENT (IN)          :: ph
+! inouts:
+      REAL, DIMENSION (nloc, nd), INTENT (INOUT)         :: ep,hp  
+! outputs
+      REAL, DIMENSION (nloc), INTENT (OUT)           :: epmax_diag
+
+! local
+      integer i,k    
+!      real hp_bak(nloc,nd)
+!      real ep_bak(nloc,nd)
+      real m_loc(nloc,nd)
+      real sig_loc(nloc,nd)
+      real w0_loc(nloc,nd)
+      integer iflag_loc(nloc)
+      real cape(nloc)
+        
+        if (coef_epmax_cape.gt.1e-12) then
+
+        ! il faut calculer la cape: on fait un calcule simple car tant qu'on ne
+        ! connait pas ep, on ne connait pas les mélanges, ddfts etc... qui sont
+        ! necessaires au calcul de la cape dans la nouvelle physique
+        
+!        write(*,*) 'cv3_routines check 4303'
+        do i=1,ncum
+        do k=1,nd
+          sig_loc(i,k)=sig(i,k)
+          w0_loc(i,k)=w0(i,k)
+          iflag_loc(i)=iflag(i)
+!          ep_bak(i,k)=ep(i,k)
+        enddo ! do k=1,nd
+        enddo !do i=1,ncum
+
+!        write(*,*) 'cv3_routines check 4311'
+!        write(*,*) 'nl=',nl
+        CALL cv3_closure(nloc, ncum, nd, icb, inb, & ! na->nd
+          pbase, p, ph, tv, buoy, &
+          sig_loc, w0_loc, cape, m_loc,iflag_loc)
+
+!        write(*,*) 'cv3_routines check 4316'
+!        write(*,*) 'ep(1,:)=',ep(1,:)
+        do i=1,ncum
+           epmax_diag(i)=epmax-coef_epmax_cape*sqrt(cape(i))
+           epmax_diag(i)=amax1(epmax_diag(i),0.0)
+!           write(*,*) 'i,icb,inb,cape,epmax_diag=', &
+!                i,icb(i),inb(i),cape(i),epmax_diag(i)
+           do k=1,nl
+                ep(i,k)=ep(i,k)/epmax*epmax_diag(i)
+                ep(i,k)=amax1(ep(i,k),0.0)
+                ep(i,k)=amin1(ep(i,k),epmax_diag(i))
+           enddo
+        enddo
+ !       write(*,*) 'ep(1,:)=',ep(1,:)
+
+      !write(*,*) 'cv3_routines check 4326'
+! On recalcule hp:
+!      do k=1,nl
+!        do i=1,ncum
+!	  hp_bak(i,k)=hp(i,k)
+!	enddo
+!      enddo
+      do k=1,nl
+        do i=1,ncum
+	  hp(i,k)=h(i,k)
+	enddo
+      enddo
+
+  IF (cvflag_ice) THEN
+
+      do k=minorig+1,nl
+       do i=1,ncum
+        if((k.ge.icb(i)).and.(k.le.inb(i)))then
+          hp(i, k) = hnk(i) + (lv(i,k)+(cpd-cpv)*t(i,k)+frac(i,k)*lf(i,k))* &
+                              ep(i, k)*clw(i, k)
+        endif
+       enddo
+      enddo !do k=minorig+1,n
+  ELSE !IF (cvflag_ice) THEN
+
+      DO k = minorig + 1, nl
+       DO i = 1, ncum
+        IF ((k>=icb(i)) .AND. (k<=inb(i))) THEN
+          hp(i,k)=hnk(i)+(lv(i,k)+(cpd-cpv)*t(i,k))*ep(i,k)*clw(i,k)
+        endif
+       enddo
+      enddo !do k=minorig+1,n
+
+  ENDIF !IF (cvflag_ice) THEN     
+      !write(*,*) 'cv3_routines check 4345'
+!      do i=1,ncum  
+!       do k=1,nl
+!        if ((abs(hp_bak(i,k)-hp(i,k))/hp_bak(i,k).gt.1e-1).or. &
+!            ((abs(hp_bak(i,k)-hp(i,k))/hp_bak(i,k).gt.1e-4).and. &
+!            (ep(i,k)-ep_bak(i,k).lt.1e-4))) then
+!           write(*,*) 'i,k=',i,k
+!           write(*,*) 'coef_epmax_cape=',coef_epmax_cape
+!           write(*,*) 'epmax_diag(i)=',epmax_diag(i)
+!           write(*,*) 'ep(i,k)=',ep(i,k)
+!           write(*,*) 'ep_bak(i,k)=',ep_bak(i,k)
+!           write(*,*) 'hp(i,k)=',hp(i,k)
+!           write(*,*) 'hp_bak(i,k)=',hp_bak(i,k)
+!           write(*,*) 'h(i,k)=',h(i,k)
+!           write(*,*) 'nk(i)=',nk(i)
+!           write(*,*) 'h(i,nk(i))=',h(i,nk(i))
+!           write(*,*) 'lv(i,k)=',lv(i,k)
+!           write(*,*) 't(i,k)=',t(i,k)
+!           write(*,*) 'clw(i,k)=',clw(i,k)
+!           write(*,*) 'cpd,cpv=',cpd,cpv
+!           stop
+!        endif
+!       enddo !do k=1,nl
+!      enddo !do i=1,ncum  
+      endif !if (coef_epmax_cape.gt.1e-12) then
+      !write(*,*) 'cv3_routines check 4367'
+
+      return
+      end subroutine cv3_epmax_fn_cape
+
+
+
Index: /LMDZ5/trunk/libf/phylmd/cv3a_uncompress.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/cv3a_uncompress.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/cv3a_uncompress.F90	(revision 2481)
@@ -13,5 +13,5 @@
                            wdtrainA, wdtrainM, &                                ! RomP
                            qtc, sigt,          &
-                         
+                           epmax_diag, & ! epmax_cape
                            iflag1, kbas1, ktop1, &
                            precip1, cbmf1, plcl1, plfc1, wbeff1, sig1, w01, ptop21, &
@@ -26,5 +26,6 @@
                            clw1, elij1, evap1, ep1, epmlmMm1, eplaMm1, &        ! RomP
                            wdtrainA1, wdtrainM1, &                              ! RomP
-                           qtc1, sigt1)
+                           qtc1, sigt1, &
+                           epmax_diag1) ! epmax_cape
 
   ! **************************************************************
@@ -52,4 +53,5 @@
   REAL, DIMENSION (nloc, nd), INTENT (IN)            :: sig, w0
   REAL, DIMENSION (nloc), INTENT (IN)                :: ptop2
+  REAL, DIMENSION (nloc), INTENT (IN)                :: epmax_diag
   REAL, DIMENSION (nloc, nd), INTENT (IN)            :: ft, fq, fu, fv
   REAL, DIMENSION (nloc, nd, ntra), INTENT (IN)      :: ftra
@@ -86,4 +88,5 @@
   REAL, DIMENSION (len), INTENT (OUT)                :: wbeff1
   REAL, DIMENSION (len, nd), INTENT (OUT)            :: sig1, w01
+  REAL, DIMENSION (len), INTENT (OUT)                :: epmax_diag1 ! epmax_cape
   REAL, DIMENSION (len), INTENT (OUT)                :: ptop21
   REAL, DIMENSION (len, nd), INTENT (OUT)            :: ft1, fq1, fu1, fv1
@@ -144,4 +147,5 @@
       supmax01(idcum(i)) = supmax0(i)
       asupmaxmin1(idcum(i)) = asupmaxmin(i)
+      epmax_diag1(idcum(i)) = epmax_diag(i)
     END DO
    
Index: /LMDZ5/trunk/libf/phylmd/cv_driver.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/cv_driver.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/cv_driver.F90	(revision 2481)
@@ -8,5 +8,6 @@
                                                                         ! RomP
     evap1, ep1, epmlmmm1, eplamm1, & ! RomP
-    wdtraina1, wdtrainm1) ! RomP
+    wdtraina1, wdtrainm1, & ! RomP
+    epmax_diag1) ! epmax_cape
 
   USE dimphy
@@ -144,4 +145,5 @@
   REAL epmlmmm1(len, nd, nd), eplamm1(len, nd)
   ! RomP <<<
+  REAL epmax_diag1 (len) ! epmax_cape     
 
   ! -------------------------------------------------------------------
@@ -341,4 +343,5 @@
   REAL sigd(nloc)
   ! RomP <<<
+  REAL epmax_diag(nloc) ! epmax_cape
 
   nent(:, :) = 0
@@ -402,4 +405,6 @@
   wd1(:) = 0.0
   cape1(:) = 0.0
+  epmax_diag1(:) = 0.0 ! epmax_cape
+
 
   IF (iflag_con==30) THEN
@@ -554,4 +559,10 @@
       CALL cv30_closure(nloc, ncum, nd, icb, inb & ! na->nd
         , pbase, p, ph, tv, buoy, sig, w0, cape, m)
+
+      ! epmax_cape
+      call cv30_epmax_fn_cape(nloc,ncum,nd &
+                ,cape,ep,hp,icb,inb,clw,nk,t,h,lv &
+                ,epmax_diag)
+        ! on écrase ep et recalcule hp
     END IF
 
@@ -560,4 +571,5 @@
         cpn, iflag, cbmf)
     END IF
+    
 
     ! -------------------------------------------------------------------
@@ -643,10 +655,10 @@
         da, phi, mp, phi2, d1a, dam, sij & !RomP
         , elij, clw, epmlmmm, eplamm & !RomP
-        , wdtraina, wdtrainm &     !RomP
+        , wdtraina, wdtrainm,epmax_diag &     !RomP
         , iflag1, precip1, vprecip1, evap1, ep1, sig1, w01 & !RomP
         , ft1, fq1, fu1, fv1, ftra1, inb1, ma1, upwd1, dnwd1, dnwd01, &
         qcondc1, wd1, cape1, da1, phi1, mp1, phi21, d1a1, dam1, sij1 & !RomP
         , elij1, clw1, epmlmmm1, eplamm1 & !RomP
-        , wdtraina1, wdtrainm1) !RomP
+        , wdtraina1, wdtrainm1,epmax_diag1) !RomP
     END IF
 
Index: /LMDZ5/trunk/libf/phylmd/cva_driver.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/cva_driver.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/cva_driver.F90	(revision 2481)
@@ -27,5 +27,6 @@
                       clw1, elij1, evap1, ep1, epmlmMm1, eplaMm1, &        ! RomP, RL
                       wdtrainA1, wdtrainM1, qtc1, sigt1, tau_cld_cv, &
-                      coefw_cld_cv)                                        ! RomP, AJ
+                      coefw_cld_cv, &                                      ! RomP, AJ
+                      epmax_diag1)  ! epmax_cape
 ! **************************************************************
 ! *
@@ -259,4 +260,5 @@
   REAL, DIMENSION (len, nd), INTENT (OUT)            :: d1a1, dam1
 ! RomP <<<
+  REAL, DIMENSION (len ), INTENT (OUT)               :: epmax_diag1      
 
 ! -------------------------------------------------------------------
@@ -524,4 +526,5 @@
   REAL d1a(len, nd), dam(len, nd)
 ! RomP <<<
+  REAL epmax_diag(nloc) ! epmax_cape
 
   LOGICAL, SAVE :: first = .TRUE.
@@ -892,4 +895,11 @@
     END IF
 
+    ! epmax_cape
+    ! on recalcule ep et hp    
+    call cv3_epmax_fn_cape(nloc,ncum,nd &
+                , ep,hp,icb,inb,clw,nk,t,h,hnk,lv,lf,frac &
+                , pbase, p, ph, tv, buoy, sig, w0,iflag &
+                , epmax_diag)
+
 ! -------------------------------------------------------------------
 ! --- MIXING(1)   (if iflag_mix .ge. 1)
@@ -1128,5 +1138,5 @@
                            clw, elij, evap, ep, epmlmMm, eplaMm, &       ! RomP
                            wdtrainA, wdtrainM, &                         ! RomP
-                           qtc, sigt, &
+                           qtc, sigt, epmax_diag, & ! epmax_cape
                            iflag1, kbas1, ktop1, &
                            precip1, cbmf1, plcl1, plfc1, wbeff1, sig1, w01, ptop21, &
@@ -1141,5 +1151,5 @@
                            clw1, elij1, evap1, ep1, epmlmMm1, eplaMm1, & ! RomP
                            wdtrainA1, wdtrainM1,                       & ! RomP
-                           qtc1, sigt1)
+                           qtc1, sigt1, epmax_diag1) ! epmax_cape
     END IF
 
Index: /LMDZ5/trunk/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/phys_local_var_mod.F90	(revision 2481)
@@ -342,4 +342,8 @@
       REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: dnwd, dnwd0, upwd, omega
 !$OMP THREADPRIVATE(dnwd, dnwd0, upwd, omega)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:) :: epmax_diag ! epmax_cape
+!$OMP THREADPRIVATE(epmax_diag)
+      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: ep ! epmax_cape
+!$OMP THREADPRIVATE(ep)
 !      REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: coefh, coefm, lambda_th
       REAL,ALLOCATABLE,SAVE,DIMENSION(:,:) :: lambda_th
@@ -560,4 +564,6 @@
 !      ALLOCATE(upwd(klon, klev), omega(klon, klev), coefh(klon, klev))
       ALLOCATE(upwd(klon, klev), omega(klon, klev))
+      ALLOCATE(epmax_diag(klon)) ! epmax_cape
+      ALLOCATE(ep(klon,klev)) ! epmax_cape
 !      ALLOCATE(coefm(klon, klev), lambda_th(klon, klev), cldemi(klon, klev))
       ALLOCATE(lambda_th(klon, klev), cldemi(klon, klev))
@@ -761,4 +767,6 @@
 !      DEALLOCATE(upwd, omega, coefh)
       DEALLOCATE(upwd, omega)
+      DEALLOCATE(epmax_diag)
+      DEALLOCATE(ep)
 !      DEALLOCATE(coefm, lambda_th, cldemi)
       DEALLOCATE(lambda_th, cldemi)
Index: /LMDZ5/trunk/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 2481)
@@ -982,4 +982,8 @@
   TYPE(ctrl_out), SAVE :: o_upwd = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'upwd', 'saturated updraft', 'kg/m2/s', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_epmax_diag = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'epmax', 'epmax en fn cape', 'su', (/ ('', i=1, 9) /))
+  TYPE(ctrl_out), SAVE :: o_ep = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
+    'ep', 'ep', 'su', (/ ('', i=1, 9) /))
   TYPE(ctrl_out), SAVE :: o_dtphy = ctrl_out((/ 2, 10, 10, 10, 10, 10, 11, 11, 11 /), &
     'dtphy', 'Physics dT', 'K/s', (/ ('', i=1, 9) /))
Index: /LMDZ5/trunk/libf/phylmd/phys_output_write_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/phys_output_write_mod.F90	(revision 2481)
@@ -37,5 +37,5 @@
          o_psol, o_mass, o_qsurf, o_qsol, &
          o_precip, o_ndayrain, o_plul, o_pluc, &
-         o_snow, o_msnow, o_fsnow, o_evap, &
+         o_snow, o_msnow, o_fsnow, o_evap, o_ep,o_epmax_diag, & ! epmax_cape
          o_tops, o_tops0, o_topl, o_topl0, &
          o_SWupTOA, o_SWupTOAclr, o_SWdnTOA, &
@@ -65,5 +65,5 @@
          o_ue, o_ve, o_uq, o_vq, o_cape, o_pbase, &
          o_ptop, o_fbase, o_plcl, o_plfc, &
-         o_wbeff, o_cape_max, o_upwd, o_Ma, &
+         o_wbeff, o_cape_max, o_upwd, o_ep,o_epmax_diag, o_Ma, &
          o_dnwd, o_dnwd0, o_ftime_con, o_mc, &
          o_prw, o_s_pblh, o_s_pblt, o_s_lcl, &
@@ -249,5 +249,6 @@
          dv_gwd_rando, dv_gwd_front, &
          east_gwstress, west_gwstress, &
-         d_q_ch4, pmfd, pmfu, ref_liq, ref_ice, rhwriteSTD
+         d_q_ch4, pmfd, pmfu, ref_liq, ref_ice, rhwriteSTD, &
+         ep, epmax_diag ! epmax_cape
 
     USE phys_output_var_mod, only: vars_defined, snow_o, zfra_o, bils_diss, &
@@ -428,4 +429,8 @@
        CALL histwrite_phy(o_precip, zx_tmp_fi2d)
        CALL histwrite_phy(o_ndayrain, nday_rain)
+
+       ! epmax_cape:
+       CALL histwrite_phy(o_epmax_diag, epmax_diag)
+       CALL histwrite_phy(o_ep, ep)
 
        IF (vars_defined) THEN
Index: /LMDZ5/trunk/libf/phylmd/physiq_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/phylmd/physiq_mod.F90	(revision 2480)
+++ /LMDZ5/trunk/libf/phylmd/physiq_mod.F90	(revision 2481)
@@ -266,5 +266,5 @@
     real phi2(klon,klev,klev)
     real d1a(klon,klev),dam(klon,klev)
-    real ev(klon,klev),ep(klon,klev)
+    real ev(klon,klev)
     real clw(klon,klev),elij(klon,klev,klev)
     real epmlmMm(klon,klev,klev),eplaMm(klon,klev)
@@ -2480,5 +2480,5 @@
                ev, ep,epmlmMm,eplaMm, &
                wdtrainA,wdtrainM,wght_cvfd,qtc_cv,sigt_cv, &
-               tau_cld_cv,coefw_cld_cv)
+               tau_cld_cv,coefw_cld_cv,epmax_diag)
           ! RomP <<<
 
