Index: LMDZ5/trunk/libf/phylmd/concvl.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/concvl.F90	(revision 2257)
+++ LMDZ5/trunk/libf/phylmd/concvl.F90	(revision 2259)
@@ -1,4 +1,4 @@
 SUBROUTINE concvl(iflag_clos, &
-                  dtime, paprs, pplay, &
+                  dtime, paprs, pplay, k_upper_cv, &
                   t, q, t_wake, q_wake, s_wake, u, v, tra, ntra, &
                   Ale, Alp, sig1, w01, &
@@ -88,4 +88,5 @@
 
   REAL dtime, paprs(klon, klev+1), pplay(klon, klev)
+  INTEGER k_upper_cv
   REAL t(klon, klev), q(klon, klev), u(klon, klev), v(klon, klev)
   REAL t_wake(klon, klev), q_wake(klon, klev)
@@ -405,5 +406,5 @@
 !LF   necessary for gathered fields
     nloc = klon
-    CALL cva_driver(klon, klev, klev+1, ntra, nloc, &
+    CALL cva_driver(klon, klev, klev+1, ntra, nloc, k_upper_cv, &
                     iflag_con, iflag_mix, iflag_ice_thermo, &
                     iflag_clos, ok_conserv_q, dtime, cvl_comp_threshold, &
Index: LMDZ5/trunk/libf/phylmd/cv3_routines.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/cv3_routines.F90	(revision 2257)
+++ LMDZ5/trunk/libf/phylmd/cv3_routines.F90	(revision 2259)
@@ -5,5 +5,5 @@
 
 
-SUBROUTINE cv3_param(nd, delt)
+SUBROUTINE cv3_param(nd, k_upper, delt)
 
   use mod_phys_lmdz_para
@@ -36,6 +36,7 @@
   include "conema3.h"
 
-  INTEGER nd
-  REAL delt ! timestep (seconds)
+  INTEGER, INTENT(IN)              :: nd
+  INTEGER, INTENT(IN)              :: k_upper
+  REAL, INTENT(IN)                 :: delt ! timestep (seconds)
 
 
@@ -51,5 +52,10 @@
 ! -- limit levels for convection:
 
-  noff = 1
+!jyg<
+!  noff is chosen such that nl = k_upper so that upmost loops end at about 22 km
+!
+  noff = min(max(nd-k_upper, 1), (nd+1)/2)
+!!  noff = 1
+!>jyg
   minorig = 1
   nl = nd - noff
@@ -2797,5 +2803,6 @@
                      iflag, precip, Vprecip, ft, fr, fu, fv, ftra, &
                      cbmf, upwd, dnwd, dnwd0, ma, mip, &
-                     tls, tps, qcondc, wd, &
+!!                     tls, tps,                             ! useless . jyg
+                     qcondc, wd, &
                      ftd, fqd, qnk, qtc, sigt, tau_cld_cv, coefw_cld_cv)
 
@@ -2845,5 +2852,5 @@
       REAL dnwd0(nloc, nd), mip(nloc, nd)
       REAL Vprecip(nloc, nd+1)
-      REAL tls(nloc, nd), tps(nloc, nd)
+!!      REAL tls(nloc, nd), tps(nloc, nd)                 ! useless . jyg
       REAL qcondc(nloc, nd) ! cld
       REAL qtc(nloc,nd), sigt(nloc,nd) ! cld
@@ -2857,5 +2864,5 @@
       REAL cpinv, rdcp, dpinv
       REAL awat(nloc)
-      REAL lvcp(nloc, na), lfcp(nloc, na), mke(nloc, na)
+      REAL lvcp(nloc, na), lfcp(nloc, na)                  ! , mke(nloc, na) ! unused . jyg
       REAL am(nloc), work(nloc), ad(nloc), amp1(nloc)
 !!      real up1(nloc), dn1(nloc)
@@ -3782,17 +3789,17 @@
 ! ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
 
-  DO i = 1, nd
-    DO il = 1, ncum
-      mke(il, i) = upwd(il, i) + dnwd(il, i)
-    END DO
-  END DO
-
-  DO i = 1, nd
-    DO il = 1, ncum
-      rdcp = (rrd*(1.-rr(il,i))-rr(il,i)*rrv)/(cpd*(1.-rr(il,i))+rr(il,i)*cpv)
-      tls(il, i) = t(il, i)*(1000.0/p(il,i))**rdcp
-      tps(il, i) = tp(il, i)
-    END DO
-  END DO
+!!  DO i = 1, nd                                  ! unused . jyg
+!!    DO il = 1, ncum                             ! unused . jyg
+!!      mke(il, i) = upwd(il, i) + dnwd(il, i)    ! unused . jyg
+!!    END DO                                      ! unused . jyg
+!!  END DO                                        ! unused . jyg
+
+!!  DO i = 1, nd                                                                 ! unused . jyg
+!!    DO il = 1, ncum                                                            ! unused . jyg
+!!      rdcp = (rrd*(1.-rr(il,i))-rr(il,i)*rrv)/(cpd*(1.-rr(il,i))+rr(il,i)*cpv) ! unused . jyg
+!!      tls(il, i) = t(il, i)*(1000.0/p(il,i))**rdcp                             ! unused . jyg
+!!      tps(il, i) = tp(il, i)                                                   ! unused . jyg
+!!    END DO                                                                     ! unused . jyg
+!!  END DO                                                                       ! unused . jyg
 
 
Index: LMDZ5/trunk/libf/phylmd/cv3a_compress.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/cv3a_compress.F90	(revision 2257)
+++ LMDZ5/trunk/libf/phylmd/cv3a_compress.F90	(revision 2259)
@@ -175,4 +175,5 @@
       pbase(nn) = pbase1(i)
       buoybase(nn) = buoybase1(i)
+      sig(nn, nd) = sig1(i, nd)
       ptop2(nn) = ptop2(i)
       Ale(nn) = Ale1(i)
@@ -192,34 +193,34 @@
       ncum = len
 !
-      wghti(:,:) = wghti1(:,:)
-      t(:,:) = t1(:,:)
-      q(:,:) = q1(:,:)
-      qs(:,:) = qs1(:,:)
-      t_wake(:,:) = t1_wake(:,:)
-      q_wake(:,:) = q1_wake(:,:)
-      qs_wake(:,:) = qs1_wake(:,:)
-      u(:,:) = u1(:,:)
-      v(:,:) = v1(:,:)
-      gz(:,:) = gz1(:,:)
-      th(:,:) = th1(:,:)
-      th_wake(:,:) = th1_wake(:,:)
-      h(:,:) = h1(:,:)
-      lv(:,:) = lv1(:,:)
-      lf(:,:) = lf1(:,:)
-      cpn(:,:) = cpn1(:,:)
-      p(:,:) = p1(:,:)
-      ph(:,:) = ph1(:,:)
-      tv(:,:) = tv1(:,:)
-      tp(:,:) = tp1(:,:)
-      tvp(:,:) = tvp1(:,:)
-      clw(:,:) = clw1(:,:)
-      h_wake(:,:) = h1_wake(:,:)
-      lv_wake(:,:) = lv1_wake(:,:)
-      lf_wake(:,:) = lf1_wake(:,:)
-      cpn_wake(:,:) = cpn1_wake(:,:)
-      tv_wake(:,:) = tv1_wake(:,:)
-      sig(:,:) = sig1(:,:)
-      w0(:,:) = w01(:,:)
-      omega(:,:) = omega1(:,:)
+      wghti(:,1:nl+1) = wghti1(:,1:nl+1)
+      t(:,1:nl+1) = t1(:,1:nl+1)
+      q(:,1:nl+1) = q1(:,1:nl+1)
+      qs(:,1:nl+1) = qs1(:,1:nl+1)
+      t_wake(:,1:nl+1) = t1_wake(:,1:nl+1)
+      q_wake(:,1:nl+1) = q1_wake(:,1:nl+1)
+      qs_wake(:,1:nl+1) = qs1_wake(:,1:nl+1)
+      u(:,1:nl+1) = u1(:,1:nl+1)
+      v(:,1:nl+1) = v1(:,1:nl+1)
+      gz(:,1:nl+1) = gz1(:,1:nl+1)
+      th(:,1:nl+1) = th1(:,1:nl+1)
+      th_wake(:,1:nl+1) = th1_wake(:,1:nl+1)
+      h(:,1:nl+1) = h1(:,1:nl+1)
+      lv(:,1:nl+1) = lv1(:,1:nl+1)
+      lf(:,1:nl+1) = lf1(:,1:nl+1)
+      cpn(:,1:nl+1) = cpn1(:,1:nl+1)
+      p(:,1:nl+1) = p1(:,1:nl+1)
+      ph(:,1:nl+1) = ph1(:,1:nl+1)
+      tv(:,1:nl+1) = tv1(:,1:nl+1)
+      tp(:,1:nl+1) = tp1(:,1:nl+1)
+      tvp(:,1:nl+1) = tvp1(:,1:nl+1)
+      clw(:,1:nl+1) = clw1(:,1:nl+1)
+      h_wake(:,1:nl+1) = h1_wake(:,1:nl+1)
+      lv_wake(:,1:nl+1) = lv1_wake(:,1:nl+1)
+      lf_wake(:,1:nl+1) = lf1_wake(:,1:nl+1)
+      cpn_wake(:,1:nl+1) = cpn1_wake(:,1:nl+1)
+      tv_wake(:,1:nl+1) = tv1_wake(:,1:nl+1)
+      sig(:,1:nl+1) = sig1(:,1:nl+1)
+      w0(:,1:nl+1) = w01(:,1:nl+1)
+      omega(:,1:nl+1) = omega1(:,1:nl+1)
 !
       s_wake(:) = s1_wake(:)
@@ -237,4 +238,5 @@
       pbase(:) = pbase1(:)
       buoybase(:) = buoybase1(:)
+      sig(:, nd) = sig1(:, nd)
       ptop2(:) = ptop2(:)
       Ale(:) = Ale1(:)
Index: LMDZ5/trunk/libf/phylmd/cv3a_uncompress.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/cv3a_uncompress.F90	(revision 2257)
+++ LMDZ5/trunk/libf/phylmd/cv3a_uncompress.F90	(revision 2259)
@@ -124,4 +124,5 @@
 !>jyg
     DO i = 1, ncum
+      sig1(idcum(i), nd) = sig(i, nd)
       ptop21(idcum(i)) = ptop2(i)
       sigd1(idcum(i)) = sigd(i)
@@ -143,5 +144,5 @@
     END DO
    
-    DO k = 1, nd
+    DO k = 1, nl+1
       DO i = 1, ncum
         sig1(idcum(i), k) = sig(i, k)
@@ -178,9 +179,4 @@
       END DO
     END DO
-
-    DO i = 1, ncum
-      sig1(idcum(i), nd) = sig(i, nd)
-    END DO
-   
    
     ! AC!        do 2100 j=1,ntra
@@ -209,9 +205,9 @@
       DO i = 1, ncum
         jdcum=idcum(i)
-        phi1(jdcum,:,:) = phi(i,:,:)          !AC!
-        phi21(jdcum,:,:) = phi2(i,:,:)        !RomP
-        sigij1(jdcum,:,:) = sigij(i,:,:)      !RomP
-        elij1(jdcum,:,:) = elij(i,:,:)        !RomP
-        epmlmMm1(jdcum,:,:) = epmlmMm(i,:,:)  !RomP+jyg
+        phi1    (jdcum, 1:nl+1, 1:nl+1) = phi    (i, 1:nl+1, 1:nl+1)          !AC!
+        phi21   (jdcum, 1:nl+1, 1:nl+1) = phi2   (i, 1:nl+1, 1:nl+1)          !RomP
+        sigij1  (jdcum, 1:nl+1, 1:nl+1) = sigij  (i, 1:nl+1, 1:nl+1)          !RomP
+        elij1   (jdcum, 1:nl+1, 1:nl+1) = elij   (i, 1:nl+1, 1:nl+1)          !RomP
+        epmlmMm1(jdcum, 1:nl+1, 1:nl+1) = epmlmMm(i, 1:nl+1, 1:nl+1)          !RomP+jyg
       END DO
 !>jyg
@@ -231,4 +227,5 @@
   ELSE  !(compress)
 !
+      sig1(:,nd) = sig(:,nd)
       ptop21(:) = ptop2(:)
       sigd1(:) = sigd(:)
@@ -249,42 +246,40 @@
       asupmaxmin1(:) = asupmaxmin(:)
 !
-      sig1(:,:) = sig(:,:)
-      w01(:,:) = w0(:,:)
-      ft1(:,:) = ft(:,:)
-      fq1(:,:) = fq(:,:)
-      fu1(:,:) = fu(:,:)
-      fv1(:,:) = fv(:,:)
-      ma1(:,:) = ma(:,:)
-      mip1(:,:) = mip(:,:)
-      vprecip1(:,:) = vprecip(:,:)
-      upwd1(:,:) = upwd(:,:)
-      dnwd1(:,:) = dnwd(:,:)
-      dnwd01(:,:) = dnwd0(:,:)
-      qcondc1(:,:) = qcondc(:,:)
-      tvp1(:,:) = tvp(:,:)
-      ftd1(:,:) = ftd(:,:)
-      fqd1(:,:) = fqd(:,:)
-      asupmax1(:,:) = asupmax(:,:)
-
-      da1(:,:) = da(:,:)              !AC!
-      mp1(:,:) = mp(:,:)              !RomP
-      d1a1(:,:) = d1a(:,:)            !RomP
-      dam1(:,:) = dam(:,:)            !RomP
-      clw1(:,:) = clw(:,:)            !RomP
-      evap1(:,:) = evap(:,:)          !RomP
-      ep1(:,:) = ep(:,:)              !RomP
-      eplamM1(:,:) = eplamM(:,:)       !RomP+jyg
-      wdtrainA1(:,:) = wdtrainA(:,:)  !RomP
-      wdtrainM1(:,:) = wdtrainM(:,:)  !RomP
-      qtc1(:,:) = qtc(:,:)
-      sigt1(:,:) = sigt(:,:)
-!
-      sig1(:,:) = sig(:,:)
-!
-      phi1(:,:,:)   = phi(:,:,:)      !AC!
-      phi21(:,:,:)  = phi2(:,:,:)     !RomP
-      sigij1(:,:,:) = sigij(:,:,:)    !RomP
-      elij1(:,:,:)  = elij(:,:,:)     !RomP
-      epmlmMm1(:,:,:) = epmlmMm(:,:,:) !RomP+jyg
+      sig1(:, 1:nl+1) = sig(:, 1:nl+1)
+      w01(:, 1:nl+1) = w0(:, 1:nl+1)
+      ft1(:, 1:nl+1) = ft(:, 1:nl+1)
+      fq1(:, 1:nl+1) = fq(:, 1:nl+1)
+      fu1(:, 1:nl+1) = fu(:, 1:nl+1)
+      fv1(:, 1:nl+1) = fv(:, 1:nl+1)
+      ma1(:, 1:nl+1) = ma(:, 1:nl+1)
+      mip1(:, 1:nl+1) = mip(:, 1:nl+1)
+      vprecip1(:, 1:nl+1) = vprecip(:, 1:nl+1)
+      upwd1(:, 1:nl+1) = upwd(:, 1:nl+1)
+      dnwd1(:, 1:nl+1) = dnwd(:, 1:nl+1)
+      dnwd01(:, 1:nl+1) = dnwd0(:, 1:nl+1)
+      qcondc1(:, 1:nl+1) = qcondc(:, 1:nl+1)
+      tvp1(:, 1:nl+1) = tvp(:, 1:nl+1)
+      ftd1(:, 1:nl+1) = ftd(:, 1:nl+1)
+      fqd1(:, 1:nl+1) = fqd(:, 1:nl+1)
+      asupmax1(:, 1:nl+1) = asupmax(:, 1:nl+1)
+
+      da1(:, 1:nl+1) = da(:, 1:nl+1)              !AC!
+      mp1(:, 1:nl+1) = mp(:, 1:nl+1)              !RomP
+      d1a1(:, 1:nl+1) = d1a(:, 1:nl+1)            !RomP
+      dam1(:, 1:nl+1) = dam(:, 1:nl+1)            !RomP
+      clw1(:, 1:nl+1) = clw(:, 1:nl+1)            !RomP
+      evap1(:, 1:nl+1) = evap(:, 1:nl+1)          !RomP
+      ep1(:, 1:nl+1) = ep(:, 1:nl+1)              !RomP
+      eplamM1(:, 1:nl+1) = eplamM(:, 1:nl+1)       !RomP+jyg
+      wdtrainA1(:, 1:nl+1) = wdtrainA(:, 1:nl+1)  !RomP
+      wdtrainM1(:, 1:nl+1) = wdtrainM(:, 1:nl+1)  !RomP
+      qtc1(:, 1:nl+1) = qtc(:, 1:nl+1)
+      sigt1(:, 1:nl+1) = sigt(:, 1:nl+1)
+!
+      phi1    (:, 1:nl+1, 1:nl+1) = phi    (:, 1:nl+1, 1:nl+1)  !AC!
+      phi21   (:, 1:nl+1, 1:nl+1) = phi2   (:, 1:nl+1, 1:nl+1)  !RomP
+      sigij1  (:, 1:nl+1, 1:nl+1) = sigij  (:, 1:nl+1, 1:nl+1)  !RomP
+      elij1   (:, 1:nl+1, 1:nl+1) = elij   (:, 1:nl+1, 1:nl+1)  !RomP
+      epmlmMm1(:, 1:nl+1, 1:nl+1) = epmlmMm(:, 1:nl+1, 1:nl+1)  !RomP+jyg
   ENDIF !(compress)
 !>jyg
Index: LMDZ5/trunk/libf/phylmd/cva_driver.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/cva_driver.F90	(revision 2257)
+++ LMDZ5/trunk/libf/phylmd/cva_driver.F90	(revision 2259)
@@ -2,5 +2,5 @@
 ! $Id$
 
-SUBROUTINE cva_driver(len, nd, ndp1, ntra, nloc, &
+SUBROUTINE cva_driver(len, nd, ndp1, ntra, nloc, k_upper, &
                       iflag_con, iflag_mix, iflag_ice_thermo, iflag_clos, ok_conserv_q, &
 !!                      delt, t1, q1, qs1, t1_wake, q1_wake, qs1_wake, s1_wake, &  ! jyg
@@ -54,4 +54,6 @@
 ! ndp1          Integer        Input        nd + 1
 ! ntra          Integer        Input        number of tracors
+! nloc          Integer        Input        dimension of arrays for compressed fields
+! k_upper       Integer        Input        upmost level for vertical loops
 ! iflag_con     Integer        Input        version of convect (3/4)
 ! iflag_mix     Integer        Input        version of mixing  (0/1/2)
@@ -165,4 +167,6 @@
   INTEGER, INTENT (IN)                               :: ndp1
   INTEGER, INTENT (IN)                               :: ntra
+  INTEGER, INTENT(IN)                                :: nloc ! (nloc=klon)  pour l'instant
+  INTEGER, INTENT (IN)                               :: k_upper
   INTEGER, INTENT (IN)                               :: iflag_con
   INTEGER, INTENT (IN)                               :: iflag_mix
@@ -435,6 +439,4 @@
 ! (local) compressed fields:
 
-  INTEGER nloc
-! parameter (nloc=klon) ! pour l'instant
 
   INTEGER idcum(nloc)
@@ -492,6 +494,7 @@
   REAL fu(nloc, klev), fv(nloc, klev)
   REAL upwd(nloc, klev), dnwd(nloc, klev), dnwd0(nloc, klev)
-  REAL ma(nloc, klev), mip(nloc, klev), tls(nloc, klev)
-  REAL tps(nloc, klev), qprime(nloc), tprime(nloc)
+  REAL ma(nloc, klev), mip(nloc, klev)
+!!  REAL tls(nloc, klev), tps(nloc, klev)                 ! unused . jyg
+  REAL qprime(nloc), tprime(nloc)
   REAL precip(nloc)
 ! real Vprecip(nloc,klev)
@@ -559,5 +562,5 @@
 
   IF (iflag_con==3) THEN
-    CALL cv3_param(nd, delt)
+    CALL cv3_param(nd, k_upper, delt)
 
   END IF
@@ -1021,5 +1024,6 @@
                      iflag, precip, vprecip, ft, fq, fu, fv, ftra, &
                      cbmf, upwd, dnwd, dnwd0, ma, mip, &
-                     tls, tps, qcondc, wd, &
+!!                     tls, tps, &                            ! useless . jyg
+                     qcondc, wd, &
                      ftd, fqd, qnk, qtc, sigt, tau_cld_cv, coefw_cld_cv)
     END IF
Index: LMDZ5/trunk/libf/phylmd/physiq.F90
===================================================================
--- LMDZ5/trunk/libf/phylmd/physiq.F90	(revision 2257)
+++ LMDZ5/trunk/libf/phylmd/physiq.F90	(revision 2259)
@@ -316,5 +316,10 @@
   SAVE top
   !$OMP THREADPRIVATE(bas, top)
-
+  !------------------------------------------------------------------
+  ! Upmost level reached by deep convection and related variable (jyg)
+  !
+  INTEGER izero
+  INTEGER k_upper_cv
+  !------------------------------------------------------------------
   !
   !=================================================================================================
@@ -528,5 +533,8 @@
   !                            !par la masse/airetot (moyglo_pondaima) et la vraie masse (moyglo_pondmass)
   !
-  ! Variables locales
+  !
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  ! Local variables
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !
   REAL rhcl(klon,klev)    ! humiditi relative ciel clair
@@ -570,5 +578,7 @@
   REAL zx_t, zx_qs, zdelta, zcor, zlvdcp, zlsdcp
   real zqsat(klon,klev)
+!
   INTEGER i, k, iq, ig, j, nsrf, ll, l, iiq
+!
   REAL t_coup
   PARAMETER (t_coup=234.0)
@@ -885,4 +895,5 @@
      igout=klon/2+1/klon
      write(lunout,*) 'DEBUT DE PHYSIQ !!!!!!!!!!!!!!!!!!!!'
+     write(lunout,*) 'igout, rlat, rlon ',igout, rlatd(igout)*180./3.141593, rlond(igout)*180./3.141593
      write(lunout,*) &
           'nlon,klev,nqtot,debut,lafin, jD_cur, jH_cur,pdtphys'
@@ -904,5 +915,5 @@
 
   if (first) then 
-
+     
      !CR:nvelles variables convection/poches froides
 
@@ -1333,5 +1344,4 @@
 #endif
      END IF
-     !
      !
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -2230,5 +2240,23 @@
      !
      IF (ok_cvl) THEN ! new driver for convectL
-
+     !
+!jyg<
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+     ! Calculate the upmost level of deep convection loops: k_upper_cv
+     !  (near 22 km)
+   izero = igout
+   DO i = 1,klon
+     IF (abs(rlatd(i)) < 4.e-2 .AND. abs(rlond(i)) < 4.e-2) izero = i
+   ENDDO
+!
+   k_upper_cv = klev
+   DO k = klev,1,-1
+     IF (pphi(izero,k) > 22.e4) k_upper_cv = k
+   ENDDO
+   IF (prt_level .ge. 5) THEN
+     Print *, 'upmost level of deep convection loops: k_upper_cv = ',k_upper_cv
+   ENDIF
+     !
+!>jyg
         IF (type_trac == 'repr') THEN
            nbtr_tmp=ntra
@@ -2239,5 +2267,5 @@
         !c          CALL concvl (iflag_con,iflag_clos,
         CALL concvl (iflag_clos, &
-             dtime,paprs,pplay,t_undi,q_undi, &
+             dtime, paprs, pplay, k_upper_cv, t_undi,q_undi, &
              t_wake,q_wake,wake_s, &
              u_seri,v_seri,tr_seri,nbtr_tmp, &
