Index: trunk/LMDZ.MARS/libf/phymars/watercloud_mod.F
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/watercloud_mod.F	(revision 2966)
+++ trunk/LMDZ.MARS/libf/phymars/watercloud_mod.F	(revision 2984)
@@ -47,7 +47,6 @@
 c  2004 - 2012
 c
-c     2023: J. Naar, adding different subtimestep on each grid cell
-c          plus not doing microphysics if no water present
-c          plus simpleclouds no longer in the loop for microphysics
+c     2023: J. Naar, now with adaptative timestep for improvedclouds
+c          (done in improvedclouds_mod). 
 c=======================================================================
 
@@ -146,5 +145,5 @@
 ! Scheme for adaptative timestep J. Naar 2023
 c      LOGICAL :: computed_micro(ngrid,nlay) ! Check if microphy was done in this cell
-      REAL :: computed_micro(ngrid,nlay) ! Check if microphy was done inthis cell (logical)
+      REAL :: count_micro(ngrid,nlay) ! Initially computed microtimestep
       REAL :: zt_micro(ngrid,nlay) ! Temperature during microphysics (K)
       REAL :: zq_micro(ngrid,nlay,nq) ! Tracers during microphysics (kg/kg) 
@@ -155,4 +154,6 @@
       REAL :: zpotcond(ngrid,nlay) ! maximal condensable water, used to
 compute adaptative subdivision of ptimestep
+      REAL :: spenttime ! timespent
+      REAL :: zdq ! used to compute adaptative timestep
 
 
@@ -298,94 +299,45 @@
       END IF ! end if (CLFvarying)
 c------------------------------------------------------------------
-c Time subsampling for microphysics
+c Cloud physics (nucleation, condensation / sublimation)
 c------------------------------------------------------------------ 
       rhocloud(1:ngrid,1:nlay) = rho_dust
 
-
-c     Initialisation of all the stuff JN2023
-c      computed_micro(1:ngrid,1:nlay)=.false.
-      computed_micro(1:ngrid,1:nlay)=0.
+c     Initialisation of all the stuff (JN,2023)
       zt_micro(:,:)=pt(:,:)
       zq_micro(:,:,:)=pq(:,:,:)
-      zq_micro(:,:,:)=pq(:,:,:)
-      call watersat(ngrid*nlay,zt_micro,pplay,zqsat_micro)
-      zpotcond_inst=zq_micro(:,:,igcm_h2o_vap) - zqsat_micro
-      call watersat(ngrid*nlay,zt_micro+pdt*ptimestep,pplay,zqsat_micro)
-      zpotcond_full=(zq_micro(:,:,igcm_h2o_vap)+
-     &             pdq(:,:,igcm_h2o_vap)*ptimestep) - zqsat_micro
-      zimicro(1:ngrid,1:nlay)=imicro
-      if (cloud_adapt_ts) then
-              call adapt_imicro(ptimestep,zpotcond(ig,l),
-     $                   zimicro(ig,l))
-      endif! (cloud_adapt_ts) then
-      DO l=1,nlay
-        DO ig=1,ngrid
-c         Start by computing the condensable water vapor amount
-          if (zpotcond_full(ig,l).gt.0.) then
-            zpotcond(ig,l)=max(zpotcond_inst(ig,l),zpotcond_full(ig,l))
-          else if (zpotcond_full(ig,l).le.0.) then
-            zpotcond(ig,l)=min(zpotcond_inst(ig,l),zpotcond_full(ig,l))
-          endif! (zpotcond_full.gt.0.) then
-          microtimestep=ptimestep/real(zimicro(ig,l))
-c         Check if microphysics is even needed, that is if enough action
-c         is happening water-wise
-          if ((pq(ig,l,igcm_h2o_ice)+pdq(ig,l,igcm_h2o_ice)*ptimestep
-     &      .gt.1e-22) .or. (abs(zpotcond(ig,l)).gt.1e-22)) then
-c         Eventuellement sortir simpleclouds de la boucle egalement
-          computed_micro(ig,l)=1.
-          DO microstep=1,zimicro(ig,l) 
-      
-
-c JN : incrementing after main microphysics scheme
-c Previously we were incrementing tendencies, we now
-c increment tracers and temperature directly
-c We are thus starting at the end of the first iteration
-c 
+
 c-------------------------------------------------------------------
 c   1.  Main call to the different cloud schemes:
 c------------------------------------------------
-        IF (microphys) THEN
-           CALL improvedclouds(microtimestep,
-     &          pplay(ig,l),zt_micro(ig,l), 
-     &          zq_micro(ig,l,:),subpdqcloud(ig,l,:),
-     &          subpdtcloud(ig,l),nq,tauscaling(ig),mmean(ig,l))
-
-        ELSE
-c Simpleclouds should maybe be taken out and put in a specific loop ?
-           CALL simpleclouds(ngrid,nlay,microtimestep,
+c ds.
+      IF (microphys) THEN
+           CALL improvedclouds(ngrid,nlay,ptimestep,
+     &          pplay,pt,pdt,pq,pdq,nq,tauscaling,imicro,
+     &          zt_micro,zq_micro)
+
+      ELSE
+
+c Specific loop for simpleclouds.
+       DO l=1,nlay
+         DO ig=1,ngrid
+           CALL simpleclouds(ngrid,nlay,ptimestep,
      &             pplay,pzlay,pteff,sum_subpdt,
      &             pqeff,sum_subpdq,subpdqcloud,subpdtcloud,
      &             nq,tau,rice)
-        ENDIF
-
 c-------------------------------------------------------------------
 c   2.  Updating tracers and temperature after cloud scheme:
+c   For improved clouds (with microphysics) this is done directly
+c   in the microphysics, during the subtimestep
+c   I put it like that to be retrocompatible (JN)
 c-----------------------------------------------
 
-        IF (microphys) THEN
-              zq_micro(ig,l,igcm_dust_mass) =
-     &         zq_micro(ig,l,igcm_dust_mass)+(pdq(ig,l,igcm_dust_mass)
-     &         +subpdqcloud(ig,l,igcm_dust_mass))*microtimestep
-              zq_micro(ig,l,igcm_dust_number) =
-     &         zq_micro(ig,l,igcm_dust_number)
-     &         +(pdq(ig,l,igcm_dust_number)
-     &         + subpdqcloud(ig,l,igcm_dust_number))*microtimestep
-              zq_micro(ig,l,igcm_ccn_mass) =
-     &         zq_micro(ig,l,igcm_ccn_mass) +
-     &         (pdq(ig,l,igcm_ccn_mass)
-     &         +subpdqcloud(ig,l,igcm_ccn_mass))*microtimestep
-              zq_micro(ig,l,igcm_ccn_number) =
-     &          zq_micro(ig,l,igcm_ccn_number) +
-     &         (pdq(ig,l,igcm_ccn_number)
-     &          + subpdqcloud(ig,l,igcm_ccn_number))*microtimestep
-        ENDIF
             zq_micro(ig,l,igcm_h2o_ice) =
      &       zq_micro(ig,l,igcm_h2o_ice)+
      &         (pdq(ig,l,igcm_h2o_ice)
-     &        + subpdqcloud(ig,l,igcm_h2o_ice))*microtimestep
+     &        + subpdqcloud(ig,l,igcm_h2o_ice))*ptimestep
             zq_micro(ig,l,igcm_h2o_vap) =
      &       zq_micro(ig,l,igcm_h2o_vap)+
      &         (pdq(ig,l,igcm_h2o_vap)
-     &        + subpdqcloud(ig,l,igcm_h2o_vap))*microtimestep
+     &        + subpdqcloud(ig,l,igcm_h2o_vap))*ptimestep
 
             IF (hdo) THEN
@@ -393,36 +345,24 @@
      &       zq_micro(ig,l,igcm_hdo_ice)+
      &         (pdq(ig,l,igcm_hdo_ice)
-     &        + subpdqcloud(ig,l,igcm_hdo_ice))*microtimestep
+     &        + subpdqcloud(ig,l,igcm_hdo_ice))*ptimestep
             zq_micro(ig,l,igcm_hdo_vap) =
      &       zq_micro(ig,l,igcm_hdo_vap)+
      &         (pdq(ig,l,igcm_hdo_vap)
-     &        + subpdqcloud(ig,l,igcm_hdo_vap))*microtimestep
+     &        + subpdqcloud(ig,l,igcm_hdo_vap))*ptimestep
             ENDIF ! hdo
 
 c  Could also set subpdtcloud to 0 if not activice to make it simpler
-            zt_micro(ig,l) = zt_micro(ig,l)+
-     &           pdt(ig,l)*microtimestep
-        IF (activice) THEN
-              zt_micro(ig,l) = zt_micro(ig,l)+
-     &           subpdtcloud(ig,l)*microtimestep
-        ENDIF
-!      !! Example of how to use writediagmicrofi useful to 
-!      !! get outputs at each microphysical sub-timestep (better to be used in 1D)
-!            CALL WRITEDIAGMICROFI(ngrid,imicro,microstep,
-!     &       microtimestep,'subpdtcloud',
-!     &      'subpdtcloud','K/s',1,subpdtcloud(:,:))     
- 
-          ENDDO ! of DO microstep=1,imicro
-          endif! (zq(ig,l,igcm_h2o_ice)+pdq(ig,l,igcm_h2o_ice)*ptimestep
-!     &      .gt.1e-22).or.(abs(zpotcond).gt.1e-22) then
-        ENDDO ! ig=1,ngrid
-      ENDDO ! l=1,nlay
-
-      
-c------ Useful outputs to check how it went
-      call write_output("computed_micro","computed_micro "//
-     &   "after microphysics","logical",computed_micro(:,:))
-      call write_output("zimicro","Used number of subtimestep "//
-     &   "in cloud microphysics","integer",real(zimicro(:,:)))
+c  or change name of the flag
+            IF (activice) THEN
+                zt_micro(ig,l) = zt_micro(ig,l)+
+     &             subpdtcloud(ig,l)*ptimestep
+            ENDIF
+
+         ENDDO !ig=1,ngrid
+       ENDDO !l=1,nlay
+      ENDIF
+
+
+      
 c-------------------------------------------------------------------
 c   3.  Compute final tendencies after time loop:
@@ -786,19 +726,3 @@
 
 
-       SUBROUTINE adapt_imicro(ptimestep,potcond,
-     $                     zimicro)
-
-c Pas de temps adaptatif pour les nuages
-
-      real,intent(in) :: ptimestep ! total duration of physics (sec)
-      real,intent(in) :: potcond ! total duration of physics (sec)
-      real :: alpha, beta ! total duration of physics (sec)
-      integer,intent(out) :: zimicro ! number of ptimestep division
-
-c       zimicro = ptimestep*alpha*potcond**beta
-       zimicro = 30
-
-       END SUBROUTINE adapt_imicro
-
-
       END MODULE watercloud_mod 
