Index: /LMDZ.3.3/trunk/libf/phylmd/physiq.F
===================================================================
--- /LMDZ.3.3/trunk/libf/phylmd/physiq.F	(revision 45)
+++ /LMDZ.3.3/trunk/libf/phylmd/physiq.F	(revision 46)
@@ -3,5 +3,4 @@
      .            paprs,pplay,pphi,pphis,paire,presnivs,clesphy0,
      .            u,v,t,qx,
-     .            d_u_dyn, d_v_dyn,  d_t_dyn, d_qx_dyn,
      .            omega,
      .            d_u, d_v, d_t, d_qx, d_ps)
@@ -40,8 +39,6 @@
 c t-------input-R-temperature (K)
 c qx------input-R-humidite specifique (kg/kg) et d'autres traceurs
-c d_u_dyn-input-R-tendance dynamique pour "u" (m/s/s)
-c d_v_dyn-input-R-tendance dynamique pour "v" (m/s/s)
 c d_t_dyn-input-R-tendance dynamique pour "t" (K/s)
-c d_qx_dyn-input-R-tendance dynamique pour "qx" (kg/kg/s)
+c d_q_dyn-input-R-tendance dynamique pour "q" (kg/kg/s)
 c omega---input-R-vitesse verticale en Pa/s
 c
@@ -62,4 +59,6 @@
       LOGICAL check ! Verifier la conservation du modele en eau
       PARAMETER (check=.FALSE.)
+      LOGICAL ok_stratus ! Ajouter artificiellement les stratus
+      PARAMETER (ok_stratus=.FALSE.)
 c======================================================================
 c Parametres lies au coupleur OASIS:
@@ -71,5 +70,7 @@
       PARAMETER (nexca=48)
       PARAMETER (itimestep=1800)
-      EXTERNAL intocpl, inicma
+      EXTERNAL fromcpl, intocpl, inicma
+      REAL cpl_sst(iim,jjm+1), cpl_sic(iim,jjm+1)
+      REAL cpl_alb_sst(iim,jjm+1), cpl_alb_sic(iim,jjm+1)
 c======================================================================
 c ok_ocean indique l'utilisation du modele oceanique "slab ocean",
@@ -156,8 +157,13 @@
       REAL qx(klon,klev,nqmax)
 
+      REAL t_ancien(klon,klev), q_ancien(klon,klev)
+      SAVE t_ancien, q_ancien
+      LOGICAL ancien_ok
+      SAVE ancien_ok
+
       REAL d_u_dyn(klon,klev)
       REAL d_v_dyn(klon,klev)
       REAL d_t_dyn(klon,klev)
-      REAL d_qx_dyn(klon,klev,2)
+      REAL d_q_dyn(klon,klev)
 
       REAL omega(klon,klev)
@@ -402,4 +408,8 @@
       CHARACTER*2 iqn
 c
+      REAL qcheck
+      REAL z_avant(klon), z_apres(klon), z_factor(klon)
+      LOGICAL zx_ajustq
+c
       REAL za, zb
       REAL zx_t, zx_qs, zdelta, zcor, zfra, zlvdcp, zlsdcp
@@ -423,5 +433,5 @@
       REAL d_u_con(klon,klev),d_v_con(klon,klev)
       REAL d_t_lsc(klon,klev),d_q_lsc(klon,klev),d_ql_lsc(klon,klev)
-c      REAL d_t_ajs(klon,klev), d_q_ajs(klon,klev)
+      REAL d_t_ajs(klon,klev), d_q_ajs(klon,klev)
       REAL d_t_eva(klon,klev),d_q_eva(klon,klev)
       REAL rneb(klon,klev)
@@ -580,5 +590,6 @@
      .         rlat,rlon,ftsol,ftsoil,deltat,fqsol,fsnow,
      .        radsol,rugmer,agesno,clesphy0,
-     .       zmea,zstd,zsig,zgam,zthe,zpic,zval,rugoro,tabcntr0 )
+     .       zmea,zstd,zsig,zgam,zthe,zpic,zval,rugoro,tabcntr0,
+     .       t_ancien, q_ancien, ancien_ok )
 
 c
@@ -1085,11 +1096,11 @@
      .                "ave(X)", zsto,zout)
 c
-c         CALL histdef(nid_mth, "dtajs", "Dry adjust. dT", "K/s",
-c     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
-c     .                "ave(X)", zsto,zout)
-c
-c         CALL histdef(nid_mth, "dqajs", "Dry adjust. dQ", "Kg/Kg/s",
-c     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
-c     .                "ave(X)", zsto,zout)
+         CALL histdef(nid_mth, "dtajs", "Dry adjust. dT", "K/s",
+     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+
+         CALL histdef(nid_mth, "dqajs", "Dry adjust. dQ", "Kg/Kg/s",
+     .                iim,jjm+1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "dtswr", "SW radiation dT", "K/s",
@@ -1332,4 +1343,23 @@
       ENDIF
 c
+c Diagnostiquer la tendance dynamique
+c
+      IF (ancien_ok) THEN
+         DO k = 1, klev
+         DO i = 1, klon
+            d_t_dyn(i,k) = (t_seri(i,k)-t_ancien(i,k))/dtime
+            d_q_dyn(i,k) = (q_seri(i,k)-q_ancien(i,k))/dtime
+         ENDDO
+         ENDDO
+      ELSE
+         DO k = 1, klev
+         DO i = 1, klon
+            d_t_dyn(i,k) = 0.0
+            d_q_dyn(i,k) = 0.0
+         ENDDO
+         ENDDO
+         ancien_ok = .TRUE.
+      ENDIF
+c
 c Ajouter le geopotentiel du sol:
 c
@@ -1360,4 +1390,53 @@
          CALL ozonecm( FLOAT(julien), rlat, paprs, wo)
       ENDIF
+cccccccccc
+      IF (ok_oasis .AND. MOD(itap-1,nexca).EQ.0) THEN
+C
+         CALL fromcpl(itap,(jjm+1)*iim,
+     .        cpl_sst,cpl_sic,cpl_alb_sst,cpl_alb_sic)
+         DO i = 1, iim-1 ! un seul point pour le pole nord
+            cpl_sst(i,1) = cpl_sst(iim,1)
+            cpl_sic(i,1) = cpl_sic(iim,1)
+            cpl_alb_sst(i,1) = cpl_alb_sst(iim,1)
+            cpl_alb_sic(i,1) = cpl_alb_sic(iim,1)
+         ENDDO
+         DO i = 2, iim ! un seul point pour le pole sud
+            cpl_sst(i,jjm+1) = cpl_sst(1,jjm+1)
+            cpl_sic(i,jjm+1) = cpl_sic(1,jjm+1)
+            cpl_alb_sst(i,jjm+1) = cpl_alb_sst(1,jjm+1)
+            cpl_alb_sic(i,jjm+1) = cpl_alb_sic(1,jjm+1)
+         ENDDO
+c
+         ig = 1
+         IF (pctsrf(ig,is_oce).GT.epsfra .OR.
+     .       pctsrf(ig,is_sic).GT.epsfra) THEN
+            pctsrf(ig,is_oce) = pctsrf(ig,is_oce)
+     .                        - (cpl_sic(1,1)-pctsrf(ig,is_sic))
+            pctsrf(ig,is_sic) = cpl_sic(1,1)
+            lmt_sst(ig) = cpl_sst(1,1)
+         ENDIF
+         DO j = 2, jjm
+         DO i = 1, iim
+         ig = ig + 1
+         IF (pctsrf(ig,is_oce).GT.epsfra .OR.
+     .       pctsrf(ig,is_sic).GT.epsfra) THEN
+           pctsrf(ig,is_oce) = pctsrf(ig,is_oce)
+     .                       - (cpl_sic(i,j)-pctsrf(ig,is_sic))
+           pctsrf(ig,is_sic) = cpl_sic(i,j)
+           lmt_sst(ig) = cpl_sst(i,j)
+         ENDIF
+         ENDDO
+         ENDDO
+         ig = ig + 1
+         IF (pctsrf(ig,is_oce).GT.epsfra .OR.
+     .       pctsrf(ig,is_sic).GT.epsfra) THEN
+            pctsrf(ig,is_oce) = pctsrf(ig,is_oce)
+     .                        - (cpl_sic(1,jjm+1)-pctsrf(ig,is_sic))
+            pctsrf(ig,is_sic) = cpl_sic(1,jjm+1)
+            lmt_sst(ig) = cpl_sst(1,jjm+1)
+         ENDIF
+c
+      ENDIF ! ok_oasis
+cccccccccc
 c
  
@@ -1482,5 +1561,5 @@
       DO k = 1, klev
       DO i = 1, klon
-         conv_q(i,k) = d_qx_dyn(i,k,ivap) 
+         conv_q(i,k) = d_q_dyn(i,k) 
      .               + d_q_vdf(i,k)/dtime
          conv_t(i,k) = d_t_dyn(i,k) 
@@ -1489,5 +1568,19 @@
       ENDDO
       IF (check) THEN
-         CALL qcheck(klon,klev,paprs,q_seri,ql_seri,"avantcon=")
+         za = qcheck(klon,klev,paprs,q_seri,ql_seri,paire)
+         PRINT*, "avantcon=", za
+      ENDIF
+      zx_ajustq = .FALSE.
+      IF (iflag_con.EQ.2) zx_ajustq=.TRUE.
+      IF (zx_ajustq) THEN
+         DO i = 1, klon
+            z_avant(i) = 0.0
+         ENDDO
+         DO k = 1, klev
+         DO i = 1, klon
+            z_avant(i) = z_avant(i) + (q_seri(i,k)+ql_seri(i,k))
+     .                        *(paprs(i,k)-paprs(i,k+1))/RG
+         ENDDO
+         ENDDO
       ENDIF
       IF (iflag_con.EQ.1) THEN
@@ -1526,12 +1619,39 @@
       ENDDO
       IF (check) THEN
-         CALL qcheck(klon,klev,paprs,q_seri,ql_seri,"aprescon=")
+         za = qcheck(klon,klev,paprs,q_seri,ql_seri,paire)
+         PRINT*, "aprescon=", za
          zx_t = 0.0
+         za = 0.0
          DO i = 1, klon
-            zx_t = zx_t + rain_con(i)+snow_con(i)
-         ENDDO
-         zx_t = zx_t/FLOAT(klon)*dtime
+            za = za + paire(i)/FLOAT(klon)
+            zx_t = zx_t + (rain_con(i)+snow_con(i))*paire(i)/FLOAT(klon)
+        ENDDO
+         zx_t = zx_t/za*dtime
          PRINT*, "Precip=", zx_t
       ENDIF
+      IF (zx_ajustq) THEN
+         DO i = 1, klon
+            z_apres(i) = 0.0
+         ENDDO
+         DO k = 1, klev
+         DO i = 1, klon
+            z_apres(i) = z_apres(i) + (q_seri(i,k)+ql_seri(i,k))
+     .                        *(paprs(i,k)-paprs(i,k+1))/RG
+         ENDDO
+         ENDDO
+         DO i = 1, klon
+         z_factor(i) = (z_avant(i)-(rain_con(i)+snow_con(i))*dtime)
+     .                /z_apres(i)
+         ENDDO
+         DO k = 1, klev
+         DO i = 1, klon
+         IF (z_factor(i).GT.(1.0+1.0E-08) .OR.
+     .       z_factor(i).LT.(1.0-1.0E-08)) THEN
+               q_seri(i,k) = q_seri(i,k) * z_factor(i)
+         ENDIF
+         ENDDO
+         ENDDO
+      ENDIF
+      zx_ajustq=.FALSE.
 c
       IF (nqmax.GT.2) THEN !--melange convectif de traceurs
@@ -1575,10 +1695,13 @@
       ENDDO
       IF (check) THEN
-         CALL qcheck(klon,klev,paprs,q_seri,ql_seri,"apresilp=")
+         za = qcheck(klon,klev,paprs,q_seri,ql_seri,paire)
+         PRINT*, "apresilp=", za
          zx_t = 0.0
+         za = 0.0
          DO i = 1, klon
-            zx_t = zx_t + rain_lsc(i)+snow_lsc(i)
-         ENDDO
-         zx_t = zx_t/FLOAT(klon)*dtime
+            za = za + paire(i)/FLOAT(klon)
+            zx_t = zx_t + (rain_lsc(i)+snow_lsc(i))*paire(i)/FLOAT(klon)
+        ENDDO
+         zx_t = zx_t/za*dtime
          PRINT*, "Precip=", zx_t
       ENDIF
@@ -1587,7 +1710,21 @@
 c
       IF (iflag_con.EQ.2) THEN ! seulement pour Tiedtke
-      CALL diagcld(paprs,pplay,t_seri,q_seri,
+      CALL diagcld1(paprs,pplay,
      .             rain_con,snow_con,ibas_con,itop_con,
      .             diafra,dialiq)
+      DO k = 1, klev
+      DO i = 1, klon
+      IF (diafra(i,k).GT.cldfra(i,k)) THEN
+         cldliq(i,k) = dialiq(i,k)
+         cldfra(i,k) = diafra(i,k)
+      ENDIF
+      ENDDO
+      ENDDO
+      ENDIF
+c
+c Nuages stratus artificiels:
+c
+      IF (ok_stratus) THEN
+      CALL diagcld2(paprs,pplay,t_seri,q_seri, diafra,dialiq)
       DO k = 1, klev
       DO i = 1, klon
@@ -2210,11 +2347,11 @@
      .                                   iim*(jjm+1)*klev,ndex3d)
 c
-C      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_ajs, zx_tmp_3d)
-C      CALL histwrite(nid_mth,"dtajs",itap,zx_tmp_3d,
-C    .                                   iim*(jjm+1)*klev,ndex3d)
-c
-C      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_ajs, zx_tmp_3d)
-C      CALL histwrite(nid_mth,"dqajs",itap,zx_tmp_3d,
-C     .                                   iim*(jjm+1)*klev,ndex3d)
+      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_t_ajs, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtajs",itap,zx_tmp_3d,
+     .                                   iim*(jjm+1)*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjm+1, d_q_ajs, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dqajs",itap,zx_tmp_3d,
+     .                                   iim*(jjm+1)*klev,ndex3d)
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjm+1, heat, zx_tmp_3d)
@@ -2480,4 +2617,13 @@
       ENDIF
 c
+c Sauvegarder les valeurs de t et q a la fin de la physique:
+c
+      DO k = 1, klev
+      DO i = 1, klon
+         t_ancien(i,k) = t_seri(i,k)
+         q_ancien(i,k) = q_seri(i,k)
+      ENDDO
+      ENDDO
+c
 c====================================================================
 c Si c'est la fin, il faut conserver l'etat de redemarrage
@@ -2485,14 +2631,15 @@
 c
       IF (lafin) THEN
-         IF (ok_oasis) CALL quitcpl
+ccc         IF (ok_oasis) CALL quitcpl
          CALL phyredem ("restartphy.nc",dtime,radpas,co2_ppm,solaire,
      .        rlat,rlon,ftsol,ftsoil,deltat,fqsol,fsnow,
      .        radsol,rugmer,agesno,
-     .        zmea,zstd,zsig,zgam,zthe,zpic,zval,rugoro)
+     .        zmea,zstd,zsig,zgam,zthe,zpic,zval,rugoro,
+     .        t_ancien, q_ancien)
       ENDIF
 
       RETURN
       END
-      SUBROUTINE qcheck(klon,klev,paprs,q,ql,marque)
+      FUNCTION qcheck(klon,klev,paprs,q,ql,aire)
       IMPLICIT none
 c
@@ -2503,18 +2650,23 @@
       INTEGER klon,klev
       REAL paprs(klon,klev+1), q(klon,klev), ql(klon,klev)
-      CHARACTER *(*) marque
-      REAL qtotal
+      REAL aire(klon)
+      REAL qtotal, zx, qcheck
       INTEGER i, k
 c
+      zx = 0.0
+      DO i = 1, klon
+         zx = zx + aire(i)
+      ENDDO
       qtotal = 0.0
       DO k = 1, klev
       DO i = 1, klon
-         qtotal = qtotal + (q(i,k)+ql(i,k))
+         qtotal = qtotal + (q(i,k)+ql(i,k)) * aire(i)
      .                     *(paprs(i,k)-paprs(i,k+1))/RG
       ENDDO
       ENDDO
 c
-      PRINT*, "Eau totale ",marque, qtotal/FLOAT(klon)
-c
+      qcheck = qtotal/zx
+c
+      RETURN
       END
       SUBROUTINE gr_fi_ecrit(nfield,nlon,iim,jjmp1,fi,ecrit)
