Index: LMDZ5/branches/testing/libf/bibio/cray.F
===================================================================
--- LMDZ5/branches/testing/libf/bibio/cray.F	(revision 1795)
+++ LMDZ5/branches/testing/libf/bibio/cray.F	(revision 1795)
@@ -0,0 +1,42 @@
+!
+! $Header$
+!
+#ifdef CRAY
+      SUBROUTINE riencray
+      END
+#else
+      subroutine scopy(n,sx,incx,sy,incy)
+c
+      IMPLICIT NONE
+c
+      integer n,incx,incy,ix,iy,i
+      real sx((n-1)*incx+1),sy((n-1)*incy+1)
+c
+      iy=1
+      ix=1
+      do 10 i=1,n
+         sy(iy)=sx(ix)
+         ix=ix+incx
+         iy=iy+incy
+10    continue
+c
+      return
+      end
+
+      function ssum(n,sx,incx)
+c
+      IMPLICIT NONE
+c
+      integer n,incx,i,ix
+      real ssum,sx((n-1)*incx+1)
+c
+      ssum=0.
+      ix=1
+      do 10 i=1,n
+         ssum=ssum+sx(ix)
+         ix=ix+incx
+10    continue
+c
+      return
+      end
+#endif
Index: LMDZ5/branches/testing/libf/bibio/ismax.F
===================================================================
--- LMDZ5/branches/testing/libf/bibio/ismax.F	(revision 1795)
+++ LMDZ5/branches/testing/libf/bibio/ismax.F	(revision 1795)
@@ -0,0 +1,24 @@
+!
+! $Header$
+!
+      function ismax(n,sx,incx)
+c
+      IMPLICIT NONE
+c
+      INTEGER n,i,incx,ismax,ix
+      real sx((n-1)*incx+1),sxmax
+c
+      ix=1
+      ismax=1
+      sxmax=sx(1)
+      do 10 i=1,n-1
+       ix=ix+incx
+       if(sx(ix).gt.sxmax) then
+         sxmax=sx(ix)
+         ismax=i+1
+       endif
+10    continue
+c
+      return
+      end
+
Index: LMDZ5/branches/testing/libf/bibio/ismin.F
===================================================================
--- LMDZ5/branches/testing/libf/bibio/ismin.F	(revision 1795)
+++ LMDZ5/branches/testing/libf/bibio/ismin.F	(revision 1795)
@@ -0,0 +1,24 @@
+!
+! $Header$
+!
+      FUNCTION ismin(n,sx,incx)
+c
+      IMPLICIT NONE
+c
+      integer n,i,incx,ismin,ix
+      real sx((n-1)*incx+1),sxmin
+c
+      ix=1
+      ismin=1
+      sxmin=sx(1)
+      DO i=1,n-1
+         ix=ix+incx
+         if(sx(ix).lt.sxmin) then
+             sxmin=sx(ix)
+             ismin=i+1
+         endif
+      ENDDO
+c
+      return
+      end
+C
Index: LMDZ5/branches/testing/libf/dyn3d/ce0l.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/ce0l.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3d/ce0l.F90	(revision 1795)
@@ -20,4 +20,5 @@
   USE comgeomphy
   USE infotrac
+  USE indice_sol_mod
 
 #ifdef CPP_IOIPSL
@@ -36,5 +37,5 @@
 #include "dimensions.h"
 #include "paramet.h"
-#include "indicesol.h"
+!#include "indicesol.h"
 #include "iniprint.h"
 #include "temps.h"
Index: LMDZ5/branches/testing/libf/dyn3d/comconst.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/comconst.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3d/comconst.h	(revision 1795)
@@ -6,5 +6,5 @@
 
       COMMON/comconsti/im,jm,lllm,imp1,jmp1,lllmm1,lllmp1,lcl,          &
-     &                 iflag_top_bound
+     &                 iflag_top_bound,mode_top_bound
       COMMON/comconstr/dtvr,daysec,                                     &
      & pi,dtphys,dtdiss,rad,r,cpp,kappa,cotot,unsim,g,omeg              &
@@ -30,6 +30,8 @@
       REAL omeg ! (rad/s) rotation rate of the planet
       REAL dissip_factz,dissip_deltaz,dissip_zref
-      INTEGER iflag_top_bound
-      REAL tau_top_bound
+! top_bound sponge:
+      INTEGER iflag_top_bound ! sponge type
+      INTEGER mode_top_bound  ! sponge mode
+      REAL tau_top_bound ! inverse of sponge characteristic time scale (Hz)
       REAL daylen ! length of solar day, in 'standard' day length
       REAL year_day ! Number of standard days in a year
Index: LMDZ5/branches/testing/libf/dyn3d/comvert.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/comvert.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3d/comvert.h	(revision 1795)
@@ -23,5 +23,6 @@
       real bps    ! hybrid sigma contribution at mid-layers
       real scaleheight ! atmospheric (reference) scale height (km)
-      real pseudoalt ! for planets
+      real pseudoalt ! pseudo-altitude of model levels (km), based on presnivs(),
+                     ! preff and scaleheight
 
       integer disvert_type ! type of vertical discretization:
Index: LMDZ5/branches/testing/libf/dyn3d/conf_gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/conf_gcm.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3d/conf_gcm.F	(revision 1795)
@@ -307,7 +307,21 @@
        CALL getin('dissip_zref',dissip_zref )
 
+! top_bound sponge: only active if ok_strato=.true. and iflag_top_bound!=0
+!                   iflag_top_bound=0 for no sponge
+!                   iflag_top_bound=1 for sponge over 4 topmost layers
+!                   iflag_top_bound=2 for sponge from top to ~1% of top layer pressure
        iflag_top_bound=1
+       CALL getin('iflag_top_bound',iflag_top_bound)
+
+! mode_top_bound : fields towards which sponge relaxation will be done:
+!                  mode_top_bound=0: no relaxation
+!                  mode_top_bound=1: u and v relax towards 0
+!                  mode_top_bound=2: u and v relax towards their zonal mean
+!                  mode_top_bound=3: u,v and pot. temp. relax towards their zonal mean
+       mode_top_bound=3
+       CALL getin('mode_top_bound',mode_top_bound)
+
+! top_bound sponge : inverse of charactericstic relaxation time scale for sponge
        tau_top_bound=1.e-5
-       CALL getin('iflag_top_bound',iflag_top_bound)
        CALL getin('tau_top_bound',tau_top_bound)
 
Index: LMDZ5/branches/testing/libf/dyn3d/cray.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/cray.F	(revision 1750)
+++ 	(revision )
@@ -1,42 +1,0 @@
-!
-! $Header$
-!
-#ifdef CRAY
-      SUBROUTINE riencray
-      END
-#else
-      subroutine scopy(n,sx,incx,sy,incy)
-c
-      IMPLICIT NONE
-c
-      integer n,incx,incy,ix,iy,i
-      real sx((n-1)*incx+1),sy((n-1)*incy+1)
-c
-      iy=1
-      ix=1
-      do 10 i=1,n
-         sy(iy)=sx(ix)
-         ix=ix+incx
-         iy=iy+incy
-10    continue
-c
-      return
-      end
-
-      function ssum(n,sx,incx)
-c
-      IMPLICIT NONE
-c
-      integer n,incx,i,ix
-      real ssum,sx((n-1)*incx+1)
-c
-      ssum=0.
-      ix=1
-      do 10 i=1,n
-         ssum=ssum+sx(ix)
-         ix=ix+incx
-10    continue
-c
-      return
-      end
-#endif
Index: LMDZ5/branches/testing/libf/dyn3d/gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/gcm.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3d/gcm.F	(revision 1795)
@@ -16,4 +16,9 @@
       USE infotrac
       USE control_mod
+
+#ifdef INCA
+! Only INCA needs these informations (from the Earth's physics)
+      USE indice_sol_mod
+#endif
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -77,5 +82,5 @@
 #ifdef INCA
 ! Only INCA needs these informations (from the Earth's physics)
-#include "indicesol.h"
+!#include "indicesol.h"
 #endif
       INTEGER         longcles
Index: LMDZ5/branches/testing/libf/dyn3d/inigeom.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/inigeom.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3d/inigeom.F	(revision 1795)
@@ -426,10 +426,10 @@
          radclatm = 0.5* rad * coslatm
 c
+         ai14            = un4rad2 * coslatp * yprp
+         ai23            = un4rad2 * coslatm * yprm
          DO 32 i = 1,iim
          xprp            = xprimp025( i )
          xprm            = xprimm025( i )
       
-         ai14            = un4rad2 * coslatp * yprp
-         ai23            = un4rad2 * coslatm * yprm
          aireij1 ( i,j ) = ai14 * xprp
          aireij2 ( i,j ) = ai23 * xprp
Index: LMDZ5/branches/testing/libf/dyn3d/ismax.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/ismax.F	(revision 1750)
+++ 	(revision )
@@ -1,24 +1,0 @@
-!
-! $Header$
-!
-      function ismax(n,sx,incx)
-c
-      IMPLICIT NONE
-c
-      INTEGER n,i,incx,ismax,ix
-      real sx((n-1)*incx+1),sxmax
-c
-      ix=1
-      ismax=1
-      sxmax=sx(1)
-      do 10 i=1,n-1
-       ix=ix+incx
-       if(sx(ix).gt.sxmax) then
-         sxmax=sx(ix)
-         ismax=i+1
-       endif
-10    continue
-c
-      return
-      end
-
Index: LMDZ5/branches/testing/libf/dyn3d/ismin.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/ismin.F	(revision 1750)
+++ 	(revision )
@@ -1,24 +1,0 @@
-!
-! $Header$
-!
-      FUNCTION ismin(n,sx,incx)
-c
-      IMPLICIT NONE
-c
-      integer n,i,incx,ismin,ix
-      real sx((n-1)*incx+1),sxmin
-c
-      ix=1
-      ismin=1
-      sxmin=sx(1)
-      DO i=1,n-1
-         ix=ix+incx
-         if(sx(ix).lt.sxmin) then
-             sxmin=sx(ix)
-             ismin=i+1
-         endif
-      ENDDO
-c
-      return
-      end
-C
Index: LMDZ5/branches/testing/libf/dyn3d/leapfrog.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/leapfrog.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3d/leapfrog.F	(revision 1795)
@@ -436,8 +436,4 @@
      $               clesphy0, dufi,dvfi,dtetafi,dqfi,dpfi  )
 
-         IF (ok_strato) THEN
-           CALL top_bound( vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
-         ENDIF
-       
 c      ajout des tendances physiques:
 c      ------------------------------
@@ -445,4 +441,9 @@
      $                  ucov, vcov, teta , q   ,ps ,
      $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
+
+         IF (ok_strato) THEN
+           CALL top_bound( vcov,ucov,teta,masse,dtphys)
+         ENDIF
+       
 c
 c  Diagnostique de conservation de l'énergie : difference
@@ -476,13 +477,14 @@
         ! Sponge layer (if any)
         IF (ok_strato) THEN
-          dufi(:,:)=0.
-          dvfi(:,:)=0.
-          dtetafi(:,:)=0.
-          dqfi(:,:,:)=0.
-          dpfi(:)=0.
-          CALL top_bound(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
-          CALL addfi( dtvr, leapf, forward   ,
-     $                  ucov, vcov, teta , q   ,ps ,
-     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
+!          dufi(:,:)=0.
+!          dvfi(:,:)=0.
+!          dtetafi(:,:)=0.
+!          dqfi(:,:,:)=0.
+!          dpfi(:)=0.
+!          CALL top_bound(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
+           CALL top_bound( vcov,ucov,teta,masse,dtvr)
+!          CALL addfi( dtvr, leapf, forward   ,
+!     $                  ucov, vcov, teta , q   ,ps ,
+!     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
         ENDIF ! of IF (ok_strato) 
       ENDIF ! of IF (iflag_phys.EQ.2)
Index: LMDZ5/branches/testing/libf/dyn3d/temps.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/temps.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3d/temps.h	(revision 1795)
@@ -13,11 +13,11 @@
 ! INCLUDE 'temps.h'
 
-      COMMON/temps/itaufin, dt, day_ini, day_end, annee_ref, day_ref,   &
-     &             itau_dyn, itau_phy, jD_ref, jH_ref, calend,          &
-     &             start_time
+      COMMON/temps/ dt, jD_ref, jH_ref, start_time,                     &
+     &             day_ini, day_end, annee_ref, day_ref,                &
+     &             itau_dyn, itau_phy, itaufin, calend
 
 
       INTEGER   itaufin
-      INTEGER itau_dyn, itau_phy
+      INTEGER itau_dyn, itau_phy 
       INTEGER day_ini, day_end, annee_ref, day_ref
       REAL      dt, jD_ref, jH_ref, start_time
Index: LMDZ5/branches/testing/libf/dyn3d/top_bound.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3d/top_bound.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3d/top_bound.F	(revision 1795)
@@ -1,3 +1,6 @@
-      SUBROUTINE top_bound( vcov,ucov,teta,masse, du,dv,dh )
+!
+! $Id$
+!
+      SUBROUTINE top_bound(vcov,ucov,teta,masse,dt)
       IMPLICIT NONE
 c
@@ -24,17 +27,39 @@
 c
 c=======================================================================
-c-----------------------------------------------------------------------
-c   Declarations:
-c   -------------
 
-! #include "comgeom.h"
+! top_bound sponge layer model:
+! Quenching is modeled as: A(t)=Am+A0*exp(-lambda*t)
+! where Am is the zonal average of the field (or zero), and lambda the inverse
+! of the characteristic quenching/relaxation time scale
+! Thus, assuming Am to be time-independent, field at time t+dt is given by:
+! A(t+dt)=A(t)-(A(t)-Am)*(1-exp(-lambda*t))
+! Moreover lambda can be a function of model level (see below), and relaxation
+! can be toward the average zonal field or just zero (see below).
+
+! NB: top_bound sponge is only called from leapfrog if ok_strato=.true.
+
+! sponge parameters: (loaded/set in conf_gcm.F ; stored in comconst.h)
+!    iflag_top_bound=0 for no sponge
+!    iflag_top_bound=1 for sponge over 4 topmost layers
+!    iflag_top_bound=2 for sponge from top to ~1% of top layer pressure
+!    mode_top_bound=0: no relaxation
+!    mode_top_bound=1: u and v relax towards 0
+!    mode_top_bound=2: u and v relax towards their zonal mean
+!    mode_top_bound=3: u,v and pot. temp. relax towards their zonal mean
+!    tau_top_bound : inverse of charactericstic relaxation time scale at
+!                       the topmost layer (Hz)
+
+
 #include "comdissipn.h"
+#include "iniprint.h"
 
 c   Arguments:
 c   ----------
 
-      REAL ucov(iip1,jjp1,llm),vcov(iip1,jjm,llm),teta(iip1,jjp1,llm)
-      REAL masse(iip1,jjp1,llm)
-      REAL dv(iip1,jjm,llm),du(iip1,jjp1,llm),dh(iip1,jjp1,llm)
+      real,intent(inout) :: ucov(iip1,jjp1,llm) ! covariant zonal wind
+      real,intent(inout) :: vcov(iip1,jjm,llm) ! covariant meridional wind
+      real,intent(inout) :: teta(iip1,jjp1,llm) ! potential temperature
+      real,intent(in) :: masse(iip1,jjp1,llm) ! mass of atmosphere 
+      real,intent(in) :: dt ! time step (s) of sponge model
 
 c   Local:
@@ -44,16 +69,11 @@
       REAL uzon(jjp1,llm),vzon(jjm,llm),tzon(jjp1,llm)
       
-      INTEGER NDAMP
-      PARAMETER (NDAMP=4)
       integer i
-      REAL,SAVE :: rdamp(llm)
-!     &   (/(0., i =1,llm-NDAMP),0.125E-5,.25E-5,.5E-5,1.E-5/) 
+      REAL,SAVE :: rdamp(llm) ! quenching coefficient
+      real,save :: lambda(llm) ! inverse or quenching time scale (Hz)
 
       LOGICAL,SAVE :: first=.true.
 
       INTEGER j,l
-
-
-C  CALCUL DES CHAMPS EN MOYENNE ZONALE:
       
       if (iflag_top_bound.eq.0) return
@@ -61,30 +81,45 @@
       if (first) then
          if (iflag_top_bound.eq.1) then
-! couche eponge dans les 4 dernieres couches du modele
-             rdamp(:)=0.
-             rdamp(llm)=tau_top_bound
-             rdamp(llm-1)=tau_top_bound/2.
-             rdamp(llm-2)=tau_top_bound/4.
-             rdamp(llm-3)=tau_top_bound/8.
+! sponge quenching over the topmost 4 atmospheric layers
+             lambda(:)=0.
+             lambda(llm)=tau_top_bound
+             lambda(llm-1)=tau_top_bound/2.
+             lambda(llm-2)=tau_top_bound/4.
+             lambda(llm-3)=tau_top_bound/8.
          else if (iflag_top_bound.eq.2) then
-! couce eponge dans toutes les couches de pression plus faible que
-! 100 fois la pression de la derniere couche
-             rdamp(:)=tau_top_bound
+! sponge quenching over topmost layers down to pressures which are
+! higher than 100 times the topmost layer pressure
+             lambda(:)=tau_top_bound
      s       *max(presnivs(llm)/presnivs(:)-0.01,0.)
          endif
+
+! quenching coefficient rdamp(:)
+!         rdamp(:)=dt*lambda(:) ! Explicit Euler approx.
+         rdamp(:)=1.-exp(-lambda(:)*dt)
+
+         write(lunout,*)'TOP_BOUND mode',mode_top_bound
+         write(lunout,*)'Sponge layer coefficients'
+         write(lunout,*)'p (Pa)  z(km)  tau(s)   1./tau (Hz)'
+         do l=1,llm
+           if (rdamp(l).ne.0.) then
+             write(lunout,'(6(1pe12.4,1x))')
+     &        presnivs(l),log(preff/presnivs(l))*scaleheight,
+     &           1./lambda(l),lambda(l)
+           endif
+         enddo
          first=.false.
-         print*,'TOP_BOUND rdamp=',rdamp
-      endif
+      endif ! of if (first)
 
       CALL massbar(masse,massebx,masseby)
 
-      do l=1,llm
+      ! compute zonal average of vcov and u
+      if (mode_top_bound.ge.2) then
+       do l=1,llm
         do j=1,jjm
           vzon(j,l)=0.
           zm=0.
           do i=1,iim
-! Rm: on peut travailler directement avec la moyenne zonale de vcov
-! plutot qu'avec celle de v car le coefficient cv qui relie les deux
-! ne varie qu'en latitude
+! NB: we can work using vcov zonal mean rather than v since the
+! cv coefficient (which relates the two) only varies with latitudes 
             vzon(j,l)=vzon(j,l)+vcov(i,j,l)*masseby(i,j,l)
             zm=zm+masseby(i,j,l)
@@ -92,16 +127,8 @@
           vzon(j,l)=vzon(j,l)/zm
         enddo
-      enddo
+       enddo
 
-      do l=1,llm
-        do i=1,iip1
-          do j=1,jjm
-            dv(i,j,l)=dv(i,j,l)-rdamp(l)*(vcov(i,j,l)-vzon(j,l))
-          enddo
-        enddo
-      enddo
-
-      do l=1,llm
-        do j=2,jjm
+       do l=1,llm
+        do j=2,jjm ! excluding poles
           uzon(j,l)=0.
           zm=0.
@@ -112,8 +139,14 @@
           uzon(j,l)=uzon(j,l)/zm
         enddo
-      enddo
+       enddo
+      else ! ucov and vcov will relax towards 0
+        vzon(:,:)=0.
+        uzon(:,:)=0.
+      endif ! of if (mode_top_bound.ge.2)
 
-      do l=1,llm
-        do j=2,jjm
+      ! compute zonal average of potential temperature, if necessary
+      if (mode_top_bound.ge.3) then
+       do l=1,llm
+        do j=2,jjm ! excluding poles
           zm=0.
           tzon(j,l)=0.
@@ -124,19 +157,40 @@
           tzon(j,l)=tzon(j,l)/zm
         enddo
-      enddo
+       enddo
+      endif ! of if (mode_top_bound.ge.3)
 
-C   AMORTISSEMENTS LINEAIRES:
-
-      do l=1,llm
+      if (mode_top_bound.ge.1) then
+       ! Apply sponge quenching on vcov:
+       do l=1,llm
         do i=1,iip1
-          do j=2,jjm
-            du(i,j,l)=du(i,j,l)
-     s               -rdamp(l)*(ucov(i,j,l)-cu(i,j)*uzon(j,l))
-            dh(i,j,l)=dh(i,j,l)-rdamp(l)*(teta(i,j,l)-tzon(j,l))
+          do j=1,jjm
+            vcov(i,j,l)=vcov(i,j,l)
+     &                  -rdamp(l)*(vcov(i,j,l)-vzon(j,l))
           enddo
         enddo
-      enddo
-      
+       enddo
 
-      RETURN
+       ! Apply sponge quenching on ucov:
+       do l=1,llm
+        do i=1,iip1
+          do j=2,jjm ! excluding poles
+            ucov(i,j,l)=ucov(i,j,l)
+     &                  -rdamp(l)*(ucov(i,j,l)-cu(i,j)*uzon(j,l))
+          enddo
+        enddo
+       enddo
+      endif ! of if (mode_top_bound.ge.1)
+
+      if (mode_top_bound.ge.3) then
+       ! Apply sponge quenching on teta:
+       do l=1,llm
+        do i=1,iip1
+          do j=2,jjm ! excluding poles
+            teta(i,j,l)=teta(i,j,l)
+     &                  -rdamp(l)*(teta(i,j,l)-tzon(j,l))
+          enddo
+        enddo
+       enddo
+      endif ! of if (mode_top_bound.ge.3)
+    
       END
Index: LMDZ5/branches/testing/libf/dyn3dmem/abort_gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/abort_gcm.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/abort_gcm.F	(revision 1795)
@@ -1,4 +1,4 @@
 !
-! $Id$
+! $Id: abort_gcm.F 1747 2013-04-23 14:06:30Z lguez $
 !
 c
@@ -24,5 +24,5 @@
 
       character(len=*) modname
-      integer ierr
+      integer ierr, ierror_mpi
       character(len=*) message
 
@@ -47,5 +47,11 @@
       else
         write(lunout,*) 'Houston, we have a problem ', ierr
+#ifdef CPP_MPI
+C$OMP CRITICAL (MPI_ABORT_GCM)
+        call MPI_ABORT(COMM_LMDZ, 1, ierror_mpi)
+C$OMP END CRITICAL (MPI_ABORT_GCM)
+#else
         stop 1
+#endif          
       endif
       END
Index: LMDZ5/branches/testing/libf/dyn3dmem/calfis_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/calfis_loc.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/calfis_loc.F	(revision 1795)
@@ -34,8 +34,8 @@
       USE dimphy
       USE mod_phys_lmdz_para, mpi_root_xx=>mpi_root 
-      USE parallel, ONLY : omp_chunk, using_mpi,jjb_u,jje_u,jjb_v,jje_v
       USE mod_interface_dyn_phys
       USE IOPHY
 #endif
+      USE parallel, ONLY : omp_chunk, using_mpi,jjb_u,jje_u,jjb_v,jje_v
       USE Write_Field
       Use Write_field_p
@@ -116,6 +116,6 @@
 c    -----------
       LOGICAL  lafin
-      REAL heure
-
+!      REAL heure
+      REAL, intent(in):: jD_cur, jH_cur
       REAL pvcov(iip1,jjb_v:jje_v,llm)
       REAL pucov(iip1,jjb_u:jje_u,llm)
@@ -130,4 +130,5 @@
       REAL pdteta(iip1,jjb_u:jje_u,llm)
       REAL pdq(iip1,jjb_u:jje_u,llm,nqtot)
+      REAL flxw(iip1,jjb_u:jje_u,llm)  ! Flux de masse verticale sur la grille dynamique
 c
       REAL pps(iip1,jjb_u:jje_u)
@@ -226,5 +227,4 @@
       REAL PVteta(klon,ntetaSTD)
       
-      REAL flxw(iip1,jjb_u:jje_u,llm)  ! Flux de masse verticale sur la grille dynamique
       
       REAL SSUM
@@ -234,5 +234,4 @@
       SAVE firstcal,debut
 c$OMP THREADPRIVATE(firstcal,debut)
-      REAL, intent(in):: jD_cur, jH_cur
       
       REAL,SAVE,dimension(1:iim,1:llm):: du_send,du_recv,dv_send,dv_recv
Index: LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/call_calfis_mod.F90	(revision 1795)
@@ -321,8 +321,4 @@
 #endif
 
-    IF (ok_strato) THEN
-      CALL top_bound_loc( vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
-    ENDIF
-
 #ifdef DEBUG_IO           
     CALL WriteField_u('ucovfi',ucov)
@@ -348,4 +344,9 @@
     ENDDO
 #endif
+
+    IF (ok_strato) THEN
+!      CALL top_bound_loc( vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
+      CALL top_bound_loc(vcov,ucov,teta,masse,dtphys)
+    ENDIF
 
   !$OMP BARRIER
Index: LMDZ5/branches/testing/libf/dyn3dmem/ce0l.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/ce0l.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/ce0l.F90	(revision 1795)
@@ -23,4 +23,5 @@
   USE infotrac
   USE parallel, ONLY: finalize_parallel
+  USE indice_sol_mod
 
 #ifdef CPP_IOIPSL
@@ -39,5 +40,5 @@
 #include "dimensions.h"
 #include "paramet.h"
-#include "indicesol.h"
+!#include "indicesol.h"
 #include "iniprint.h"
 #include "temps.h"
Index: LMDZ5/branches/testing/libf/dyn3dmem/comconst.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/comconst.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/comconst.h	(revision 1795)
@@ -1,4 +1,4 @@
 !
-! $Id$
+! $Id: comconst.h 1671 2012-10-24 07:10:10Z emillour $
 !
 !-----------------------------------------------------------------------
@@ -6,5 +6,5 @@
 
       COMMON/comconsti/im,jm,lllm,imp1,jmp1,lllmm1,lllmp1,lcl,          &
-     &                 iflag_top_bound
+     &                 iflag_top_bound,mode_top_bound
       COMMON/comconstr/dtvr,daysec,                                     &
      & pi,dtphys,dtdiss,rad,r,cpp,kappa,cotot,unsim,g,omeg              &
@@ -21,6 +21,6 @@
       REAL dtdiss ! (s) time step for the dissipation
       REAL rad ! (m) radius of the planet
-      REAL r ! Reduced Gas constant r=R/mu 
-             ! with R=8.31.. J.K-1.mol-1, mu: mol mass of atmosphere (kg/mol) 
+      REAL r ! Reduced Gas constant r=R/mu
+             ! with R=8.31.. J.K-1.mol-1, mu: mol mass of atmosphere (kg/mol)
       REAL cpp   ! Specific heat Cp (J.kg-1.K-1)
       REAL kappa ! kappa=R/Cp 
@@ -30,6 +30,8 @@
       REAL omeg ! (rad/s) rotation rate of the planet
       REAL dissip_factz,dissip_deltaz,dissip_zref
-      INTEGER iflag_top_bound
-      REAL tau_top_bound
+! top_bound sponge:
+      INTEGER iflag_top_bound ! sponge type
+      INTEGER mode_top_bound  ! sponge mode
+      REAL tau_top_bound ! inverse of sponge characteristic time scale (Hz)
       REAL daylen ! length of solar day, in 'standard' day length
       REAL year_day ! Number of standard days in a year
Index: LMDZ5/branches/testing/libf/dyn3dmem/comvert.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/comvert.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/comvert.h	(revision 1795)
@@ -1,4 +1,4 @@
 !
-! $Id$
+! $Id: comvert.h 1654 2012-09-24 15:07:18Z aslmd $
 !
 !-----------------------------------------------------------------------
@@ -23,5 +23,6 @@
       real bps    ! hybrid sigma contribution at mid-layers
       real scaleheight ! atmospheric (reference) scale height (km)
-      real pseudoalt ! for planets
+      real pseudoalt ! pseudo-altitude of model levels (km), based on presnivs(),
+                     ! preff and scaleheight
 
       integer disvert_type ! type of vertical discretization:
Index: LMDZ5/branches/testing/libf/dyn3dmem/conf_gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/conf_gcm.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/conf_gcm.F	(revision 1795)
@@ -335,7 +335,21 @@
        CALL getin('dissip_zref',dissip_zref )
 
+! top_bound sponge: only active if ok_strato=.true. and iflag_top_bound!=0
+!                   iflag_top_bound=0 for no sponge
+!                   iflag_top_bound=1 for sponge over 4 topmost layers
+!                   iflag_top_bound=2 for sponge from top to ~1% of top layer pressure
        iflag_top_bound=1
+       CALL getin('iflag_top_bound',iflag_top_bound)
+
+! mode_top_bound : fields towards which sponge relaxation will be done:
+!                  mode_top_bound=0: no relaxation
+!                  mode_top_bound=1: u and v relax towards 0
+!                  mode_top_bound=2: u and v relax towards their zonal mean
+!                  mode_top_bound=3: u,v and pot. temp. relax towards their zonal mean
+       mode_top_bound=3
+       CALL getin('mode_top_bound',mode_top_bound)
+
+! top_bound sponge : inverse of charactericstic relaxation time scale for sponge
        tau_top_bound=1.e-5
-       CALL getin('iflag_top_bound',iflag_top_bound)
        CALL getin('tau_top_bound',tau_top_bound)
 
Index: LMDZ5/branches/testing/libf/dyn3dmem/cray.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/cray.F	(revision 1750)
+++ 	(revision )
@@ -1,54 +1,0 @@
-!
-! $Header$
-!
-#ifdef CRAY
-      SUBROUTINE riencray
-      END
-#else
-      subroutine scopy(n,sx,incx,sy,incy)
-c
-      IMPLICIT NONE
-c
-      integer n,incx,incy,ix,iy,i
-      real sx((n-1)*incx+1),sy((n-1)*incy+1)
-c
-      if (incx.eq.1.and.incy.eq.1) then
-      do 10 i=1,n
-         sy(i)=sx(i)
-10    continue
-      else
-      iy=1
-      ix=1
-      do 11 i=1,n
-         sy(iy)=sx(ix)
-         ix=ix+incx
-         iy=iy+incy
-11    continue
-      endif
-c
-      return
-      end
-
-      function ssum(n,sx,incx)
-c
-      IMPLICIT NONE
-c
-      integer n,incx,i,ix
-      real ssum,sx((n-1)*incx+1)
-c
-      ssum=0.
-      if (incx.eq.1) then
-      do 10 i=1,n
-         ssum=ssum+sx(i)
-10    continue
-      else
-      ix=1
-      do 11 i=1,n
-         ssum=ssum+sx(ix)
-         ix=ix+incx
-11    continue
-      endif
-c
-      return
-      end
-#endif
Index: LMDZ5/branches/testing/libf/dyn3dmem/divgrad_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/divgrad_p.F	(revision 1750)
+++ 	(revision )
@@ -1,91 +1,0 @@
-      SUBROUTINE divgrad_p (klevel,h, lh, divgra_out )
-      USE parallel
-      USE times
-      IMPLICIT NONE
-c
-c=======================================================================
-c
-c  Auteur :   P. Le Van
-c  ----------
-c
-c                              lh
-c      calcul de  (div( grad ))   de h  .....
-c      h  et lh  sont des arguments  d'entree pour le s-prog
-c      divgra     est  un argument  de sortie pour le s-prog
-c
-c=======================================================================
-c
-c   declarations:
-c   -------------
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom.h"
-#include "comdissipn.h"
-#include "logic.h"
-c
-      INTEGER klevel
-      REAL h( ip1jmp1,klevel ), divgra_out( ip1jmp1,klevel )
-      REAL,SAVE :: divgra( ip1jmp1,llm )
-
-c
-      REAL ghy(ip1jm,llm), ghx(ip1jmp1,llm)
-
-      INTEGER  l,ij,iter,lh
-c
-      INTEGER ijb,ije,jjb,jje
-c
-c
-c      CALL SCOPY ( ip1jmp1*klevel,h,1,divgra,1 )
-      
-      ijb=ij_begin
-      ije=ij_end
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-      DO l = 1, klevel      
-      divgra(ijb:ije,l)=h(ijb:ije,l)
-      ENDDO
-c$OMP END DO NOWAIT
-c
-
-c
-      DO 10 iter = 1,lh
-
-      jjb=jj_begin
-      jje=jj_end
-      CALL filtreg_p ( divgra,jjb,jje,jjp1,klevel,2,1,.true.,1  )
-
-c      call exchange_Hallo(divgra,ip1jmp1,llm,0,1)
-c$OMP BARRIER
-c$OMP MASTER      
-      call suspend_timer(timer_dissip)
-      call exchange_Hallo(divgra,ip1jmp1,llm,1,1)
-      call resume_timer(timer_dissip)
-c$OMP END MASTER
-c$OMP BARRIER       
-      CALL    grad_p (klevel,divgra, ghx  , ghy          )
-
-c$OMP BARRIER
-c$OMP MASTER   
-      call suspend_timer(timer_dissip)
-      call exchange_Hallo(ghy,ip1jm,llm,1,0)
-      call resume_timer(timer_dissip)
-c$OMP END MASTER
-c$OMP BARRIER            
-
-      CALL  diverg_p (klevel,  ghx , ghy  , divgra       )
-
-      jjb=jj_begin
-      jje=jj_end
-      CALL filtreg_p( divgra,jjb,jje,jjp1,klevel,2,1,.true.,1)
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-      DO 5 l = 1,klevel
-      DO 4  ij = ijb, ije
-      divgra_out( ij,l ) = - cdivh * divgra( ij,l )
-   4  CONTINUE
-   5  CONTINUE
-c$OMP END DO NOWAIT
-c
-  10  CONTINUE
-      RETURN
-      END
Index: LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu_loc.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/exner_milieu_loc.F	(revision 1795)
@@ -27,4 +27,5 @@
 c
       USE parallel
+      USE mod_filtreg_p
       IMPLICIT NONE
 c
@@ -120,5 +121,6 @@
         jjb=jj_begin
         jje=jj_end
-        CALL filtreg_p ( pkf,jjb,jje, jmp1, llm, 2, 1, .TRUE., 1 )
+        CALL filtreg_p ( pkf,jjb_u,jje_u,jjb,jje, jmp1, llm,
+     &                 2, 1, .TRUE., 1 )
 
         ! our work is done, exit routine
@@ -206,5 +208,6 @@
       jjb=jj_begin
       jje=jj_end
-      CALL filtreg_p ( pkf,jjb,jje, jmp1, llm, 2, 1, .TRUE., 1 )
+      CALL filtreg_p ( pkf,jjb_u,jje_u,jjb,jje, jmp1, llm,
+     &                 2, 1, .TRUE., 1 )
       
 c    EST-CE UTILE ?? : calcul de beta
Index: LMDZ5/branches/testing/libf/dyn3dmem/gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/gcm.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/gcm.F	(revision 1795)
@@ -19,4 +19,9 @@
       USE filtreg_mod
       USE control_mod
+
+#ifdef INCA
+! Only INCA needs these informations (from the Earth's physics)
+      USE indice_sol_mod
+#endif
 
 #ifdef CPP_PHYS
@@ -75,5 +80,5 @@
 #ifdef INCA
 ! Only INCA needs these informations (from the Earth's physics)
-#include "indicesol.h"
+!#include "indicesol.h"
 #endif
 
@@ -270,5 +275,5 @@
       ! constants & fields, if we run the 'newtonian' or 'SW' cases:
         if (iflag_phys.ne.1) then
-          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
+          CALL iniacademic_loc(vcov,ucov,teta,q,masse,ps,phis,time_0)
         endif
 
@@ -291,5 +296,5 @@
      .              'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
       if (.not.read_start) then
-         CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
+         CALL iniacademic_loc(vcov,ucov,teta,q,masse,ps,phis,time_0)
       endif
 
@@ -398,5 +403,7 @@
 #endif
 
-
+      if (iflag_phys.eq.1) then
+      ! these initialisations have already been done (via iniacademic)
+      ! if running in SW or Newtonian mode
 c-----------------------------------------------------------------------
 c   Initialisation des constantes dynamiques :
@@ -414,4 +421,5 @@
 c   --------------------------
         CALL inifilr
+      endif ! of if (iflag_phys.eq.1)
 c
 c-----------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/gradiv_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/gradiv_p.F	(revision 1750)
+++ 	(revision )
@@ -1,109 +1,0 @@
-      SUBROUTINE gradiv_p(klevel, xcov, ycov, ld, gdx_out, gdy_out )
-c
-c    Auteur :   P. Le Van
-c
-c   ***************************************************************
-c
-c                                ld
-c       calcul  de  (grad (div) )   du vect. v ....
-c
-c     xcov et ycov etant les composant.covariantes de v
-c   ****************************************************************
-c    xcov , ycov et ld  sont des arguments  d'entree pour le s-prog
-c     gdx   et  gdy     sont des arguments de sortie pour le s-prog
-c
-c     
-      USE parallel
-      USE times
-      IMPLICIT NONE
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "comdissipn.h"
-#include "logic.h"
-
-      INTEGER klevel
-c
-      REAL xcov( ip1jmp1,klevel ), ycov( ip1jm,klevel )
-      REAL,SAVE :: gdx( ip1jmp1,llm ),   gdy( ip1jm,llm )
-
-      REAL gdx_out( ip1jmp1,klevel ),   gdy_out( ip1jm,klevel )
-
-      REAL,SAVE ::  div(ip1jmp1,llm)
-
-      INTEGER l,ij,iter,ld
-c
-      INTEGER ijb,ije,jjb,jje
-c
-c
-c      CALL SCOPY( ip1jmp1*klevel,xcov,1,gdx,1 )
-c      CALL SCOPY( ip1jm*klevel,  ycov,1,gdy,1 )
-      
-      ijb=ij_begin
-      ije=ij_end
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      DO l = 1,klevel
-        gdx(ijb:ije,l)=xcov(ijb:ije,l)
-      ENDDO
-c$OMP END DO NOWAIT
-      
-      ijb=ij_begin
-      ije=ij_end
-      if(pole_sud) ije=ij_end-iip1
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      DO l = 1,klevel
-        gdy(ijb:ije,l)=ycov(ijb:ije,l)
-      ENDDO
-c$OMP END DO NOWAIT
-
-c
-      DO 10 iter = 1,ld
-
-c$OMP BARRIER
-c$OMP MASTER      
-      call suspend_timer(timer_dissip)
-      call exchange_Hallo(gdy,ip1jm,llm,1,0)
-      call resume_timer(timer_dissip)
-c$OMP END MASTER      
-c$OMP BARRIER
-
-      CALL  diverg_p( klevel,  gdx , gdy, div          )
-      
-      jjb=jj_begin
-      jje=jj_end
-      CALL filtreg_p( div,jjb,jje, jjp1, klevel, 2,1, .true.,2 )
-      
-c      call exchange_Hallo(div,ip1jmp1,llm,0,1)
-
-c$OMP BARRIER
-c$OMP MASTER       
-      call suspend_timer(timer_dissip)
-      call exchange_Hallo(div,ip1jmp1,llm,1,1)
-      call resume_timer(timer_dissip)
-c$OMP END MASTER
-c$OMP BARRIER
-      
-      CALL    grad_p( klevel,  div, gdx, gdy           )
-c
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      DO 5  l = 1, klevel
-      
-      if(pole_sud) ije=ij_end
-      DO 3 ij = ijb, ije
-        gdx_out( ij,l ) = - gdx( ij,l ) * cdivu
-   3  CONTINUE
-   
-      if(pole_sud) ije=ij_end-iip1
-      DO 4 ij = ijb, ije
-        gdy_out( ij,l ) = - gdy( ij,l ) * cdivu
-   4  CONTINUE
-
-   5  CONTINUE
-c$OMP END DO NOWAIT
-c
-  10  CONTINUE
-      RETURN
-      END
Index: LMDZ5/branches/testing/libf/dyn3dmem/iniacademic.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/iniacademic.F90	(revision 1750)
+++ 	(revision )
@@ -1,277 +1,0 @@
-!
-! $Id: iniacademic.F90 1625 2012-05-09 13:14:48Z lguez $
-!
-SUBROUTINE iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
-
-  USE filtreg_mod
-  USE infotrac, ONLY : nqtot
-  USE control_mod, ONLY: day_step,planet_type
-#ifdef CPP_IOIPSL
-  USE IOIPSL
-#else
-  ! if not using IOIPSL, we still need to use (a local version of) getin
-  USE ioipsl_getincom
-#endif
-  USE Write_Field
-
-  !   Author:    Frederic Hourdin      original: 15/01/93
-  ! The forcing defined here is from Held and Suarez, 1994, Bulletin
-  ! of the American Meteorological Society, 75, 1825.
-
-  IMPLICIT NONE
-
-  !   Declararations:
-  !   ---------------
-
-  include "dimensions.h"
-  include "paramet.h"
-  include "comvert.h"
-  include "comconst.h"
-  include "comgeom.h"
-  include "academic.h"
-  include "ener.h"
-  include "temps.h"
-  include "iniprint.h"
-  include "logic.h"
-
-  !   Arguments:
-  !   ----------
-
-  real time_0
-
-  !   variables dynamiques
-  REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
-  REAL teta(ip1jmp1,llm)                 ! temperature potentielle
-  REAL q(ip1jmp1,llm,nqtot)               ! champs advectes
-  REAL ps(ip1jmp1)                       ! pression  au sol
-  REAL masse(ip1jmp1,llm)                ! masse d'air
-  REAL phis(ip1jmp1)                     ! geopotentiel au sol
-
-  !   Local:
-  !   ------
-
-  REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
-  REAL pks(ip1jmp1)                      ! exner au  sol
-  REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
-  REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
-  REAL phi(ip1jmp1,llm)                  ! geopotentiel
-  REAL ddsin,zsig,tetapv,w_pv  ! variables auxiliaires
-  real tetastrat ! potential temperature in the stratosphere, in K
-  real tetajl(jjp1,llm)
-  INTEGER i,j,l,lsup,ij
-
-  REAL teta0,ttp,delt_y,delt_z,eps ! Constantes pour profil de T
-  REAL k_f,k_c_a,k_c_s         ! Constantes de rappel
-  LOGICAL ok_geost             ! Initialisation vent geost. ou nul
-  LOGICAL ok_pv                ! Polar Vortex
-  REAL phi_pv,dphi_pv,gam_pv   ! Constantes pour polar vortex 
-
-  real zz,ran1
-  integer idum
-
-  REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm),zdtvr
-  
-  character(len=*),parameter :: modname="iniacademic"
-  character(len=80) :: abort_message
-
-  !-----------------------------------------------------------------------
-  ! 1. Initializations for Earth-like case
-  ! --------------------------------------
-  !
-  ! initialize planet radius, rotation rate,...
-  call conf_planete
-
-  time_0=0.
-  day_ref=1
-  annee_ref=0
-
-  im         = iim
-  jm         = jjm
-  day_ini    = 1
-  dtvr    = daysec/REAL(day_step)
-  zdtvr=dtvr
-  etot0      = 0.
-  ptot0      = 0.
-  ztot0      = 0.
-  stot0      = 0.
-  ang0       = 0.
-
-  if (llm == 1) then
-     ! specific initializations for the shallow water case
-     kappa=1
-  endif
-
-  CALL iniconst
-  CALL inigeom
-  CALL inifilr
-
-  if (llm == 1) then
-     ! initialize fields for the shallow water case, if required
-     if (.not.read_start) then
-        phis(:)=0.
-        q(:,:,:)=0
-        CALL sw_case_williamson91_6(vcov,ucov,teta,masse,ps)
-     endif
-  endif
-
-  academic_case: if (iflag_phys >= 2) then
-     ! initializations
-
-     ! 1. local parameters
-     ! by convention, winter is in the southern hemisphere
-     ! Geostrophic wind or no wind?
-     ok_geost=.TRUE.
-     CALL getin('ok_geost',ok_geost)
-     ! Constants for Newtonian relaxation and friction
-     k_f=1.                !friction 
-     CALL getin('k_j',k_f)
-     k_f=1./(daysec*k_f)
-     k_c_s=4.  !cooling surface
-     CALL getin('k_c_s',k_c_s)
-     k_c_s=1./(daysec*k_c_s)
-     k_c_a=40. !cooling free atm
-     CALL getin('k_c_a',k_c_a)
-     k_c_a=1./(daysec*k_c_a)
-     ! Constants for Teta equilibrium profile
-     teta0=315.     ! mean Teta (S.H. 315K)
-     CALL getin('teta0',teta0)
-     ttp=200.       ! Tropopause temperature (S.H. 200K)
-     CALL getin('ttp',ttp)
-     eps=0.         ! Deviation to N-S symmetry(~0-20K)
-     CALL getin('eps',eps)
-     delt_y=60.     ! Merid Temp. Gradient (S.H. 60K)
-     CALL getin('delt_y',delt_y)
-     delt_z=10.     ! Vertical Gradient (S.H. 10K)
-     CALL getin('delt_z',delt_z)
-     ! Polar vortex
-     ok_pv=.false.
-     CALL getin('ok_pv',ok_pv)
-     phi_pv=-50.            ! Latitude of edge of vortex
-     CALL getin('phi_pv',phi_pv)
-     phi_pv=phi_pv*pi/180.
-     dphi_pv=5.             ! Width of the edge
-     CALL getin('dphi_pv',dphi_pv)
-     dphi_pv=dphi_pv*pi/180.
-     gam_pv=4.              ! -dT/dz vortex (in K/km)
-     CALL getin('gam_pv',gam_pv)
-
-     ! 2. Initialize fields towards which to relax
-     ! Friction
-     knewt_g=k_c_a
-     DO l=1,llm
-        zsig=presnivs(l)/preff
-        knewt_t(l)=(k_c_s-k_c_a)*MAX(0.,(zsig-0.7)/0.3)
-        kfrict(l)=k_f*MAX(0.,(zsig-0.7)/0.3)
-     ENDDO
-     DO j=1,jjp1
-        clat4((j-1)*iip1+1:j*iip1)=cos(rlatu(j))**4
-     ENDDO
-
-     ! Potential temperature 
-     DO l=1,llm
-        zsig=presnivs(l)/preff
-        tetastrat=ttp*zsig**(-kappa)
-        tetapv=tetastrat
-        IF ((ok_pv).AND.(zsig.LT.0.1)) THEN
-           tetapv=tetastrat*(zsig*10.)**(kappa*cpp*gam_pv/1000./g)
-        ENDIF
-        DO j=1,jjp1
-           ! Troposphere
-           ddsin=sin(rlatu(j))
-           tetajl(j,l)=teta0-delt_y*ddsin*ddsin+eps*ddsin &
-                -delt_z*(1.-ddsin*ddsin)*log(zsig)
-           if (planet_type=="giant") then
-             tetajl(j,l)=teta0+(delt_y*                   &
-                ((sin(rlatu(j)*3.14159*eps+0.0001))**2)   &
-                / ((rlatu(j)*3.14159*eps+0.0001)**2))     &
-                -delt_z*log(zsig)
-           endif
-           ! Profil stratospherique isotherme (+vortex)
-           w_pv=(1.-tanh((rlatu(j)-phi_pv)/dphi_pv))/2.
-           tetastrat=tetastrat*(1.-w_pv)+tetapv*w_pv             
-           tetajl(j,l)=MAX(tetajl(j,l),tetastrat)  
-        ENDDO
-     ENDDO
-
-     !          CALL writefield('theta_eq',tetajl)
-
-     do l=1,llm
-        do j=1,jjp1
-           do i=1,iip1
-              ij=(j-1)*iip1+i
-              tetarappel(ij,l)=tetajl(j,l)
-           enddo
-        enddo
-     enddo
-
-     ! 3. Initialize fields (if necessary)
-     IF (.NOT. read_start) THEN
-        ! surface pressure
-        if (iflag_phys>2) then
-           ! specific value for CMIP5 aqua/terra planets
-           ! "Specify the initial dry mass to be equivalent to
-           !  a global mean surface pressure (101325 minus 245) Pa."
-           ps(:)=101080.  
-        else
-           ! use reference surface pressure
-           ps(:)=preff
-        endif
-        
-        ! ground geopotential
-        phis(:)=0.
-
-        CALL pression ( ip1jmp1, ap, bp, ps, p       )
-        if (pressure_exner) then
-          CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
-        else
-          call exner_milieu(ip1jmp1,ps,p,beta,pks,pk,pkf)
-        endif
-        CALL massdair(p,masse)
-
-        ! bulk initialization of temperature
-        teta(:,:)=tetarappel(:,:)
-
-        ! geopotential
-        CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
-
-        ! winds
-        if (ok_geost) then
-           call ugeostr(phi,ucov)
-        else
-           ucov(:,:)=0.
-        endif
-        vcov(:,:)=0.
-
-        ! bulk initialization of tracers
-        if (planet_type=="earth") then
-           ! Earth: first two tracers will be water
-           do i=1,nqtot
-              if (i == 1) q(:,:,i)=1.e-10
-              if (i == 2) q(:,:,i)=1.e-15
-              if (i.gt.2) q(:,:,i)=0.
-           enddo
-        else
-           q(:,:,:)=0
-        endif ! of if (planet_type=="earth")
-
-        ! add random perturbation to temperature
-        idum  = -1
-        zz = ran1(idum)
-        idum  = 0
-        do l=1,llm
-           do ij=iip2,ip1jm
-              teta(ij,l)=teta(ij,l)*(1.+0.005*ran1(idum))
-           enddo
-        enddo
-
-        ! maintain periodicity in longitude
-        do l=1,llm
-           do ij=1,ip1jmp1,iip1
-              teta(ij+iim,l)=teta(ij,l)
-           enddo
-        enddo
-
-     ENDIF ! of IF (.NOT. read_start)
-  endif academic_case
-
-END SUBROUTINE iniacademic
Index: LMDZ5/branches/testing/libf/dyn3dmem/iniacademic_loc.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/iniacademic_loc.F90	(revision 1795)
+++ LMDZ5/branches/testing/libf/dyn3dmem/iniacademic_loc.F90	(revision 1795)
@@ -0,0 +1,308 @@
+!
+! $Id: iniacademic.F90 1625 2012-05-09 13:14:48Z lguez $
+!
+SUBROUTINE iniacademic_loc(vcov,ucov,teta,q,masse,ps,phis,time_0)
+
+  USE filtreg_mod
+  USE infotrac, ONLY : nqtot
+  USE control_mod, ONLY: day_step,planet_type
+  USE parallel
+#ifdef CPP_IOIPSL
+  USE IOIPSL
+#else
+  ! if not using IOIPSL, we still need to use (a local version of) getin
+  USE ioipsl_getincom
+#endif
+  USE Write_Field
+
+  !   Author:    Frederic Hourdin      original: 15/01/93
+  ! The forcing defined here is from Held and Suarez, 1994, Bulletin
+  ! of the American Meteorological Society, 75, 1825.
+
+  IMPLICIT NONE
+
+  !   Declararations:
+  !   ---------------
+
+  include "dimensions.h"
+  include "paramet.h"
+  include "comvert.h"
+  include "comconst.h"
+  include "comgeom.h"
+  include "academic.h"
+  include "ener.h"
+  include "temps.h"
+  include "iniprint.h"
+  include "logic.h"
+
+  !   Arguments:
+  !   ----------
+
+  real time_0
+
+  !   variables dynamiques
+  REAL vcov(ijb_v:ije_v,llm),ucov(ijb_u:ije_u,llm) ! vents covariants
+  REAL teta(ijb_u:ije_u,llm)                 ! temperature potentielle
+  REAL q(ijb_u:ije_u,llm,nqtot)               ! champs advectes
+  REAL ps(ijb_u:ije_u)                       ! pression  au sol
+  REAL masse(ijb_u:ije_u,llm)                ! masse d'air
+  REAL phis(ijb_u:ije_u)                     ! geopotentiel au sol
+
+  !   Local:
+  !   ------
+
+  REAL,ALLOCATABLE :: vcov_glo(:,:),ucov_glo(:,:),teta_glo(:,:)
+  REAL,ALLOCATABLE :: q_glo(:,:),masse_glo(:,:),ps_glo(:)
+  REAL,ALLOCATABLE :: phis_glo(:)
+  REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
+  REAL pks(ip1jmp1)                      ! exner au  sol
+  REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
+  REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
+  REAL phi(ip1jmp1,llm)                  ! geopotentiel
+  REAL ddsin,zsig,tetapv,w_pv  ! variables auxiliaires
+  real tetastrat ! potential temperature in the stratosphere, in K
+  real tetajl(jjp1,llm)
+  INTEGER i,j,l,lsup,ij
+
+  REAL teta0,ttp,delt_y,delt_z,eps ! Constantes pour profil de T
+  REAL k_f,k_c_a,k_c_s         ! Constantes de rappel
+  LOGICAL ok_geost             ! Initialisation vent geost. ou nul
+  LOGICAL ok_pv                ! Polar Vortex
+  REAL phi_pv,dphi_pv,gam_pv   ! Constantes pour polar vortex 
+
+  real zz,ran1
+  integer idum
+
+  REAL zdtvr
+  real,allocatable :: alpha(:,:),beta(:,:)
+  
+  character(len=*),parameter :: modname="iniacademic"
+  character(len=80) :: abort_message
+
+  !-----------------------------------------------------------------------
+  ! 1. Initializations for Earth-like case
+  ! --------------------------------------
+  !
+  ! initialize planet radius, rotation rate,...
+  call conf_planete
+
+  time_0=0.
+  day_ref=1
+  annee_ref=0
+
+  im         = iim
+  jm         = jjm
+  day_ini    = 1
+  dtvr    = daysec/REAL(day_step)
+  zdtvr=dtvr
+  etot0      = 0.
+  ptot0      = 0.
+  ztot0      = 0.
+  stot0      = 0.
+  ang0       = 0.
+
+  if (llm == 1) then
+     ! specific initializations for the shallow water case
+     kappa=1
+  endif
+
+  CALL iniconst
+  CALL inigeom
+  CALL inifilr
+
+  if (llm == 1) then
+     ! initialize fields for the shallow water case, if required
+     if (.not.read_start) then
+        phis(ijb_u:ije_u)=0.
+        q(ijb_u:ije_u,1:llm,1:nqtot)=0
+        CALL sw_case_williamson91_6_loc(vcov,ucov,teta,masse,ps)
+     endif
+  endif
+
+  academic_case: if (iflag_phys >= 2) then
+     ! initializations
+
+     ! 1. local parameters
+     ! by convention, winter is in the southern hemisphere
+     ! Geostrophic wind or no wind?
+     ok_geost=.TRUE.
+     CALL getin('ok_geost',ok_geost)
+     ! Constants for Newtonian relaxation and friction
+     k_f=1.                !friction 
+     CALL getin('k_j',k_f)
+     k_f=1./(daysec*k_f)
+     k_c_s=4.  !cooling surface
+     CALL getin('k_c_s',k_c_s)
+     k_c_s=1./(daysec*k_c_s)
+     k_c_a=40. !cooling free atm
+     CALL getin('k_c_a',k_c_a)
+     k_c_a=1./(daysec*k_c_a)
+     ! Constants for Teta equilibrium profile
+     teta0=315.     ! mean Teta (S.H. 315K)
+     CALL getin('teta0',teta0)
+     ttp=200.       ! Tropopause temperature (S.H. 200K)
+     CALL getin('ttp',ttp)
+     eps=0.         ! Deviation to N-S symmetry(~0-20K)
+     CALL getin('eps',eps)
+     delt_y=60.     ! Merid Temp. Gradient (S.H. 60K)
+     CALL getin('delt_y',delt_y)
+     delt_z=10.     ! Vertical Gradient (S.H. 10K)
+     CALL getin('delt_z',delt_z)
+     ! Polar vortex
+     ok_pv=.false.
+     CALL getin('ok_pv',ok_pv)
+     phi_pv=-50.            ! Latitude of edge of vortex
+     CALL getin('phi_pv',phi_pv)
+     phi_pv=phi_pv*pi/180.
+     dphi_pv=5.             ! Width of the edge
+     CALL getin('dphi_pv',dphi_pv)
+     dphi_pv=dphi_pv*pi/180.
+     gam_pv=4.              ! -dT/dz vortex (in K/km)
+     CALL getin('gam_pv',gam_pv)
+
+     ! 2. Initialize fields towards which to relax
+     ! Friction
+     knewt_g=k_c_a
+     DO l=1,llm
+        zsig=presnivs(l)/preff
+        knewt_t(l)=(k_c_s-k_c_a)*MAX(0.,(zsig-0.7)/0.3)
+        kfrict(l)=k_f*MAX(0.,(zsig-0.7)/0.3)
+     ENDDO
+     DO j=1,jjp1
+        clat4((j-1)*iip1+1:j*iip1)=cos(rlatu(j))**4
+     ENDDO
+
+     ! Potential temperature 
+     DO l=1,llm
+        zsig=presnivs(l)/preff
+        tetastrat=ttp*zsig**(-kappa)
+        tetapv=tetastrat
+        IF ((ok_pv).AND.(zsig.LT.0.1)) THEN
+           tetapv=tetastrat*(zsig*10.)**(kappa*cpp*gam_pv/1000./g)
+        ENDIF
+        DO j=1,jjp1
+           ! Troposphere
+           ddsin=sin(rlatu(j))
+           tetajl(j,l)=teta0-delt_y*ddsin*ddsin+eps*ddsin &
+                -delt_z*(1.-ddsin*ddsin)*log(zsig)
+           if (planet_type=="giant") then
+             tetajl(j,l)=teta0+(delt_y*                   &
+                ((sin(rlatu(j)*3.14159*eps+0.0001))**2)   &
+                / ((rlatu(j)*3.14159*eps+0.0001)**2))     &
+                -delt_z*log(zsig)
+           endif
+           ! Profil stratospherique isotherme (+vortex)
+           w_pv=(1.-tanh((rlatu(j)-phi_pv)/dphi_pv))/2.
+           tetastrat=tetastrat*(1.-w_pv)+tetapv*w_pv             
+           tetajl(j,l)=MAX(tetajl(j,l),tetastrat)  
+        ENDDO
+     ENDDO
+
+     !          CALL writefield('theta_eq',tetajl)
+
+     do l=1,llm
+        do j=1,jjp1
+           do i=1,iip1
+              ij=(j-1)*iip1+i
+              tetarappel(ij,l)=tetajl(j,l)
+           enddo
+        enddo
+     enddo
+
+     ! 3. Initialize fields (if necessary)
+     IF (.NOT. read_start) THEN
+       ! allocate global fields:
+!       allocate(vcov_glo(ip1jm,llm))
+       allocate(ucov_glo(ip1jmp1,llm))
+       allocate(teta_glo(ip1jmp1,llm))
+       allocate(ps_glo(ip1jmp1))
+       allocate(masse_glo(ip1jmp1,llm))
+       allocate(phis_glo(ip1jmp1))
+       allocate(alpha(ip1jmp1,llm))
+       allocate(beta(ip1jmp1,llm))
+
+        ! surface pressure
+        if (iflag_phys>2) then
+           ! specific value for CMIP5 aqua/terra planets
+           ! "Specify the initial dry mass to be equivalent to
+           !  a global mean surface pressure (101325 minus 245) Pa."
+           ps_glo(:)=101080.  
+        else
+           ! use reference surface pressure
+           ps_glo(:)=preff
+        endif
+        
+        ! ground geopotential
+        phis_glo(:)=0.
+
+        CALL pression ( ip1jmp1, ap, bp, ps_glo, p       )
+        if (pressure_exner) then
+          CALL exner_hyb( ip1jmp1, ps_glo, p,alpha,beta, pks, pk, pkf )
+        else
+          call exner_milieu(ip1jmp1,ps_glo,p,beta,pks,pk,pkf)
+        endif
+        CALL massdair(p,masse_glo)
+
+        ! bulk initialization of temperature
+        teta_glo(:,:)=tetarappel(:,:)
+
+        ! geopotential
+        CALL geopot(ip1jmp1,teta_glo,pk,pks,phis_glo,phi)
+
+        ! winds
+        if (ok_geost) then
+           call ugeostr(phi,ucov_glo)
+        else
+           ucov_glo(:,:)=0.
+        endif
+        vcov(ijb_v:ije_v,1:llm)=0.
+
+        ! bulk initialization of tracers
+        if (planet_type=="earth") then
+           ! Earth: first two tracers will be water
+           do i=1,nqtot
+              if (i == 1) q(ijb_u:ije_u,:,i)=1.e-10
+              if (i == 2) q(ijb_u:ije_u,:,i)=1.e-15
+              if (i.gt.2) q(ijb_u:ije_u,:,i)=0.
+           enddo
+        else
+           q(ijb_u:ije_u,:,:)=0
+        endif ! of if (planet_type=="earth")
+
+        ! add random perturbation to temperature
+        idum  = -1
+        zz = ran1(idum)
+        idum  = 0
+        do l=1,llm
+           do ij=iip2,ip1jm
+              teta_glo(ij,l)=teta_glo(ij,l)*(1.+0.005*ran1(idum))
+           enddo
+        enddo
+
+        ! maintain periodicity in longitude
+        do l=1,llm
+           do ij=1,ip1jmp1,iip1
+              teta_glo(ij+iim,l)=teta_glo(ij,l)
+           enddo
+        enddo
+
+        ! copy data from global array to local array:
+        teta(ijb_u:ije_u,:)=teta_glo(ijb_u:ije_u,:)
+        ucov(ijb_u:ije_u,:)=ucov_glo(ijb_u:ije_u,:)
+!        vcov(ijb_v:ije_v,:)=vcov_glo(ijb_v:ije_v,:)
+        masse(ijb_u:ije_u,:)=masse_glo(ijb_u:ije_u,:)
+        ps(ijb_u:ije_u)=ps_glo(ijb_u:ije_u)
+        phis(ijb_u:ije_u)=phis_glo(ijb_u:ije_u)
+
+        deallocate(teta_glo)
+        deallocate(ucov_glo)
+!        deallocate(vcov_glo)
+        deallocate(masse_glo)
+        deallocate(ps_glo)
+        deallocate(phis_glo)
+        deallocate(alpha)
+        deallocate(beta)
+     ENDIF ! of IF (.NOT. read_start)
+  endif academic_case
+
+END SUBROUTINE iniacademic_loc
Index: LMDZ5/branches/testing/libf/dyn3dmem/inigeom.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/inigeom.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/inigeom.F	(revision 1795)
@@ -426,10 +426,10 @@
          radclatm = 0.5* rad * coslatm
 c
+         ai14            = un4rad2 * coslatp * yprp
+         ai23            = un4rad2 * coslatm * yprm
          DO 32 i = 1,iim
          xprp            = xprimp025( i )
          xprm            = xprimm025( i )
       
-         ai14            = un4rad2 * coslatp * yprp
-         ai23            = un4rad2 * coslatm * yprm
          aireij1 ( i,j ) = ai14 * xprp
          aireij2 ( i,j ) = ai23 * xprp
Index: LMDZ5/branches/testing/libf/dyn3dmem/ismax.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/ismax.F	(revision 1750)
+++ 	(revision )
@@ -1,24 +1,0 @@
-!
-! $Header$
-!
-      function ismax(n,sx,incx)
-c
-      IMPLICIT NONE
-c
-      INTEGER n,i,incx,ismax,ix
-      real sx((n-1)*incx+1),sxmax
-c
-      ix=1
-      ismax=1
-      sxmax=sx(1)
-      do 10 i=1,n-1
-       ix=ix+incx
-       if(sx(ix).gt.sxmax) then
-         sxmax=sx(ix)
-         ismax=i+1
-       endif
-10    continue
-c
-      return
-      end
-
Index: LMDZ5/branches/testing/libf/dyn3dmem/ismin.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/ismin.F	(revision 1750)
+++ 	(revision )
@@ -1,24 +1,0 @@
-!
-! $Header$
-!
-      FUNCTION ismin(n,sx,incx)
-c
-      IMPLICIT NONE
-c
-      integer n,i,incx,ismin,ix
-      real sx((n-1)*incx+1),sxmin
-c
-      ix=1
-      ismin=1
-      sxmin=sx(1)
-      DO i=1,n-1
-         ix=ix+incx
-         if(sx(ix).lt.sxmin) then
-             sxmin=sx(ix)
-             ismin=i+1
-         endif
-      ENDDO
-c
-      return
-      end
-C
Index: LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/leapfrog_loc.F	(revision 1795)
@@ -1125,30 +1125,5 @@
         ! Sponge layer (if any)
         IF (ok_strato) THEN
-          ! set dufi,dvfi,... to zero
-          ijb=ij_begin
-          ije=ij_end
-!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-          do l=1,llm
-            dufi(ijb:ije,l)=0
-            dtetafi(ijb:ije,l)=0
-            dqfi(ijb:ije,l,1:nqtot)=0
-          enddo
-!$OMP END DO
-!$OMP MASTER
-          dpfi(ijb:ije)=0
-!$OMP END MASTER
-          ijb=ij_begin
-          ije=ij_end
-          if (pole_sud) ije=ije-iip1
-!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-          do l=1,llm
-            dvfi(ijb:ije,l)=0
-          enddo
-!$OMP END DO
-
-          CALL top_bound_loc(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
-          CALL addfi_loc( dtvr, leapf, forward   ,
-     $                  ucov, vcov, teta , q   ,ps ,
-     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
+          CALL top_bound_loc(vcov,ucov,teta,masse,dtvr)
 !$OMP BARRIER
         ENDIF ! of IF (ok_strato) 
Index: LMDZ5/branches/testing/libf/dyn3dmem/sw_case_williamson91_6.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/sw_case_williamson91_6.F	(revision 1750)
+++ 	(revision )
@@ -1,140 +1,0 @@
-!
-! $Id $
-!
-      SUBROUTINE sw_case_williamson91_6(vcov,ucov,teta,masse,ps)
-
-c=======================================================================
-c
-c   Author:    Thomas Dubos      original: 26/01/2010
-c   -------
-c
-c   Subject:
-c   ------
-c   Realise le cas-test 6 de Williamson et al. (1991) : onde de Rossby-Haurwitz
-c
-c   Method:
-c   --------
-c
-c   Interface:
-c   ----------
-c
-c      Input:
-c      ------
-c
-c      Output:
-c      -------
-c
-c=======================================================================
-      IMPLICIT NONE
-c-----------------------------------------------------------------------
-c   Declararations:
-c   ---------------
-
-#include "dimensions.h"
-#include "paramet.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "comgeom.h"
-#include "iniprint.h"
-
-c   Arguments:
-c   ----------
-
-c   variables dynamiques
-      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
-      REAL teta(ip1jmp1,llm)                 ! temperature potentielle
-      REAL ps(ip1jmp1)                       ! pression  au sol
-      REAL masse(ip1jmp1,llm)                ! masse d'air
-      REAL phis(ip1jmp1)                     ! geopotentiel au sol
-
-c   Local:
-c   ------
-
-      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
-      REAL pks(ip1jmp1)                      ! exner au  sol
-      REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
-      REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
-      REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm)
-
-      REAL :: sinth,costh,costh2, Ath,Bth,Cth, lon,dps
-      INTEGER i,j,ij
-
-      REAL, PARAMETER    :: rho=1 ! masse volumique de l'air (arbitraire)
-      REAL, PARAMETER    :: K    = 7.848e-6  ! K = \omega
-      REAL, PARAMETER    :: gh0  = 9.80616 * 8e3 
-      INTEGER, PARAMETER :: R0=4, R1=R0+1, R2=R0+2         ! mode 4
-c NB : rad = 6371220 dans W91 (6371229 dans LMDZ)
-c      omeg = 7.292e-5 dans W91 (7.2722e-5 dans LMDZ)
- 
-      IF(0==0) THEN
-c Williamson et al. (1991) : onde de Rossby-Haurwitz
-         teta = preff/rho/cpp
-c geopotentiel (pression de surface)
-         do j=1,jjp1
-            costh2 = cos(rlatu(j))**2
-            Ath = (R0+1)*(costh2**2) + (2*R0*R0-R0-2)*costh2 - 2*R0*R0
-            Ath = .25*(K**2)*(costh2**(R0-1))*Ath
-            Ath = .5*K*(2*omeg+K)*costh2 + Ath 
-            Bth = (R1*R1+1)-R1*R1*costh2
-            Bth = 2*(omeg+K)*K/(R1*R2) * (costh2**(R0/2))*Bth
-            Cth = R1*costh2 - R2
-            Cth = .25*K*K*(costh2**R0)*Cth
-            do i=1,iip1
-               ij=(j-1)*iip1+i
-               lon = rlonv(i)
-               dps = Ath + Bth*cos(R0*lon) + Cth*cos(2*R0*lon)
-               ps(ij) = rho*(gh0 + (rad**2)*dps)
-            enddo
-         enddo
-         write(lunout,*) 'W91 ps', MAXVAL(ps), MINVAL(ps)
-c vitesse zonale ucov
-         do j=1,jjp1
-            costh  = cos(rlatu(j))
-            costh2 = costh**2
-            Ath = rad*K*costh
-            Bth = R0*(1-costh2)-costh2
-            Bth = rad*K*Bth*(costh**(R0-1))
-            do i=1,iip1
-               ij=(j-1)*iip1+i
-               lon = rlonu(i)
-               ucov(ij,1) = (Ath + Bth*cos(R0*lon))
-            enddo
-         enddo
-         write(lunout,*) 'W91 u', MAXVAL(ucov(:,1)), MINVAL(ucov(:,1))
-         ucov(:,1)=ucov(:,1)*cu
-c vitesse meridienne vcov
-         do j=1,jjm
-            sinth  = sin(rlatv(j))
-            costh  = cos(rlatv(j))
-            Ath = -rad*K*R0*sinth*(costh**(R0-1))
-            do i=1,iip1
-               ij=(j-1)*iip1+i
-               lon = rlonv(i)
-               vcov(ij,1) = Ath*sin(R0*lon)
-            enddo
-         enddo
-         write(lunout,*) 'W91 v', MAXVAL(vcov(:,1)), MINVAL(vcov(:,1))
-         vcov(:,1)=vcov(:,1)*cv
-         
-c         ucov=0
-c         vcov=0
-      ELSE
-c test non-tournant, onde se propageant en latitude
-         do j=1,jjp1
-            do i=1,iip1
-               ij=(j-1)*iip1+i
-               ps(ij) = 1e5*(1 + .1*exp(-100*(1+sin(rlatu(j)))**2) )
-            enddo
-         enddo
-         
-c     rho = preff/(cpp*teta)
-         teta = .01*preff/cpp   ! rho = 100 ; phi = ps/rho = 1e3 ; c=30 m/s = 2600 km/j = 23 degres / j
-         ucov=0.
-         vcov=0.
-      END IF      
-      
-      CALL pression ( ip1jmp1, ap, bp, ps, p       )
-      CALL massdair(p,masse)
-
-      END
-c-----------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/sw_case_williamson91_6_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/sw_case_williamson91_6_loc.F	(revision 1795)
+++ LMDZ5/branches/testing/libf/dyn3dmem/sw_case_williamson91_6_loc.F	(revision 1795)
@@ -0,0 +1,189 @@
+!
+! $Id $
+!
+      SUBROUTINE sw_case_williamson91_6_loc(vcov,ucov,teta,masse,ps)
+
+c=======================================================================
+c
+c   Author:    Thomas Dubos      original: 26/01/2010
+c   -------
+c
+c   Subject:
+c   ------
+c   Realise le cas-test 6 de Williamson et al. (1991) : onde de Rossby-Haurwitz
+c
+c   Method:
+c   --------
+c
+c   Interface:
+c   ----------
+c
+c      Input:
+c      ------
+c
+c      Output:
+c      -------
+c
+c=======================================================================
+      USE parallel
+
+      IMPLICIT NONE
+c-----------------------------------------------------------------------
+c   Declararations:
+c   ---------------
+
+#include "dimensions.h"
+#include "paramet.h"
+#include "comvert.h"
+#include "comconst.h"
+#include "comgeom.h"
+#include "iniprint.h"
+
+c   Arguments:
+c   ----------
+
+c   variables dynamiques
+      REAL vcov(ijb_v:ije_v,llm),ucov(ijb_u:ije_u,llm) ! vents covariants
+      REAL teta(ijb_u:ije_u,llm)                 ! temperature potentielle
+      REAL ps(ijb_u:ije_u)                       ! pression  au sol
+      REAL masse(ijb_u:ije_u,llm)                ! masse d'air
+      REAL phis(ijb_u:ije_u)                     ! geopotentiel au sol
+
+c   Local:
+c   ------
+
+      real,allocatable :: ucov_glo(:,:)
+      real,allocatable :: vcov_glo(:,:)
+      real,allocatable :: teta_glo(:,:)
+      real,allocatable :: masse_glo(:,:)
+      real,allocatable :: ps_glo(:)
+
+!      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
+!      REAL pks(ip1jmp1)                      ! exner au  sol
+!      REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
+!      REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
+!      REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm)
+
+      real,allocatable :: p(:,:)
+      real,allocatable :: pks(:)
+      real,allocatable :: pk(:,:)
+      real,allocatable :: pkf(:,:)
+      real,allocatable :: alpha(:,:),beta(:,:)
+
+      REAL :: sinth,costh,costh2, Ath,Bth,Cth, lon,dps
+      INTEGER i,j,ij
+
+      REAL, PARAMETER    :: rho=1 ! masse volumique de l'air (arbitraire)
+      REAL, PARAMETER    :: K    = 7.848e-6  ! K = \omega
+      REAL, PARAMETER    :: gh0  = 9.80616 * 8e3 
+      INTEGER, PARAMETER :: R0=4, R1=R0+1, R2=R0+2         ! mode 4
+c NB : rad = 6371220 dans W91 (6371229 dans LMDZ)
+c      omeg = 7.292e-5 dans W91 (7.2722e-5 dans LMDZ)
+
+
+       ! allocate (global) arrays
+       allocate(vcov_glo(ip1jm,llm))
+       allocate(ucov_glo(ip1jmp1,llm))
+       allocate(teta_glo(ip1jmp1,llm))
+       allocate(ps_glo(ip1jmp1))
+       allocate(masse_glo(ip1jmp1,llm))
+
+       allocate(p(ip1jmp1,llmp1))
+       allocate(pks(ip1jmp1))
+       allocate(pk(ip1jmp1,llm))
+       allocate(pkf(ip1jmp1,llm))
+       allocate(alpha(ip1jmp1,llm))
+       allocate(beta(ip1jmp1,llm))
+ 
+      IF(0==0) THEN
+!c Williamson et al. (1991) : onde de Rossby-Haurwitz
+         teta_glo(:,:) = preff/rho/cpp
+!c geopotentiel (pression de surface)
+         do j=1,jjp1
+            costh2 = cos(rlatu(j))**2
+            Ath = (R0+1)*(costh2**2) + (2*R0*R0-R0-2)*costh2 - 2*R0*R0
+            Ath = .25*(K**2)*(costh2**(R0-1))*Ath
+            Ath = .5*K*(2*omeg+K)*costh2 + Ath 
+            Bth = (R1*R1+1)-R1*R1*costh2
+            Bth = 2*(omeg+K)*K/(R1*R2) * (costh2**(R0/2))*Bth
+            Cth = R1*costh2 - R2
+            Cth = .25*K*K*(costh2**R0)*Cth
+            do i=1,iip1
+               ij=(j-1)*iip1+i
+               lon = rlonv(i)
+               dps = Ath + Bth*cos(R0*lon) + Cth*cos(2*R0*lon)
+               ps_glo(ij) = rho*(gh0 + (rad**2)*dps)
+            enddo
+         enddo
+!         write(lunout,*) 'W91 ps', MAXVAL(ps), MINVAL(ps)
+c vitesse zonale ucov
+         do j=1,jjp1
+            costh  = cos(rlatu(j))
+            costh2 = costh**2
+            Ath = rad*K*costh
+            Bth = R0*(1-costh2)-costh2
+            Bth = rad*K*Bth*(costh**(R0-1))
+            do i=1,iip1
+               ij=(j-1)*iip1+i
+               lon = rlonu(i)
+               ucov_glo(ij,1) = (Ath + Bth*cos(R0*lon))
+            enddo
+         enddo
+!         write(lunout,*) 'W91 u', MAXVAL(ucov(:,1)), MINVAL(ucov(:,1))
+         ucov_glo(:,1)=ucov_glo(:,1)*cu
+c vitesse meridienne vcov
+         do j=1,jjm
+            sinth  = sin(rlatv(j))
+            costh  = cos(rlatv(j))
+            Ath = -rad*K*R0*sinth*(costh**(R0-1))
+            do i=1,iip1
+               ij=(j-1)*iip1+i
+               lon = rlonv(i)
+               vcov_glo(ij,1) = Ath*sin(R0*lon)
+            enddo
+         enddo
+         write(lunout,*) 'W91 v', MAXVAL(vcov(:,1)), MINVAL(vcov(:,1))
+         vcov_glo(:,1)=vcov_glo(:,1)*cv
+        
+c         ucov_glo=0
+c         vcov_glo=0
+      ELSE
+c test non-tournant, onde se propageant en latitude
+         do j=1,jjp1
+            do i=1,iip1
+               ij=(j-1)*iip1+i
+               ps_glo(ij) = 1e5*(1 + .1*exp(-100*(1+sin(rlatu(j)))**2))
+            enddo
+         enddo
+         
+c     rho = preff/(cpp*teta)
+         teta_glo(:,:) = .01*preff/cpp   ! rho = 100 ; phi = ps/rho = 1e3 ; c=30 m/s = 2600 km/j = 23 degres / j
+         ucov_glo(:,:)=0.
+         vcov_glo(:,:)=0.
+      END IF      
+      
+      CALL pression ( ip1jmp1, ap, bp, ps_glo, p       )
+      CALL massdair(p,masse_glo)
+
+      ! copy data from global array to local array:
+      teta(ijb_u:ije_u,:)=teta_glo(ijb_u:ije_u,:)
+      ucov(ijb_u:ije_u,:)=ucov_glo(ijb_u:ije_u,:)
+      vcov(ijb_v:ije_v,:)=vcov_glo(ijb_v:ije_v,:)
+      masse(ijb_u:ije_u,:)=masse_glo(ijb_u:ije_u,:)
+      ps(ijb_u:ije_u)=ps_glo(ijb_u:ije_u)
+
+      ! cleanup
+      deallocate(teta_glo)
+      deallocate(ucov_glo)
+      deallocate(vcov_glo)
+      deallocate(masse_glo)
+      deallocate(ps_glo)
+      deallocate(p)
+      deallocate(pks)
+      deallocate(pk)
+      deallocate(pkf)
+      deallocate(alpha)
+      deallocate(beta)
+
+      END
+c-----------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/dyn3dmem/temps.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/temps.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/temps.h	(revision 1795)
@@ -13,11 +13,11 @@
 ! INCLUDE 'temps.h'
 
-      COMMON/temps/itaufin, dt, day_ini, day_end, annee_ref, day_ref,   &
-     &             itau_dyn, itau_phy, jD_ref, jH_ref, calend,          &
-     &             start_time
+      COMMON/temps/ dt, jD_ref, jH_ref, start_time,                     &
+     &             day_ini, day_end, annee_ref, day_ref,                &
+     &             itau_dyn, itau_phy, itaufin, calend
 
 
       INTEGER   itaufin
-      INTEGER itau_dyn, itau_phy
+      INTEGER itau_dyn, itau_phy 
       INTEGER day_ini, day_end, annee_ref, day_ref
       REAL      dt, jD_ref, jH_ref, start_time
Index: LMDZ5/branches/testing/libf/dyn3dmem/top_bound_loc.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dmem/top_bound_loc.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dmem/top_bound_loc.F	(revision 1795)
@@ -1,3 +1,6 @@
-      SUBROUTINE top_bound_loc( vcov,ucov,teta,masse, du,dv,dh )
+!
+! $Id: $
+!
+      SUBROUTINE top_bound_loc(vcov,ucov,teta,masse,dt)
       USE parallel
       IMPLICIT NONE
@@ -25,18 +28,42 @@
 c
 c=======================================================================
-c-----------------------------------------------------------------------
-c   Declarations:
-c   -------------
+
+! top_bound sponge layer model:
+! Quenching is modeled as: A(t)=Am+A0*exp(-lambda*t)
+! where Am is the zonal average of the field (or zero), and lambda the inverse
+! of the characteristic quenching/relaxation time scale
+! Thus, assuming Am to be time-independent, field at time t+dt is given by:
+! A(t+dt)=A(t)-(A(t)-Am)*(1-exp(-lambda*t))
+! Moreover lambda can be a function of model level (see below), and relaxation
+! can be toward the average zonal field or just zero (see below).
+
+! NB: top_bound sponge is only called from leapfrog if ok_strato=.true.
+
+! sponge parameters: (loaded/set in conf_gcm.F ; stored in comconst.h)
+!    iflag_top_bound=0 for no sponge
+!    iflag_top_bound=1 for sponge over 4 topmost layers
+!    iflag_top_bound=2 for sponge from top to ~1% of top layer pressure
+!    mode_top_bound=0: no relaxation
+!    mode_top_bound=1: u and v relax towards 0
+!    mode_top_bound=2: u and v relax towards their zonal mean
+!    mode_top_bound=3: u,v and pot. temp. relax towards their zonal mean
+!    tau_top_bound : inverse of charactericstic relaxation time scale at
+!                       the topmost layer (Hz)
+
 
 #include "comdissipn.h"
+#include "iniprint.h"
 
 c   Arguments:
 c   ----------
 
-      REAL ucov(iip1,jjb_u:jje_u,llm),vcov(iip1,jjb_v:jje_v,llm)
-      REAL teta(iip1,jjb_u:jje_u,llm)
-      REAL masse(iip1,jjb_u:jje_u,llm)
-      REAL dv(iip1,jjb_v:jje_v,llm),du(iip1,jjb_u:jje_u,llm)
-      REAL dh(iip1,jjb_u:jje_u,llm)
+      real,intent(inout) :: ucov(iip1,jjb_u:jje_u,llm) ! covariant zonal wind
+      real,intent(inout) :: vcov(iip1,jjb_v:jje_v,llm) ! covariant meridional wind
+      real,intent(inout) :: teta(iip1,jjb_u:jje_u,llm) ! potential temperature
+      real,intent(in) :: masse(iip1,jjb_u:jje_u,llm) ! mass of atmosphere 
+      real,intent(in) :: dt ! time step (s) of sponge model
+
+!      REAL dv(iip1,jjb_v:jje_v,llm),du(iip1,jjb_u:jje_u,llm)
+!      REAL dh(iip1,jjb_u:jje_u,llm)
 
 c   Local:
@@ -47,9 +74,7 @@
       REAL tzon(jjb_u:jje_u,llm)
       
-      INTEGER NDAMP
-      PARAMETER (NDAMP=4)
       integer i	
       REAL,SAVE :: rdamp(llm)
-!     &   (/(0., i =1,llm-NDAMP),0.125E-5,.25E-5,.5E-5,1.E-5/) 
+      real,save :: lambda(llm) ! inverse or quenching time scale (Hz)
       LOGICAL,SAVE :: first=.true.
       INTEGER j,l,jjb,jje
@@ -57,43 +82,57 @@
 
       if (iflag_top_bound == 0) return
+
       if (first) then
 c$OMP BARRIER
 c$OMP MASTER
          if (iflag_top_bound == 1) then
-! couche eponge dans les 4 dernieres couches du modele
-             rdamp(:)=0.
-             rdamp(llm)=tau_top_bound
-             rdamp(llm-1)=tau_top_bound/2.
-             rdamp(llm-2)=tau_top_bound/4.
-             rdamp(llm-3)=tau_top_bound/8.
+! sponge quenching over the topmost 4 atmospheric layers
+             lambda(:)=0.
+             lambda(llm)=tau_top_bound
+             lambda(llm-1)=tau_top_bound/2.
+             lambda(llm-2)=tau_top_bound/4.
+             lambda(llm-3)=tau_top_bound/8.
          else if (iflag_top_bound == 2) then
-! couce eponge dans toutes les couches de pression plus faible que
-! 100 fois la pression de la derniere couche
-             rdamp(:)=tau_top_bound
+! sponge quenching over topmost layers down to pressures which are
+! higher than 100 times the topmost layer pressure
+             lambda(:)=tau_top_bound
      s       *max(presnivs(llm)/presnivs(:)-0.01,0.)
          endif
+
+! quenching coefficient rdamp(:)
+!         rdamp(:)=dt*lambda(:) ! Explicit Euler approx.
+         rdamp(:)=1.-exp(-lambda(:)*dt)
+
+         write(lunout,*)'TOP_BOUND mode',mode_top_bound
+         write(lunout,*)'Sponge layer coefficients'
+         write(lunout,*)'p (Pa)  z(km)  tau(s)   1./tau (Hz)'
+         do l=1,llm
+           if (rdamp(l).ne.0.) then
+             write(lunout,'(6(1pe12.4,1x))')
+     &        presnivs(l),log(preff/presnivs(l))*scaleheight,
+     &           1./lambda(l),lambda(l)
+           endif
+         enddo
          first=.false.
-         print*,'TOP_BOUND rdamp=',rdamp
 c$OMP END MASTER
 c$OMP BARRIER
-      endif
+      endif ! of if (first)
 
 
       CALL massbar_loc(masse,massebx,masseby)
-C  CALCUL DES CHAMPS EN MOYENNE ZONALE:
-
-      jjb=jj_begin
-      jje=jj_end
-      IF (pole_sud) jje=jj_end-1
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      do l=1,llm
+
+      ! compute zonal average of vcov (or set it to zero)
+      if (mode_top_bound.ge.2) then
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_sud) jje=jj_end-1
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
         do j=jjb,jje
           zm=0.
           vzon(j,l)=0
           do i=1,iim
-! Rm: on peut travailler directement avec la moyenne zonale de vcov
-! plutot qu'avec celle de v car le coefficient cv qui relie les deux
-! ne varie qu'en latitude
+! NB: we can work using vcov zonal mean rather than v since the
+! cv coefficient (which relates the two) only varies with latitudes 
             vzon(j,l)=vzon(j,l)+vcov(i,j,l)*masseby(i,j,l)
             zm=zm+masseby(i,j,l)
@@ -101,24 +140,22 @@
           vzon(j,l)=vzon(j,l)/zm
         enddo
-      enddo
+       enddo
 c$OMP END DO NOWAIT   
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      do l=1,llm
-        do j=jjb,jje
-          do i=1,iip1
-            dv(i,j,l)=dv(i,j,l)-rdamp(l)*(vcov(i,j,l)-vzon(j,l))
-          enddo
-        enddo
-      enddo
-c$OMP END DO NOWAIT
-
-      jjb=jj_begin
-      jje=jj_end
-      IF (pole_nord) jjb=jj_begin+1
-      IF (pole_sud)  jje=jj_end-1
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      do l=1,llm
+      else
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
+         vzon(:,l)=0.
+       enddo
+c$OMP END DO NOWAIT
+      endif ! of if (mode_top_bound.ge.2)
+
+      ! compute zonal average of u (or set it to zero)
+      if (mode_top_bound.ge.2) then
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_nord) jjb=jj_begin+1
+       IF (pole_sud)  jje=jj_end-1
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
         do j=jjb,jje
           uzon(j,l)=0.
@@ -130,9 +167,22 @@
           uzon(j,l)=uzon(j,l)/zm
         enddo
-      enddo
-c$OMP END DO NOWAIT
-
+       enddo
+c$OMP END DO NOWAIT
+      else
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
+         uzon(:,l)=0.
+       enddo
+c$OMP END DO NOWAIT
+      endif ! of if (mode_top_bound.ge.2)
+
+      ! compute zonal average of potential temperature, if necessary
+      if (mode_top_bound.ge.3) then
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_nord) jjb=jj_begin+1
+       IF (pole_sud)  jje=jj_end-1
 c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)   
-      do l=1,llm
+       do l=1,llm
         do j=jjb,jje
           zm=0.
@@ -144,22 +194,61 @@
           tzon(j,l)=tzon(j,l)/zm
         enddo
-      enddo
-c$OMP END DO NOWAIT
-
-C   AMORTISSEMENTS LINEAIRES:
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      do l=1,llm
+       enddo
+c$OMP END DO NOWAIT
+      endif ! of if (mode_top_bound.ge.3)
+
+      if (mode_top_bound.ge.1) then
+       ! Apply sponge quenching on vcov:
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_sud) jje=jj_end-1
+
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
         do j=jjb,jje
           do i=1,iip1
-            du(i,j,l)=du(i,j,l)
-     s               -rdamp(l)*(ucov(i,j,l)-cu(i,j)*uzon(j,l))
-            dh(i,j,l)=dh(i,j,l)-rdamp(l)*(teta(i,j,l)-tzon(j,l))
-          enddo
-       enddo
-      enddo
-c$OMP END DO NOWAIT
-      
-
-      RETURN
+            vcov(i,j,l)=vcov(i,j,l)
+     &                  -rdamp(l)*(vcov(i,j,l)-vzon(j,l))
+          enddo
+        enddo
+       enddo
+c$OMP END DO NOWAIT
+
+       ! Apply sponge quenching on ucov:
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_nord) jjb=jj_begin+1
+       IF (pole_sud)  jje=jj_end-1
+
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
+        do j=jjb,jje
+          do i=1,iip1
+            ucov(i,j,l)=ucov(i,j,l)
+     &                  -rdamp(l)*(ucov(i,j,l)-cu(i,j)*uzon(j,l))
+          enddo
+       enddo
+       enddo
+c$OMP END DO NOWAIT
+      endif ! of if (mode_top_bound.ge.1)
+
+      if (mode_top_bound.ge.3) then   
+       ! Apply sponge quenching on teta:
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_nord) jjb=jj_begin+1
+       IF (pole_sud)  jje=jj_end-1
+
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
+        do j=jjb,jje
+          do i=1,iip1
+            teta(i,j,l)=teta(i,j,l)
+     &                  -rdamp(l)*(teta(i,j,l)-tzon(j,l))
+          enddo
+       enddo
+       enddo
+c$OMP END DO NOWAIT
+      endif ! of if (mode_top_bond.ge.3)
+
       END
Index: LMDZ5/branches/testing/libf/dyn3dpar/abort_gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/abort_gcm.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dpar/abort_gcm.F	(revision 1795)
@@ -24,5 +24,5 @@
 
       character(len=*) modname
-      integer ierr
+      integer ierr, ierror_mpi
       character(len=*) message
 
@@ -47,5 +47,11 @@
       else
         write(lunout,*) 'Houston, we have a problem ', ierr
+#ifdef CPP_MPI
+C$OMP CRITICAL (MPI_ABORT_GCM)
+        call MPI_ABORT(COMM_LMDZ, 1, ierror_mpi)
+C$OMP END CRITICAL (MPI_ABORT_GCM)
+#else
         stop 1
+#endif          
       endif
       END
Index: LMDZ5/branches/testing/libf/dyn3dpar/ce0l.F90
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/ce0l.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dpar/ce0l.F90	(revision 1795)
@@ -23,4 +23,5 @@
   USE infotrac
   USE parallel, ONLY: finalize_parallel
+  USE indice_sol_mod
 
 #ifdef CPP_IOIPSL
@@ -39,5 +40,5 @@
 #include "dimensions.h"
 #include "paramet.h"
-#include "indicesol.h"
+!#include "indicesol.h"
 #include "iniprint.h"
 #include "temps.h"
Index: LMDZ5/branches/testing/libf/dyn3dpar/comconst.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/comconst.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dpar/comconst.h	(revision 1795)
@@ -6,5 +6,5 @@
 
       COMMON/comconsti/im,jm,lllm,imp1,jmp1,lllmm1,lllmp1,lcl,          &
-     &                 iflag_top_bound
+     &                 iflag_top_bound,mode_top_bound
       COMMON/comconstr/dtvr,daysec,                                     &
      & pi,dtphys,dtdiss,rad,r,cpp,kappa,cotot,unsim,g,omeg              &
@@ -30,6 +30,8 @@
       REAL omeg ! (rad/s) rotation rate of the planet
       REAL dissip_factz,dissip_deltaz,dissip_zref
-      INTEGER iflag_top_bound
-      REAL tau_top_bound
+! top_bound sponge:
+      INTEGER iflag_top_bound ! sponge type
+      INTEGER mode_top_bound  ! sponge mode
+      REAL tau_top_bound ! inverse of sponge characteristic time scale (Hz)
       REAL daylen ! length of solar day, in 'standard' day length
       REAL year_day ! Number of standard days in a year
Index: LMDZ5/branches/testing/libf/dyn3dpar/comvert.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/comvert.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dpar/comvert.h	(revision 1795)
@@ -23,5 +23,6 @@
       real bps    ! hybrid sigma contribution at mid-layers
       real scaleheight ! atmospheric (reference) scale height (km)
-      real pseudoalt ! for planets
+      real pseudoalt ! pseudo-altitude of model levels (km), based on presnivs(),
+                     ! preff and scaleheight
 
       integer disvert_type ! type of vertical discretization:
Index: LMDZ5/branches/testing/libf/dyn3dpar/conf_gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/conf_gcm.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dpar/conf_gcm.F	(revision 1795)
@@ -334,7 +334,21 @@
        CALL getin('dissip_zref',dissip_zref )
 
+! top_bound sponge: only active if ok_strato=.true. and iflag_top_bound!=0
+!                   iflag_top_bound=0 for no sponge
+!                   iflag_top_bound=1 for sponge over 4 topmost layers
+!                   iflag_top_bound=2 for sponge from top to ~1% of top layer pressure
        iflag_top_bound=1
+       CALL getin('iflag_top_bound',iflag_top_bound)
+
+! mode_top_bound : fields towards which sponge relaxation will be done:
+!                  mode_top_bound=0: no relaxation
+!                  mode_top_bound=1: u and v relax towards 0
+!                  mode_top_bound=2: u and v relax towards their zonal mean
+!                  mode_top_bound=3: u,v and pot. temp. relax towards their zonal mean
+       mode_top_bound=3
+       CALL getin('mode_top_bound',mode_top_bound)
+
+! top_bound sponge : inverse of charactericstic relaxation time scale for sponge
        tau_top_bound=1.e-5
-       CALL getin('iflag_top_bound',iflag_top_bound)
        CALL getin('tau_top_bound',tau_top_bound)
 
Index: LMDZ5/branches/testing/libf/dyn3dpar/cray.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/cray.F	(revision 1750)
+++ 	(revision )
@@ -1,54 +1,0 @@
-!
-! $Header$
-!
-#ifdef CRAY
-      SUBROUTINE riencray
-      END
-#else
-      subroutine scopy(n,sx,incx,sy,incy)
-c
-      IMPLICIT NONE
-c
-      integer n,incx,incy,ix,iy,i
-      real sx((n-1)*incx+1),sy((n-1)*incy+1)
-c
-      if (incx.eq.1.and.incy.eq.1) then
-      do 10 i=1,n
-         sy(i)=sx(i)
-10    continue
-      else
-      iy=1
-      ix=1
-      do 11 i=1,n
-         sy(iy)=sx(ix)
-         ix=ix+incx
-         iy=iy+incy
-11    continue
-      endif
-c
-      return
-      end
-
-      function ssum(n,sx,incx)
-c
-      IMPLICIT NONE
-c
-      integer n,incx,i,ix
-      real ssum,sx((n-1)*incx+1)
-c
-      ssum=0.
-      if (incx.eq.1) then
-      do 10 i=1,n
-         ssum=ssum+sx(i)
-10    continue
-      else
-      ix=1
-      do 11 i=1,n
-         ssum=ssum+sx(ix)
-         ix=ix+incx
-11    continue
-      endif
-c
-      return
-      end
-#endif
Index: LMDZ5/branches/testing/libf/dyn3dpar/gcm.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/gcm.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dpar/gcm.F	(revision 1795)
@@ -19,4 +19,9 @@
       USE filtreg_mod
       USE control_mod
+
+#ifdef INCA
+! Only INCA needs these informations (from the Earth's physics)
+      USE indice_sol_mod
+#endif
 
 #ifdef CPP_PHYS
@@ -75,5 +80,5 @@
 #ifdef INCA
 ! Only INCA needs these informations (from the Earth's physics)
-#include "indicesol.h"
+!#include "indicesol.h"
 #endif
 
Index: LMDZ5/branches/testing/libf/dyn3dpar/inigeom.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/inigeom.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dpar/inigeom.F	(revision 1795)
@@ -426,10 +426,10 @@
          radclatm = 0.5* rad * coslatm
 c
+         ai14            = un4rad2 * coslatp * yprp
+         ai23            = un4rad2 * coslatm * yprm
          DO 32 i = 1,iim
          xprp            = xprimp025( i )
          xprm            = xprimm025( i )
       
-         ai14            = un4rad2 * coslatp * yprp
-         ai23            = un4rad2 * coslatm * yprm
          aireij1 ( i,j ) = ai14 * xprp
          aireij2 ( i,j ) = ai23 * xprp
Index: LMDZ5/branches/testing/libf/dyn3dpar/ismax.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/ismax.F	(revision 1750)
+++ 	(revision )
@@ -1,24 +1,0 @@
-!
-! $Header$
-!
-      function ismax(n,sx,incx)
-c
-      IMPLICIT NONE
-c
-      INTEGER n,i,incx,ismax,ix
-      real sx((n-1)*incx+1),sxmax
-c
-      ix=1
-      ismax=1
-      sxmax=sx(1)
-      do 10 i=1,n-1
-       ix=ix+incx
-       if(sx(ix).gt.sxmax) then
-         sxmax=sx(ix)
-         ismax=i+1
-       endif
-10    continue
-c
-      return
-      end
-
Index: LMDZ5/branches/testing/libf/dyn3dpar/ismin.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/ismin.F	(revision 1750)
+++ 	(revision )
@@ -1,24 +1,0 @@
-!
-! $Header$
-!
-      FUNCTION ismin(n,sx,incx)
-c
-      IMPLICIT NONE
-c
-      integer n,i,incx,ismin,ix
-      real sx((n-1)*incx+1),sxmin
-c
-      ix=1
-      ismin=1
-      sxmin=sx(1)
-      DO i=1,n-1
-         ix=ix+incx
-         if(sx(ix).lt.sxmin) then
-             sxmin=sx(ix)
-             ismin=i+1
-         endif
-      ENDDO
-c
-      return
-      end
-C
Index: LMDZ5/branches/testing/libf/dyn3dpar/leapfrog_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/leapfrog_p.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dpar/leapfrog_p.F	(revision 1795)
@@ -904,12 +904,12 @@
 c      ajout des tendances physiques:
 c      ------------------------------
-         IF (ok_strato) THEN
-           CALL top_bound_p( vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
-         ENDIF
-       
           CALL addfi_p( dtphys, leapf, forward   ,
      $                  ucov, vcov, teta , q   ,ps ,
      $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
 
+         IF (ok_strato) THEN
+           CALL top_bound_p(vcov,ucov,teta,masse,dtphys)
+         ENDIF
+       
 c$OMP BARRIER
 c$OMP MASTER
@@ -1024,30 +1024,5 @@
         ! Sponge layer (if any)
         IF (ok_strato) THEN
-          ! set dufi,dvfi,... to zero
-          ijb=ij_begin
-          ije=ij_end
-!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-          do l=1,llm
-            dufi(ijb:ije,l)=0
-            dtetafi(ijb:ije,l)=0
-            dqfi(ijb:ije,l,1:nqtot)=0
-          enddo
-!$OMP END DO
-!$OMP MASTER
-          dpfi(ijb:ije)=0
-!$OMP END MASTER
-          ijb=ij_begin
-          ije=ij_end
-          if (pole_sud) ije=ije-iip1
-!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
-          do l=1,llm
-            dvfi(ijb:ije,l)=0
-          enddo
-!$OMP END DO
-
-          CALL top_bound_p(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
-          CALL addfi_p( dtvr, leapf, forward   ,
-     $                  ucov, vcov, teta , q   ,ps ,
-     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
+          CALL top_bound_p(vcov,ucov,teta,masse,dtvr)
 !$OMP BARRIER
         ENDIF ! of IF (ok_strato) 
Index: LMDZ5/branches/testing/libf/dyn3dpar/temps.h
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/temps.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dpar/temps.h	(revision 1795)
@@ -13,11 +13,11 @@
 ! INCLUDE 'temps.h'
 
-      COMMON/temps/itaufin, dt, day_ini, day_end, annee_ref, day_ref,   &
-     &             itau_dyn, itau_phy, jD_ref, jH_ref, calend,          &
-     &             start_time
+      COMMON/temps/ dt, jD_ref, jH_ref, start_time,                     &
+     &             day_ini, day_end, annee_ref, day_ref,                &
+     &             itau_dyn, itau_phy, itaufin, calend
 
 
       INTEGER   itaufin
-      INTEGER itau_dyn, itau_phy
+      INTEGER itau_dyn, itau_phy 
       INTEGER day_ini, day_end, annee_ref, day_ref
       REAL      dt, jD_ref, jH_ref, start_time
Index: LMDZ5/branches/testing/libf/dyn3dpar/top_bound_p.F
===================================================================
--- LMDZ5/branches/testing/libf/dyn3dpar/top_bound_p.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/dyn3dpar/top_bound_p.F	(revision 1795)
@@ -1,3 +1,6 @@
-      SUBROUTINE top_bound_p( vcov,ucov,teta,masse, du,dv,dh )
+!
+! $Id$
+!
+      SUBROUTINE top_bound_p(vcov,ucov,teta,masse,dt)
       USE parallel
       IMPLICIT NONE
@@ -25,16 +28,39 @@
 c
 c=======================================================================
-c-----------------------------------------------------------------------
-c   Declarations:
-c   -------------
+
+! top_bound sponge layer model:
+! Quenching is modeled as: A(t)=Am+A0*exp(-lambda*t)
+! where Am is the zonal average of the field (or zero), and lambda the inverse
+! of the characteristic quenching/relaxation time scale
+! Thus, assuming Am to be time-independent, field at time t+dt is given by:
+! A(t+dt)=A(t)-(A(t)-Am)*(1-exp(-lambda*t))
+! Moreover lambda can be a function of model level (see below), and relaxation
+! can be toward the average zonal field or just zero (see below).
+
+! NB: top_bound sponge is only called from leapfrog if ok_strato=.true.
+
+! sponge parameters: (loaded/set in conf_gcm.F ; stored in comconst.h)
+!    iflag_top_bound=0 for no sponge
+!    iflag_top_bound=1 for sponge over 4 topmost layers
+!    iflag_top_bound=2 for sponge from top to ~1% of top layer pressure
+!    mode_top_bound=0: no relaxation
+!    mode_top_bound=1: u and v relax towards 0
+!    mode_top_bound=2: u and v relax towards their zonal mean
+!    mode_top_bound=3: u,v and pot. temp. relax towards their zonal mean
+!    tau_top_bound : inverse of charactericstic relaxation time scale at
+!                       the topmost layer (Hz)
+
 
 #include "comdissipn.h"
+#include "iniprint.h"
 
 c   Arguments:
 c   ----------
 
-      REAL ucov(iip1,jjp1,llm),vcov(iip1,jjm,llm),teta(iip1,jjp1,llm)
-      REAL masse(iip1,jjp1,llm)
-      REAL dv(iip1,jjm,llm),du(iip1,jjp1,llm),dh(iip1,jjp1,llm)
+      real,intent(inout) :: ucov(iip1,jjp1,llm) ! covariant zonal wind
+      real,intent(inout) :: vcov(iip1,jjm,llm) ! covariant meridional wind
+      real,intent(inout) :: teta(iip1,jjp1,llm) ! potential temperature
+      real,intent(in) :: masse(iip1,jjp1,llm) ! mass of atmosphere 
+      real,intent(in) :: dt ! time step (s) of sponge model
 
 c   Local:
@@ -43,9 +69,7 @@
       REAL uzon(jjp1,llm),vzon(jjm,llm),tzon(jjp1,llm)
       
-      INTEGER NDAMP
-      PARAMETER (NDAMP=4)
       integer i	
-      REAL,SAVE :: rdamp(llm)
-!     &   (/(0., i =1,llm-NDAMP),0.125E-5,.25E-5,.5E-5,1.E-5/) 
+      REAL,SAVE :: rdamp(llm) ! quenching coefficient
+      real,save :: lambda(llm) ! inverse or quenching time scale (Hz)
       LOGICAL,SAVE :: first=.true.
       INTEGER j,l,jjb,jje
@@ -53,43 +77,57 @@
 
       if (iflag_top_bound == 0) return
+
       if (first) then
 c$OMP BARRIER
 c$OMP MASTER
          if (iflag_top_bound == 1) then
-! couche eponge dans les 4 dernieres couches du modele
-             rdamp(:)=0.
-             rdamp(llm)=tau_top_bound
-             rdamp(llm-1)=tau_top_bound/2.
-             rdamp(llm-2)=tau_top_bound/4.
-             rdamp(llm-3)=tau_top_bound/8.
+! sponge quenching over the topmost 4 atmospheric layers
+             lambda(:)=0.
+             lambda(llm)=tau_top_bound
+             lambda(llm-1)=tau_top_bound/2.
+             lambda(llm-2)=tau_top_bound/4.
+             lambda(llm-3)=tau_top_bound/8.
          else if (iflag_top_bound == 2) then
-! couce eponge dans toutes les couches de pression plus faible que
-! 100 fois la pression de la derniere couche
-             rdamp(:)=tau_top_bound
+! sponge quenching over topmost layers down to pressures which are
+! higher than 100 times the topmost layer pressure
+             lambda(:)=tau_top_bound
      s       *max(presnivs(llm)/presnivs(:)-0.01,0.)
          endif
+
+! quenching coefficient rdamp(:)
+!         rdamp(:)=dt*lambda(:) ! Explicit Euler approx.
+         rdamp(:)=1.-exp(-lambda(:)*dt)
+
+         write(lunout,*)'TOP_BOUND mode',mode_top_bound
+         write(lunout,*)'Sponge layer coefficients'
+         write(lunout,*)'p (Pa)  z(km)  tau(s)   1./tau (Hz)'
+         do l=1,llm
+           if (rdamp(l).ne.0.) then
+             write(lunout,'(6(1pe12.4,1x))')
+     &        presnivs(l),log(preff/presnivs(l))*scaleheight,
+     &           1./lambda(l),lambda(l)
+           endif
+         enddo
          first=.false.
-         print*,'TOP_BOUND rdamp=',rdamp
 c$OMP END MASTER
 c$OMP BARRIER
-      endif
+      endif ! of if (first)
 
 
       CALL massbar_p(masse,massebx,masseby)
-C  CALCUL DES CHAMPS EN MOYENNE ZONALE:
-
-      jjb=jj_begin
-      jje=jj_end
-      IF (pole_sud) jje=jj_end-1
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      do l=1,llm
+
+      ! compute zonal average of vcov (or set it to zero)
+      if (mode_top_bound.ge.2) then
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_sud) jje=jj_end-1
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
         do j=jjb,jje
           zm=0.
           vzon(j,l)=0
           do i=1,iim
-! Rm: on peut travailler directement avec la moyenne zonale de vcov
-! plutot qu'avec celle de v car le coefficient cv qui relie les deux
-! ne varie qu'en latitude
+! NB: we can work using vcov zonal mean rather than v since the
+! cv coefficient (which relates the two) only varies with latitudes 
             vzon(j,l)=vzon(j,l)+vcov(i,j,l)*masseby(i,j,l)
             zm=zm+masseby(i,j,l)
@@ -97,24 +135,22 @@
           vzon(j,l)=vzon(j,l)/zm
         enddo
-      enddo
+       enddo
 c$OMP END DO NOWAIT   
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      do l=1,llm
-        do j=jjb,jje
-          do i=1,iip1
-            dv(i,j,l)=dv(i,j,l)-rdamp(l)*(vcov(i,j,l)-vzon(j,l))
-          enddo
-        enddo
-      enddo
-c$OMP END DO NOWAIT
-
-      jjb=jj_begin
-      jje=jj_end
-      IF (pole_nord) jjb=jj_begin+1
-      IF (pole_sud)  jje=jj_end-1
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      do l=1,llm
+      else
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
+         vzon(:,l)=0.
+       enddo
+c$OMP END DO NOWAIT
+      endif ! of if (mode_top_bound.ge.2)
+
+      ! compute zonal average of u (or set it to zero)
+      if (mode_top_bound.ge.2) then
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_nord) jjb=jj_begin+1
+       IF (pole_sud)  jje=jj_end-1
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
         do j=jjb,jje
           uzon(j,l)=0.
@@ -126,9 +162,22 @@
           uzon(j,l)=uzon(j,l)/zm
         enddo
-      enddo
-c$OMP END DO NOWAIT
-
+       enddo
+c$OMP END DO NOWAIT
+      else
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
+         uzon(:,l)=0.
+       enddo
+c$OMP END DO NOWAIT
+      endif ! of if (mode_top_bound.ge.2)
+
+      ! compute zonal average of potential temperature, if necessary
+      if (mode_top_bound.ge.3) then
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_nord) jjb=jj_begin+1
+       IF (pole_sud)  jje=jj_end-1
 c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)   
-      do l=1,llm
+       do l=1,llm
         do j=jjb,jje
           zm=0.
@@ -140,22 +189,61 @@
           tzon(j,l)=tzon(j,l)/zm
         enddo
-      enddo
-c$OMP END DO NOWAIT
-
-C   AMORTISSEMENTS LINEAIRES:
-
-c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
-      do l=1,llm
+       enddo
+c$OMP END DO NOWAIT
+      endif ! of if (mode_top_bound.ge.3)
+
+      if (mode_top_bound.ge.1) then
+       ! Apply sponge quenching on vcov:
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_sud) jje=jj_end-1
+
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
         do j=jjb,jje
           do i=1,iip1
-            du(i,j,l)=du(i,j,l)
-     s               -rdamp(l)*(ucov(i,j,l)-cu(i,j)*uzon(j,l))
-            dh(i,j,l)=dh(i,j,l)-rdamp(l)*(teta(i,j,l)-tzon(j,l))
-          enddo
-       enddo
-      enddo
-c$OMP END DO NOWAIT
-      
-
-      RETURN
+            vcov(i,j,l)=vcov(i,j,l)
+     &                  -rdamp(l)*(vcov(i,j,l)-vzon(j,l))
+          enddo
+        enddo
+       enddo
+c$OMP END DO NOWAIT
+
+       ! Apply sponge quenching on ucov:
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_nord) jjb=jj_begin+1
+       IF (pole_sud)  jje=jj_end-1
+
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
+        do j=jjb,jje
+          do i=1,iip1
+            ucov(i,j,l)=ucov(i,j,l)
+     &                  -rdamp(l)*(ucov(i,j,l)-cu(i,j)*uzon(j,l))
+          enddo
+       enddo
+       enddo
+c$OMP END DO NOWAIT
+      endif ! of if (mode_top_bound.ge.1)
+
+      if (mode_top_bound.ge.3) then   
+       ! Apply sponge quenching on teta:
+       jjb=jj_begin
+       jje=jj_end
+       IF (pole_nord) jjb=jj_begin+1
+       IF (pole_sud)  jje=jj_end-1
+
+c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)      
+       do l=1,llm
+        do j=jjb,jje
+          do i=1,iip1
+            teta(i,j,l)=teta(i,j,l)
+     &                  -rdamp(l)*(teta(i,j,l)-tzon(j,l))
+          enddo
+       enddo
+       enddo
+c$OMP END DO NOWAIT
+      endif ! of if (mode_top_bond.ge.3)
+
       END
Index: LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_no_writelim
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_no_writelim	(revision 1750)
+++ LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_no_writelim	(revision 1795)
@@ -27,4 +27,5 @@
 #include "compar1d.h"
 #include "flux_arp.h"
+#include "tsoilnudge.h"
 #include "fcg_gcssold.h"
 #include "fcg_racmo.h"
@@ -100,7 +101,22 @@
 !             initial profiles from RICO idealized
 !             LS convergence imposed from  RICO (cst) 
+!         = 6 ==> forcing_amma = .true.
 !         = 40 ==> forcing_GCSSold = .true.
 !             initial profile from GCSS file
 !             LS convergence imposed from GCSS file
+!         = 59 ==> forcing_sandu = .true.
+!             initial profiles from sanduref file: see prof.inp.001
+!             SST varying with time and divergence constante: see ifa_sanduref.txt file
+!             Radiation has to be computed interactively
+!         = 60 ==> forcing_astex = .true.
+!             initial profiles from file: see prof.inp.001 
+!             SST,divergence,ug,vg,ufa,vfa varying with time : see ifa_astex.txt file
+!             Radiation has to be computed interactively
+!         = 61 ==> forcing_armcu = .true.
+!             initial profiles from file: see prof.inp.001 
+!             sensible and latent heat flux imposed: see ifa_arm_cu_1.txt
+!             large scale advective forcing & radiative tendencies applied below 1000m: see ifa_arm_cu_2.txt
+!             use geostrophic wind ug=10m/s vg=0m/s. Duration of the case 53100s 
+!             Radiation to be switched off
 !
        forcing_type = 0
@@ -126,4 +142,11 @@
        CALL getin('ok_flux_surf',ok_flux_surf)
 
+!Config  Key  = ok_old_disvert
+!Config  Desc = utilisation de l ancien programme disvert0 (dans 1DUTILS.h)
+!Config  Def  = false
+!Config  Help = utilisation de l ancien programme disvert0 (dans 1DUTILS.h)
+       ok_old_disvert = .FALSE.
+       CALL getin('ok_old_disvert',ok_old_disvert)
+
 !Config  Key  = time_ini
 !Config  Desc = meaningless in this  case
@@ -227,4 +250,37 @@
        zpicinp = 300.
        CALL getin('zpicinp',zpicinp)
+!Config key = nudge_tsoil
+!Config  Desc = activation of soil temperature nudging
+!Config  Def  = .FALSE.
+!Config  Help = ...
+
+       nudge_tsoil=.FALSE.
+       CALL getin('nudge_tsoil',nudge_tsoil)
+
+!Config key = isoil_nudge
+!Config  Desc = level number where soil temperature is nudged
+!Config  Def  = 3
+!Config  Help = ...
+
+       isoil_nudge=3
+       CALL getin('isoil_nudge',isoil_nudge)
+
+!Config key = Tsoil_nudge
+!Config  Desc = target temperature for tsoil(isoil_nudge)
+!Config  Def  = 300.
+!Config  Help = ...
+
+       Tsoil_nudge=300.
+       CALL getin('Tsoil_nudge',Tsoil_nudge)
+
+!Config key = tau_soil_nudge
+!Config  Desc = nudging relaxation time for tsoil
+!Config  Def  = 3600.
+!Config  Help = ...
+
+       tau_soil_nudge=3600.
+       CALL getin('tau_soil_nudge',tau_soil_nudge)
+
+
 
 
@@ -250,4 +306,8 @@
       write(lunout,*)' qsolinp = ', qsolinp
       write(lunout,*)' zpicinp = ', zpicinp
+      write(lunout,*)' nudge_tsoil = ', nudge_tsoil
+      write(lunout,*)' isoil_nudge = ', isoil_nudge
+      write(lunout,*)' Tsoil_nudge = ', Tsoil_nudge
+      write(lunout,*)' tau_soil_nudge = ', tau_soil_nudge
       IF (forcing_type .eq.40) THEN
         write(lunout,*) '--- Forcing type GCSS Old --- with:'
@@ -703,21 +763,4 @@
       RETURN
       END
-      subroutine scopy(n,sx,incx,sy,incy)
-!
-      IMPLICIT NONE
-!
-      integer n,incx,incy,ix,iy,i
-      real sx((n-1)*incx+1),sy((n-1)*incy+1)
-!
-      iy=1
-      ix=1
-      do 10 i=1,n
-	 sy(iy)=sx(ix)
-         ix=ix+incx
-         iy=iy+incy
-10    continue
-!
-      return
-      end
       subroutine wrgradsfi(if,nl,field,name,titlevar)
       implicit none
@@ -956,6 +999,10 @@
       END
  
-      SUBROUTINE disvert(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
- 
+      SUBROUTINE disvert0(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
+ 
+!    Ancienne version disvert dont on a modifie nom pour utiliser
+!    le disvert de dyn3d (qui permet d'utiliser grille avec ab,bp imposes)
+!    (MPL 18092012)
+!
 !    Auteur :  P. Le Van .
 !
@@ -1402,4 +1449,88 @@
           end
 
+c-------------------------------------------------------------------------
+      SUBROUTINE read_sandu(fich_sandu,nlev_sandu,nt_sandu,ts_sandu)
+      implicit none
+
+c-------------------------------------------------------------------------
+c Read I.SANDU case forcing data
+c-------------------------------------------------------------------------
+
+      integer nlev_sandu,nt_sandu
+      real ts_sandu(nt_sandu)
+      character*80 fich_sandu
+
+      integer no,l,k,ip
+      real riy,rim,rid,rih,bid
+
+      integer iy,im,id,ih
+
+       real plev_min
+
+       plev_min = 55000.  ! pas de tendance de vap. d eau au-dessus de 55 hPa
+
+      open(21,file=trim(fich_sandu),form='formatted')
+      read(21,'(a)')
+      do ip = 1, nt_sandu
+      read(21,'(a)')
+      read(21,'(a)')
+      read(21,223) iy, im, id, ih, ts_sandu(ip)
+      print *,'ts=',iy,im,id,ih,ip,ts_sandu(ip)
+      enddo
+      close(21)
+
+  223 format(4i3,f8.2)
+  226 format(f7.1,1x,10f8.2)
+  227 format(f7.1,1x,1p,4e11.3)
+  230 format(6f9.3,4e11.3)
+
+          return
+          end
+
+!=====================================================================
+c-------------------------------------------------------------------------
+      SUBROUTINE read_astex(fich_astex,nlev_astex,nt_astex,div_astex,
+     : ts_astex,ug_astex,vg_astex,ufa_astex,vfa_astex)
+      implicit none
+
+c-------------------------------------------------------------------------
+c Read Astex case forcing data
+c-------------------------------------------------------------------------
+
+      integer nlev_astex,nt_astex
+      real div_astex(nt_astex),ts_astex(nt_astex),ug_astex(nt_astex)
+      real vg_astex(nt_astex),ufa_astex(nt_astex),vfa_astex(nt_astex)
+      character*80 fich_astex
+
+      integer no,l,k,ip
+      real riy,rim,rid,rih,bid
+
+      integer iy,im,id,ih
+
+       real plev_min
+
+       plev_min = 55000.  ! pas de tendance de vap. d eau au-dessus de 55 hPa
+
+      open(21,file=trim(fich_astex),form='formatted')
+      read(21,'(a)')
+      read(21,'(a)')
+      do ip = 1, nt_astex
+      read(21,'(a)')
+      read(21,'(a)')
+      read(21,223) iy, im, id, ih, div_astex(ip),ts_astex(ip),
+     :ug_astex(ip),vg_astex(ip),ufa_astex(ip),vfa_astex(ip)
+      ts_astex(ip)=ts_astex(ip)+273.15
+      print *,'ts=',iy,im,id,ih,ip,div_astex(ip),ts_astex(ip),
+     :ug_astex(ip),vg_astex(ip),ufa_astex(ip),vg_astex(ip)
+      enddo
+      close(21)
+
+  223 format(4i3,e13.2,f7.2,f7.3,f7.2,f7.3,f7.2)
+  226 format(f7.1,1x,10f8.2)
+  227 format(f7.1,1x,1p,4e11.3)
+  230 format(6f9.3,4e11.3)
+
+          return
+          end
 !=====================================================================
       subroutine read_twpice(fich_twpice,nlevel,ntime
@@ -1884,4 +2015,245 @@
        return
        end
+!=====================================================================
+
+       SUBROUTINE interp_sandu_vertical(play,nlev_sandu,plev_prof
+     :         ,t_prof,thl_prof,q_prof,u_prof,v_prof,w_prof
+     :         ,omega_prof,o3mmr_prof
+     :         ,t_mod,thl_mod,q_mod,u_mod,v_mod,w_mod
+     :         ,omega_mod,o3mmr_mod,mxcalc)
+
+       implicit none
+
+#include "dimensions.h"
+
+c-------------------------------------------------------------------------
+c Vertical interpolation of SANDUREF forcing data onto model levels
+c-------------------------------------------------------------------------
+
+       integer nlevmax
+       parameter (nlevmax=41)
+       integer nlev_sandu,mxcalc
+!       real play(llm), plev_prof(nlevmax)
+!       real t_prof(nlevmax),q_prof(nlevmax)
+!       real u_prof(nlevmax),v_prof(nlevmax), w_prof(nlevmax)
+!       real ht_prof(nlevmax),vt_prof(nlevmax)
+!       real hq_prof(nlevmax),vq_prof(nlevmax)
+
+       real play(llm), plev_prof(nlev_sandu)
+       real t_prof(nlev_sandu),thl_prof(nlev_sandu),q_prof(nlev_sandu)
+       real u_prof(nlev_sandu),v_prof(nlev_sandu), w_prof(nlev_sandu)
+       real omega_prof(nlev_sandu),o3mmr_prof(nlev_sandu)
+
+       real t_mod(llm),thl_mod(llm),q_mod(llm)
+       real u_mod(llm),v_mod(llm), w_mod(llm)
+       real omega_mod(llm),o3mmr_mod(llm)
+
+       integer l,k,k1,k2,kp
+       real aa,frac,frac1,frac2,fact
+
+       do l = 1, llm
+
+        if (play(l).ge.plev_prof(nlev_sandu)) then
+
+        mxcalc=l
+         k1=0
+         k2=0
+
+         if (play(l).le.plev_prof(1)) then
+
+         do k = 1, nlev_sandu-1
+          if (play(l).le.plev_prof(k)
+     :       .and. play(l).gt.plev_prof(k+1)) then
+            k1=k
+            k2=k+1
+          endif
+         enddo
+
+         if (k1.eq.0 .or. k2.eq.0) then
+          write(*,*) 'PB! k1, k2 = ',k1,k2
+          write(*,*) 'l,play(l) = ',l,play(l)/100
+         do k = 1, nlev_sandu-1
+          write(*,*) 'k,plev_prof(k) = ',k,plev_prof(k)/100
+         enddo
+         endif
+
+         frac = (plev_prof(k2)-play(l))/(plev_prof(k2)-plev_prof(k1))
+         t_mod(l)= t_prof(k2) - frac*(t_prof(k2)-t_prof(k1))
+         thl_mod(l)= thl_prof(k2) - frac*(thl_prof(k2)-thl_prof(k1))
+         q_mod(l)= q_prof(k2) - frac*(q_prof(k2)-q_prof(k1))
+         u_mod(l)= u_prof(k2) - frac*(u_prof(k2)-u_prof(k1))
+         v_mod(l)= v_prof(k2) - frac*(v_prof(k2)-v_prof(k1))
+         w_mod(l)= w_prof(k2) - frac*(w_prof(k2)-w_prof(k1))
+         omega_mod(l)=omega_prof(k2)-
+     :      frac*(omega_prof(k2)-omega_prof(k1))
+         o3mmr_mod(l)=o3mmr_prof(k2)-
+     :      frac*(o3mmr_prof(k2)-o3mmr_prof(k1))
+
+         else !play>plev_prof(1)
+
+         k1=1
+         k2=2
+         frac1 = (play(l)-plev_prof(k2))/(plev_prof(k1)-plev_prof(k2))
+         frac2 = (play(l)-plev_prof(k1))/(plev_prof(k1)-plev_prof(k2))
+         t_mod(l)= frac1*t_prof(k1) - frac2*t_prof(k2)
+         thl_mod(l)= frac1*thl_prof(k1) - frac2*thl_prof(k2)
+         q_mod(l)= frac1*q_prof(k1) - frac2*q_prof(k2)
+         u_mod(l)= frac1*u_prof(k1) - frac2*u_prof(k2)
+         v_mod(l)= frac1*v_prof(k1) - frac2*v_prof(k2)
+         w_mod(l)= frac1*w_prof(k1) - frac2*w_prof(k2)
+         omega_mod(l)= frac1*omega_prof(k1) - frac2*omega_prof(k2)
+         o3mmr_mod(l)= frac1*o3mmr_prof(k1) - frac2*o3mmr_prof(k2)
+
+         endif ! play.le.plev_prof(1)
+
+        else ! above max altitude of forcing file
+
+cjyg
+         fact=20.*(plev_prof(nlev_sandu)-play(l))/plev_prof(nlev_sandu) !jyg
+         fact = max(fact,0.)                                           !jyg
+         fact = exp(-fact)                                             !jyg
+         t_mod(l)= t_prof(nlev_sandu)                                   !jyg
+         thl_mod(l)= thl_prof(nlev_sandu)                                   !jyg
+         q_mod(l)= q_prof(nlev_sandu)*fact                              !jyg
+         u_mod(l)= u_prof(nlev_sandu)*fact                              !jyg
+         v_mod(l)= v_prof(nlev_sandu)*fact                              !jyg
+         w_mod(l)= w_prof(nlev_sandu)*fact                              !jyg
+         omega_mod(l)= omega_prof(nlev_sandu)*fact                      !jyg
+         o3mmr_mod(l)= o3mmr_prof(nlev_sandu)*fact                      !jyg
+
+        endif ! play
+
+       enddo ! l
+
+       do l = 1,llm
+!      print *,'t_mod(l),thl_mod(l),q_mod(l),u_mod(l),v_mod(l) ',
+!    $        l,t_mod(l),thl_mod(l),q_mod(l),u_mod(l),v_mod(l)
+       enddo
+
+          return
+          end
+!=====================================================================
+       SUBROUTINE interp_astex_vertical(play,nlev_astex,plev_prof
+     :         ,t_prof,thl_prof,qv_prof,ql_prof,qt_prof,u_prof,v_prof
+     :         ,w_prof,tke_prof,o3mmr_prof
+     :         ,t_mod,thl_mod,qv_mod,ql_mod,qt_mod,u_mod,v_mod,w_mod
+     :         ,tke_mod,o3mmr_mod,mxcalc)
+
+       implicit none
+
+#include "dimensions.h"
+
+c-------------------------------------------------------------------------
+c Vertical interpolation of Astex forcing data onto model levels
+c-------------------------------------------------------------------------
+
+       integer nlevmax
+       parameter (nlevmax=41)
+       integer nlev_astex,mxcalc
+!       real play(llm), plev_prof(nlevmax)
+!       real t_prof(nlevmax),qv_prof(nlevmax)
+!       real u_prof(nlevmax),v_prof(nlevmax), w_prof(nlevmax)
+!       real ht_prof(nlevmax),vt_prof(nlevmax)
+!       real hq_prof(nlevmax),vq_prof(nlevmax)
+
+       real play(llm), plev_prof(nlev_astex)
+       real t_prof(nlev_astex),thl_prof(nlev_astex),qv_prof(nlev_astex)
+       real u_prof(nlev_astex),v_prof(nlev_astex), w_prof(nlev_astex)
+       real o3mmr_prof(nlev_astex),ql_prof(nlev_astex)
+       real qt_prof(nlev_astex),tke_prof(nlev_astex)
+
+       real t_mod(llm),thl_mod(llm),qv_mod(llm)
+       real u_mod(llm),v_mod(llm), w_mod(llm),tke_mod(llm)
+       real o3mmr_mod(llm),ql_mod(llm),qt_mod(llm)
+
+       integer l,k,k1,k2,kp
+       real aa,frac,frac1,frac2,fact
+
+       do l = 1, llm
+
+        if (play(l).ge.plev_prof(nlev_astex)) then
+
+        mxcalc=l
+         k1=0
+         k2=0
+
+         if (play(l).le.plev_prof(1)) then
+
+         do k = 1, nlev_astex-1
+          if (play(l).le.plev_prof(k)
+     :       .and. play(l).gt.plev_prof(k+1)) then
+            k1=k
+            k2=k+1
+          endif
+         enddo
+
+         if (k1.eq.0 .or. k2.eq.0) then
+          write(*,*) 'PB! k1, k2 = ',k1,k2
+          write(*,*) 'l,play(l) = ',l,play(l)/100
+         do k = 1, nlev_astex-1
+          write(*,*) 'k,plev_prof(k) = ',k,plev_prof(k)/100
+         enddo
+         endif
+
+         frac = (plev_prof(k2)-play(l))/(plev_prof(k2)-plev_prof(k1))
+         t_mod(l)= t_prof(k2) - frac*(t_prof(k2)-t_prof(k1))
+         thl_mod(l)= thl_prof(k2) - frac*(thl_prof(k2)-thl_prof(k1))
+         qv_mod(l)= qv_prof(k2) - frac*(qv_prof(k2)-qv_prof(k1))
+         ql_mod(l)= ql_prof(k2) - frac*(ql_prof(k2)-ql_prof(k1))
+         qt_mod(l)= qt_prof(k2) - frac*(qt_prof(k2)-qt_prof(k1))
+         u_mod(l)= u_prof(k2) - frac*(u_prof(k2)-u_prof(k1))
+         v_mod(l)= v_prof(k2) - frac*(v_prof(k2)-v_prof(k1))
+         w_mod(l)= w_prof(k2) - frac*(w_prof(k2)-w_prof(k1))
+         tke_mod(l)= tke_prof(k2) - frac*(tke_prof(k2)-tke_prof(k1))
+         o3mmr_mod(l)=o3mmr_prof(k2)-
+     :      frac*(o3mmr_prof(k2)-o3mmr_prof(k1))
+
+         else !play>plev_prof(1)
+
+         k1=1
+         k2=2
+         frac1 = (play(l)-plev_prof(k2))/(plev_prof(k1)-plev_prof(k2))
+         frac2 = (play(l)-plev_prof(k1))/(plev_prof(k1)-plev_prof(k2))
+         t_mod(l)= frac1*t_prof(k1) - frac2*t_prof(k2)
+         thl_mod(l)= frac1*thl_prof(k1) - frac2*thl_prof(k2)
+         qv_mod(l)= frac1*qv_prof(k1) - frac2*qv_prof(k2)
+         ql_mod(l)= frac1*ql_prof(k1) - frac2*ql_prof(k2)
+         qt_mod(l)= frac1*qt_prof(k1) - frac2*qt_prof(k2)
+         u_mod(l)= frac1*u_prof(k1) - frac2*u_prof(k2)
+         v_mod(l)= frac1*v_prof(k1) - frac2*v_prof(k2)
+         w_mod(l)= frac1*w_prof(k1) - frac2*w_prof(k2)
+         tke_mod(l)= frac1*tke_prof(k1) - frac2*tke_prof(k2)
+         o3mmr_mod(l)= frac1*o3mmr_prof(k1) - frac2*o3mmr_prof(k2)
+
+         endif ! play.le.plev_prof(1)
+
+        else ! above max altitude of forcing file
+
+cjyg
+         fact=20.*(plev_prof(nlev_astex)-play(l))/plev_prof(nlev_astex) !jyg
+         fact = max(fact,0.)                                           !jyg
+         fact = exp(-fact)                                             !jyg
+         t_mod(l)= t_prof(nlev_astex)                                   !jyg
+         thl_mod(l)= thl_prof(nlev_astex)                                   !jyg
+         qv_mod(l)= qv_prof(nlev_astex)*fact                              !jyg
+         ql_mod(l)= ql_prof(nlev_astex)*fact                              !jyg
+         qt_mod(l)= qt_prof(nlev_astex)*fact                              !jyg
+         u_mod(l)= u_prof(nlev_astex)*fact                              !jyg
+         v_mod(l)= v_prof(nlev_astex)*fact                              !jyg
+         w_mod(l)= w_prof(nlev_astex)*fact                              !jyg
+         tke_mod(l)= tke_prof(nlev_astex)*fact                              !jyg
+         o3mmr_mod(l)= o3mmr_prof(nlev_astex)*fact                      !jyg
+
+        endif ! play
+
+       enddo ! l
+
+       do l = 1,llm
+!      print *,'t_mod(l),thl_mod(l),qv_mod(l),u_mod(l),v_mod(l) ',
+!    $        l,t_mod(l),thl_mod(l),qv_mod(l),u_mod(l),v_mod(l)
+       enddo
+
+          return
+          end
 
 !======================================================================
@@ -2048,4 +2420,79 @@
           end
 
+!======================================================================
+        SUBROUTINE interp_sandu_time(day,day1,annee_ref
+     i             ,year_ini_sandu,day_ini_sandu,nt_sandu,dt_sandu
+     i             ,nlev_sandu,ts_sandu,ts_prof)
+        implicit none
+
+!---------------------------------------------------------------------------------------
+! Time interpolation of a 2D field to the timestep corresponding to day
+!
+! day: current julian day (e.g. 717538.2)
+! day1: first day of the simulation
+! nt_sandu: total nb of data in the forcing (e.g. 13 for Sanduref)
+! dt_sandu: total time interval (in sec) between 2 forcing data (e.g. 6h for Sanduref)
+!---------------------------------------------------------------------------------------
+! inputs:
+        integer annee_ref
+        integer nt_sandu,nlev_sandu
+        integer year_ini_sandu
+        real day, day1,day_ini_sandu,dt_sandu
+        real ts_sandu(nt_sandu)
+! outputs:
+        real ts_prof
+! local:
+        integer it_sandu1, it_sandu2,k
+        real timeit,time_sandu1,time_sandu2,frac
+! Check that initial day of the simulation consistent with SANDU period:
+       if (annee_ref.ne.2006 ) then
+        print*,'Pour SANDUREF, annee_ref doit etre 2006 '
+        print*,'Changer annee_ref dans run.def'
+        stop
+       endif
+!      if (annee_ref.eq.2006 .and. day1.lt.day_ini_sandu) then
+!       print*,'SANDUREF debute le 15 Juillet 2006 (jour julien=196)'
+!       print*,'Changer dayref dans run.def'
+!       stop
+!      endif
+
+! Determine timestep relative to the 1st day of TOGA-COARE:
+!       timeit=(day-day1)*86400.
+!       if (annee_ref.eq.1992) then
+!        timeit=(day-day_ini_sandu)*86400.
+!       else
+!        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
+!       endif
+      timeit=(day-day_ini_sandu)*86400
+
+! Determine the closest observation times:
+       it_sandu1=INT(timeit/dt_sandu)+1
+       it_sandu2=it_sandu1 + 1
+       time_sandu1=(it_sandu1-1)*dt_sandu
+       time_sandu2=(it_sandu2-1)*dt_sandu
+       print *,'timeit day day_ini_sandu',timeit,day,day_ini_sandu
+       print *,'it_sandu1,it_sandu2,time_sandu1,time_sandu2',
+     .          it_sandu1,it_sandu2,time_sandu1,time_sandu2
+
+       if (it_sandu1 .ge. nt_sandu) then
+        write(*,*) 'PB-stop: day, it_sandu1, it_sandu2, timeit: '
+     :        ,day,it_sandu1,it_sandu2,timeit/86400.
+        stop
+       endif
+
+! time interpolation:
+       frac=(time_sandu2-timeit)/(time_sandu2-time_sandu1)
+       frac=max(frac,0.0)
+
+       ts_prof = ts_sandu(it_sandu2)
+     :          -frac*(ts_sandu(it_sandu2)-ts_sandu(it_sandu1))
+
+         print*,
+     :'day,annee_ref,day_ini_sandu,timeit,it_sandu1,it_sandu2,SST:',
+     :day,annee_ref,day_ini_sandu,timeit/86400.,it_sandu1,
+     :it_sandu2,ts_prof
+
+        return
+        END
 !=====================================================================
 c-------------------------------------------------------------------------
@@ -2209,4 +2656,95 @@
           end
  
+!======================================================================
+        SUBROUTINE interp_astex_time(day,day1,annee_ref
+     i             ,year_ini_astex,day_ini_astex,nt_astex,dt_astex
+     i             ,nlev_astex,div_astex,ts_astex,ug_astex,vg_astex
+     i             ,ufa_astex,vfa_astex,div_prof,ts_prof,ug_prof,vg_prof
+     i             ,ufa_prof,vfa_prof)
+        implicit none
+
+!---------------------------------------------------------------------------------------
+! Time interpolation of a 2D field to the timestep corresponding to day
+!
+! day: current julian day (e.g. 717538.2)
+! day1: first day of the simulation
+! nt_astex: total nb of data in the forcing (e.g. 41 for Astex)
+! dt_astex: total time interval (in sec) between 2 forcing data (e.g. 1h for Astex)
+!---------------------------------------------------------------------------------------
+
+! inputs:
+        integer annee_ref
+        integer nt_astex,nlev_astex
+        integer year_ini_astex
+        real day, day1,day_ini_astex,dt_astex
+        real div_astex(nt_astex),ts_astex(nt_astex),ug_astex(nt_astex)
+        real vg_astex(nt_astex),ufa_astex(nt_astex),vfa_astex(nt_astex)
+! outputs:
+        real div_prof,ts_prof,ug_prof,vg_prof,ufa_prof,vfa_prof
+! local:
+        integer it_astex1, it_astex2,k
+        real timeit,time_astex1,time_astex2,frac
+
+! Check that initial day of the simulation consistent with ASTEX period:
+       if (annee_ref.ne.1992 ) then
+        print*,'Pour Astex, annee_ref doit etre 1992 '
+        print*,'Changer annee_ref dans run.def'
+        stop
+       endif
+       if (annee_ref.eq.1992 .and. day1.lt.day_ini_astex) then
+        print*,'Astex debute le 13 Juin 1992 (jour julien=165)'
+        print*,'Changer dayref dans run.def'
+        stop
+       endif
+
+! Determine timestep relative to the 1st day of TOGA-COARE:
+!       timeit=(day-day1)*86400.
+!       if (annee_ref.eq.1992) then
+!        timeit=(day-day_ini_astex)*86400.
+!       else
+!        timeit=(day+2.-1.)*86400. ! 2 days between Jun13 and Jun15 1992
+!       endif
+      timeit=(day-day_ini_astex)*86400
+
+! Determine the closest observation times:
+       it_astex1=INT(timeit/dt_astex)+1
+       it_astex2=it_astex1 + 1
+       time_astex1=(it_astex1-1)*dt_astex
+       time_astex2=(it_astex2-1)*dt_astex
+       print *,'timeit day day_ini_astex',timeit,day,day_ini_astex
+       print *,'it_astex1,it_astex2,time_astex1,time_astex2',
+     .          it_astex1,it_astex2,time_astex1,time_astex2
+
+       if (it_astex1 .ge. nt_astex) then
+        write(*,*) 'PB-stop: day, it_astex1, it_astex2, timeit: '
+     :        ,day,it_astex1,it_astex2,timeit/86400.
+        stop
+       endif
+
+! time interpolation:
+       frac=(time_astex2-timeit)/(time_astex2-time_astex1)
+       frac=max(frac,0.0)
+
+       div_prof = div_astex(it_astex2)
+     :          -frac*(div_astex(it_astex2)-div_astex(it_astex1))
+       ts_prof = ts_astex(it_astex2)
+     :          -frac*(ts_astex(it_astex2)-ts_astex(it_astex1))
+       ug_prof = ug_astex(it_astex2)
+     :          -frac*(ug_astex(it_astex2)-ug_astex(it_astex1))
+       vg_prof = vg_astex(it_astex2)
+     :          -frac*(vg_astex(it_astex2)-vg_astex(it_astex1))
+       ufa_prof = ufa_astex(it_astex2)
+     :          -frac*(ufa_astex(it_astex2)-ufa_astex(it_astex1))
+       vfa_prof = vfa_astex(it_astex2)
+     :          -frac*(vfa_astex(it_astex2)-vfa_astex(it_astex1))
+
+         print*,
+     :'day,annee_ref,day_ini_astex,timeit,it_astex1,it_astex2,SST:',
+     :day,annee_ref,day_ini_astex,timeit/86400.,it_astex1,
+     :it_astex2,div_prof,ts_prof,ug_prof,vg_prof,ufa_prof,vfa_prof
+
+        return
+        END
+
 !======================================================================
         SUBROUTINE interp_toga_time(day,day1,annee_ref
@@ -2479,4 +3017,76 @@
         return
         end
+!======================================================================
+      subroutine readprofile_sandu(nlev_max,kmax,height,pprof,tprof,
+     .       thlprof,qprof,uprof,vprof,wprof,omega,o3mmr)
+!======================================================================
+      implicit none
+
+        integer nlev_max,kmax,kmax2
+        logical :: llesread = .true.
+
+        real height(nlev_max),pprof(nlev_max),tprof(nlev_max),
+     .  thlprof(nlev_max),
+     .  qprof(nlev_max),uprof(nlev_max),vprof(nlev_max),
+     .  wprof(nlev_max),omega(nlev_max),o3mmr(nlev_max)
+
+        integer, parameter :: ilesfile=1
+        integer :: ierr,irad,imax,jtot,k
+        logical :: lmoist,lcoriol,ltimedep
+        real :: xsize,ysize
+        real :: ustin,wsvsurf,timerad
+        character(80) :: chmess
+
+        if(.not.(llesread)) return
+
+       open (ilesfile,file='prof.inp.001',status='old',iostat=ierr)
+        if (ierr /= 0) stop 'ERROR:Prof.inp does not exist'
+        read (ilesfile,*) kmax
+        do k=1,kmax
+          read (ilesfile,*) height(k),pprof(k),  tprof(k),thlprof(k),
+     .                      qprof (k),uprof(k),  vprof(k),  wprof(k),
+     .                      omega (k),o3mmr(k)
+        enddo
+        close(ilesfile)
+
+        return
+        end
+
+!======================================================================
+      subroutine readprofile_astex(nlev_max,kmax,height,pprof,tprof,
+     .    thlprof,qvprof,qlprof,qtprof,uprof,vprof,wprof,tkeprof,o3mmr)
+!======================================================================
+      implicit none
+
+        integer nlev_max,kmax,kmax2
+        logical :: llesread = .true.
+
+        real height(nlev_max),pprof(nlev_max),tprof(nlev_max),
+     .  thlprof(nlev_max),qlprof(nlev_max),qtprof(nlev_max),
+     .  qvprof(nlev_max),uprof(nlev_max),vprof(nlev_max),
+     .  wprof(nlev_max),tkeprof(nlev_max),o3mmr(nlev_max)
+
+        integer, parameter :: ilesfile=1
+        integer :: ierr,irad,imax,jtot,k
+        logical :: lmoist,lcoriol,ltimedep
+        real :: xsize,ysize
+        real :: ustin,wsvsurf,timerad
+        character(80) :: chmess
+
+        if(.not.(llesread)) return
+
+       open (ilesfile,file='prof.inp.001',status='old',iostat=ierr)
+        if (ierr /= 0) stop 'ERROR:Prof.inp does not exist'
+        read (ilesfile,*) kmax
+        do k=1,kmax
+          read (ilesfile,*) height(k),pprof(k),  tprof(k),thlprof(k),
+     .                qvprof (k),qlprof (k),qtprof (k),
+     .                uprof(k),  vprof(k),  wprof(k),tkeprof(k),o3mmr(k)
+        enddo
+        close(ilesfile)
+
+        return
+        end
+
 
 
@@ -2539,44 +3149,606 @@
         return
         end
-!===============================================================
-      function ismin(n,sx,incx)
+!=====================================================================
+      subroutine read_amma(fich_amma,nlevel,ntime
+     :     ,zz,pp,temp,qv,u,v,dw
+     :     ,dt,dq,sens,flat)
+
+!program reading forcings of the AMMA case study
+
 
       implicit none
-      integer n,i,incx,ismin,ix
-      real sx((n-1)*incx+1),sxmin
-
-      ix=1
-      ismin=1
-      sxmin=sx(1)
-      do i=1,n-1
-         ix=ix+incx
-         if(sx(ix).lt.sxmin) then
-             sxmin=sx(ix)
-             ismin=i+1
-         endif
-      enddo
-
-      return
-      end
-
-!===============================================================
-      function ismax(n,sx,incx)
+
+#include "netcdf.inc"
+
+      integer ntime,nlevel
+      integer l,k
+      character*80 :: fich_amma
+      real*8 time(ntime)
+      real*8 zz(nlevel)	
+
+      real*8 temp(nlevel),pp(nlevel)
+      real*8 qv(nlevel),u(nlevel)
+      real*8 v(nlevel)
+      real*8 dw(nlevel,ntime)
+      real*8 dt(nlevel,ntime)
+      real*8 dq(nlevel,ntime)	
+      real*8 flat(ntime),sens(ntime)
+
+      integer nid, ierr
+      integer nbvar3d
+      parameter(nbvar3d=30)
+      integer var3didin(nbvar3d)
+
+      ierr = NF_OPEN(fich_amma,NF_NOWRITE,nid)
+      if (ierr.NE.NF_NOERR) then
+         write(*,*) 'ERROR: Pb opening forcings nc file '
+         write(*,*) NF_STRERROR(ierr)
+         stop ""
+      endif
+
+
+       ierr=NF_INQ_VARID(nid,"zz",var3didin(1)) 
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'lev'
+         endif
+
+
+      ierr=NF_INQ_VARID(nid,"temp",var3didin(2))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'temp'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"qv",var3didin(3))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'qv'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"u",var3didin(4))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'u'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"v",var3didin(5))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'v'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"dw",var3didin(6))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'dw'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"dt",var3didin(7))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'dt'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"dq",var3didin(8))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'dq'
+         endif
+      
+      ierr=NF_INQ_VARID(nid,"sens",var3didin(9))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'sens'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"flat",var3didin(10))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'flat'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"pp",var3didin(11))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'pp'
+      endif
+
+!dimensions lecture
+!      call catchaxis(nid,ntime,nlevel,time,z,ierr)
+ 
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(1),zz)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(1),zz)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture z ok',zz
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(2),temp)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(2),temp)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture th ok',temp
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(3),qv)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(3),qv)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture qv ok',qv
+ 
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(4),u)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(4),u)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture u ok',u
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(5),v)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(5),v)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture v ok',v
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(6),dw)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(6),dw)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture w ok',dw
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(7),dt)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(7),dt)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dt ok',dt
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(8),dq)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(8),dq)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dq ok',dq
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(9),sens)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(9),sens)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture sens ok',sens
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(10),flat)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(10),flat)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture flat ok',flat
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(11),pp)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(11),pp)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture pp ok',pp
+
+         return 
+         end subroutine read_amma
+!======================================================================
+        SUBROUTINE interp_amma_time(day,day1,annee_ref
+     i         ,year_ini_amma,day_ini_amma,nt_amma,dt_amma,nlev_amma
+     i         ,vitw_amma,ht_amma,hq_amma,lat_amma,sens_amma
+     o         ,vitw_prof,ht_prof,hq_prof,lat_prof,sens_prof)
+        implicit none
+
+!---------------------------------------------------------------------------------------
+! Time interpolation of a 2D field to the timestep corresponding to day
+!
+! day: current julian day (e.g. 717538.2)
+! day1: first day of the simulation
+! nt_amma: total nb of data in the forcing (e.g. 48 for AMMA)
+! dt_amma: total time interval (in sec) between 2 forcing data (e.g. 30min for AMMA)
+!---------------------------------------------------------------------------------------
+
+#include "compar1d.h"
+
+! inputs:
+        integer annee_ref
+        integer nt_amma,nlev_amma
+        integer year_ini_amma
+        real day, day1,day_ini_amma,dt_amma
+        real vitw_amma(nlev_amma,nt_amma)
+        real ht_amma(nlev_amma,nt_amma)
+        real hq_amma(nlev_amma,nt_amma)
+        real lat_amma(nt_amma)
+        real sens_amma(nt_amma)
+! outputs:
+        real vitw_prof(nlev_amma)
+        real ht_prof(nlev_amma)
+        real hq_prof(nlev_amma)
+        real lat_prof,sens_prof
+! local:
+        integer it_amma1, it_amma2,k
+        real timeit,time_amma1,time_amma2,frac
+
+
+        if (forcing_type.eq.6) then
+! Check that initial day of the simulation consistent with AMMA case:
+       if (annee_ref.ne.2006) then
+        print*,'Pour AMMA, annee_ref doit etre 2006'
+        print*,'Changer annee_ref dans run.def'
+        stop
+       endif
+       if (annee_ref.eq.2006 .and. day1.lt.day_ini_amma) then
+        print*,'AMMA a débuté le 10 juillet 2006',day1,day_ini_amma
+        print*,'Changer dayref dans run.def'
+        stop
+       endif
+       if (annee_ref.eq.2006 .and. day1.gt.day_ini_amma+1) then
+        print*,'AMMA a fini le 11 juillet'
+        print*,'Changer dayref ou nday dans run.def'
+        stop
+       endif
+       endif
+
+! Determine timestep relative to the 1st day of AMMA:
+!       timeit=(day-day1)*86400.
+!       if (annee_ref.eq.1992) then
+!        timeit=(day-day_ini_toga)*86400.
+!       else
+!        timeit=(day+61.-1.)*86400. ! 61 days between Nov01 and Dec31 1992
+!       endif
+      timeit=(day-day_ini_amma)*86400
+
+! Determine the closest observation times:
+!       it_amma1=INT(timeit/dt_amma)+1
+!       it_amma2=it_amma1 + 1
+!       time_amma1=(it_amma1-1)*dt_amma
+!       time_amma2=(it_amma2-1)*dt_amma
+
+       it_amma1=INT(timeit/dt_amma)+1
+       IF (it_amma1 .EQ. nt_amma) THEN
+       it_amma2=it_amma1 
+       ELSE
+       it_amma2=it_amma1 + 1
+       ENDIF
+       time_amma1=(it_amma1-1)*dt_amma
+       time_amma2=(it_amma2-1)*dt_amma
+
+       if (it_amma1 .gt. nt_amma) then
+        write(*,*) 'PB-stop: day, it_amma1, it_amma2, timeit: '
+     :        ,day,day_ini_amma,it_amma1,it_amma2,timeit/86400.
+        stop
+       endif
+
+! time interpolation:
+       frac=(time_amma2-timeit)/(time_amma2-time_amma1)
+       frac=max(frac,0.0)
+
+       lat_prof = lat_amma(it_amma2)
+     :          -frac*(lat_amma(it_amma2)-lat_amma(it_amma1))
+       sens_prof = sens_amma(it_amma2)
+     :          -frac*(sens_amma(it_amma2)-sens_amma(it_amma1))
+
+       do k=1,nlev_amma
+        vitw_prof(k) = vitw_amma(k,it_amma2)
+     :          -frac*(vitw_amma(k,it_amma2)-vitw_amma(k,it_amma1))
+        ht_prof(k) = ht_amma(k,it_amma2)
+     :          -frac*(ht_amma(k,it_amma2)-ht_amma(k,it_amma1))
+        hq_prof(k) = hq_amma(k,it_amma2)
+     :          -frac*(hq_amma(k,it_amma2)-hq_amma(k,it_amma1))
+        enddo
+
+        return
+        END
+
+!=====================================================================
+      subroutine read_fire(fich_fire,nlevel,ntime
+     :     ,zz,thl,qt,u,v,tke
+     :     ,ug,vg,wls,dqtdx,dqtdy,dqtdt,thl_rad)
+
+!program reading forcings of the FIRE case study
+
 
       implicit none
-      integer n,i,incx,ismax,ix
-      real sx((n-1)*incx+1),sxmax
-
-      ix=1
-      ismax=1
-      sxmax=sx(1)
-      do i=1,n-1
-         ix=ix+incx
-         if(sx(ix).gt.sxmax) then
-             sxmax=sx(ix)
-             ismax=i+1
-         endif
-      enddo
-
-      return
-      end
-
+
+#include "netcdf.inc"
+
+      integer ntime,nlevel
+      integer l,k
+      character*80 :: fich_fire
+      real*8 time(ntime)
+      real*8 zz(nlevel)	
+
+      real*8 thl(nlevel)
+      real*8 qt(nlevel),u(nlevel)
+      real*8 v(nlevel),tke(nlevel)
+      real*8 ug(nlevel,ntime),vg(nlevel,ntime),wls(nlevel,ntime)
+      real*8 dqtdx(nlevel,ntime),dqtdy(nlevel,ntime)
+      real*8 dqtdt(nlevel,ntime),thl_rad(nlevel,ntime)	
+
+      integer nid, ierr
+      integer nbvar3d
+      parameter(nbvar3d=30)
+      integer var3didin(nbvar3d)
+
+      ierr = NF_OPEN(fich_fire,NF_NOWRITE,nid)
+      if (ierr.NE.NF_NOERR) then
+         write(*,*) 'ERROR: Pb opening forcings nc file '
+         write(*,*) NF_STRERROR(ierr)
+         stop ""
+      endif
+
+
+       ierr=NF_INQ_VARID(nid,"zz",var3didin(1)) 
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'lev'
+         endif
+
+
+      ierr=NF_INQ_VARID(nid,"thetal",var3didin(2))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'temp'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"qt",var3didin(3))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'qv'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"u",var3didin(4))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'u'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"v",var3didin(5))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'v'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"tke",var3didin(6))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'tke'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"ugeo",var3didin(7))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'ug'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"vgeo",var3didin(8))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'vg'
+         endif
+      
+      ierr=NF_INQ_VARID(nid,"wls",var3didin(9))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'wls'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"dqtdx",var3didin(10))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'dqtdx'
+         endif
+
+      ierr=NF_INQ_VARID(nid,"dqtdy",var3didin(11))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'dqtdy'
+      endif
+
+      ierr=NF_INQ_VARID(nid,"dqtdt",var3didin(12))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'dqtdt'
+      endif
+
+      ierr=NF_INQ_VARID(nid,"thl_rad",var3didin(13))
+         if(ierr/=NF_NOERR) then
+           write(*,*) NF_STRERROR(ierr)
+           stop 'thl_rad'
+      endif
+!dimensions lecture
+!      call catchaxis(nid,ntime,nlevel,time,z,ierr)
+ 
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(1),zz)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(1),zz)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture z ok',zz
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(2),thl)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(2),thl)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture thl ok',thl
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(3),qt)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(3),qt)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture qt ok',qt
+ 
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(4),u)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(4),u)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture u ok',u
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(5),v)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(5),v)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture v ok',v
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(6),tke)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(6),tke)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture tke ok',tke
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(7),ug)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(7),ug)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture ug ok',ug
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(8),vg)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(8),vg)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture vg ok',vg
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(9),wls)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(9),wls)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture wls ok',wls
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(10),dqtdx)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(10),dqtdx)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dqtdx ok',dqtdx
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(11),dqtdy)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(11),dqtdy)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dqtdy ok',dqtdy
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(12),dqtdt)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(12),dqtdt)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture dqtdt ok',dqtdt
+
+#ifdef NC_DOUBLE
+         ierr = NF_GET_VAR_DOUBLE(nid,var3didin(13),thl_rad)
+#else
+         ierr = NF_GET_VAR_REAL(nid,var3didin(13),thl_rad)
+#endif
+         if(ierr/=NF_NOERR) then
+            write(*,*) NF_STRERROR(ierr)
+            stop "getvarup"
+         endif
+!          write(*,*)'lecture thl_rad ok',thl_rad
+
+         return 
+         end subroutine read_fire
Index: LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim	(revision 1750)
+++ LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim	(revision 1795)
@@ -125,4 +125,11 @@
        ok_flux_surf = .FALSE.
        CALL getin('ok_flux_surf',ok_flux_surf)
+
+!Config  Key  = ok_old_disvert
+!Config  Desc = utilisation de l ancien programme disvert0 (dans 1DUTILS.h)
+!Config  Def  = false
+!Config  Help = utilisation de l ancien programme disvert0 (dans 1DUTILS.h)
+       ok_old_disvert = .FALSE.
+       CALL getin('ok_old_disvert',ok_old_disvert)
 
 !Config  Key  = time_ini
@@ -703,21 +710,4 @@
       RETURN
       END
-      subroutine scopy(n,sx,incx,sy,incy)
-!
-      IMPLICIT NONE
-!
-      integer n,incx,incy,ix,iy,i
-      real sx((n-1)*incx+1),sy((n-1)*incy+1)
-!
-      iy=1
-      ix=1
-      do 10 i=1,n
-	 sy(iy)=sx(ix)
-         ix=ix+incx
-         iy=iy+incy
-10    continue
-!
-      return
-      end
       subroutine wrgradsfi(if,nl,field,name,titlevar)
       implicit none
@@ -1079,5 +1069,5 @@
  
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      SUBROUTINE disvert(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
+      SUBROUTINE disvert0(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
  
 !    Auteur :  P. Le Van .
@@ -2662,44 +2652,3 @@
         return
         end
-!===============================================================
-      function ismin(n,sx,incx)
-
-      implicit none
-      integer n,i,incx,ismin,ix
-      real sx((n-1)*incx+1),sxmin
-
-      ix=1
-      ismin=1
-      sxmin=sx(1)
-      do i=1,n-1
-         ix=ix+incx
-         if(sx(ix).lt.sxmin) then
-             sxmin=sx(ix)
-             ismin=i+1
-         endif
-      enddo
-
-      return
-      end
-
-!===============================================================
-      function ismax(n,sx,incx)
-
-      implicit none
-      integer n,i,incx,ismax,ix
-      real sx((n-1)*incx+1),sxmax
-
-      ix=1
-      ismax=1
-      sxmax=sx(1)
-      do i=1,n-1
-         ix=ix+incx
-         if(sx(ix).gt.sxmax) then
-             sxmax=sx(ix)
-             ismax=i+1
-         endif
-      enddo
-
-      return
-      end
-
+
Index: LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim_old
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim_old	(revision 1750)
+++ LMDZ5/branches/testing/libf/phy1d/1DUTILS.h_with_writelim_old	(revision 1795)
@@ -125,4 +125,11 @@
        ok_flux_surf = .FALSE.
        CALL getin('ok_flux_surf',ok_flux_surf)
+
+!Config  Key  = ok_old_disvert
+!Config  Desc = utilisation de l ancien programme disvert0 (dans 1DUTILS.h)
+!Config  Def  = false
+!Config  Help = utilisation de l ancien programme disvert0 (dans 1DUTILS.h)
+       ok_old_disvert = .FALSE.
+       CALL getin('ok_old_disvert',ok_old_disvert)
 
 !Config  Key  = time_ini
@@ -703,21 +710,4 @@
       RETURN
       END
-      subroutine scopy(n,sx,incx,sy,incy)
-!
-      IMPLICIT NONE
-!
-      integer n,incx,incy,ix,iy,i
-      real sx((n-1)*incx+1),sy((n-1)*incy+1)
-!
-      iy=1
-      ix=1
-      do 10 i=1,n
-	 sy(iy)=sx(ix)
-         ix=ix+incx
-         iy=iy+incy
-10    continue
-!
-      return
-      end
       subroutine wrgradsfi(if,nl,field,name,titlevar)
       implicit none
@@ -1079,5 +1069,5 @@
  
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-      SUBROUTINE disvert(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
+      SUBROUTINE disvert0(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
  
 !    Auteur :  P. Le Van .
@@ -2604,44 +2594,3 @@
         end
 
-!===============================================================
-      function ismin(n,sx,incx)
-
-      implicit none
-      integer n,i,incx,ismin,ix
-      real sx((n-1)*incx+1),sxmin
-
-      ix=1
-      ismin=1
-      sxmin=sx(1)
-      do i=1,n-1
-         ix=ix+incx
-         if(sx(ix).lt.sxmin) then
-             sxmin=sx(ix)
-             ismin=i+1
-         endif
-      enddo
-
-      return
-      end
-
-!===============================================================
-      function ismax(n,sx,incx)
-
-      implicit none
-      integer n,i,incx,ismax,ix
-      real sx((n-1)*incx+1),sxmax
-
-      ix=1
-      ismax=1
-      sxmax=sx(1)
-      do i=1,n-1
-         ix=ix+incx
-         if(sx(ix).gt.sxmax) then
-             sxmax=sx(ix)
-             ismax=i+1
-         endif
-      enddo
-
-      return
-      end
-
+
Index: LMDZ5/branches/testing/libf/phy1d/1D_decl_cases.h
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/1D_decl_cases.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/phy1d/1D_decl_cases.h	(revision 1795)
@@ -81,4 +81,92 @@
         real ht_proftwp(nlev_twpi),vt_proftwp(nlev_twpi)
         real hq_proftwp(nlev_twpi),vq_proftwp(nlev_twpi)
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!Declarations specifiques au cas AMMA
+        character*80 :: fich_amma
+! Option du cas AMMA ou on impose la discretisation verticale (Ap,Bp)
+        logical  :: fixe_disvert=.true.
+        integer nlev_amma, nt_amma
+!       parameter (nlev_amma=29, nt_amma=48)  ! Fleur, juillet 2012
+        parameter (nlev_amma=36, nt_amma=48)  ! Romain, octobre 2012
+!       parameter (nlev_amma=26, nt_amma=48)  ! Test MPL feverier 2013
+        integer year_ini_amma, day_ini_amma, mth_ini_amma
+        real heure_ini_amma
+        real day_ju_ini_amma   ! Julian day of amma first day
+        parameter (year_ini_amma=2006) 
+        parameter (mth_ini_amma=7)
+        parameter (day_ini_amma=10)  ! 10 = 10Juil2006
+        parameter (heure_ini_amma=0.) !0h en secondes
+        real dt_amma
+        parameter (dt_amma=1800.)
+
+!profils initiaux:
+        real plev_amma(nlev_amma)
+        real tv_amma(nlev_amma),rho_amma(nlev_amma)
+        real thv_amma(nlev_amma)
+        
+        real z_amma(nlev_amma)
+        real th_amma(nlev_amma),q_amma(nlev_amma)
+        real u_amma(nlev_amma)
+        real v_amma(nlev_amma)
+
+        real thvsurf_amma,tvsurf_amma,rhosurf_amma,thsurf
+
+        real th_ammai(nlev_amma),q_ammai(nlev_amma)
+        real u_ammai(nlev_amma)
+        real v_ammai(nlev_amma)
+        real vitw_ammai(nlev_amma) 
+        real ht_ammai(nlev_amma)
+        real hq_ammai(nlev_amma)
+        real vt_ammai(nlev_amma)
+        real vq_ammai(nlev_amma)
+        
+!forcings
+        real ht_amma(nlev_amma,nt_amma)
+        real hq_amma(nlev_amma,nt_amma)
+        real vitw_amma(nlev_amma,nt_amma)
+        real lat_amma(nt_amma),sens_amma(nt_amma)
+
+!champs interpoles
+        real plev_profamma(nlev_amma),vitw_profamma(nlev_amma)
+        real ht_profamma(nlev_amma)
+        real hq_profamma(nlev_amma)
+        real lat_profamma,sens_profamma
+        real vt_profamma(nlev_amma)
+        real vq_profamma(nlev_amma)
+        real th_profamma(nlev_amma)
+        real q_profamma(nlev_amma)
+        real u_profamma(nlev_amma)
+        real v_profamma(nlev_amma)
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!Declarations specifiques au cas FIRE
+        character*80 :: fich_fire
+        integer nlev_fire, nt_fire
+        parameter (nlev_fire=120, nt_fire=1)  
+        integer year_ini_fire, day_ini_fire, mth_ini_fire
+        real heure_ini_fire
+        real day_ju_ini_fire   ! Julian day of fire first day
+        parameter (year_ini_fire=1987) 
+        parameter (mth_ini_fire=7)
+        parameter (day_ini_fire=14)  ! 14 = 14Juil1987
+        parameter (heure_ini_fire=0.) !0h en secondes
+
+!profils initiaux:
+        real z_fire(nlev_fire)
+        real thl_fire(nlev_fire),qt_fire(nlev_fire)
+        real u_fire(nlev_fire), v_fire(nlev_fire)
+        real tke_fire(nlev_fire) 
+        
+!forcings
+        real ugeo_fire(nlev_fire),vgeo_fire(nlev_fire)
+        real wls_fire(nlev_fire),dqtdx_fire(nlev_fire)
+        real dqtdy_fire(nlev_fire)
+        real dqtdt_fire(nlev_fire),thl_rad_fire(nlev_fire)
+         
+        real ugeo_mod(llm),vgeo_mod(llm),wls_mod(llm)
+        real dqtdx_mod(llm),dqtdy_mod(llm),dqtdt_mod(llm)
+        real thl_rad_mod(llm)
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 ! Declarations specifiques au cas GCSSold
@@ -127,3 +215,63 @@
         real sens_prof,flat_prof,fact
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
+! declarations specifiques au cas Sandu
+        character*80 :: fich_sandu
+!        integer nlev_prof
+!        parameter (nlev_prof = 41)
+        integer nlev_sandu, nt_sandu
+        parameter (nlev_sandu=87, nt_sandu=13)
+        integer year_ini_sandu, day_ini_sandu, mth_ini_sandu
+        real day_ju_ini_sandu                                ! Julian day of sandu case first day
+        parameter (year_ini_sandu=2006)
+        parameter (mth_ini_sandu=7)
+        parameter (day_ini_sandu=15)  ! 196 = 15 juillet 2006
+        real dt_sandu, tau_sandu
+        logical  :: trouve_700=.true.
+        parameter (dt_sandu=6.*3600.)   ! forcages donnes ttes les 6 heures par ifa_sandu.txt
+!       parameter (tau_sandu=3600.)  ! temps de relaxation u,v,thetal,qt vers profil init et au dessus 700hPa
+!!
+        integer it_sandu1, it_sandu2
+        real time_sandu1,time_sandu2
+
+        real ts_sandu(nt_sandu)
+! profs comme "profil sandu"
+        real plev_profs(nlev_sandu)
+        real t_profs(nlev_sandu),thl_profs(nlev_sandu)
+        real q_profs(nlev_sandu)
+        real u_profs(nlev_sandu),v_profs(nlev_sandu),w_profs(nlev_sandu)
+        real omega_profs(nlev_sandu),o3mmr_profs(nlev_sandu)
+
+        real thl_mod(llm),omega_mod(llm),o3mmr_mod(llm),tke_mod(llm)
+! pour relaxer u,v,thl et qt vers les profils initiaux au dessus de 700hPa
+        real relax_u(llm),relax_v(llm),relax_thl(llm),relax_q(llm,2)
+!vertical advection computation
+        real d_t_z(llm), d_q_z(llm)
+        real d_t_dyn_z(llm), d_q_dyn_z(llm)
+        real zz(llm)
+        real zfact
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Declarations specifiques au cas Astex
+        character*80 :: fich_astex
+        integer nlev_astex, nt_astex
+        parameter (nlev_astex=34, nt_astex=49)
+        integer year_ini_astex, day_ini_astex, mth_ini_astex
+        real day_ju_ini_astex                                ! Julian day of astex case first day
+        parameter (year_ini_astex=1992)
+        parameter (mth_ini_astex=6)
+        parameter (day_ini_astex=13)  ! 165 = 13 juin 1992
+        real dt_astex, tau_astex
+        parameter (dt_astex=3600.)    ! forcages donnes ttes les heures par ifa_astex.txt
+        integer it_astex1, it_astex2
+        real time_astex1,time_astex2
+        real ts_astex(nt_astex),div_astex(nt_astex),ug_astex(nt_astex)
+        real vg_astex(nt_astex),ufa_astex(nt_astex),vfa_astex(nt_astex)
+        real div_prof,ug_prof,vg_prof,ufa_prof,vfa_prof
+! profa comme "profil astex"
+        real plev_profa(nlev_astex)
+        real t_profa(nlev_astex),thl_profa(nlev_astex)
+        real qv_profa(nlev_astex),ql_profa(nlev_astex)
+        real qt_profa(nlev_astex),o3mmr_profa(nlev_astex)
+        real u_profa(nlev_astex),v_profa(nlev_astex),w_profa(nlev_astex)
+        real tke_profa(nlev_astex)
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
Index: LMDZ5/branches/testing/libf/phy1d/1D_interp_cases.h
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/1D_interp_cases.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/phy1d/1D_interp_cases.h	(revision 1795)
@@ -181,4 +181,91 @@
 
       endif ! forcing_twpice
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!---------------------------------------------------------------------
+! Interpolation forcing AMMA
+!---------------------------------------------------------------------
+
+       if (forcing_amma) then
+
+        print*,
+     : '#### ITAP,day,day1,(day-day1)*86400,(day-day1)*86400/dt_amma=',
+     :    daytime,day1,(daytime-day1)*86400.,
+     :    (daytime-day1)*86400/dt_amma
+
+! time interpolation using TOGA interpolation routine
+        CALL interp_amma_time(daytime,day1,annee_ref
+     i       ,year_ini_amma,day_ju_ini_amma,nt_amma,dt_amma,nlev_amma
+     i       ,vitw_amma,ht_amma,hq_amma,lat_amma,sens_amma
+     o       ,vitw_profamma,ht_profamma,hq_profamma,lat_profamma
+     :       ,sens_profamma)
+
+      print*,'apres interpolation temporelle AMMA'
+
+      do k=1,nlev_amma
+         th_profamma(k)=0.
+         q_profamma(k)=0.
+         u_profamma(k)=0.
+         v_profamma(k)=0.
+         vt_profamma(k)=0.
+         vq_profamma(k)=0.
+       enddo
+! vertical interpolation using TOGA interpolation routine:
+!      write(*,*)'avant interp vert', t_proftwp
+      CALL interp_toga_vertical(play,nlev_amma,plev_amma
+     :         ,th_profamma,q_profamma,u_profamma,v_profamma
+     :         ,vitw_profamma
+     :         ,ht_profamma,vt_profamma,hq_profamma,vq_profamma
+     :         ,t_mod,q_mod,u_mod,v_mod,w_mod
+     :         ,ht_mod,vt_mod,hq_mod,vq_mod,mxcalc)
+       write(*,*) 'Profil initial forcing AMMA interpole'
+
+
+!calcul de l'advection verticale a partir du omega
+cCalcul des gradients verticaux
+cinitialisation
+      do l=1,llm
+      d_t_z(l)=0.
+      d_q_z(l)=0.
+      enddo
+
+      DO l=2,llm-1
+       d_t_z(l)=(temp(l+1)-temp(l-1))
+     &          /(play(l+1)-play(l-1))
+       d_q_z(l)=(q(l+1,1)-q(l-1,1))
+     &          /(play(l+1)-play(l-1))
+      ENDDO
+      d_t_z(1)=d_t_z(2)
+      d_q_z(1)=d_q_z(2)
+      d_t_z(llm)=d_t_z(llm-1)
+      d_q_z(llm)=d_q_z(llm-1)
+
+
+      do l = 1, llm
+       rho(l)  = play(l)/(rd*temp(l)*(1.+(rv/rd-1.)*q(l,1)))
+       omega(l) = w_mod(l)*(-rg*rho(l))
+       omega2(l)= omega(l)/rg*airefi ! flxmass_w calcule comme ds physiq
+       alpha = rd*temp(l)*(1.+(rv/rd-1.)*q(l,1))/play(l)
+!calcul de l'advection totale
+!        d_th_adv(l) = alpha*omega(l)/rcpd+ht_mod(l)-omega(l)*d_t_z(l)
+!attention: on impose dth
+        d_th_adv(l) = alpha*omega(l)/rcpd+
+     &         ht_mod(l)*(play(l)/pzero)**rkappa-omega(l)*d_t_z(l)
+!        d_th_adv(l) = 0.
+!        print*,'temp vert adv',l,ht_mod(l),vt_mod(l),-d_t_dyn_z(l)
+        d_q_adv(l,1) = hq_mod(l)-omega(l)*d_q_z(l)
+!        d_q_adv(l,1) = 0.
+!        print*,'q vert adv',l,hq_mod(l),vq_mod(l),-d_q_dyn_z(l)
+   
+       dt_cooling(l) = 0.0
+      enddo
+
+
+!     ok_flux_surf=.false.
+      fsens=-1.*sens_profamma
+      flat=-1.*lat_profamma
+
+      endif ! forcing_amma
+
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !---------------------------------------------------------------------
@@ -254,3 +341,168 @@
       endif ! forcing_armcu
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
+!---------------------------------------------------------------------
+! Interpolation forcing in time and onto model levels
+!---------------------------------------------------------------------
+      if (forcing_sandu) then
+
+        print*,
+     : '#### ITAP,day,day1,(day-day1)*86400,(day-day1)*86400/dt_sandu=',
+     :    day,day1,(day-day1)*86400.,(day-day1)*86400/dt_sandu
+
+! time interpolation:
+! ATTENTION, cet appel ne convient pas pour TOGA !!
+! revoir 1DUTILS.h et les arguments
+      CALL interp_sandu_time(daytime,day1,annee_ref
+     i             ,year_ini_sandu,day_ju_ini_sandu,nt_sandu,dt_sandu
+     i             ,nlev_sandu
+     i             ,ts_sandu,ts_prof)
+
+        if (type_ts_forcing.eq.1) ts_cur = ts_prof ! SST used in read_tsurf1d
+
+! vertical interpolation:
+      CALL interp_sandu_vertical(play,nlev_sandu,plev_profs
+     :         ,t_profs,thl_profs,q_profs,u_profs,v_profs,w_profs
+     :         ,omega_profs,o3mmr_profs
+     :         ,t_mod,thl_mod,q_mod,u_mod,v_mod,w_mod
+     :         ,omega_mod,o3mmr_mod,mxcalc)
+!calcul de l'advection verticale
+cCalcul des gradients verticaux
+cinitialisation
+      d_t_z(:)=0.
+      d_q_z(:)=0.
+      d_t_dyn_z(:)=0.
+      d_q_dyn_z(:)=0.
+! schema centre
+!     DO l=2,llm-1
+!      d_t_z(l)=(temp(l+1)-temp(l-1))
+!    &          /(play(l+1)-play(l-1))
+!      d_q_z(l)=(q(l+1,1)-q(l-1,1))
+!    &          /(play(l+1)-play(l-1))
+! schema amont
+      DO l=2,llm-1
+       d_t_z(l)=(temp(l+1)-temp(l))/(play(l+1)-play(l))
+       d_q_z(l)=(q(l+1,1)-q(l,1))/(play(l+1)-play(l))
+!     print *,'l temp2 temp0 play2 play0 omega_mod',
+!    & temp(l+1),temp(l-1),play(l+1),play(l-1),omega_mod(l)
+      ENDDO
+      d_t_z(1)=d_t_z(2)
+      d_q_z(1)=d_q_z(2)
+      d_t_z(llm)=d_t_z(llm-1)
+      d_q_z(llm)=d_q_z(llm-1)
+
+!  calcul de l advection verticale
+! Confusion w (m/s) et omega (Pa/s) !!
+      d_t_dyn_z(:)=omega_mod(:)*d_t_z(:)
+      d_q_dyn_z(:)=omega_mod(:)*d_q_z(:)
+!     do l=1,llm
+!      print *,'d_t_dyn omega_mod d_t_z d_q_dyn d_q_z',
+!    :l,d_t_dyn_z(l),omega_mod(l),d_t_z(l),d_q_dyn_z(l),d_q_z(l)
+!     enddo
+
+
+! large-scale forcing : pour le cas Sandu ces forcages sont la SST
+! et une divergence constante -> profil de omega
+      tsurf = ts_prof
+      write(*,*) 'SST suivante: ',tsurf
+      do l = 1, llm
+       omega(l) = omega_mod(l)
+       omega2(l)= omega(l)/rg*airefi ! flxmass_w calcule comme ds physiq
+
+       alpha = rd*temp(l)*(1.+(rv/rd-1.)*q(l,1))/play(l)
+!
+!      d_th_adv(l) = 0.0
+!      d_q_adv(l,1) = 0.0
+!CR:test advection=0
+!calcul de l'advection verticale
+        d_th_adv(l) = alpha*omega(l)/rcpd-d_t_dyn_z(l)
+!        print*,'temp adv',l,-d_t_dyn_z(l)
+        d_q_adv(l,1) = -d_q_dyn_z(l)
+!        print*,'q adv',l,-d_q_dyn_z(l)
+       dt_cooling(l) = 0.0
+      enddo
+      endif ! forcing_sandu
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!---------------------------------------------------------------------
+! Interpolation forcing in time and onto model levels
+!---------------------------------------------------------------------
+      if (forcing_astex) then
+
+        print*,
+     : '#### ITAP,day,day1,(day-day1)*86400,(day-day1)*86400/dt_astex=',
+     :    day,day1,(day-day1)*86400.,(day-day1)*86400/dt_astex
+
+! time interpolation:
+! ATTENTION, cet appel ne convient pas pour TOGA !!
+! revoir 1DUTILS.h et les arguments
+      CALL interp_astex_time(daytime,day1,annee_ref
+     i             ,year_ini_astex,day_ju_ini_astex,nt_astex,dt_astex
+     i             ,nlev_astex,div_astex,ts_astex,ug_astex,vg_astex
+     i             ,ufa_astex,vfa_astex,div_prof,ts_prof,ug_prof,vg_prof
+     i             ,ufa_prof,vfa_prof)
+
+        if (type_ts_forcing.eq.1) ts_cur = ts_prof ! SST used in read_tsurf1d
+
+! vertical interpolation:
+      CALL interp_astex_vertical(play,nlev_astex,plev_profa
+     :         ,t_profa,thl_profa,qv_profa,ql_profa,qt_profa
+     :         ,u_profa,v_profa,w_profa,tke_profa,o3mmr_profa
+     :         ,t_mod,thl_mod,qv_mod,ql_mod,qt_mod,u_mod,v_mod,w_mod
+     :         ,tke_mod,o3mmr_mod,mxcalc)
+!calcul de l'advection verticale
+!Calcul des gradients verticaux
+!initialisation
+      d_t_z(:)=0.
+      d_q_z(:)=0.
+      d_t_dyn_z(:)=0.
+      d_q_dyn_z(:)=0.
+! schema centre
+!     DO l=2,llm-1
+!      d_t_z(l)=(temp(l+1)-temp(l-1))
+!    &          /(play(l+1)-play(l-1))
+!      d_q_z(l)=(q(l+1,1)-q(l-1,1))
+!    &          /(play(l+1)-play(l-1))
+! schema amont
+      DO l=2,llm-1
+       d_t_z(l)=(temp(l+1)-temp(l))/(play(l+1)-play(l))
+       d_q_z(l)=(q(l+1,1)-q(l,1))/(play(l+1)-play(l))
+!     print *,'l temp2 temp0 play2 play0 omega_mod',
+!    & temp(l+1),temp(l-1),play(l+1),play(l-1),omega_mod(l)
+      ENDDO
+      d_t_z(1)=d_t_z(2)
+      d_q_z(1)=d_q_z(2)
+      d_t_z(llm)=d_t_z(llm-1)
+      d_q_z(llm)=d_q_z(llm-1)
+
+!  calcul de l advection verticale
+! Confusion w (m/s) et omega (Pa/s) !!
+      d_t_dyn_z(:)=w_mod(:)*d_t_z(:)
+      d_q_dyn_z(:)=w_mod(:)*d_q_z(:)
+!     do l=1,llm
+!      print *,'d_t_dyn omega_mod d_t_z d_q_dyn d_q_z',
+!    :l,d_t_dyn_z(l),omega_mod(l),d_t_z(l),d_q_dyn_z(l),d_q_z(l)
+!     enddo
+
+
+! large-scale forcing : pour le cas Astex ces forcages sont la SST
+! la divergence,ug,vg,ufa,vfa
+      tsurf = ts_prof
+      write(*,*) 'SST suivante: ',tsurf
+      do l = 1, llm
+       omega(l) = w_mod(l)
+       omega2(l)= omega(l)/rg*airefi ! flxmass_w calcule comme ds physiq
+
+       alpha = rd*temp(l)*(1.+(rv/rd-1.)*q(l,1))/play(l)
+!
+!      d_th_adv(l) = 0.0
+!      d_q_adv(l,1) = 0.0
+!CR:test advection=0
+!calcul de l'advection verticale
+        d_th_adv(l) = alpha*omega(l)/rcpd-d_t_dyn_z(l)
+!        print*,'temp adv',l,-d_t_dyn_z(l)
+        d_q_adv(l,1) = -d_q_dyn_z(l)
+!        print*,'q adv',l,-d_q_dyn_z(l)
+       dt_cooling(l) = 0.0
+      enddo
+      endif ! forcing_astex
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
Index: LMDZ5/branches/testing/libf/phy1d/1D_read_forc_cases.h
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/1D_read_forc_cases.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/phy1d/1D_read_forc_cases.h	(revision 1795)
@@ -4,6 +4,19 @@
 !----------------------------------------------------------------------
 
-      if (forcing_les .or. forcing_radconv .or. forcing_GCSSold ) then
-
+      if (forcing_les .or. forcing_radconv
+     :    .or. forcing_GCSSold .or. forcing_fire) then
+
+      if (forcing_fire) then
+!----------------------------------------------------------------------
+!read fire forcings from fire.nc
+!----------------------------------------------------------------------
+      fich_fire='fire.nc'
+      call read_fire(fich_fire,nlev_fire,nt_fire
+     :     ,height,tttprof,qtprof,uprof,vprof,e12prof
+     :     ,ugprof,vgprof,wfls,dqtdxls
+     :     ,dqtdyls,dqtdtls,thlpcar)
+      write(*,*) 'Forcing FIRE lu'
+      kmax=120            ! nombre de niveaux dans les profils et forcages
+      else 
 !----------------------------------------------------------------------
 ! Read profiles from files: prof.inp.001 and lscale.inp.001
@@ -16,4 +29,5 @@
      .           wfls,dqtdxls,dqtdyls,dqtdtls,
      .           thlpcar) 
+      endif
 
 ! compute altitudes of play levels.
@@ -35,11 +49,11 @@
         frac = (height(kmax)-zlay(l))/(height (kmax)-height(kmax-1))
         ttt =tttprof(kmax)-frac*(tttprof(kmax)-tttprof(kmax-1))
-        if (forcing_GCSSold .AND. tp_ini_GCSSold) then ! pot. temp. in initial profile
+       if ((forcing_GCSSold .AND. tp_ini_GCSSold) .OR. forcing_fire)then ! pot. temp. in initial profile
           temp(l) = ttt*(play(l)/pzero)**rkappa
           teta(l) = ttt
-        else
+       else
           temp(l) = ttt
           teta(l) = ttt*(pzero/play(l))**rkappa
-        endif
+       endif
           print *,' temp,teta ',l,temp(l),teta(l)
         q(l,1)  = qtprof(kmax)-frac*( qtprof(kmax)- qtprof(kmax-1))
@@ -58,11 +72,11 @@
           if(zlay(l)>height(k-1).and.zlay(l)<height(k)) then
             ttt =tttprof(k)-frac*(tttprof(k)-tttprof(k-1))
-        if (forcing_GCSSold .AND. tp_ini_GCSSold) then ! pot. temp. in initial profile
+       if ((forcing_GCSSold .AND. tp_ini_GCSSold) .OR. forcing_fire)then ! pot. temp. in initial profile
           temp(l) = ttt*(play(l)/pzero)**rkappa
           teta(l) = ttt
-        else
+       else
           temp(l) = ttt
           teta(l) = ttt*(pzero/play(l))**rkappa
-        endif
+       endif
           print *,' temp,teta ',l,temp(l),teta(l)
             q(l,1)  = qtprof(k)-frac*( qtprof(k)- qtprof(k-1))
@@ -77,11 +91,11 @@
           elseif(zlay(l)<height(1)) then ! profils uniformes pour z<height(1)
             ttt =tttprof(1)
-        if (forcing_GCSSold .AND. tp_ini_GCSSold) then ! pot. temp. in initial profile
+       if ((forcing_GCSSold .AND. tp_ini_GCSSold) .OR. forcing_fire)then ! pot. temp. in initial profile
           temp(l) = ttt*(play(l)/pzero)**rkappa
           teta(l) = ttt
-        else
+       else
           temp(l) = ttt
           teta(l) = ttt*(pzero/play(l))**rkappa
-        endif
+       endif
             q(l,1)  = qtprof(1)
             u(l)    =  uprof(1)
@@ -112,5 +126,5 @@
       enddo
 
-      endif ! forcing_les .or. forcing_GCSSold
+      endif ! forcing_les .or. forcing_GCSSold .or. forcing_fire
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !---------------------------------------------------------------------
@@ -263,4 +277,80 @@
        
       endif !forcing_twpice
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!---------------------------------------------------------------------
+! Forcing from AMMA experiment (Couvreux et al. 2010) :
+!---------------------------------------------------------------------
+
+      if (forcing_amma) then
+!read AMMA forcings
+      fich_amma='amma.nc'
+      call read_amma(fich_amma,nlev_amma,nt_amma
+     :     ,z_amma,plev_amma,th_amma,q_amma,u_amma,v_amma,vitw_amma
+     :     ,ht_amma,hq_amma,sens_amma,lat_amma)
+
+      write(*,*) 'Forcing AMMA lu'
+
+!champs initiaux:
+      do k=1,nlev_amma
+         th_ammai(k)=th_amma(k)
+         q_ammai(k)=q_amma(k)
+         u_ammai(k)=u_amma(k)
+         v_ammai(k)=v_amma(k)
+         vitw_ammai(k)=vitw_amma(k,12)
+         ht_ammai(k)=ht_amma(k,12)
+         hq_ammai(k)=hq_amma(k,12)
+         vt_ammai(k)=0.
+         vq_ammai(k)=0.
+      enddo   
+      omega(:)=0.      
+      omega2(:)=0.
+      rho(:)=0.
+! vertical interpolation using TOGA interpolation routine:
+!      write(*,*)'avant interp vert', t_proftwp
+      CALL interp_toga_vertical(play,nlev_amma,plev_amma
+     :         ,th_ammai,q_ammai,u_ammai,v_ammai,vitw_ammai
+     :         ,ht_ammai,vt_ammai,hq_ammai,vq_ammai
+     :         ,t_mod,q_mod,u_mod,v_mod,w_mod
+     :         ,ht_mod,vt_mod,hq_mod,vq_mod,mxcalc)
+!       write(*,*) 'Profil initial forcing TWP-ICE interpole',t_mod
+
+! initial and boundary conditions :
+!      tsurf = ts_proftwp
+      write(*,*) 'SST initiale mxcalc: ',tsurf,mxcalc
+      do l = 1, llm
+! Ligne du dessous à decommenter si on lit theta au lieu de temp
+!      temp(l) = t_mod(l)*(play(l)/pzero)**rkappa 
+       temp(l) = t_mod(l) 
+       q(l,1) = q_mod(l)
+       q(l,2) = 0.0
+!      print *,'read_forc: l,temp,q=',l,temp(l),q(l,1)
+       u(l) = u_mod(l)
+       v(l) = v_mod(l)
+       rho(l)  = play(l)/(rd*temp(l)*(1.+(rv/rd-1.)*q(l,1)))
+       omega(l) = w_mod(l)*(-rg*rho(l))
+       omega2(l)=omega(l)/rg*airefi ! flxmass_w calcule comme ds physiq
+
+       alpha = rd*temp(l)*(1.+(rv/rd-1.)*q(l,1))/play(l)
+!on applique le forcage total au premier pas de temps
+!attention: signe different de toga
+       d_th_adv(l) = alpha*omega(l)/rcpd+ht_mod(l)
+!forcage en th
+!       d_th_adv(l) = ht_mod(l)
+       d_q_adv(l,1) = hq_mod(l)
+       d_q_adv(l,2) = 0.0
+       dt_cooling(l)=0.
+      enddo     
+       write(*,*) 'Profil initial forcing AMMA interpole temp39',
+     &           temp(39)
+      
+
+!     ok_flux_surf=.false.
+      fsens=-1.*sens_amma(12)
+      flat=-1.*lat_amma(12)
+       
+      endif !forcing_amma
+
+
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !---------------------------------------------------------------------
@@ -366,3 +456,152 @@
       endif ! forcing_armcu
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
+!---------------------------------------------------------------------
+! Forcing from transition case of Irina Sandu                  
+!---------------------------------------------------------------------
+
+      if (forcing_sandu) then
+       write(*,*) 'Avant lecture Forcing SANDU'
+
+! read sanduref forcing :
+      fich_sandu = './ifa_sanduref.txt'
+      CALL read_sandu(fich_sandu,nlev_sandu,nt_sandu,ts_sandu)
+
+       write(*,*) 'Forcing SANDU lu'
+
+!----------------------------------------------------------------------
+! Read profiles from file: prof.inp.001 
+!----------------------------------------------------------------------
+
+      call readprofile_sandu(nlev_max,kmax,height,plev_profs,t_profs,
+     .           thl_profs,q_profs,u_profs,v_profs,
+     .           w_profs,omega_profs,o3mmr_profs)
+
+! time interpolation for initial conditions:
+      write(*,*) 'AVT 1ere INTERPOLATION: day,day1 = ',day,day1
+! ATTENTION, cet appel ne convient pas pour le cas SANDU !!
+! revoir 1DUTILS.h et les arguments
+
+      print *,'Avant interp_sandu_time'
+      print *,'daytime=',daytime
+      print *,'day1=',day1
+      print *,'annee_ref=',annee_ref
+      print *,'year_ini_sandu=',year_ini_sandu
+      print *,'day_ju_ini_sandu=',day_ju_ini_sandu
+      print *,'nt_sandu=',nt_sandu
+      print *,'dt_sandu=',dt_sandu
+      print *,'nlev_sandu=',nlev_sandu
+      CALL interp_sandu_time(daytime,day1,annee_ref
+     i             ,year_ini_sandu,day_ju_ini_sandu,nt_sandu,dt_sandu
+     i             ,nlev_sandu
+     i             ,ts_sandu,ts_prof)
+
+! vertical interpolation:
+      print *,'Avant interp_vertical: nlev_sandu=',nlev_sandu
+      CALL interp_sandu_vertical(play,nlev_sandu,plev_profs
+     :         ,t_profs,thl_profs,q_profs,u_profs,v_profs,w_profs
+     :         ,omega_profs,o3mmr_profs
+     :         ,t_mod,thl_mod,q_mod,u_mod,v_mod,w_mod
+     :         ,omega_mod,o3mmr_mod,mxcalc)
+       write(*,*) 'Profil initial forcing SANDU interpole'
+
+! initial and boundary conditions :
+      tsurf = ts_prof
+      write(*,*) 'SST initiale: ',tsurf
+      do l = 1, llm
+       temp(l) = t_mod(l)
+       tetal(l)=thl_mod(l)
+       q(l,1) = q_mod(l)
+       q(l,2) = 0.0
+       u(l) = u_mod(l)
+       v(l) = v_mod(l)
+       w(l) = w_mod(l)
+       omega(l) = omega_mod(l)
+       omega2(l)=omega(l)/rg*airefi ! flxmass_w calcule comme ds physiq
+!?       rho(l)  = play(l)/(rd*temp(l)*(1.+(rv/rd-1.)*q(l,1)))
+!?       omega2(l)=-rho(l)*omega(l)
+       alpha = rd*temp(l)*(1.+(rv/rd-1.)*q(l,1))/play(l)
+!      d_th_adv(l) = alpha*omega(l)/rcpd+vt_mod(l)
+!      d_q_adv(l,1) = vq_mod(l)
+       d_th_adv(l) = alpha*omega(l)/rcpd
+       d_q_adv(l,1) = 0.0
+       d_q_adv(l,2) = 0.0
+      enddo
+
+      endif ! forcing_sandu
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!---------------------------------------------------------------------
+! Forcing from Astex case
+!---------------------------------------------------------------------
+
+      if (forcing_astex) then
+       write(*,*) 'Avant lecture Forcing Astex'
+
+! read astex forcing :
+      fich_astex = './ifa_astex.txt'
+      CALL read_astex(fich_astex,nlev_astex,nt_astex,div_astex,ts_astex,
+     :  ug_astex,vg_astex,ufa_astex,vfa_astex)
+
+       write(*,*) 'Forcing Astex lu'
+
+!----------------------------------------------------------------------
+! Read profiles from file: prof.inp.001
+!----------------------------------------------------------------------
+
+      call readprofile_astex(nlev_max,kmax,height,plev_profa,t_profa,
+     .           thl_profa,qv_profa,ql_profa,qt_profa,u_profa,v_profa,
+     .           w_profa,tke_profa,o3mmr_profa)
+
+! time interpolation for initial conditions:
+      write(*,*) 'AVT 1ere INTERPOLATION: day,day1 = ',day,day1
+! ATTENTION, cet appel ne convient pas pour le cas SANDU !!
+! revoir 1DUTILS.h et les arguments
+
+      print *,'Avant interp_astex_time'
+      print *,'daytime=',daytime
+      print *,'day1=',day1
+      print *,'annee_ref=',annee_ref
+      print *,'year_ini_astex=',year_ini_astex
+      print *,'day_ju_ini_astex=',day_ju_ini_astex
+      print *,'nt_astex=',nt_astex
+      print *,'dt_astex=',dt_astex
+      print *,'nlev_astex=',nlev_astex
+      CALL interp_astex_time(daytime,day1,annee_ref
+     i             ,year_ini_astex,day_ju_ini_astex,nt_astex,dt_astex
+     i             ,nlev_astex,div_astex,ts_astex,ug_astex,vg_astex
+     i             ,ufa_astex,vfa_astex,div_prof,ts_prof,ug_prof,vg_prof
+     i             ,ufa_prof,vfa_prof)
+
+! vertical interpolation:
+      print *,'Avant interp_vertical: nlev_astex=',nlev_astex
+      CALL interp_astex_vertical(play,nlev_astex,plev_profa
+     :         ,t_profa,thl_profa,qv_profa,ql_profa,qt_profa
+     :         ,u_profa,v_profa,w_profa,tke_profa,o3mmr_profa
+     :         ,t_mod,thl_mod,qv_mod,ql_mod,qt_mod,u_mod,v_mod,w_mod
+     :         ,tke_mod,o3mmr_mod,mxcalc)
+       write(*,*) 'Profil initial forcing Astex interpole'
+
+! initial and boundary conditions :
+      tsurf = ts_prof
+      write(*,*) 'SST initiale: ',tsurf
+      do l = 1, llm
+       temp(l) = t_mod(l)
+       tetal(l)=thl_mod(l)
+       q(l,1) = qv_mod(l)
+       q(l,2) = ql_mod(l)
+       u(l) = u_mod(l)
+       v(l) = v_mod(l)
+       w(l) = w_mod(l)
+       omega(l) = w_mod(l)
+!      omega2(l)=omega(l)/rg*airefi ! flxmass_w calcule comme ds physiq
+!      rho(l)  = play(l)/(rd*temp(l)*(1.+(rv/rd-1.)*q(l,1)))
+!      omega2(l)=-rho(l)*omega(l)
+       alpha = rd*temp(l)*(1.+(rv/rd-1.)*q(l,1))/play(l)
+!      d_th_adv(l) = alpha*omega(l)/rcpd+vt_mod(l)
+!      d_q_adv(l,1) = vq_mod(l)
+       d_th_adv(l) = alpha*omega(l)/rcpd
+       d_q_adv(l,1) = 0.0
+       d_q_adv(l,2) = 0.0
+      enddo
+
+      endif ! forcing_astex
+
Index: LMDZ5/branches/testing/libf/phy1d/compar1d.h
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/compar1d.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/phy1d/compar1d.h	(revision 1795)
@@ -25,9 +25,10 @@
 
       logical :: restart
+      logical :: ok_old_disvert
 
       common/com_par1d/forcing_type,nat_surf,tsurf,rugos,               &
      & qsol,qsurf,psurf,zsurf,albedo,time,time_ini,xlat,xlon,airefi,    &
      & wtsurf,wqsurf,restart_runoff,xagesno,qsolinp,zpicinp,            &
-     & restart
+     & restart,ok_old_disvert
 
 !$OMP THREADPRIVATE(/com_par1d/)
Index: LMDZ5/branches/testing/libf/phy1d/lmdz1d.F
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/lmdz1d.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phy1d/lmdz1d.F	(revision 1795)
@@ -6,9 +6,11 @@
       use dimphy
       use surface_data, only : type_ocean,ok_veget
-      use pbl_surface_mod, only : pbl_surface_init, pbl_surface_final
+      use pbl_surface_mod, only : ftsoil, pbl_surface_init,
+     $                            pbl_surface_final
       use fonte_neige_mod, only : fonte_neige_init, fonte_neige_final 
 
       use infotrac ! new
       use control_mod
+      USE indice_sol_mod
 
       implicit none
@@ -20,9 +22,10 @@
 #include "clesphys.h"
 #include "dimsoil.h"
-#include "indicesol.h"
+!#include "indicesol.h"
 
 #include "comvert.h"
 #include "compar1d.h"
 #include "flux_arp.h"
+#include "tsoilnudge.h"
 #include "fcg_gcssold.h"
 !!!#include "fbforcing.h"
@@ -86,6 +89,6 @@
 
         integer :: kmax = llm
-        integer nlev_max
-        parameter (nlev_max = 100)
+        integer nlev_max,llm700
+        parameter (nlev_max = 1000)
         real timestep, frac, timeit
         real height(nlev_max),tttprof(nlev_max),qtprof(nlev_max),
@@ -98,19 +101,23 @@
 c        integer :: forcing_type
         logical :: forcing_les     = .false.
-        logical :: forcing_armcu  = .false.
+        logical :: forcing_armcu   = .false.
         logical :: forcing_rico    = .false.
         logical :: forcing_radconv = .false.
         logical :: forcing_toga    = .false.
         logical :: forcing_twpice  = .false.
+        logical :: forcing_amma    = .false.
         logical :: forcing_GCM2SCM = .false.
         logical :: forcing_GCSSold = .false.
+        logical :: forcing_sandu   = .false.
+        logical :: forcing_astex   = .false.
+        logical :: forcing_fire    = .false.
         integer :: type_ts_forcing ! 0 = SST constant; 1 = SST read from a file
 !                                                            (cf read_tsurf1d.F)
 
 !vertical advection computation
-        real d_t_z(llm), d_q_z(llm)
-        real d_t_dyn_z(llm), d_q_dyn_z(llm)
-        real zz(llm)
-        real zfact
+!       real d_t_z(llm), d_q_z(llm)
+!       real d_t_dyn_z(llm), d_q_dyn_z(llm)
+!       real zz(llm)
+!       real zfact
 
 !flag forcings
@@ -129,5 +136,5 @@
       real :: pzero=1.e5
       real :: play (llm),zlay (llm),sig_s(llm),plev(llm+1)
-      real :: playd(llm),zlayd(llm)
+      real :: playd(llm),zlayd(llm),ap_amma(llm+1),bp_amma(llm+1),poub
 
 !---------------------------------------------------------------------
@@ -137,7 +144,9 @@
       integer :: iq
       real :: phi(llm)
-      real :: teta(llm),temp(llm),u(llm),v(llm)
+      real :: teta(llm),tetal(llm),temp(llm),u(llm),v(llm),w(llm)
+      real :: rlat_rad(1),rlon_rad(1)
       real :: omega(llm+1),omega2(llm),rho(llm+1)
       real :: ug(llm),vg(llm),fcoriolis
+      real :: sfdt, cfdt
       real :: du_phys(llm),dv_phys(llm),dt_phys(llm)
       real :: du_dyn(llm),dv_dyn(llm),dt_dyn(llm)
@@ -194,5 +203,5 @@
 !  Fichiers et d'autres variables
 !---------------------------------------------------------------------
-      real ttt
+      real ttt,bow,q1
       integer :: ierr,k,l,i,it=1,mxcalc
       integer jjmp1
@@ -250,10 +259,24 @@
 !             initial profiles from RICO files 
 !             LS convergence imposed from RICO files 
+!forcing_type = 6 ==> forcing_amma = .true.
+!             initial profiles from AMMA nc file 
+!             LS convergence, omega and surface fluxes imposed from AMMA file  
 !forcing_type = 40 ==> forcing_GCSSold = .true.
 !             initial profile from GCSS file
 !             LS convergence imposed from GCSS file
+!forcing_type = 59 ==> forcing_sandu = .true.
+!             initial profiles from sanduref file: see prof.inp.001
+!             SST varying with time and divergence constante: see ifa_sanduref.txt file
+!             Radiation has to be computed interactively
+!forcing_type = 60 ==> forcing_astex = .true.
+!             initial profiles from file: see prof.inp.001 
+!             SST,divergence,ug,vg,ufa,vfa varying with time : see ifa_astex.txt file
+!             Radiation has to be computed interactively
 !forcing_type = 61 ==> forcing_armcu = .true.
-!             initial profile from arm_cu file
-!             LS convergence imposed from arm_cu file
+!             initial profiles from file: see prof.inp.001 
+!             sensible and latent heat flux imposed: see ifa_arm_cu_1.txt
+!             large scale advective forcing & radiative tendencies applied below 1000m: see ifa_arm_cu_2.txt
+!             use geostrophic wind ug=10m/s vg=0m/s. Duration of the case 53100s 
+!             Radiation to be switched off
 !
       if (forcing_type .eq.0) THEN
@@ -269,6 +292,12 @@
       elseif (forcing_type .eq.5) THEN
        forcing_rico = .true.
+      elseif (forcing_type .eq.6) THEN
+       forcing_amma = .true.
       elseif (forcing_type .eq.40) THEN
        forcing_GCSSold = .true.
+      elseif (forcing_type .eq.59) THEN
+       forcing_sandu   = .true.
+      elseif (forcing_type .eq.60) THEN
+       forcing_astex   = .true.
       elseif (forcing_type .eq.61) THEN
        forcing_armcu = .true.
@@ -276,5 +305,5 @@
       else
        write (*,*) 'ERROR : unknown forcing_type ', forcing_type
-       stop 'Forcing_type should be 0,1,2,3 or 40'
+       stop 'Forcing_type should be 0,1,2,3,4,5,6 or 40,59,60,61'
       ENDIF
       print*,"forcing type=",forcing_type
@@ -286,5 +315,6 @@
 
         type_ts_forcing = 0
-        if (forcing_toga) type_ts_forcing = 1
+        if (forcing_toga .or. forcing_sandu .or. forcing_astex) 
+     :    type_ts_forcing = 1
 
 !---------------------------------------------------------------------
@@ -325,4 +355,6 @@
 c Special case for arm_cu which lasts less than one day : 53100s !! (MPL 20111026)
       IF(forcing_type .EQ. 61) fnday=53100./86400.
+c Special case for amma which lasts less than one day : 64800s !! (MPL 20120216)
+      IF(forcing_type .EQ. 6) fnday=64800./86400.
       annee_ref = anneeref
       mois = 1
@@ -334,17 +366,40 @@
       day_ini = day
       day_end = day_ini + nday
+
+      IF (forcing_type .eq.2) THEN
 ! Convert the initial date of Toga-Coare to Julian day
       call ymds2ju
      $ (year_ini_toga,mth_ini_toga,day_ini_toga,heure,day_ju_ini_toga)
 
+      ELSEIF (forcing_type .eq.4) THEN
 ! Convert the initial date of TWPICE to Julian day
       call ymds2ju
      $ (year_ini_twpi,mth_ini_twpi,day_ini_twpi,heure_ini_twpi
      $ ,day_ju_ini_twpi)
-
-! Convert the initial date of Arm_cu to Julian day
+      ELSEIF (forcing_type .eq.6) THEN
+! Convert the initial date of AMMA to Julian day
+      call ymds2ju
+     $ (year_ini_amma,mth_ini_amma,day_ini_amma,heure_ini_amma
+     $ ,day_ju_ini_amma)
+
+      ELSEIF (forcing_type .eq.59) THEN
+! Convert the initial date of Sandu case to Julian day
+      call ymds2ju
+     $   (year_ini_sandu,mth_ini_sandu,day_ini_sandu,
+     $    time_ini*3600.,day_ju_ini_sandu)
+
+      ELSEIF (forcing_type .eq.60) THEN
+! Convert the initial date of Astex case to Julian day
+      call ymds2ju
+     $   (year_ini_astex,mth_ini_astex,day_ini_astex,
+     $    time_ini*3600.,day_ju_ini_astex)
+
+      ELSEIF (forcing_type .eq.61) THEN
+
+! Convert the initial date of Arm_cu case to Julian day
       call ymds2ju
      $ (year_ini_armcu,mth_ini_armcu,day_ini_armcu,heure_ini_armcu
      $ ,day_ju_ini_armcu)
+      ENDIF
 
       daytime = day + time_ini/24. ! 1st day and initial time of the simulation 
@@ -418,5 +473,14 @@
 !!      preff= 1.01325e5
       preff = psurf
-      call disvert(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
+      IF (ok_old_disvert) THEN
+        call disvert0(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
+        print *,'On utilise disvert0'
+      ELSE
+        call disvert(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig,
+     :                 scaleheight)
+        print *,'On utilise disvert'
+c       Nouvelle version disvert permettant d imposer ap,bp (modif L.Guez) MPL 18092012
+c       Dans ce cas, on lit ap,bp dans le fichier hybrid.txt
+      ENDIF
       sig_s=presnivs/preff
       plev =ap+bp*psurf
@@ -424,9 +488,17 @@
 ccc      zlay=-rd*300.*log(play/psurf)/rg ! moved after reading profiles
 
+      IF (forcing_type .eq. 59) THEN
+! pour forcing_sandu, on cherche l'indice le plus proche de 700hpa#3000m
       write(*,*) '***********************'
       do l = 1, llm
        write(*,*) 'l,play(l),presnivs(l): ',l,play(l),presnivs(l)
+       if (trouve_700 .and. play(l).le.70000) then
+         llm700=l
+         print *,'llm700,play=',llm700,play(l)/100.
+         trouve_700= .false.
+       endif
       enddo
       write(*,*) '***********************'
+      ENDIF
 
 c
@@ -460,5 +532,5 @@
 ! rday: defini dans suphel.F (86400.)
 ! day_ini: lu dans run.def (dayref)
-! rlat,rlon lus dans lmdz1d.def
+! rlat_rad,rlon-rad: transformes en radian de rlat,rlon lus dans lmdz1d.def (en degres)
 ! airefi,zcufi,zcvfi initialises au debut de ce programme
 ! rday,ra,rg,rd,rcpd declares dans YOMCST.h et calcules dans suphel.F
@@ -470,7 +542,10 @@
       zcufi=airefi
       zcvfi=airefi
+!
+      rlat_rad(:)=rlat(:)*rpi/180.
+      rlon_rad(:)=rlon(:)*rpi/180.
 
       call iniphysiq(ngrid,llm,rday,day_ini,timestep,
-     .     rlat,rlon,airefi,zcufi,zcvfi,ra,rg,rd,rcpd,1)
+     .     rlat_rad,rlon_rad,airefi,zcufi,zcvfi,ra,rg,rd,rcpd,(/1/))
       print*,'apres iniphysiq'
 
@@ -501,4 +576,17 @@
         agesno  = xagesno
         tsoil(:,:,:)=tsurf
+!------ AMMA 2e run avec modele sol et rayonnement actif (MPL 23052012)
+!       tsoil(1,1,1)=299.18
+!       tsoil(1,2,1)=300.08
+!       tsoil(1,3,1)=301.88
+!       tsoil(1,4,1)=305.48
+!       tsoil(1,5,1)=308.00
+!       tsoil(1,6,1)=308.00
+!       tsoil(1,7,1)=308.00
+!       tsoil(1,8,1)=308.00
+!       tsoil(1,9,1)=308.00
+!       tsoil(1,10,1)=308.00
+!       tsoil(1,11,1)=308.00
+!-----------------------------------------------------------------------
         call pbl_surface_init(qsol, fder, snsrf, qsurfsrf,
      &                                    evap, frugs, agesno, tsoil)
@@ -734,5 +822,6 @@
        endif
 
-       if (forcing_toga .or. forcing_GCSSold .or. forcing_twpice) then
+       if (forcing_toga .or. forcing_GCSSold .or. forcing_twpice
+     :    .or.forcing_amma) then
          fcoriolis=0.0 ; ug=0. ; vg=0.
        endif
@@ -748,4 +837,30 @@
      : -fcoriolis*(u(1:mxcalc)-ug(1:mxcalc))
 
+!!!!!!!!!!!!!!!!!!!!!!!!
+! Geostrophic wind
+!!!!!!!!!!!!!!!!!!!!!!!!
+       sfdt = sin(0.5*fcoriolis*timestep)
+       cfdt = cos(0.5*fcoriolis*timestep)
+!
+        du_age(1:mxcalc)= -2.*sfdt/timestep*
+     :          (sfdt*(u(1:mxcalc)-ug(1:mxcalc)) -
+     :           cfdt*(v(1:mxcalc)-vg(1:mxcalc))  )
+!!     : fcoriolis*(v(1:mxcalc)-vg(1:mxcalc))
+!
+       dv_age(1:mxcalc)= -2.*sfdt/timestep*
+     :          (cfdt*(u(1:mxcalc)-ug(1:mxcalc)) +
+     :           sfdt*(v(1:mxcalc)-vg(1:mxcalc))  )
+!!     : -fcoriolis*(u(1:mxcalc)-ug(1:mxcalc))
+!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!         call  writefield_phy('dv_age' ,dv_age,llm)
+!         call  writefield_phy('du_age' ,du_age,llm)
+!         call  writefield_phy('du_phys' ,du_phys,llm)
+!         call  writefield_phy('u_tend' ,u,llm)
+!         call  writefield_phy('u_g' ,ug,llm)
+!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Increment state variables
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
         u(1:mxcalc)=u(1:mxcalc) + timestep*(
      :              du_phys(1:mxcalc)
@@ -773,4 +888,13 @@
 
         teta=temp*(pzero/play)**rkappa
+!
+!---------------------------------------------------------------------
+!   Nudge soil temperature if requested
+!---------------------------------------------------------------------
+
+      IF (nudge_tsoil) THEN
+       ftsoil(1,isoil_nudge,:) = ftsoil(1,isoil_nudge,:) 
+     .  -timestep/tau_soil_nudge*(ftsoil(1,isoil_nudge,:)-Tsoil_nudge)
+      ENDIF
 
 !---------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/phy1d/ocean_forced_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/ocean_forced_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phy1d/ocean_forced_mod.F90	(revision 1795)
@@ -31,5 +31,6 @@
     USE limit_read_mod
     USE mod_grid_phy_lmdz
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+!    INCLUDE "indicesol.h"
     INCLUDE "YOMCST.h"
 
@@ -145,6 +146,7 @@
     USE limit_read_mod
     USE fonte_neige_mod,  ONLY : fonte_neige
-
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
+!    INCLUDE "indicesol.h"
     INCLUDE "dimsoil.h"
     INCLUDE "YOMCST.h"
Index: LMDZ5/branches/testing/libf/phy1d/surf_land_bucket_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/surf_land_bucket_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phy1d/surf_land_bucket_mod.F90	(revision 1795)
@@ -26,9 +26,10 @@
     USE mod_grid_phy_lmdz
     USE mod_phys_lmdz_para
+    USE indice_sol_mod
 !****************************************************************************************
 ! Bucket calculations for surface. 
 !
     INCLUDE "clesphys.h"
-    INCLUDE "indicesol.h"
+!    INCLUDE "indicesol.h"
     INCLUDE "dimsoil.h"
     INCLUDE "YOMCST.h"
Index: LMDZ5/branches/testing/libf/phy1d/tsoilnudge.h
===================================================================
--- LMDZ5/branches/testing/libf/phy1d/tsoilnudge.h	(revision 1795)
+++ LMDZ5/branches/testing/libf/phy1d/tsoilnudge.h	(revision 1795)
@@ -0,0 +1,7 @@
+      logical nudge_tsoil
+      integer isoil_nudge
+      real Tsoil_nudge, tau_soil_nudge
+
+      common /tsoilnudge/ nudge_tsoil, isoil_nudge, Tsoil_nudge,        &
+     &                   tau_soil_nudge
+
Index: LMDZ5/branches/testing/libf/phydev/physiq.F90
===================================================================
--- LMDZ5/branches/testing/libf/phydev/physiq.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phydev/physiq.F90	(revision 1795)
@@ -75,4 +75,5 @@
 integer,save :: iwrite_phys ! output every iwrite_phys physics step
 !$OMP THREADPRIVATE(iwrite_phys)
+integer :: iwrite_phys_omp ! intermediate variable to read iwrite_phys
 real :: t_ops ! frequency of the IOIPSL operations (eg average over...)
 real :: t_wrt ! frequency of the IOIPSL outputs
@@ -86,6 +87,11 @@
 ! Initialize outputs:
   itau0=0
-  iwrite_phys=1 !default: output every physics timestep
-  call getin("iwrite_phys",iwrite_phys)
+!$OMP MASTER
+  iwrite_phys_omp=1 !default: output every physics timestep
+  ! NB: getin() is not threadsafe; only one thread should call it.
+  call getin("iwrite_phys",iwrite_phys_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+  iwrite_phys=iwrite_phys_omp
   t_ops=pdtphys*iwrite_phys ! frequency of the IOIPSL operation
   t_wrt=pdtphys*iwrite_phys ! frequency of the outputs in the file
Index: LMDZ5/branches/testing/libf/phylmd/aero_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/aero_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/aero_mod.F90	(revision 1795)
@@ -5,5 +5,7 @@
 
   ! Total number of aerosols
-  INTEGER, PARAMETER :: naero_tot = 10 
+!  INTEGER, PARAMETER :: naero_tot = 10 
+!--STRAT AER
+  INTEGER, PARAMETER :: naero_tot = 11
 
   ! Identification number used in aeropt_2bands and aeropt_5wv
@@ -19,4 +21,7 @@
   INTEGER, PARAMETER :: id_AIBCM    = 9
   INTEGER, PARAMETER :: id_AIPOMM   = 10
+!--STRAT AER
+  INTEGER, PARAMETER :: id_strat   = 11
+
 
   ! Total number of aerosols actually used in LMDZ 
@@ -31,8 +36,11 @@
   ! 9 =  AIBCM
   !10 =  AIPOMM
-  INTEGER, PARAMETER :: naero_spc = 10
+!--STRAT AER
+  !11 = aerosols stratos
+!  INTEGER, PARAMETER :: naero_spc = 10
+  INTEGER, PARAMETER :: naero_spc = 11
 
   ! Corresponding names for the aerosols
-  CHARACTER(len=7),DIMENSION(naero_spc) :: name_aero=(/&
+  CHARACTER(len=7),DIMENSION(naero_spc), PARAMETER :: name_aero=(/&
        "ASBCM  ", &
        "ASPOMM ", &
@@ -44,5 +52,7 @@
        "CIDUSTM", &
        "AIBCM  ", &
-       "AIPOMM " /)
+!       "AIPOMM " /)
+       "AIPOMM ", &
+       "STRAT  " /)
 
 
@@ -65,4 +75,3 @@
   INTEGER, parameter :: nbands = 2
 
-
 END MODULE aero_mod
Index: LMDZ5/branches/testing/libf/phylmd/calbeta.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/calbeta.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/calbeta.F90	(revision 1795)
@@ -6,4 +6,5 @@
 
   USE dimphy
+  USE indice_sol_mod
   IMPLICIT none
 !======================================================================
@@ -13,7 +14,5 @@
 !
 ! Calculer quelques parametres pour appliquer la couche limite
-! ------------------------------------------------------------
-  INCLUDE "indicesol.h"
-  
+! ------------------------------------------------------------ 
 ! Variables d'entrees
 !****************************************************************************************
Index: LMDZ5/branches/testing/libf/phylmd/calcul_fluxs_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/calcul_fluxs_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/calcul_fluxs_mod.F90	(revision 1795)
@@ -12,4 +12,5 @@
     
     USE dimphy, ONLY : klon
+    USE indice_sol_mod
 
 ! Cette routine calcule les fluxs en h et q a l'interface et eventuellement
@@ -49,5 +50,4 @@
     INCLUDE "YOETHF.h"
     INCLUDE "FCTTRE.h"
-    INCLUDE "indicesol.h"
     INCLUDE "YOMCST.h"
 
Index: LMDZ5/branches/testing/libf/phylmd/calltherm.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/calltherm.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/calltherm.F90	(revision 1795)
@@ -17,7 +17,9 @@
      &      ,alp_bl_conv,alp_bl_stat &
 !!! fin nrlmd le 10/04/2012
-     &                    )
+     &      ,zqla,ztva )
 
       USE dimphy
+      USE indice_sol_mod
+
       implicit none
 #include "dimensions.h"
@@ -26,10 +28,8 @@
 #include "iniprint.h"
 
-!!! nrlmd le 10/04/2012
-#include "indicesol.h"
-!!! fin nrlmd le 10/04/2012
 
 !IM 140508
-      INTEGER itap
+      INTEGER, SAVE ::  itap
+!$OMP THREADPRIVATE(itap)
       REAL dtime
       LOGICAL debut
@@ -62,5 +62,5 @@
       real zqla(klon,klev)
       real zqta(klon,klev)
-      real ztv(klon,klev)
+      real ztv(klon,klev),ztva(klon,klev)
       real zpspsk(klon,klev)
       real ztla(klon,klev)
@@ -256,5 +256,5 @@
      &      ,alp_bl_conv,alp_bl_stat &
 !!! fin nrlmd le 10/04/2012
-     &                         )
+     &      ,ztva ) 
            if (prt_level.gt.10) write(lunout,*)'Apres thermcell_main OK'
          else
Index: LMDZ5/branches/testing/libf/phylmd/carbon_cycle_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/carbon_cycle_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/carbon_cycle_mod.F90	(revision 1795)
@@ -19,11 +19,14 @@
 !$OMP THREADPRIVATE(carbon_cycle_cpl)
 
+  LOGICAL :: carbon_cycle_emis_comp_omp=.FALSE.
   LOGICAL :: carbon_cycle_emis_comp=.FALSE. ! Calculation of emission compatible
 !$OMP THREADPRIVATE(carbon_cycle_emis_comp)
 
+  LOGICAL :: RCO2_inter_omp
   LOGICAL :: RCO2_inter  ! RCO2 interactive : if true calculate new value RCO2 for the radiation scheme
 !$OMP THREADPRIVATE(RCO2_inter)
 
 ! Scalare values when no transport, from physiq.def
+  REAL :: fos_fuel_s_omp
   REAL :: fos_fuel_s  ! carbon_cycle_fos_fuel dans physiq.def
 !$OMP THREADPRIVATE(fos_fuel_s)
@@ -112,6 +115,10 @@
     ! Read fosil fuel value if no transport
     IF (.NOT. carbon_cycle_tr) THEN
-       fos_fuel_s = 0.
-       CALL getin ('carbon_cycle_fos_fuel',fos_fuel_s)
+!$OMP MASTER
+       fos_fuel_s_omp = 0.
+       CALL getin ('carbon_cycle_fos_fuel',fos_fuel_s_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+       fos_fuel_s=fos_fuel_s_omp
        WRITE(lunout,*) 'carbon_cycle_fos_fuel = ', fos_fuel_s 
     END IF
@@ -120,6 +127,10 @@
     ! Read parmeter for calculation compatible emission
     IF (.NOT. carbon_cycle_tr) THEN
-       carbon_cycle_emis_comp=.FALSE.
-       CALL getin('carbon_cycle_emis_comp',carbon_cycle_emis_comp)
+!$OMP MASTER
+       carbon_cycle_emis_comp_omp=.FALSE.
+       CALL getin('carbon_cycle_emis_comp',carbon_cycle_emis_comp_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+       carbon_cycle_emis_comp=carbon_cycle_emis_comp_omp
        WRITE(lunout,*) 'carbon_cycle_emis_comp = ',carbon_cycle_emis_comp
        IF (carbon_cycle_emis_comp) THEN
@@ -129,6 +140,10 @@
 
     ! Read parameter for interactive calculation of the CO2 value for the radiation scheme
-    RCO2_inter=.FALSE.
-    CALL getin('RCO2_inter',RCO2_inter)
+!$OMP MASTER
+    RCO2_inter_omp=.FALSE.
+    CALL getin('RCO2_inter',RCO2_inter_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+    RCO2_inter=RCO2_inter_omp
     WRITE(lunout,*) 'RCO2_inter = ', RCO2_inter
     IF (RCO2_inter) THEN
@@ -294,9 +309,9 @@
     USE phys_cal_mod, ONLY : day_cur
     USE comgeomphy
+    USE indice_sol_mod
 
     IMPLICIT NONE
 
     INCLUDE "clesphys.h"
-    INCLUDE "indicesol.h"
     INCLUDE "iniprint.h"
     INCLUDE "YOMCST.h"
Index: LMDZ5/branches/testing/libf/phylmd/change_srf_frac_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/change_srf_frac_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/change_srf_frac_mod.F90	(revision 1795)
@@ -28,7 +28,7 @@
     USE cpl_mod, ONLY : cpl_receive_frac
     USE ocean_slab_mod, ONLY : ocean_slab_frac
+    USE indice_sol_mod
 
     INCLUDE "iniprint.h"
-    INCLUDE "indicesol.h"
     INCLUDE "YOMCST.h"
 
Index: LMDZ5/branches/testing/libf/phylmd/clcdrag.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/clcdrag.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/clcdrag.F90	(revision 1795)
@@ -8,4 +8,6 @@
 
   USE dimphy
+  USE indice_sol_mod
+
   IMPLICIT NONE
 ! ================================================================= c
@@ -17,5 +19,5 @@
 !
 ! knon----input-I- nombre de points pour un type de surface
-! nsrf----input-I- indice pour le type de surface; voir indicesol.h
+! nsrf----input-I- indice pour le type de surface; voir indice_sol_mod.F90
 ! u1-------input-R- vent zonal au 1er niveau du modele
 ! v1-------input-R- vent meridien au 1er niveau du modele
@@ -41,5 +43,4 @@
   INCLUDE "YOMCST.h"
   INCLUDE "YOETHF.h"
-  INCLUDE "indicesol.h"
   INCLUDE "clesphys.h"
 !
Index: LMDZ5/branches/testing/libf/phylmd/clesphys.h
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/clesphys.h	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/clesphys.h	(revision 1795)
@@ -12,5 +12,5 @@
        LOGICAL cycle_diurne,soil_model,new_oliq,ok_orodr,ok_orolf 
        LOGICAL ok_limitvrai
-       INTEGER nbapp_rad, iflag_con
+       INTEGER nbapp_rad, iflag_con,iflag_ener_conserv
        REAL co2_ppm, co2_ppm0, solaire
        REAL(kind=8) RCO2, RCH4, RN2O, RCFC11, RCFC12  
@@ -79,4 +79,5 @@
        COMMON/clesphys/cycle_diurne, soil_model, new_oliq,              &
      &     ok_orodr, ok_orolf, ok_limitvrai, nbapp_rad, iflag_con       &
+     &     , iflag_ener_conserv                                         &
      &     , co2_ppm, solaire                                           &
      &     , RCO2, RCH4, RN2O, RCFC11, RCFC12                           &
Index: LMDZ5/branches/testing/libf/phylmd/cltracrn.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/cltracrn.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/cltracrn.F90	(revision 1795)
@@ -9,4 +9,6 @@
   USE dimphy
   USE traclmdz_mod, ONLY : id_rn, id_pb
+  USE indice_sol_mod
+
   IMPLICIT NONE
 !======================================================================
@@ -44,5 +46,4 @@
 !======================================================================
   include "YOMCST.h"
-  include "indicesol.h"
 !
 !Entrees
Index: LMDZ5/branches/testing/libf/phylmd/coef_diff_turb_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/coef_diff_turb_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/coef_diff_turb_mod.F90	(revision 1795)
@@ -17,4 +17,5 @@
  
     USE dimphy
+    USE indice_sol_mod
 !
 ! Calculate coefficients(ycoefm, ycoefh) for turbulent diffusion in the 
@@ -55,5 +56,4 @@
 !****************************************************************************************
     INCLUDE "clesphys.h"
-    INCLUDE "indicesol.h"
     INCLUDE "iniprint.h"
     INCLUDE "compbl.h"
@@ -158,10 +158,10 @@
          
 !   iflag_pbl peut etre utilise comme longuer de melange
-       IF (iflag_pbl.GE.18) THEN
+       IF (iflag_pbl.GE.31) THEN
           CALL vdif_kcay(knon,dtime,RG,RD,ypaprs,yt, &
                yzlev,yzlay,yu,yv,yteta, &
                ycdragm,yq2,q2diag,ykmm,ykmn,yustar, &
                iflag_pbl)
-       ELSE
+       ELSE IF (iflag_pbl<20) THEN
           CALL yamada4(knon,dtime,RG,RD,ypaprs,yt, &
                yzlev,yzlay,yu,yv,yteta, &
@@ -187,4 +187,5 @@
     
     USE dimphy
+    USE indice_sol_mod
   
 !======================================================================
@@ -211,5 +212,4 @@
     INCLUDE "FCTTRE.h"
     INCLUDE "iniprint.h"
-    INCLUDE "indicesol.h"
     INCLUDE "compbl.h"
     INCLUDE "YOMCST.h"
@@ -479,4 +479,5 @@
 
     USE dimphy
+    USE indice_sol_mod
 
 !======================================================================
@@ -523,5 +524,4 @@
     REAL zdthmin(knon), zdthdp
 
-    INCLUDE "indicesol.h"
     INCLUDE "YOMCST.h"
 !
Index: LMDZ5/branches/testing/libf/phylmd/coefcdrag.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/coefcdrag.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/coefcdrag.F90	(revision 1795)
@@ -6,4 +6,7 @@
                             ts, qsurf, rugos, okri, ri1, &
                             cdram, cdrah, cdran, zri1, pref)
+
+      USE indice_sol_mod
+
       IMPLICIT none
 !-------------------------------------------------------------------------
@@ -18,5 +21,5 @@
 ! klon----input-I- dimension de la grille physique (= nb_pts_latitude X nb_pts_longitude)
 ! knon----input-I- nombre de points pour un type de surface
-! nsrf----input-I- indice pour le type de surface; voir indicesol.h
+! nsrf----input-I- indice pour le type de surface; voir indice_sol_mod.F90
 ! zxli----input-L- TRUE si calcul des cdrags selon Laurent Li
 ! speed---input-R- module du vent au 1er niveau du modele
@@ -49,5 +52,4 @@
       include "YOMCST.h"
       include "YOETHF.h"
-      include "indicesol.h"
 ! Quelques constantes :
       REAL, parameter :: RKAR=0.40, CB=5.0, CC=5.0, CD=5.0, cepdu2=(0.1)**2
Index: LMDZ5/branches/testing/libf/phylmd/concvl.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/concvl.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/concvl.F	(revision 1795)
@@ -387,8 +387,9 @@
      $              dd_t,dd_q,Plim1,Plim2,asupmax,supmax0,
      $              asupmaxmin,lalim_conv,
-!AC!+!RomP
-     $              da,phi,mp,phi2,d1a,dam,sij,clw,  ! RomP
-     $              elij,evap,ep,wdtrainA,wdtrainM)  ! RomP
-!AC!+!RomP
+!AC!+!RomP+jyg
+     $              da,phi,mp,phi2,d1a,dam,sij,clw,elij,       ! RomP
+     $              evap,ep,epmlmMm,eplaMm,                    ! RomP
+     $              wdtrainA,wdtrainM)                         ! RomP
+!AC!+!RomP+jyg
       endif  
 C------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/phylmd/condsurf.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/condsurf.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/condsurf.F	(revision 1795)
@@ -5,4 +5,5 @@
       USE mod_grid_phy_lmdz
       USE mod_phys_lmdz_para
+      USE indice_sol_mod
       IMPLICIT none
 c
@@ -25,5 +26,4 @@
 cym#include "dimensions.h"
 cym#include "dimphy.h"
-#include "indicesol.h"
 #include "temps.h"
 #include "clesphys.h"
Index: LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/conf_phys_m.F90	(revision 1795)
@@ -18,5 +18,5 @@
                        iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs, &
   		       ok_ade, ok_aie, ok_cdnc, aerosol_couple, &
-                       flag_aerosol, new_aod, &
+                       flag_aerosol, flag_aerosol_strat, new_aod, &
                        bl95_b0, bl95_b1,&
                        read_climoz, &
@@ -60,4 +60,5 @@
 ! ok_ade, ok_aie: apply or not aerosol direct and indirect effects
 ! ok_cdnc, ok cloud droplet number concentration
+! flag_aerosol_strat : flag pour les aerosols stratos
 ! bl95_b*: parameters in the formula to link CDNC to aerosol mass conc 
 !
@@ -72,4 +73,5 @@
   LOGICAL              :: ok_ade, ok_aie, ok_cdnc, aerosol_couple
   INTEGER              :: flag_aerosol
+  LOGICAL              :: flag_aerosol_strat
   LOGICAL              :: new_aod
   REAL                 :: bl95_b0, bl95_b1
@@ -87,4 +89,5 @@
   LOGICAL,SAVE        :: ok_ade_omp, ok_aie_omp, ok_cdnc_omp, aerosol_couple_omp
   INTEGER, SAVE       :: flag_aerosol_omp
+  LOGICAL, SAVE       :: flag_aerosol_strat_omp
   LOGICAL, SAVE       :: new_aod_omp
   REAL,SAVE           :: bl95_b0_omp, bl95_b1_omp
@@ -169,4 +172,5 @@
   LOGICAL,SAVE :: ok_orodr_omp, ok_orolf_omp, ok_limitvrai_omp
   INTEGER, SAVE :: nbapp_rad_omp, iflag_con_omp
+  INTEGER, SAVE :: iflag_ener_conserv_omp
   LOGICAL,SAVE :: ok_strato_omp
   LOGICAL,SAVE :: ok_hines_omp
@@ -306,4 +310,13 @@
   flag_aerosol_omp = 0
   CALL getin('flag_aerosol',flag_aerosol_omp)
+!
+!Config Key  = flag_aerosol_strat
+!Config Desc = use stratospheric aerosols T/F
+!Config Def  = false
+!Config Help = Used in physiq.F
+!
+!
+  flag_aerosol_strat_omp = .false.
+  CALL getin('flag_aerosol_strat',flag_aerosol_strat_omp)
 
 ! Temporary variable for testing purpose!!
@@ -653,4 +666,14 @@
        CALL getin('iflag_con',iflag_con_omp)
 
+!Config  Key  = iflag_ener_conserv
+!Config  Desc = Flag de convection
+!Config  Def  = 1
+!Config  Help = Flag  pour la convection les options suivantes existent :
+!Config         -1 pour Kinetic energy correction
+!Config         1  conservation kinetic and enthalpy
+       iflag_ener_conserv_omp = -1
+       CALL getin('iflag_ener_conserv',iflag_ener_conserv_omp)
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !!
@@ -1637,4 +1660,5 @@
     nbapp_rad = nbapp_rad_omp
     iflag_con = iflag_con_omp
+    iflag_ener_conserv = iflag_ener_conserv_omp
 
     epmax = epmax_omp
@@ -1705,4 +1729,5 @@
     aerosol_couple = aerosol_couple_omp
     flag_aerosol=flag_aerosol_omp
+    flag_aerosol_strat=flag_aerosol_strat_omp
     new_aod=new_aod_omp
     aer_type = aer_type_omp
@@ -1845,4 +1870,5 @@
   write(lunout,*)'nbapp_rad=',nbapp_rad
   write(lunout,*)'iflag_con=',iflag_con
+  write(lunout,*)'iflag_ener_conserv=',iflag_ener_conserv
   write(lunout,*)' epmax = ', epmax
   write(lunout,*)' ok_adj_ema = ', ok_adj_ema
@@ -1888,4 +1914,5 @@
   write(lunout,*)' aerosol_couple = ', aerosol_couple
   write(lunout,*)' flag_aerosol = ', flag_aerosol
+  write(lunout,*)' flag_aerosol_strat = ', flag_aerosol_strat
   write(lunout,*)' new_aod = ', new_aod
   write(lunout,*)' aer_type = ',aer_type
Index: LMDZ5/branches/testing/libf/phylmd/cpl_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/cpl_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/cpl_mod.F90	(revision 1795)
@@ -101,7 +101,7 @@
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, fco2_ocn_day
     USE surface_data
+    USE indice_sol_mod
 
     INCLUDE "dimensions.h"
-    INCLUDE "indicesol.h"
     INCLUDE "temps.h"
     INCLUDE "iniprint.h"
@@ -295,6 +295,6 @@
     USE phys_state_var_mod, ONLY : rlon, rlat
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
-    
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "temps.h"
     INCLUDE "iniprint.h"
@@ -424,5 +424,5 @@
 !
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, fco2_ocn_day
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
 
 ! Input arguments
@@ -541,5 +541,5 @@
 !
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
     INCLUDE "dimensions.h"
 
@@ -732,5 +732,5 @@
 !
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
     INCLUDE "dimensions.h"
 
@@ -1026,7 +1026,7 @@
     USE surface_data
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
+    USE indice_sol_mod
 ! Some includes
 !*************************************************************************************
-    INCLUDE "indicesol.h"
     INCLUDE "temps.h"
     INCLUDE "dimensions.h"
Index: LMDZ5/branches/testing/libf/phylmd/cv3_routines.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/cv3_routines.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/cv3_routines.F	(revision 1795)
@@ -3561,5 +3561,6 @@
       SUBROUTINE cv3_tracer(nloc,len,ncum,nd,na,
      &                       ment,sigij,da,phi,phi2,d1a,dam,
-     &                       ep,Vprecip,elij,clw,icb,inb)
+     &                       ep,Vprecip,elij,clw,epmlmMm,eplaMm,
+     &                       icb,inb)
         implicit none
 
@@ -3577,4 +3578,5 @@
 	real phi2(nloc,na,na)
 	real d1a(nloc,na),dam(nloc,na)
+	real epmlmMm(nloc,na,na),eplaMm(nloc,na)
 ! variables pour tracer dans precip de l'AA et des mel
 c local variables:
@@ -3595,12 +3597,21 @@
        dam(:,:)=0.
        epm(:,:,:)=0.
-c
-!  fraction deau condensee dans les melanges convertie en precip
+       eplaMm(:,:)=0.
+       epmlmMm(:,:,:)=0.
+       phi(:,:,:)=0.
+       phi2(:,:,:)=0.
+c
+!  fraction deau condensee dans les melanges convertie en precip : epm
+! et eau condensée précipitée dans masse d'air saturé : l_m*dM_m/dzdz.dzdz
         do j=1,na
          do k=1,na
            do i=1,ncum
             if(k.ge.icb(i).and.k.le.inb(i).and.
-     &         j.ge.k.and.j.le.inb(i)) then
-             epm(i,j,k)=1.-(1.-ep(i,j))*clw(i,j)/elij(i,k,j)
+!!jyg     &         j.ge.k.and.j.le.inb(i)) then
+!!jyg             epm(i,j,k)=1.-(1.-ep(i,j))*clw(i,j)/elij(i,k,j)
+     &         j.gt.k.and.j.le.inb(i)) then
+             epm(i,j,k)=1.-(1.-ep(i,j))*clw(i,j)/
+     &                     max(elij(i,k,j),1.e-16)
+!!
              epm(i,j,k)=max(epm(i,j,k),0.0)
             endif
@@ -3608,4 +3619,27 @@
          end do 
         end do 
+
+!
+        do j=1,na
+         do k=1,na
+           do i=1,ncum
+            if(k.ge.icb(i).and.k.le.inb(i)) then
+             eplaMm(i,j)=eplaMm(i,j) + ep(i,j)*clw(i,j)
+     &                  *ment(i,j,k)*(1.-sigij(i,j,k))
+            endif
+           end do 
+         end do 
+        end do
+!
+        do j=1,na
+         do k=1,j-1
+           do i=1,ncum
+            if(k.ge.icb(i).and.k.le.inb(i).and.
+     &         j.le.inb(i)) then
+             epmlmMm(i,j,k)=epm(i,j,k)*elij(i,k,j)*ment(i,k,j)
+            endif
+           end do 
+         end do 
+        end do
 
 !  matrices pour calculer la tendance des concentrations dans cvltr.F90
@@ -3622,7 +3656,4 @@
 
              phi2(i,j,k)=phi(i,j,k)*epm(i,j,k)   
-            else
-             dam(i,j)=0.
-             phi2(i,j,k)=0.
             endif
             end do 
Index: LMDZ5/branches/testing/libf/phylmd/cv3a_uncompress.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/cv3a_uncompress.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/cv3a_uncompress.F	(revision 1795)
@@ -10,23 +10,21 @@
      :         ,asupmaxmin
 !
-     :         ,da,phi                               !AC!
-     :         ,mp,phi2,d1a,dam,sigij                  !RomP
-     :         ,wdtrainA,wdtrainM,elij,clw           !RomP
-     :         ,evap,ep                              !RomP
+     :          ,da,phi,mp,phi2,d1a,dam,sigij         ! RomP+AC+jyg
+     :          ,clw,elij,evap,ep,epmlmMm,eplaMm      ! RomP
+     :          ,wdtrainA,wdtrainM                    ! RomP
 !
      o         ,iflag1,kbas1,ktop1
-     :         ,precip1,cbmf1,plcl1,plfc1,wbeff1,sig1,w01,ptop21
-     :         ,ft1,fq1,fu1,fv1,ftra1
-     :         ,sigd1,Ma1,mip1,Vprecip1,upwd1,dnwd1,dnwd01
-     :         ,qcondc1,wd1,cape1,cin1
-     :         ,tvp1
-     :         ,ftd1,fqd1
-     :         ,Plim11,Plim21,asupmax1,supmax01
-     :         ,asupmaxmin1     
-!
-     o         ,da1,phi1                             !AC!
-     o         ,mp1,phi21,d1a1,dam1,sigij1             !RomP
-     o         ,wdtrainA1,wdtrainM1,elij1,clw1       !RomP
-     o         ,evap1,ep1)                           !RomP
+     o         ,precip1,cbmf1,plcl1,plfc1,wbeff1,sig1,w01,ptop21
+     o         ,ft1,fq1,fu1,fv1,ftra1
+     o         ,sigd1,Ma1,mip1,Vprecip1,upwd1,dnwd1,dnwd01
+     o         ,qcondc1,wd1,cape1,cin1
+     o         ,tvp1
+     o         ,ftd1,fqd1
+     o         ,Plim11,Plim21,asupmax1,supmax01
+     o         ,asupmaxmin1     
+!
+     o          ,da1,phi1,mp1,phi21,d1a1,dam1,sigij1  ! RomP+AC+jyg
+     o          ,clw1,elij1,evap1,ep1,epmlmMm1,eplaMm1! RomP
+     o          ,wdtrainA1,wdtrainM1)                 ! RomP
 !
 ***************************************************************
@@ -67,8 +65,9 @@
       real phi2(nloc,nd,nd)                               !RomP
       real d1a(nloc,nd),dam(nloc,nd)                      !RomP
+      real sigij(nloc,nd,nd)                              !RomP
+      real clw(nloc,nd),elij(nloc,nd,nd)                  !RomP
+      real evap(nloc,nd),ep(nloc,nd)                      !RomP
+      real epmlmMm(nloc,nd,nd),eplaMm(nloc,nd)            !RomP+jyg
       real wdtrainA(nloc,nd), wdtrainM(nloc,nd)           !RomP
-      real sigij(nloc,nd,nd)                                !RomP
-      real elij(nloc,nd,nd),clw(nloc,nd)                  !RomP
-      real evap(nloc,nd),ep(nloc,nd)                      !RomP
 !
 c outputs:
@@ -94,12 +93,14 @@
       real phi21(nloc,nd,nd)                              !RomP
       real d1a1(nloc,nd),dam1(nloc,nd)                    !RomP
+      real sigij1(len,nd,nd)                              !RomP
+      real clw1(len,nd),elij1(len,nd,nd)                  !RomP
+      real evap1(len,nd),ep1(len,nd)                      !RomP
+      real epmlmMm1(len,nd,nd),eplaMm1(len,nd)            !RomP+jyg
       real wdtrainA1(len,nd), wdtrainM1(len,nd)           !RomP
-      real sigij1(len,nd,nd)                                !RomP
-      real elij1(len,nd,nd),clw1(len,nd)                  !RomP
-      real evap1(len,nd),ep1(len,nd)                      !RomP
 !
 c
 c local variables:
-      integer i,k,j,k1,k2
+      integer i,k,j
+cc    integer k1,k2
 
         do 2000 i=1,ncum
@@ -147,9 +148,10 @@
             d1a1(idcum(i),k)     = d1a(i,k)               !RomP
             dam1(idcum(i),k)     = dam(i,k)               !RomP
-            wdtrainA1(idcum(i),k)= wdtrainA(i,k)          !RomP
-            wdtrainM1(idcum(i),k)= wdtrainM(i,k)          !RomP
             clw1(idcum(i),k)     = clw(i,k)               !RomP
             evap1(idcum(i),k)    = evap(i,k)              !RomP
             ep1(idcum(i),k)      = ep(i,k)                !RomP
+            eplaMm(idcum(i),k)   = eplaMm(i,k)            !RomP+jyg
+            wdtrainA1(idcum(i),k)= wdtrainA(i,k)          !RomP
+            wdtrainM1(idcum(i),k)= wdtrainM(i,k)          !RomP
 !
  2010    continue
@@ -171,11 +173,12 @@
 
 !AC!
-       do k2=1,nd
-         do k1=1,nd 
+       do j=1,nd
+         do k=1,nd 
           do i=1,ncum
-            phi1(idcum(i),k1,k2)=phi(i,k1,k2)                 !AC!
-            phi21(idcum(i),k1,k2)= phi2(idcum(i),k1,k2)   !RomP
-            sigij1(idcum(i),k1,k2) = sigij(idcum(i),k1,k2)    !RomP
-            elij1(idcum(i),k1,k2)= elij(idcum(i),k1,k2)   !RomP
+            phi1(idcum(i),k,j)   = phi(i,k,j)           !AC!
+            phi21(idcum(i),k,j)  = phi2(i,k,j)          !RomP
+            sigij1(idcum(i),k,j) = sigij(i,k,j)         !RomP
+            elij1(idcum(i),k,j)  = elij(i,k,j)          !RomP
+            epmlmMm(idcum(i),k,j)= epmlmMm(i,k,j)       !RomP+jyg
           end do
          end do
Index: LMDZ5/branches/testing/libf/phylmd/cv_driver.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/cv_driver.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/cv_driver.F	(revision 1795)
@@ -9,7 +9,7 @@
      &                   icb1,inb1,
      &                   delt,Ma1,upwd1,dnwd1,dnwd01,qcondc1,wd1,cape1,
-     &                   da1,phi1,mp1,phi21,d1a1,dam1,sij1,clw1,elij1,
-     &                   evap1,ep1,epmlmMm1,eplaMm1,
-     &                   wdtrainA1,wdtrainM1)
+     &                   da1,phi1,mp1,phi21,d1a1,dam1,sij1,clw1,elij1,  ! RomP
+     &                   evap1,ep1,epmlmMm1,eplaMm1,                    ! RomP 
+     &                   wdtrainA1,wdtrainM1)                           ! RomP
 C
       USE dimphy
@@ -18,4 +18,8 @@
 C.............................START PROLOGUE............................
 C
+!
+! All argument names (except len,nd,ntra,nloc,delt and the flags) have a "1" appended.
+! The "1" is removed for the corresponding compressed (local) variables.
+!
 C PARAMETERS:
 C      Name            Type         Usage            Description
@@ -54,4 +58,22 @@
 C      wd1           Real           Output       downdraft velocity scale for sfc fluxes
 C      cape1         Real           Output       CAPE
+!    
+!      wdtrainA1     Real           Output   precipitation detrained from adiabatic draught;
+!                                                       used in tracer transport (cvltr)
+!      wdtrainM1     Real           Output   precipitation detrained from mixed draughts;
+!                                                       used in tracer transport (cvltr)
+!      da1           Real           Output   used in tracer transport (cvltr)
+!      phi1          Real           Output   used in tracer transport (cvltr)
+!      mp1           Real           Output   used in tracer transport (cvltr)
+!    
+!      phi21         Real           Output   used in tracer transport (cvltr)
+!    
+!      d1a1          Real           Output   used in tracer transport (cvltr)
+!      dam1          Real           Output   used in tracer transport (cvltr)
+!    
+!      evap1         Real           Output
+!      ep1           Real           Output
+!      sij1        Real           Output
+!      elij1         Real           Output
 C
 C S. Bony, Mar 2002:
@@ -119,6 +141,7 @@
       real epmlmMm1(len,nd,nd),eplaMm1(len,nd)
 ! RomP <<<
-
-
+!
+!-------------------------------------------------------------------
+!        Original Prologue by Kerry Emanuel.
 !-------------------------------------------------------------------
 ! --- ARGUMENTS
@@ -291,12 +314,4 @@
       real ments(nloc,klev,klev), qents(nloc,klev,klev)
       real sij(nloc,klev,klev), elij(nloc,klev,klev)
-! RomP >>>
-      real da(nloc,klev),phi(nloc,klev,klev),mp(nloc,klev)
-      real epmlmMm(nloc,klev,klev),eplaMm(nloc,klev)  
-      real phi2(nloc,klev,klev)
-      real d1a(nloc,klev), dam(nloc,klev)
-      real wdtrainA(nloc,klev),wdtrainM(nloc,klev)
-      real sigd(nloc)
-! RomP <<<
       real qp(nloc,klev), up(nloc,klev), vp(nloc,klev)
       real wt(nloc,klev), water(nloc,klev), evap(nloc,klev)
@@ -312,4 +327,13 @@
       real qcondc(nloc,klev)  ! cld
       real wd(nloc)           ! gust
+!
+! RomP >>>
+      real da(nloc,klev),phi(nloc,klev,klev),mp(nloc,klev)
+      real epmlmMm(nloc,klev,klev),eplaMm(nloc,klev)  
+      real phi2(nloc,klev,klev)
+      real d1a(nloc,klev), dam(nloc,klev)
+      real wdtrainA(nloc,klev),wdtrainM(nloc,klev)
+      real sigd(nloc)
+! RomP <<<
 
       nent(:,:)=0
@@ -380,4 +404,21 @@
         enddo
       endif
+
+! RomP >>> 
+       wdtrainA1(:,:)  =0.
+        wdtrainM1(:,:) =0.
+       da1(:,:)        =0.
+       phi1(:,:,:)     =0.
+       epmlmMm1(:,:,:) =0.
+       eplaMm1(:,:)    =0.
+       mp1(:,:)        =0.
+       evap1(:,:)      =0.
+       ep1(:,:)        =0.
+       sij1(:,:,:)     =0.
+       elij1(:,:,:)    =0.
+       phi21(:,:,:)    =0.
+       d1a1(:,:)       =0.
+       dam1(:,:)       =0.
+! RomP <<<
 
 !--------------------------------------------------------------------
@@ -729,3 +770,2 @@
       return
       end
-
Index: LMDZ5/branches/testing/libf/phylmd/cva_driver.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/cva_driver.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/cva_driver.F	(revision 1795)
@@ -22,5 +22,5 @@
      &                   ,lalim_conv, 
      &                   da1,phi1,mp1,phi21,d1a1,dam1,sigij1,clw1,     ! RomP
-     &                   elij1,evap1,ep1,                              ! RomP 
+     &                   elij1,evap1,ep1,epmlmMm1,eplaMm1,             ! RomP 
      &                   wdtrainA1,wdtrainM1)                          ! RomP
 ***************************************************************
@@ -39,4 +39,7 @@
 C.............................START PROLOGUE............................
 C
+!
+! All argument names (except len,nd,ntra,nloc,delt and the flags) have a "1" appended.
+! The "1" is removed for the corresponding compressed variables.
 C PARAMETERS:
 C      Name            Type         Usage            Description
@@ -99,4 +102,33 @@
 C      supmax01      Real           Output
 C      asupmaxmin1   Real           Output
+!
+!      ftd1          Real           Output  Array of temperature tendency due to precipitations (K/s) of dimension ND,
+!                                           defined at same grid levels as T, Q, QS and P.
+!    
+!      fqd1          Real           Output  Array of specific humidity tendencies due to precipitations ((gm/gm)/s)
+!                                           of dimension ND, defined at same grid levels as T, Q, QS and P.
+!    
+!      wdtrainA1     Real           Output   precipitation detrained from adiabatic draught;
+!                                                       used in tracer transport (cvltr)
+!      wdtrainM1     Real           Output   precipitation detrained from mixed draughts;
+!                                                       used in tracer transport (cvltr)
+!      da1           Real           Output   used in tracer transport (cvltr)
+!      phi1          Real           Output   used in tracer transport (cvltr)
+!      mp1           Real           Output   used in tracer transport (cvltr)
+!    
+!      phi21         Real           Output   used in tracer transport (cvltr)
+!    
+!      d1a1          Real           Output   used in tracer transport (cvltr)
+!      dam1          Real           Output   used in tracer transport (cvltr)
+!    
+!      epmlmMm1      Real           Output   used in tracer transport (cvltr)
+!      eplaMm1       Real           Output   used in tracer transport (cvltr)
+!
+!      evap1         Real           Output
+!      ep1           Real           Output
+!      sigij1        Real           Output
+!      elij1         Real           Output
+
+C
 C S. Bony, Mar 2002:
 C 	* Several modules corresponding to different physical processes
@@ -188,14 +220,14 @@
 ! RomP >>> 
       real wdtrainA1(len,nd), wdtrainM1(len,nd)
-      real wdtrainA(nloc,klev),wdtrainM(nloc,klev)
       real da1(len,nd),phi1(len,nd,nd),mp1(len,nd)
-      real da(len,nd),phi(len,nd,nd)
+      real epmlmMm1(len,nd,nd),eplaMm1(len,nd)
       real evap1(len,nd),ep1(len,nd)
       real sigij1(len,nd,nd),elij1(len,nd,nd)
-      real phi2(len,nd,nd)
-      real d1a(len,nd), dam(len,nd)
       real phi21(len,nd,nd)
       real d1a1(len,nd), dam1(len,nd)
 ! RomP <<<
+!
+!-------------------------------------------------------------------
+!        Prolog by Kerry Emanuel.
 !-------------------------------------------------------------------
 ! --- ARGUMENTS
@@ -320,11 +352,4 @@
 !
 !  det:   Array of detrainment mass flux of dimension ND.
-!
-!  ftd:  Array of temperature tendency due to precipitations (K/s) of dimension ND,
-!        defined at same grid levels as T, Q, QS and P.
-!
-!  fqd:  Array of specific humidity tendencies due to precipitations ((gm/gm)/s)
-!        of dimension ND, defined at same grid levels as T, Q, QS and P.
-!
 !-------------------------------------------------------------------
 c
@@ -446,4 +471,13 @@
       real wghti(nloc,nd)
       real hnk(nloc),unk(nloc),vnk(nloc)
+!
+! RomP >>> 
+      real wdtrainA(nloc,klev),wdtrainM(nloc,klev)
+      real da(len,nd),phi(len,nd,nd)
+      real epmlmMm(nloc,klev,klev),eplaMm(nloc,klev)  
+      real phi2(len,nd,nd)
+      real d1a(len,nd), dam(len,nd)
+! RomP <<<
+!
       logical, save :: first=.true.
 c$OMP THREADPRIVATE(first)
@@ -498,45 +532,34 @@
       nword4=len*nd*nd
  
-!      call izilch(iflag1  ,nword1)
-!      call  zilch(iflag1  ,nword1)
-      do i=1,len
-         iflag1(i)=0
-         ktop1(i)=0
-         kbas1(i)=0
-      enddo
-      call  zilch(ft1     ,nword2)
-      call  zilch(fq1     ,nword2)
-      call  zilch(fu1     ,nword2)
-      call  zilch(fv1     ,nword2)
-      call  zilch(ftra1   ,nword3)
-      call  zilch(precip1 ,nword1)
-!      call izilch(kbas1   ,nword1)
-!      call  zilch(kbas1   ,nword1)
-!      call izilch(ktop1   ,nword1)
-!      call  zilch(ktop1   ,nword1)
-      call  zilch(cbmf1   ,nword1)
-      call  zilch(ptop21  ,nword1)
-      sigd1(:)=0.
-      call  zilch(Ma1     ,nword2)
-      call  zilch(mip1    ,nword2)
-!      call  zilch(Vprecip1,nword2)
-      Vprecip1=0.
-      call  zilch(upwd1   ,nword2)
-      call  zilch(dnwd1   ,nword2)
-      call  zilch(dnwd01  ,nword2)
-      call  zilch(qcondc1 ,nword2)
-!test
-!      call  zilch(qcondc ,nword2)
-      call  zilch(wd1     ,nword1)
-      call  zilch(cape1   ,nword1)
-      call  zilch(cin1    ,nword1)
-      call  zilch(tvp1    ,nword2)
-      call  zilch(ftd1    ,nword2)
-      call  zilch(fqd1    ,nword2)
-      call  zilch(Plim11  ,nword1)
-      call  zilch(Plim21  ,nword1)
-      call  zilch(asupmax1,nword2)
-      call  zilch(supmax01,nword1)
-      call  zilch(asupmaxmin1,nword1)
+      iflag1(:)     = 0
+      ktop1(:)      = 0
+      kbas1(:)      = 0
+      ft1(:,:)      = 0.0
+      fq1(:,:)      = 0.0
+      fu1(:,:)      = 0.0
+      fv1(:,:)      = 0.0
+      ftra1(:,:,:)  = 0.
+      precip1(:)    = 0.
+      cbmf1(:)      = 0.
+      ptop21(:)     = 0.
+      sigd1(:)      = 0.
+      Ma1(:,:)      = 0.
+      mip1(:,:)     = 0.
+      Vprecip1(:,:) = 0.
+      upwd1   (:,:) = 0.
+      dnwd1   (:,:) = 0.
+      dnwd01  (:,:) = 0.
+      qcondc1 (:,:) = 0.
+      wd1     (:)   = 0.
+      cape1   (:)   = 0.
+      cin1    (:)   = 0.
+      tvp1    (:,:) = 0.
+      ftd1    (:,:) = 0.
+      fqd1    (:,:) = 0.
+      Plim11  (:)   = 0.
+      Plim21  (:)   = 0.
+      asupmax1(:,:) = 0.
+      supmax01(:)   = 0.
+      asupmaxmin1(:)= 0.
 c
       DO il = 1,len
@@ -552,4 +575,20 @@
       endif
   
+! RomP >>> 
+       wdtrainA1(:,:)  = 0.
+       wdtrainM1(:,:)  = 0.
+       da1(:,:)        = 0.
+       phi1(:,:,:)     = 0.
+       epmlmMm1(:,:,:) = 0.
+       eplaMm1(:,:)    = 0.
+       mp1(:,:)        = 0.
+       evap1(:,:)      = 0.
+       ep1(:,:)        = 0.
+       sigij1(:,:,:)   = 0.
+       elij1(:,:,:)    = 0.
+       phi21(:,:,:)    = 0.
+       d1a1(:,:)       = 0.
+       dam1(:,:)       = 0.
+! RomP <<<
 !---------------------------------------------------------------------
 ! --- INITIALIZE LOCAL ARRAYS AND PARAMETERS
@@ -941,5 +980,6 @@
        CALL cv3_tracer(nloc,len,ncum,nd,nd,
      :                  ment,sigij,da,phi,phi2,d1a,dam,
-     :                  ep,Vprecip,elij,clw,icb,inb)
+     :                  ep,Vprecip,elij,clw,epmlmMm,eplaMm,
+     :                  icb,inb)
 !RomP <<<
       endif
@@ -964,6 +1004,6 @@
      :          ,asupmaxmin
      :          ,da,phi,mp,phi2,d1a,dam,sigij         ! RomP
-     :          ,wdtrainA,wdtrainM,elij,clw           ! RomP
-     :          ,evap,ep                              ! RomP
+     :          ,clw,elij,evap,ep,epmlmMm,eplaMm      ! RomP
+     :          ,wdtrainA,wdtrainM                    ! RomP
      o          ,iflag1,kbas1,ktop1
      o          ,precip1,cbmf1,plcl1,plfc1,wbeff1,sig1,w01,ptop21
@@ -976,6 +1016,6 @@
      o          ,asupmaxmin1
      o          ,da1,phi1,mp1,phi21,d1a1,dam1,sigij1  ! RomP
-     o          ,wdtrainA1,wdtrainM1,elij1,clw1       ! RomP
-     o          ,evap1,ep1)                           ! RomP
+     o          ,clw1,elij1,evap1,ep1,epmlmMm1,eplaMm1! RomP
+     o          ,wdtrainA1,wdtrainM1)                 ! RomP
       endif
 
Index: LMDZ5/branches/testing/libf/phylmd/cvltr.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/cvltr.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/cvltr.F90	(revision 1795)
@@ -121,7 +121,10 @@
    coefcoli         = 0.
 
+!$OMP MASTER
   call getin('ccntrAA_coef',ccntrAA_coef)
   call getin('ccntrENV_coef',ccntrENV_coef)
   call getin('coefcoli',coefcoli)
+!$OMP END MASTER
+!$OMP BARRIER
   print*,'cvltr coef lessivage convectif', ccntrAA_coef,ccntrENV_coef,coefcoli
 
Index: LMDZ5/branches/testing/libf/phylmd/ener_conserv.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/ener_conserv.F90	(revision 1795)
+++ LMDZ5/branches/testing/libf/phylmd/ener_conserv.F90	(revision 1795)
@@ -0,0 +1,171 @@
+subroutine ener_conserv(klon,klev,pdtphys, &
+ &    puo,pvo,pto,pqo,pun,pvn,ptn,pqn,dtke,masse,exner,d_t_ec)
+
+!=============================================================
+! Energy conservation
+! Based on the TKE equation
+! The M2 and N2 terms at the origin of TKE production are
+! concerted into heating in the d_t_ec term
+! Option 1 is the standard
+!        101 is for M2 term only
+!        101 for N2 term only
+!         -1 is a previours treatment for kinetic energy only
+!  FH (hourdin@lmd.jussieu.fr), 2013/04/25
+!=============================================================
+
+!=============================================================
+! Declarations
+!=============================================================
+
+! From module
+USE phys_local_var_mod, ONLY : d_u_vdf,d_v_vdf,d_t_vdf,d_u_ajs,d_v_ajs,d_t_ajs,d_u_con,d_v_con,d_t_con,d_t_diss
+USE phys_output_var_mod, ONLY : bils_ec,bils_tke,bils_kinetic,bils_enthalp,bils_latent,bils_diss
+
+IMPLICIT none
+#include "YOMCST.h"
+#include "YOETHF.h"
+#include "clesphys.h"
+#include "compbl.h"
+
+! Arguments
+INTEGER, INTENT(IN) :: klon,klev
+REAL, INTENT(IN) :: pdtphys
+REAL, DIMENSION(klon,klev),INTENT(IN) :: puo,pvo,pto,pqo
+REAL, DIMENSION(klon,klev),INTENT(IN) :: pun,pvn,ptn,pqn
+REAL, DIMENSION(klon,klev),INTENT(IN) :: masse,exner
+REAL, DIMENSION(klon,klev+1),INTENT(IN) :: dtke
+REAL, DIMENSION(klon,klev),INTENT(OUT) :: d_t_ec
+      integer k,i
+
+! Local
+REAL, DIMENSION(klon,klev+1) :: fluxu,fluxv,fluxt
+REAL, DIMENSION(klon,klev+1) :: dddu,dddv,dddt
+REAL, DIMENSION(klon,klev) :: d_u,d_v,d_t,zv,zu
+REAL ZRCPD
+
+character*80 abort_message
+character*20 :: modname
+
+
+modname='ener_conser'
+d_t_ec(:,:)=0.
+
+IF (iflag_ener_conserv==-1) THEN
+!+jld ec_conser
+   DO k = 1, klev
+   DO i = 1, klon
+      ZRCPD = RCPD*(1.0+RVTMP2*pqn(i,k))
+      d_t_ec(i,k)=0.5/ZRCPD &
+ &      *(puo(i,k)**2+pvo(i,k)**2-pun(i,k)**2-pvn(i,k)**2)
+      ENDDO
+      ENDDO
+!-jld ec_conser
+
+
+
+ELSEIF (iflag_ener_conserv>=1) THEN
+
+   IF (iflag_ener_conserv<=2) THEN
+!     print*,'ener_conserv pbl=',iflag_pbl
+      IF (iflag_pbl>=20 .AND. iflag_pbl<=27) THEN !d_t_diss accounts for conserv
+         d_t(:,:)=d_t_ajs(:,:)   ! d_t_ajs = adjust + thermals
+         d_u(:,:)=d_u_ajs(:,:)+d_u_con(:,:)
+         d_v(:,:)=d_v_ajs(:,:)+d_v_con(:,:)
+      ELSE
+         d_t(:,:)=d_t_vdf(:,:)+d_t_ajs(:,:)   ! d_t_ajs = adjust + thermals
+         d_u(:,:)=d_u_vdf(:,:)+d_u_ajs(:,:)+d_u_con(:,:)
+         d_v(:,:)=d_v_vdf(:,:)+d_v_ajs(:,:)+d_v_con(:,:)
+      ENDIF
+   ELSEIF (iflag_ener_conserv==101) THEN
+      d_t(:,:)=0.
+      d_u(:,:)=d_u_vdf(:,:)+d_u_ajs(:,:)+d_u_con(:,:)
+      d_v(:,:)=d_v_vdf(:,:)+d_v_ajs(:,:)+d_v_con(:,:)
+   ELSEIF (iflag_ener_conserv==110) THEN
+      d_t(:,:)=d_t_vdf(:,:)+d_t_ajs(:,:)
+      d_u(:,:)=0.
+      d_v(:,:)=0.
+   ELSE
+      abort_message = 'iflag_ener_conserv non prevu'
+      CALL abort_gcm (modname,abort_message,1)
+   ENDIF
+
+!----------------------------------------------------------------------------
+! Two options wether we consider time integration in the energy conservation
+!----------------------------------------------------------------------------
+
+   if (iflag_ener_conserv==2) then
+      zu(:,:)=puo(:,:)
+      zv(:,:)=pvo(:,:)
+   else
+      IF (iflag_pbl>=20 .AND. iflag_pbl<=27) THEN
+         zu(:,:)=puo(:,:)+d_u_vdf(:,:)+0.5*d_u(:,:)
+         zv(:,:)=pvo(:,:)+d_v_vdf(:,:)+0.5*d_v(:,:)
+      ELSE
+         zu(:,:)=puo(:,:)+0.5*d_u(:,:)
+         zv(:,:)=pvo(:,:)+0.5*d_v(:,:)
+      ENDIF
+   endif
+
+   fluxu(:,klev+1)=0.
+   fluxv(:,klev+1)=0.
+   fluxt(:,klev+1)=0.
+
+   do k=klev,1,-1
+      fluxu(:,k)=fluxu(:,k+1)+masse(:,k)*d_u(:,k)
+      fluxv(:,k)=fluxv(:,k+1)+masse(:,k)*d_v(:,k)
+      fluxt(:,k)=fluxt(:,k+1)+masse(:,k)*d_t(:,k)/exner(:,k)
+   enddo
+
+   dddu(:,1)=2*zu(:,1)*fluxu(:,1)
+   dddv(:,1)=2*zv(:,1)*fluxv(:,1)
+   dddt(:,1)=(exner(:,1)-1.)*fluxt(:,1)
+
+   do k=2,klev
+      dddu(:,k)=(zu(:,k)-zu(:,k-1))*fluxu(:,k)
+      dddv(:,k)=(zv(:,k)-zv(:,k-1))*fluxv(:,k)
+      dddt(:,k)=(exner(:,k)-exner(:,k-1))*fluxt(:,k)
+   enddo
+   dddu(:,klev+1)=0.
+   dddv(:,klev+1)=0.
+   dddt(:,klev+1)=0.
+
+   do k=1,klev
+      d_t_ec(:,k)=-(dddu(:,k)+dddu(:,k+1)+dddv(:,k)+dddv(:,k+1) &
+   &  +rcpd*(dddt(:,k)+dddt(:,k+1)))/(2.*rcpd*masse(:,k))
+   enddo
+! d_t_ec=0.
+
+ENDIF
+
+!================================================================
+!  Computation of integrated enthalpie and kinetic energy variation
+!  FH (hourdin@lmd.jussieu.fr), 2013/04/25
+!================================================================
+
+      bils_ec(:)=0.
+      bils_tke(:)=0.
+      bils_diss(:)=0.
+      bils_kinetic(:)=0.
+      bils_enthalp(:)=0.
+      bils_latent(:)=0.
+      DO k=1,klev
+        bils_ec(:)=bils_ec(:)-d_t_ec(:,k)*masse(:,k)
+        bils_tke(:)=bils_tke(:)+0.5*(dtke(:,k)+dtke(:,k+1))*masse(:,k)
+        bils_diss(:)=bils_diss(:)-d_t_diss(:,k)*masse(:,k)
+        bils_kinetic(:)=bils_kinetic(:)+masse(:,k)* &
+     &           (pun(:,k)*pun(:,k)+pvn(:,k)*pvn(:,k) &
+     &            -puo(:,k)*puo(:,k)-pvo(:,k)*pvo(:,k))
+        bils_enthalp(:)= &
+     &  bils_enthalp(:)+masse(:,k)*(ptn(:,k)-pto(:,k)+d_t_ec(:,k))
+        bils_latent(:)=bils_latent(:)+masse(:,k)* &
+     &             (pqn(:,k)-pqo(:,k))
+      ENDDO
+      bils_ec(:)=rcpd*bils_ec(:)/pdtphys
+      bils_tke(:)=bils_tke(:)/pdtphys
+      bils_diss(:)=rcpd*bils_diss(:)/pdtphys
+      bils_kinetic(:)= 0.5*bils_kinetic(:)/pdtphys
+      bils_enthalp(:)=rcpd*bils_enthalp(:)/pdtphys
+      bils_latent(:)=rlvtt*bils_latent(:)/pdtphys
+RETURN
+
+END
Index: LMDZ5/branches/testing/libf/phylmd/etat0_netcdf.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/etat0_netcdf.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/etat0_netcdf.F90	(revision 1795)
@@ -24,8 +24,9 @@
   USE conf_phys_m,            ONLY: conf_phys
 ! For parameterization of ozone chemistry:
-  use regr_lat_time_coefoz_m, only: regr_lat_time_coefoz
-  use press_coefoz_m, only: press_coefoz
-  use regr_pr_o3_m, only: regr_pr_o3
+  USE regr_lat_time_coefoz_m, only: regr_lat_time_coefoz
+  USE press_coefoz_m, only: press_coefoz
+  USE regr_pr_o3_m, only: regr_pr_o3
   USE netcdf, ONLY : NF90_OPEN, NF90_NOWRITE, NF90_CLOSE, NF90_NOERR
+  USE indice_sol_mod
 #endif
   IMPLICIT NONE
@@ -47,5 +48,4 @@
 #include "comvert.h"
 #include "comconst.h"
-#include "indicesol.h"
 #include "dimsoil.h"
 #include "temps.h"
@@ -101,4 +101,5 @@
   LOGICAL :: ok_LES, ok_ade, ok_aie, ok_cdnc, aerosol_couple, new_aod, callstats
   INTEGER :: iflag_radia, flag_aerosol
+  LOGICAL :: flag_aerosol_strat
   REAL    :: bl95_b0, bl95_b1, fact_cldcon, facttemps, ratqsbas, ratqshaut
   REAL    :: tau_ratqs
@@ -137,5 +138,5 @@
                    iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,            &
                    ok_ade, ok_aie, ok_cdnc, aerosol_couple,             &
-                   flag_aerosol, new_aod,                               &
+                   flag_aerosol, flag_aerosol_strat, new_aod,           &
                    bl95_b0, bl95_b1,                                    &
                    read_climoz,                                         &
Index: LMDZ5/branches/testing/libf/phylmd/fonte_neige_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/fonte_neige_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/fonte_neige_mod.F90	(revision 1795)
@@ -9,4 +9,5 @@
 !****************************************************************************************
   USE dimphy, ONLY : klon
+  USE indice_sol_mod
 
   IMPLICIT NONE
@@ -44,5 +45,4 @@
 ! restart file. The other variables are initialized to zero.
 !
-    INCLUDE "indicesol.h"
 !****************************************************************************************
 ! Input argument
@@ -120,4 +120,6 @@
        tsurf, precip_rain, precip_snow, &
        snow, qsol, tsurf_new, evap)
+
+  USE indice_sol_mod
         
 ! Routine de traitement de la fonte de la neige dans le cas du traitement
@@ -139,5 +141,4 @@
 !   evap
 !
-  INCLUDE "indicesol.h"
   INCLUDE "dimensions.h"
   INCLUDE "YOETHF.h"
@@ -315,11 +316,14 @@
        fqfonte_out, ffonte_out)
 
+
+
 ! Cumulate ffonte, fqfonte and fqcalving respectively for
 ! all type of surfaces according to their fraction.
 !
 ! This routine is called from physiq.F before histwrite.
-
-    INCLUDE "indicesol.h"
-!****************************************************************************************
+!****************************************************************************************
+
+  USE indice_sol_mod
+
     REAL, DIMENSION(klon,nbsrf), INTENT(IN) :: pctsrf
 
Index: LMDZ5/branches/testing/libf/phylmd/hgardfou.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/hgardfou.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/hgardfou.F	(revision 1795)
@@ -2,6 +2,7 @@
 ! $Id$
       SUBROUTINE hgardfou (t,tsol,text)
-      use dimphy
-      use phys_state_var_mod
+      USE dimphy
+      USE phys_state_var_mod
+      USE indice_sol_mod
       IMPLICIT none
 c======================================================================
@@ -10,5 +11,4 @@
 #include "dimensions.h"
 #include "YOMCST.h"
-#include "indicesol.h"
 #include "iniprint.h"
       REAL t(klon,klev), tsol(klon,nbsrf)
@@ -57,5 +57,5 @@
            DO i = 1, jbad
              WRITE(lunout,*)
-     $       'i,k,temperature,lon,lat,pourc ter,oce,lic,sic =',
+     $       'i,k,temperature,lon,lat,pourc ter,lic,oce,sic =',
      $       jadrs(i),k,zt(jadrs(i)),rlon(jadrs(i)),rlat(jadrs(i)),
      $       (pctsrf(jadrs(i),nsrf),nsrf=1,nbsrf)
@@ -78,5 +78,5 @@
            DO i = 1, jbad
              WRITE(lunout,*)
-     $       'i,k,temperature,lon,lat,pourc ter,oce,lic,sic =',
+     $       'i,k,temperature,lon,lat,pourc ter,lic,oce,sic =',
      $       jadrs(i),k,zt(jadrs(i)),rlon(jadrs(i)),rlat(jadrs(i)),
      $       (pctsrf(jadrs(i),nsrf),nsrf=1,nbsrf)
@@ -104,5 +104,5 @@
            DO i = 1, jbad
             WRITE(lunout,*) 
-     $      'i,nsrf,temperature,lon,lat,pourc ter,oce,lic,sic ='
+     $      'i,nsrf,temperature,lon,lat,pourc ter,lic,oce,sic ='
      $      ,jadrs(i),nsrf,zt(jadrs(i)),rlon(jadrs(i)),rlat(jadrs(i))
      $      ,pctsrf(jadrs(i),nsrf)
@@ -125,5 +125,5 @@
            DO i = 1, jbad
             WRITE(lunout,*) 
-     $      'i,nsrf,temperature,lon,lat,pourc ter,oce,lic,sic ='
+     $      'i,nsrf,temperature,lon,lat,pourc ter,lic,oce,sic ='
      $      ,jadrs(i),nsrf,zt(jadrs(i)),rlon(jadrs(i)),rlat(jadrs(i))
      $      ,pctsrf(jadrs(i),nsrf)
Index: LMDZ5/branches/testing/libf/phylmd/hydrol.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/hydrol.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/hydrol.F	(revision 1795)
@@ -7,4 +7,6 @@
      .                  agesno, tsol,qsol,snow,runoff)
       USE dimphy
+      USE indice_sol_mod
+
       IMPLICIT none
 c======================================================================
@@ -26,5 +28,4 @@
 cym#include "dimphy.h"
 #include "YOMCST.h"
-#include "indicesol.h"
 c
       REAL chasno ! epaisseur du sol: 0.15 m
Index: LMDZ5/branches/testing/libf/phylmd/indice_sol_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/indice_sol_mod.F90	(revision 1795)
+++ LMDZ5/branches/testing/libf/phylmd/indice_sol_mod.F90	(revision 1795)
@@ -0,0 +1,12 @@
+      MODULE indice_sol_mod
+            INTEGER, PARAMETER :: nbsrf = 4 ! nombre de sous-fractions pour une maille
+            INTEGER, PARAMETER :: is_ter=1, is_lic=2, is_oce = 3, is_sic=4
+                              ! terre ! ocean ! glacier continental ! glace de mer
+
+            INTEGER, PARAMETER :: is_ave=nbsrf+1 ! glacier continental
+            REAL, PARAMETER :: epsfra=1.0E-05
+
+            CHARACTER(len=3), DIMENSION(nbsrf), PARAMETER :: clnsurf = (/'ter', 'lic', 'oce', 'sic'/)
+
+      END MODULE indice_sol_mod
+
Index: LMDZ5/branches/testing/libf/phylmd/indicesol.h
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/indicesol.h	(revision 1750)
+++ 	(revision )
@@ -1,29 +1,0 @@
-!
-! $Header$
-!
-!
-!  ATTENTION!!!!: ce fichier include est compatible format fixe/format libre
-!                 veillez à n'utiliser que des ! pour les commentaires
-!                 et à bien positionner les & des lignes de continuation
-!                 (les placer en colonne 6 et en colonne 73)
-!
-!
-      INTEGER nbsrf
-      PARAMETER (nbsrf=4) ! nombre de sous-fractions pour une maille
-!
-      INTEGER is_oce
-      PARAMETER (is_oce=3) ! ocean
-      INTEGER is_sic
-      PARAMETER (is_sic=4) ! glace de mer
-      INTEGER is_ter
-      PARAMETER (is_ter=1) ! terre
-      INTEGER is_lic
-      PARAMETER (is_lic=2) ! glacier continental
-!
-      REAL epsfra
-      PARAMETER (epsfra=1.0E-05)
-!
-      CHARACTER(len=3) clnsurf(nbsrf)
-      DATA clnsurf/'ter', 'lic', 'oce', 'sic'/
-      SAVE clnsurf
-!$OMP THREADPRIVATE(clnsurf)
Index: LMDZ5/branches/testing/libf/phylmd/init_be.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/init_be.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/init_be.F90	(revision 1795)
@@ -7,4 +7,5 @@
   USE comgeomphy
   USE infotrac, ONLY : nbtr
+  USE indice_sol_mod
     
   IMPLICIT NONE 
@@ -21,5 +22,4 @@
   INCLUDE "YOMCST.h"
   INCLUDE "YOECUMF.h" 
-  INCLUDE "indicesol.h"
 
 !
@@ -47,5 +47,5 @@
   INTEGER              :: nref
   PARAMETER (nref=39)
-  REAL,DIMENSION(nref) :: pref      ! grille de pression de reference (bas des couches)
+  REAL,DIMENSION(nref), SAVE :: pref      ! grille de pression de reference (bas des couches)
   DATA pref  /   &
       101249.99999999994, 100387.17261011522, 99447.35334189111,  98357.43412194174,   &
Index: LMDZ5/branches/testing/libf/phylmd/initphysto.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/initphysto.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/initphysto.F90	(revision 1795)
@@ -9,4 +9,5 @@
   USE iophy
   USE control_mod
+  USE indice_sol_mod
   
   IMPLICIT NONE
@@ -46,5 +47,4 @@
   INCLUDE "description.h"
   INCLUDE "serre.h"
-  INCLUDE "indicesol.h"
 
 !   Arguments
Index: LMDZ5/branches/testing/libf/phylmd/initrrnpb.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/initrrnpb.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/initrrnpb.F90	(revision 1795)
@@ -6,4 +6,5 @@
   USE infotrac, ONLY : nbtr
   USE traclmdz_mod, ONLY : id_rn, id_pb
+  USE indice_sol_mod
   IMPLICIT NONE
 !======================================================================
@@ -24,7 +25,5 @@
 ! scavtr...output-R- Coefficient de lessivage
 !======================================================================
-  INCLUDE "indicesol.h"
-!======================================================================
-
+ 
   REAL,DIMENSION(klon,nbsrf),INTENT(IN) :: pctsrf
   REAL,DIMENSION(klon,nbsrf),INTENT(IN) :: ftsol
Index: LMDZ5/branches/testing/libf/phylmd/interfoce_lim.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/interfoce_lim.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/interfoce_lim.F90	(revision 1795)
@@ -9,8 +9,8 @@
   USE mod_grid_phy_lmdz
   USE mod_phys_lmdz_para
+  USE indice_sol_mod
   
   IMPLICIT NONE
   
-  INCLUDE "indicesol.h"
   INCLUDE "netcdf.inc"
 
Index: LMDZ5/branches/testing/libf/phylmd/iophy.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/iophy.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/iophy.F90	(revision 1795)
@@ -6,12 +6,15 @@
 ! abd  REAL,private,allocatable,dimension(:),save :: io_lat
 ! abd  REAL,private,allocatable,dimension(:),save :: io_lon
-  REAL,allocatable,dimension(:),save :: io_lat
-  REAL,allocatable,dimension(:),save :: io_lon
-  INTEGER, save :: phys_domain_id
-  INTEGER, save :: npstn
-  INTEGER, allocatable, dimension(:), save :: nptabij
+  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: io_lat
+  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: io_lon
+  INTEGER, SAVE :: phys_domain_id
+  INTEGER, SAVE :: npstn
+  INTEGER, ALLOCATABLE, DIMENSION(:), SAVE :: nptabij
+  INTEGER, SAVE :: itau_iophy
+
+!$OMP THREADPRIVATE(itau_iophy)
   
   INTERFACE histwrite_phy
-    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy
+    MODULE PROCEDURE histwrite2d_phy,histwrite3d_phy,histwrite2d_phy_old,histwrite3d_phy_old
   END INTERFACE
 
@@ -322,10 +325,12 @@
   end subroutine histbeg_phy_points
  
-  subroutine histwrite2d_phy(nid,lpoint,name,itau,field)
-  USE dimphy
-  USE mod_phys_lmdz_para
+  SUBROUTINE histwrite2d_phy_old(nid,lpoint,name,itau,field)
+  USE dimphy
+  USE mod_phys_lmdz_para
+  USE phys_output_var_mod
   USE ioipsl
-  implicit none
+  IMPLICIT NONE
   include 'dimensions.h'
+  include 'iniprint.h'
     
     integer,intent(in) :: nid
@@ -341,4 +346,5 @@
     real,allocatable,dimension(:) :: fieldok
 
+
     IF (size(field)/=klon) CALL abort_gcm('iophy::histwrite2d','Field first dimension not equal to klon',1)
     
@@ -349,5 +355,7 @@
      ALLOCATE(index2d(iim*jj_nb))
      ALLOCATE(fieldok(iim*jj_nb))
+     IF (prt_level >= 9) write(lunout,*)'Sending ',name,' to IOIPSL'
      CALL histwrite(nid,name,itau,Field2d,iim*jj_nb,index2d)
+     IF (prt_level >= 9) write(lunout,*)'Finished sending ',name,' to IOIPSL'
     else
      ALLOCATE(fieldok(npstn))
@@ -369,19 +377,25 @@
       ENDDO
      endif
+     IF (prt_level >= 9) write(lunout,*)'Sending ',name,' to IOIPSL'
      CALL histwrite(nid,name,itau,fieldok,npstn,index2d)
+     IF (prt_level >= 9) write(lunout,*)'Finished sending ',name,' to IOIPSL'
 !
     endif
     deallocate(index2d)
     deallocate(fieldok)
-!$OMP END MASTER    
-  end subroutine histwrite2d_phy
-
-  subroutine histwrite3d_phy(nid,lpoint,name,itau,field)
-  USE dimphy
-  USE mod_phys_lmdz_para
+!$OMP END MASTER   
+
+ 
+  end subroutine histwrite2d_phy_old
+
+  subroutine histwrite3d_phy_old(nid,lpoint,name,itau,field)
+  USE dimphy
+  USE mod_phys_lmdz_para
+  USE phys_output_var_mod
 
   use ioipsl
   implicit none
   include 'dimensions.h'
+  include 'iniprint.h'
     
     integer,intent(in) :: nid
@@ -396,4 +410,5 @@
     real,allocatable, dimension(:,:) :: fieldok
 
+
     IF (size(field,1)/=klon) CALL abort_gcm('iophy::histwrite3d','Field first dimension not equal to klon',1)
     nlev=size(field,2)
@@ -411,6 +426,8 @@
      ALLOCATE(index3d(iim*jj_nb*nlev))
      ALLOCATE(fieldok(iim*jj_nb,nlev))
+     IF (prt_level >= 9) write(lunout,*)'Sending ',name,' to IOIPSL'
      CALL histwrite(nid,name,itau,Field3d,iim*jj_nb*nlev,index3d)
-    else
+     IF (prt_level >= 9) write(lunout,*)'Finished sending ',name,' to IOIPSL'
+   else
       nlev=size(field,2)
       ALLOCATE(index3d(npstn*nlev))
@@ -435,10 +452,204 @@
        ENDDO
       endif
+      IF (prt_level >= 9) write(lunout,*)'Sending ',name,' to IOIPSL'
       CALL histwrite(nid,name,itau,fieldok,npstn*nlev,index3d)
+      IF (prt_level >= 9) write(lunout,*)'Finished sending ',name,' to IOIPSL'
     endif 
   deallocate(index3d)
   deallocate(fieldok)
 !$OMP END MASTER    
-  end subroutine histwrite3d_phy
+
+  end subroutine histwrite3d_phy_old
+
+
+! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
+  SUBROUTINE histwrite2d_phy(var,field, STD_iff)
+  USE dimphy
+  USE mod_phys_lmdz_para
+  USE ioipsl
+!Pour avoir nfiles, nidfiles tout ça tout ça...
+  USE phys_output_var_mod
+  
+  
+
+#ifdef CPP_XIOS
+!  USE WXIOS
+#endif
+
+  IMPLICIT NONE
+  include 'dimensions.h'
+    
+!    integer,intent(in) :: nid
+!    logical,intent(in) :: lpoint 
+!    character*(*), intent(IN) :: name
+!    integer, intent(in) :: itau
+!    real,dimension(:),intent(in) :: field
+
+      TYPE(ctrl_out), INTENT(IN) :: var
+      REAL, DIMENSION(:), INTENT(IN) :: field
+      INTEGER, INTENT(IN), OPTIONAL :: STD_iff ! ug RUSTINE POUR LES STD LEVS.....
+      
+      INTEGER :: iff, iff_beg, iff_end
+      
+    REAL,dimension(klon_mpi) :: buffer_omp
+    INTEGER, allocatable, dimension(:) :: index2d
+    REAL :: Field2d(iim,jj_nb)
+
+    INTEGER :: ip
+    REAL, ALLOCATABLE, DIMENSION(:) :: fieldok
+
+! ug RUSTINE POUR LES STD LEVS.....
+      IF (PRESENT(STD_iff)) THEN
+            iff_beg = STD_iff
+            iff_end = STD_iff
+      ELSE
+            iff_beg = 1
+            iff_end = nfiles
+      END IF
+
+    IF (size(field)/=klon) CALL abort_gcm('iophy::histwrite2d','Field first dimension not equal to klon',1)
+    
+    CALL Gather_omp(field,buffer_omp)    
+!$OMP MASTER
+    CALL grid1Dto2D_mpi(buffer_omp,Field2d)
+    
+! La boucle sur les fichiers:
+      DO iff=iff_beg, iff_end
+            IF (var%flag(iff) <= lev_files(iff) .AND. clef_files(iff)) THEN 
+    
+                  IF(.NOT.clef_stations(iff)) THEN
+                        ALLOCATE(index2d(iim*jj_nb))
+                        ALLOCATE(fieldok(iim*jj_nb))
+     
+                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field2d,iim*jj_nb,index2d)
+#ifdef CPP_XIOS
+!                        IF (iff .EQ. 1) THEN
+!                              CALL wxios_write_2D(var%name, Field2d)
+!                        ENDIF
+#endif
+                  ELSE 
+                        ALLOCATE(fieldok(npstn))
+                        ALLOCATE(index2d(npstn))
+
+                        IF (is_sequential) THEN
+!                            klon_mpi_begin=1
+!                             klon_mpi_end=klon
+                              DO ip=1, npstn
+                                    fieldok(ip)=buffer_omp(nptabij(ip))
+                              ENDDO
+                             ELSE
+                              DO ip=1, npstn
+!                                   print*,'histwrite2d is_sequential npstn ip name nptabij',npstn,ip,name,nptabij(ip)
+                                     IF(nptabij(ip).GE.klon_mpi_begin.AND. &
+                                        nptabij(ip).LE.klon_mpi_end) THEN
+                                       fieldok(ip)=buffer_omp(nptabij(ip)-klon_mpi_begin+1)
+                                     ENDIF
+                              ENDDO
+                       ENDIF
+     
+                       CALL histwrite(nid_files(iff),var%name,itau_iophy,fieldok,npstn,index2d)
+                  ENDIF
+                  
+                deallocate(index2d)
+                deallocate(fieldok)
+            ENDIF !levfiles
+      ENDDO
+!$OMP END MASTER   
+
+  END SUBROUTINE histwrite2d_phy
+
+
+! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
+  SUBROUTINE histwrite3d_phy(var, field)
+  USE dimphy
+  USE mod_phys_lmdz_para
+
+  use ioipsl
+!Pour avoir nfiles, nidfiles tout ça tout ça...
+  USE phys_output_var_mod  
+  
+
+#ifdef CPP_XIOS
+! USE WXIOS
+#endif
+
+
+  IMPLICIT NONE
+  include 'dimensions.h'
+    
+!    integer,intent(in) :: nid
+!    logical,intent(in) :: lpoint
+!    character*(*), intent(IN) :: name
+!    integer, intent(in) :: itau
+!    real,dimension(:,:),intent(in) :: field  ! --> field(klon,:)
+
+      TYPE(ctrl_out), INTENT(IN) :: var
+      REAL, DIMENSION(:,:), INTENT(IN) :: field ! --> field(klon,:)
+
+
+    REAL,DIMENSION(klon_mpi,SIZE(field,2)) :: buffer_omp
+    REAL :: Field3d(iim,jj_nb,SIZE(field,2))
+    INTEGER :: ip, n, nlev, iff
+    INTEGER, ALLOCATABLE, DIMENSION(:) :: index3d
+    REAL,ALLOCATABLE, DIMENSION(:,:) :: fieldok
+
+    IF (size(field,1)/=klon) CALL abort_gcm('iophy::histwrite3d','Field first dimension not equal to klon',1)
+    nlev=size(field,2)
+
+!   print*,'hist3d_phy mpi_rank npstn=',mpi_rank,npstn
+
+!   DO ip=1, npstn
+!    print*,'hist3d_phy mpi_rank nptabij',mpi_rank,nptabij(ip)
+!   ENDDO
+
+    CALL Gather_omp(field,buffer_omp)
+!$OMP MASTER
+    CALL grid1Dto2D_mpi(buffer_omp,field3d)
+
+
+! BOUCLE SUR LES FICHIERS
+      DO iff=1, nfiles
+            IF (var%flag(iff) <= lev_files(iff) .AND. clef_files(iff)) THEN
+                IF (.NOT.clef_stations(iff)) THEN
+                        ALLOCATE(index3d(iim*jj_nb*nlev))
+                        ALLOCATE(fieldok(iim*jj_nb,nlev))
+                        CALL histwrite(nid_files(iff),var%name,itau_iophy,Field3d,iim*jj_nb*nlev,index3d)
+#ifdef CPP_XIOS
+!                        IF (iff .EQ. 1) THEN
+!                              CALL wxios_write_3D(var%name, Field3d(:,:,1:klev))
+!                        ENDIF
+#endif
+                        
+                ELSE 
+                        nlev=size(field,2)
+                        ALLOCATE(index3d(npstn*nlev))
+                        ALLOCATE(fieldok(npstn,nlev))
+
+                        IF (is_sequential) THEN
+            !                  klon_mpi_begin=1
+            !                  klon_mpi_end=klon
+                              DO n=1, nlev
+                                    DO ip=1, npstn
+                                          fieldok(ip,n)=buffer_omp(nptabij(ip),n)
+                                    ENDDO
+                              ENDDO
+                        ELSE
+                              DO n=1, nlev
+                                    DO ip=1, npstn
+                                                IF(nptabij(ip).GE.klon_mpi_begin.AND. &
+                                                      nptabij(ip).LE.klon_mpi_end) THEN
+                                                fieldok(ip,n)=buffer_omp(nptabij(ip)-klon_mpi_begin+1,n)
+                                          ENDIF
+                                    ENDDO
+                              ENDDO
+                        ENDIF
+                        CALL histwrite(nid_files(iff),var%name,itau_iophy,fieldok,npstn*nlev,index3d)
+                  ENDIF 
+                  deallocate(index3d)
+                  deallocate(fieldok)
+            ENDIF
+      ENDDO
+!$OMP END MASTER   
+  END SUBROUTINE histwrite3d_phy
   
 end module iophy
Index: LMDZ5/branches/testing/libf/phylmd/limit_netcdf.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/limit_netcdf.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/limit_netcdf.F90	(revision 1795)
@@ -21,4 +21,5 @@
 !-------------------------------------------------------------------------------
   USE control_mod
+  USE indice_sol_mod
 #ifdef CPP_EARTH
   USE dimphy
@@ -50,5 +51,4 @@
 #include "comgeom2.h"
 #include "comconst.h"
-#include "indicesol.h"
 
 !--- INPUT NETCDF FILES NAMES --------------------------------------------------
@@ -276,7 +276,8 @@
   USE phys_state_var_mod, ONLY : pctsrf
   USE control_mod
-  use pchsp_95_m, only: pchsp_95
-  use pchfe_95_m, only: pchfe_95
-  use arth_m, only: arth
+  USE pchsp_95_m, only: pchsp_95
+  USE pchfe_95_m, only: pchfe_95
+  USE arth_m, only: arth
+  USE indice_sol_mod
 
   IMPLICIT NONE
@@ -284,5 +285,4 @@
 #include "paramet.h"
 #include "comgeom2.h"
-#include "indicesol.h"
 #include "iniprint.h"
 !-----------------------------------------------------------------------------
Index: LMDZ5/branches/testing/libf/phylmd/limit_read_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/limit_read_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/limit_read_mod.F90	(revision 1795)
@@ -38,5 +38,5 @@
 
     USE dimphy
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
 
 ! Input arguments
@@ -146,8 +146,8 @@
     USE surface_data, ONLY : type_ocean, ok_veget
     USE netcdf
+    USE indice_sol_mod
 
     IMPLICIT NONE
     
-    INCLUDE "indicesol.h"
     INCLUDE "iniprint.h"
 
Index: LMDZ5/branches/testing/libf/phylmd/limit_slab.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/limit_slab.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/limit_slab.F90	(revision 1795)
@@ -7,8 +7,8 @@
   USE mod_phys_lmdz_para
   USE netcdf 
+  USE indice_sol_mod
 
   IMPLICIT NONE
 
-  INCLUDE "indicesol.h"
   INCLUDE "temps.h"
   INCLUDE "clesphys.h"
Index: LMDZ5/branches/testing/libf/phylmd/ocean_cpl_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/ocean_cpl_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/ocean_cpl_mod.F90	(revision 1795)
@@ -62,6 +62,6 @@
     USE cpl_mod
     USE calcul_fluxs_mod
-
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "YOMCST.h"
 !    
@@ -197,6 +197,6 @@
     USE cpl_mod
     USE calcul_fluxs_mod
-
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "YOMCST.h"
 
Index: LMDZ5/branches/testing/libf/phylmd/ocean_forced_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/ocean_forced_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/ocean_forced_mod.F90	(revision 1795)
@@ -30,5 +30,6 @@
     USE calcul_fluxs_mod
     USE limit_read_mod
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "YOMCST.h"
 
@@ -137,6 +138,6 @@
     USE limit_read_mod
     USE fonte_neige_mod,  ONLY : fonte_neige
-
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "dimsoil.h"
     INCLUDE "YOMCST.h"
Index: LMDZ5/branches/testing/libf/phylmd/ocean_slab_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/ocean_slab_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/ocean_slab_mod.F90	(revision 1795)
@@ -18,5 +18,6 @@
     USE limit_read_mod
     USE surface_data
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
 !    INCLUDE "clesphys.h"
 
@@ -60,6 +61,6 @@
     USE dimphy
     USE calcul_fluxs_mod
-  
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "iniprint.h"
 
Index: LMDZ5/branches/testing/libf/phylmd/pbl_surface_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/pbl_surface_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/pbl_surface_mod.F90	(revision 1795)
@@ -42,5 +42,6 @@
   REAL, ALLOCATABLE, DIMENSION(:,:), PRIVATE, SAVE   :: agesno ! age of snow at surface
   !$OMP THREADPRIVATE(agesno)
-  REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE :: ftsoil ! soil temperature
+! Correction pour le cas AMMA (PRIVATE)
+  REAL, ALLOCATABLE, DIMENSION(:,:,:), SAVE :: ftsoil ! soil temperature
   !$OMP THREADPRIVATE(ftsoil)
 
@@ -56,5 +57,6 @@
 ! for the index of the different surfaces and tests the choice of type of ocean.
 
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "dimsoil.h"
     INCLUDE "iniprint.h"
@@ -176,5 +178,5 @@
        alb1_m,    alb2_m,    zxsens,   zxevap,        &
        zxtsol,    zxfluxlat, zt2m,     qsat2m,        &
-       d_t,       d_q,       d_u,      d_v,           & 
+       d_t,       d_q,       d_u,      d_v, d_t_diss, & 
        zcoefh,    zcoefm,    slab_wfbils,             &
        qsol_d,    zq2m,      s_pblh,   s_plcl,        &
@@ -247,7 +249,8 @@
 !
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
+    USE indice_sol_mod
+
     IMPLICIT NONE
 
-    INCLUDE "indicesol.h"
     INCLUDE "dimsoil.h"
     INCLUDE "YOMCST.h"
@@ -259,4 +262,6 @@
     INCLUDE "YOETHF.h"
     INCLUDE "temps.h"
+!****************************************************************************************
+! Declarations specifiques pour le 1D. A reprendre 
 ! Input variables
 !****************************************************************************************
@@ -291,5 +296,5 @@
     REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: u10m    ! u speed at 10m
     REAL, DIMENSION(klon, nbsrf), INTENT(INOUT)     :: v10m    ! v speed at 10m
-    REAL, DIMENSION(klon, klev+1, nbsrf), INTENT(INOUT) :: tke 
+    REAL, DIMENSION(klon, klev+1, nbsrf+1), INTENT(INOUT) :: tke 
 
 ! Output variables
@@ -310,9 +315,10 @@
     REAL, DIMENSION(klon),        INTENT(OUT)       :: qsat2m
     REAL, DIMENSION(klon, klev),  INTENT(OUT)       :: d_t        ! change in temperature 
+    REAL, DIMENSION(klon, klev),  INTENT(OUT)       :: d_t_diss       ! change in temperature 
     REAL, DIMENSION(klon, klev),  INTENT(OUT)       :: d_q        ! change in water vapour
     REAL, DIMENSION(klon, klev),  INTENT(OUT)       :: d_u        ! change in u speed
     REAL, DIMENSION(klon, klev),  INTENT(OUT)       :: d_v        ! change in v speed
-    REAL, DIMENSION(klon, klev),  INTENT(OUT)       :: zcoefh     ! coef for turbulent diffusion of T and Q, mean for each grid point
-    REAL, DIMENSION(klon, klev),  INTENT(OUT)       :: zcoefm     ! coef for turbulent diffusion of U and V (?), mean for each grid point
+    REAL, DIMENSION(klon, klev,nbsrf+1),  INTENT(OUT)       :: zcoefh     ! coef for turbulent diffusion of T and Q, mean for each grid point
+    REAL, DIMENSION(klon, klev,nbsrf+1),  INTENT(OUT)       :: zcoefm     ! coef for turbulent diffusion of U and V (?), mean for each grid point
 
 ! Output only for diagnostics
@@ -424,9 +430,9 @@
     REAL, DIMENSION(klon)              :: ztsol
     REAL, DIMENSION(klon)              :: alb_m  ! mean albedo for whole SW interval
-    REAL, DIMENSION(klon,klev)         :: y_d_t, y_d_q
+    REAL, DIMENSION(klon,klev)         :: y_d_t, y_d_q, y_d_t_diss
     REAL, DIMENSION(klon,klev)         :: y_d_u, y_d_v
     REAL, DIMENSION(klon,klev)         :: y_flux_t, y_flux_q
     REAL, DIMENSION(klon,klev)         :: y_flux_u, y_flux_v
-    REAL, DIMENSION(klon,klev)         :: ycoefh, ycoefm
+    REAL, DIMENSION(klon,klev)         :: ycoefh, ycoefm,ycoefq
     REAL, DIMENSION(klon)              :: ycdragh, ycdragm
     REAL, DIMENSION(klon,klev)         :: yu, yv
@@ -470,8 +476,8 @@
 !****************************************************************************************
 ! Declarations specifiques pour le 1D. A reprendre 
+!****************************************************************************************
   REAL  :: fsens,flat
   LOGICAL :: ok_flux_surf ! initialized during first_call below
   COMMON /flux_arp/fsens,flat,ok_flux_surf
-!****************************************************************************************
 ! End of declarations
 !****************************************************************************************
@@ -546,11 +552,17 @@
     d_ts = 0.0    ; yfluxlat=0.0     ; flux_t = 0.0    ; flux_q = 0.0     
     flux_u = 0.0  ; flux_v = 0.0     ; d_t = 0.0       ; d_q = 0.0      
-    d_u = 0.0     ; d_v = 0.0        ; yqsol = 0.0    
+    d_t_diss= 0.0 ;d_u = 0.0     ; d_v = 0.0        ; yqsol = 0.0    
     ytherm = 0.0  ; ytke=0.
     
-    zcoefh(:,:) = 0.0
-    zcoefh(:,1) = 999999. ! zcoefh(:,k=1) should never be used
-    zcoefm(:,:) = 0.0
-    zcoefm(:,1) = 999999. !
+    tke(:,:,is_ave)=0.
+    IF (iflag_pbl<20.or.iflag_pbl>=30) THEN
+       zcoefh(:,:,:) = 0.0
+       zcoefh(:,1,:) = 999999. ! zcoefh(:,k=1) should never be used
+       zcoefm(:,:,:) = 0.0
+       zcoefm(:,1,:) = 999999. !
+    ELSE
+      zcoefm(:,:,is_ave)=0.
+      zcoefh(:,:,is_ave)=0.
+    ENDIF
     ytsoil = 999999. 
 
@@ -713,5 +725,5 @@
           ENDDO
        ENDDO
-       
+
        DO k = 1, nsoilmx
           DO j = 1, knon
@@ -747,4 +759,15 @@
             ypaprs, ypplay, yu, yv, yq, yt, yts, yrugos, yqsurf, ycdragm, &
             ycoefm, ycoefh, ytke)
+
+       IF (iflag_pbl>=20.AND.iflag_pbl<30) THEN
+! In this case, coef_diff_turb is called for the Cd only
+       DO k = 2, klev
+          DO j = 1, knon
+             i = ni(j)
+             ycoefh(j,k)   = zcoefh(i,k,nsrf)
+             ycoefm(j,k)   = zcoefm(i,k,nsrf)
+          ENDDO
+       ENDDO
+       ENDIF
        
 !****************************************************************************************
@@ -924,4 +947,12 @@
 
 
+     y_d_t_diss(:,:)=0.
+     IF (iflag_pbl>=20 .and. iflag_pbl<30) THEN
+        CALL yamada_c(knon,dtime,ypaprs,ypplay &
+    &   ,yu,yv,yt,y_d_u,y_d_v,y_d_t,ycdragm,ytke,ycoefm,ycoefh,ycoefq,y_d_t_diss,yustar &
+    &   ,iflag_pbl,nsrf)
+     ENDIF
+!     print*,'yamada_c OK'
+
        DO j = 1, knon
           y_dflux_t(j) = y_dflux_t(j) * ypct(j)
@@ -937,8 +968,8 @@
 !****************************************************************************************
 
-       tke(:,:,nsrf) = 0.
        DO k = 1, klev
           DO j = 1, knon
              i = ni(j)
+             y_d_t_diss(j,k)  = y_d_t_diss(j,k) * ypct(j)
              y_d_t(j,k)  = y_d_t(j,k) * ypct(j)
              y_d_q(j,k)  = y_d_q(j,k) * ypct(j)
@@ -951,8 +982,9 @@
              flux_v(i,k,nsrf) = y_flux_v(j,k)
 
-             tke(i,k,nsrf)    = ytke(j,k)
 
           ENDDO
        ENDDO
+
+!      print*,'Dans pbl OK1'
 
        evap(:,nsrf) = - flux_q(:,1,nsrf)
@@ -980,11 +1012,19 @@
        END DO
 
+!      print*,'Dans pbl OK2'
+
        DO k = 2, klev
           DO j = 1, knon
              i = ni(j)
-             zcoefh(i,k) = zcoefh(i,k) + ycoefh(j,k)*ypct(j)
-             zcoefm(i,k) = zcoefm(i,k) + ycoefm(j,k)*ypct(j)
+             tke(i,k,nsrf)    = ytke(j,k)
+             zcoefh(i,k,nsrf) = ycoefh(j,k)
+             zcoefm(i,k,nsrf) = ycoefm(j,k)
+             tke(i,k,is_ave) = tke(i,k,is_ave) + ytke(j,k)*ypct(j)
+             zcoefh(i,k,is_ave) = zcoefh(i,k,is_ave) + ycoefh(j,k)*ypct(j)
+             zcoefm(i,k,is_ave) = zcoefm(i,k,is_ave) + ycoefm(j,k)*ypct(j)
           END DO
        END DO
+
+!      print*,'Dans pbl OK3'
 
        IF ( nsrf .EQ. is_ter ) THEN 
@@ -1007,4 +1047,5 @@
           DO j = 1, knon
              i = ni(j)
+             d_t_diss(i,k) = d_t_diss(i,k) + y_d_t_diss(j,k)
              d_t(i,k) = d_t(i,k) + y_d_t(j,k)
              d_q(i,k) = d_q(i,k) + y_d_q(j,k)
@@ -1013,4 +1054,6 @@
           END DO
        END DO
+
+!      print*,'Dans pbl OK4'
 
 !****************************************************************************************
@@ -1040,9 +1083,12 @@
 ! Calculations of diagnostic t,q at 2m and u, v at 10m
 
+!      print*,'Dans pbl OK41'
+!      print*,'tair1,yt(:,1),y_d_t(:,1)'
+!      print*, tair1,yt(:,1),y_d_t(:,1)
        DO j=1, knon
           i = ni(j)
           uzon(j) = yu(j,1) + y_d_u(j,1)
           vmer(j) = yv(j,1) + y_d_v(j,1)
-          tair1(j) = yt(j,1) + y_d_t(j,1)
+          tair1(j) = yt(j,1) + y_d_t(j,1) + y_d_t_diss(j,1)
           qair1(j) = yq(j,1) + y_d_q(j,1)
           zgeo1(j) = RD * tair1(j) / (0.5*(ypaprs(j,1)+ypplay(j,1))) &
@@ -1058,4 +1104,7 @@
        END DO
        
+!      print*,'Dans pbl OK42A'
+!      print*,'tair1,yt(:,1),y_d_t(:,1)'
+!      print*, tair1,yt(:,1),y_d_t(:,1)
 
 ! Calculate the temperature et relative humidity at 2m and the wind at 10m 
@@ -1064,4 +1113,5 @@
             tairsol, qairsol, rugo1, psfce, patm, &
             yt2m, yq2m, yt10m, yq10m, yu10m, yustar)
+!      print*,'Dans pbl OK42B'
 
        DO j=1, knon
@@ -1077,4 +1127,5 @@
        END DO
 
+!      print*,'Dans pbl OK43'
 !IM Calcule de l'humidite relative a 2m (rh2m) pour diagnostique
 !IM Ajoute dependance type surface
@@ -1093,4 +1144,5 @@
        END IF
 
+!   print*,'OK pbl 5'
        CALL HBTM(knon, ypaprs, ypplay, &
             yt2m,yt10m,yq2m,yq10m,yustar, &
@@ -1113,4 +1165,5 @@
        END DO
        
+!   print*,'OK pbl 6'
 #else 
 ! T2m not defined
@@ -1130,4 +1183,5 @@
 !****************************************************************************************
     
+!   print*,'OK pbl 7'
     zxfluxt(:,:) = 0.0 ; zxfluxq(:,:) = 0.0
     zxfluxu(:,:) = 0.0 ; zxfluxv(:,:) = 0.0
@@ -1143,4 +1197,5 @@
     END DO
 
+!   print*,'OK pbl 8'
     DO i = 1, klon
        zxsens(i)     = - zxfluxt(i,1) ! flux de chaleur sensible au sol
@@ -1161,4 +1216,5 @@
     s_trmb2(:) = 0.0 ; s_trmb3(:) = 0.0
     
+!   print*,'OK pbl 9'
     
     DO nsrf = 1, nbsrf
@@ -1192,4 +1248,5 @@
        END DO
     END DO
+!   print*,'OK pbl 10'
 
     IF (check) THEN
@@ -1264,5 +1321,6 @@
        evap_rst, rugos_rst, agesno_rst, ftsoil_rst)
 
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "dimsoil.h"
 
@@ -1314,5 +1372,6 @@
     ! Give default values where new fraction has appread
 
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "dimsoil.h"
     INCLUDE "clesphys.h"
Index: LMDZ5/branches/testing/libf/phylmd/phyaqua.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phyaqua.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/phyaqua.F	(revision 1795)
@@ -16,11 +16,12 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-      use comgeomphy, only : rlatd,rlond
-      use dimphy, only : klon
-      use surface_data, only : type_ocean,ok_veget
-      use pbl_surface_mod, only : pbl_surface_init
+      USE comgeomphy, only : rlatd,rlond
+      USE dimphy, only : klon
+      USE surface_data, only : type_ocean,ok_veget
+      USE pbl_surface_mod, only : pbl_surface_init
       USE fonte_neige_mod, only : fonte_neige_init
-      use phys_state_var_mod
-      use control_mod, only : dayref,nday,iphysiq
+      USE phys_state_var_mod
+      USE control_mod, only : dayref,nday,iphysiq
+      USE indice_sol_mod
 
       USE IOIPSL 
@@ -33,5 +34,4 @@
 #include "clesphys.h"
 #include "dimsoil.h"
-#include "indicesol.h"
 #include "temps.h"
 
@@ -89,5 +89,9 @@
       integer, save::  read_climoz=0 ! read ozone climatology
 
-
+! intermediate variables to use getin
+      integer :: nbapp_rad_omp
+      real :: co2_ppm_omp,solaire_omp
+      logical :: alb_ocean_omp
+      real :: rugos_omp
 !-------------------------------------------------------------------------
 !  declaration pour l'appel a phyredem
@@ -160,6 +164,10 @@
          zcufi=1.
          zcvfi=1.
-      nbapp_rad=24
-      CALL getin('nbapp_rad',nbapp_rad)
+!$OMP MASTER
+      nbapp_rad_omp=24
+      CALL getin('nbapp_rad',nbapp_rad_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+      nbapp_rad=nbapp_rad_omp
 
 !---------------------------------------------------------------------
@@ -168,13 +176,20 @@
 ! Initialisations des constantes
 ! Ajouter les manquants dans planete.def... (albedo etc)
-      co2_ppm=348.
-      CALL getin('co2_ppm',co2_ppm)
-      solaire=1365.
-      CALL getin('solaire',solaire)
+!$OMP MASTER
+      co2_ppm_omp=348.
+      CALL getin('co2_ppm',co2_ppm_omp)
+      solaire_omp=1365.
+      CALL getin('solaire',solaire_omp)
+!      CALL getin('albedo',albedo) ! albedo is set below, depending on type_aqua
+      alb_ocean_omp=.true.
+      CALL getin('alb_ocean',alb_ocean_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+      co2_ppm=co2_ppm_omp
+      solaire=solaire_omp
+      alb_ocean=alb_ocean_omp
+
       radsol=0.
       qsol_f=10.
-!      CALL getin('albedo',albedo) ! albedo is set below, depending on type_aqua
-      alb_ocean=.true.
-      CALL getin('alb_ocean',alb_ocean)
 
 c  Conditions aux limites:
@@ -208,5 +223,10 @@
       endif
 
-      CALL getin('rugos',rugos)
+!$OMP MASTER
+      rugos_omp=rugos
+      CALL getin('rugos',rugos_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+      rugos=rugos_omp
       zmasq(:)=pctsrf(:,is_oce)
 
Index: LMDZ5/branches/testing/libf/phylmd/phyetat0.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phyetat0.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/phyetat0.F	(revision 1795)
@@ -23,4 +23,5 @@
       USE carbon_cycle_mod,ONLY :
      &     carbon_cycle_tr, carbon_cycle_cpl, co2_send
+      USE indice_sol_mod
 
       IMPLICIT none
@@ -31,5 +32,4 @@
 #include "dimensions.h"
 #include "netcdf.inc"
-#include "indicesol.h"
 #include "dimsoil.h"
 #include "clesphys.h"
Index: LMDZ5/branches/testing/libf/phylmd/phyredem.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phyredem.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/phyredem.F	(revision 1795)
@@ -16,4 +16,5 @@
       USE control_mod
       USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, co2_send
+      USE indice_sol_mod
 
       IMPLICIT none
@@ -23,5 +24,4 @@
 c======================================================================
 #include "netcdf.inc"
-#include "indicesol.h"
 #include "dimsoil.h"
 #include "clesphys.h"
Index: LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/phys_local_var_mod.F90	(revision 1795)
@@ -55,6 +55,6 @@
       REAL, SAVE, ALLOCATABLE :: d_u_oli(:,:), d_v_oli(:,:)
       !$OMP THREADPRIVATE(d_u_oli, d_v_oli)
-      REAL, SAVE, ALLOCATABLE :: d_t_vdf(:,:), d_q_vdf(:,:)
-      !$OMP THREADPRIVATE( d_t_vdf, d_q_vdf)
+      REAL, SAVE, ALLOCATABLE :: d_t_vdf(:,:), d_q_vdf(:,:), d_t_diss(:,:)
+      !$OMP THREADPRIVATE( d_t_vdf, d_q_vdf,d_t_diss)
       REAL, SAVE, ALLOCATABLE :: d_u_vdf(:,:), d_v_vdf(:,:)
       !$OMP THREADPRIVATE(d_u_vdf, d_v_vdf)
@@ -191,10 +191,10 @@
 !======================================================================
 SUBROUTINE phys_local_var_init
-use dimphy
-use infotrac, ONLY : nbtr
+USE dimphy
+USE infotrac, ONLY : nbtr
 USE aero_mod
+USE indice_sol_mod
 
 IMPLICIT NONE
-#include "indicesol.h"
       allocate(t_seri(klon,klev),q_seri(klon,klev),ql_seri(klon,klev),qs_seri(klon,klev))
       allocate(u_seri(klon,klev),v_seri(klon,klev))
@@ -216,5 +216,5 @@
       allocate(d_t_lscth(klon,klev),d_q_lscth(klon,klev))
       allocate(plul_st(klon),plul_th(klon))
-      allocate(d_t_vdf(klon,klev),d_q_vdf(klon,klev))
+      allocate(d_t_vdf(klon,klev),d_q_vdf(klon,klev),d_t_diss(klon,klev))
       allocate(d_u_vdf(klon,klev),d_v_vdf(klon,klev))
       allocate(d_t_oli(klon,klev),d_t_oro(klon,klev))
@@ -283,7 +283,7 @@
 !======================================================================
 SUBROUTINE phys_local_var_end
-use dimphy
+USE dimphy
+USE indice_sol_mod
 IMPLICIT NONE
-#include "indicesol.h"
       deallocate(t_seri,q_seri,ql_seri,qs_seri)
       deallocate(u_seri,v_seri)
@@ -305,5 +305,5 @@
       deallocate(d_t_lscth,d_q_lscth)
       deallocate(plul_st,plul_th)
-      deallocate(d_t_vdf,d_q_vdf)
+      deallocate(d_t_vdf,d_q_vdf,d_t_diss)
       deallocate(d_u_vdf,d_v_vdf)
       deallocate(d_t_oli,d_t_oro)
Index: LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 1795)
+++ LMDZ5/branches/testing/libf/phylmd/phys_output_ctrlout_mod.F90	(revision 1795)
@@ -0,0 +1,1119 @@
+MODULE phys_output_ctrlout_mod
+
+  USE phys_output_var_mod
+  USE indice_sol_mod
+  USE aero_mod, only : naero_spc,name_aero
+
+
+
+  IMPLICIT NONE
+      INTEGER, PRIVATE :: i
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Definition pour chaque variable du niveau d ecriture dans chaque fichier,
+!! de son nom, de sa description, de son unité et du type d'écriture.
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/ histmth, histday, histhf, histins /),'!!!!!!!!!!!!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!  CHARACTER(len=20), dimension(nfiles) :: TEF = type_ecri_files
+
+!!! Comosantes de la coordonnee sigma-hybride
+!!! Ap et Bp
+  TYPE(ctrl_out), SAVE :: o_Ahyb = ctrl_out((/ 1, 1, 1, 1, 1, 1 /), &
+	'Ap', '', '', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_Bhyb = ctrl_out((/ 1, 1, 1, 1, 1, 1 /), &
+	'Bp', '', '', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_Alt = ctrl_out((/ 1, 1, 1, 1, 1, 1 /), &
+	'Alt', '', '', (/ ('', i=1, 6) /))
+
+!!! 1D
+  TYPE(ctrl_out), SAVE :: o_phis = ctrl_out((/ 1, 1, 10, 5, 1, 1 /), &
+	'phis', 'Surface geop.height', 'm2/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_aire = ctrl_out((/ 1, 1, 10,  10, 1, 1 /), &
+	'aire', 'Grid area', '-', (/ 'once', 'once', 'once', 'once', 'once', 'once' /))
+  TYPE(ctrl_out), SAVE :: o_contfracATM = ctrl_out((/ 10, 1,  1, 10, 10, 10 /), &
+	'contfracATM', '% sfce ter+lic', '-', &
+      (/ "once", "once", "once", "once", "once", "once" /))
+  TYPE(ctrl_out), SAVE :: o_contfracOR = ctrl_out((/ 10, 1,  1, 10, 10, 10 /), &
+	'contfracOR', '% sfce terre OR', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_aireTER = ctrl_out((/ 10, 10, 1, 10, 10, 10 /), &
+	'aireTER', 'Grid area CONT', '-', (/ ('', i=1, 6) /))
+
+!!! 2D
+  TYPE(ctrl_out), SAVE :: o_flat = ctrl_out((/ 5, 1, 10, 10, 5, 10 /), &
+	'flat', 'Latent heat flux', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_slp = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'slp', 'Sea Level Pressure', 'Pa', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tsol = ctrl_out((/ 1, 1, 1, 5, 10, 10 /), &
+	'tsol', 'Surface Temperature', 'K', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_t2m = ctrl_out((/ 1, 1, 1, 5, 10, 10 /), &
+	't2m', 'Temperature 2m', 'K', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_t2m_min = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	't2m_min', 'Temp 2m min', 'K', &
+      (/ "t_min(X)", "t_min(X)", "t_min(X)", "t_min(X)", "t_min(X)", "t_min(X)" /))
+  TYPE(ctrl_out), SAVE :: o_t2m_max = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	't2m_max', 'Temp 2m max', 'K', &
+      (/ "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)" /))
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_t2m_srf = (/ &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /), &
+	't2m_ter', "Temp 2m "//clnsurf(1), "K", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /), &
+	't2m_lic', "Temp 2m "//clnsurf(2), "K", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /), &
+	't2m_oce', "Temp 2m "//clnsurf(3), "K", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /), &
+	't2m_sic', "Temp 2m "//clnsurf(4), "K", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE :: o_wind10m = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'wind10m', '10-m wind speed', 'm/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wind10max = ctrl_out((/ 10, 1, 10, 10, 10, 10 /), &
+	'wind10max', '10m wind speed max', 'm/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_sicf = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'sicf', 'Sea-ice fraction', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_q2m = ctrl_out((/ 1, 1, 1, 5, 10, 10 /), &
+	'q2m', 'Specific humidity 2m', 'kg/kg', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ustar = ctrl_out((/ 1, 1, 1, 5, 10, 10 /), &
+	'ustar', 'Friction velocity', 'm/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_u10m = ctrl_out((/ 1, 1, 1, 5, 10, 10 /), &
+	'u10m', 'Vent zonal 10m', 'm/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_v10m = ctrl_out((/ 1, 1, 1, 5, 10, 10 /), &
+	'v10m', 'Vent meridien 10m', 'm/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_psol = ctrl_out((/ 1, 1, 1, 5, 10, 10 /), &
+	'psol', 'Surface Pressure', 'Pa', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_qsurf = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'qsurf', 'Surface Air humidity', 'kg/kg', (/ ('', i=1, 6) /))
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_ustar_srf     = (/ &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_ter', &
+      "Friction velocity "//clnsurf(1),"m/s", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_lic', &
+      "Friction velocity "//clnsurf(2),"m/s", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_oce', &
+      "Friction velocity "//clnsurf(3),"m/s", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_sic', &
+      "Friction velocity "//clnsurf(4),"m/s", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_u10m_srf     = (/ &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'u10m_ter', &
+      "Vent Zonal 10m "//clnsurf(1),"m/s", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'u10m_lic', &
+      "Vent Zonal 10m "//clnsurf(2),"m/s", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'u10m_oce', &
+      "Vent Zonal 10m "//clnsurf(3),"m/s", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'u10m_sic', &
+      "Vent Zonal 10m "//clnsurf(4),"m/s", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_v10m_srf     = (/ &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'v10m_ter', &
+      "Vent meredien 10m "//clnsurf(1),"m/s", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'v10m_lic', &
+      "Vent meredien 10m "//clnsurf(2),"m/s", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'v10m_oce', &
+      "Vent meredien 10m "//clnsurf(3),"m/s", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'v10m_sic', &
+      "Vent meredien 10m "//clnsurf(4),"m/s", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE :: o_qsol = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'qsol', 'Soil watter content', 'mm', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ndayrain = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'ndayrain', 'Number of dayrain(liq+sol)', '-', &
+      (/ "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)", "inst(X)" /))
+  TYPE(ctrl_out), SAVE :: o_precip = ctrl_out((/ 1, 1, 1, 10, 5, 10 /), &
+	'precip', 'Precip Totale liq+sol', 'kg/(s*m2)', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_plul = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'plul', 'Large-scale Precip.', 'kg/(s*m2)', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_pluc = ctrl_out((/ 1, 1, 1, 10, 5, 10 /), &
+	'pluc', 'Convective Precip.', 'kg/(s*m2)', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_snow = ctrl_out((/ 1, 1, 10, 10, 5, 10 /), &
+	'snow', 'Snow fall', 'kg/(s*m2)', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_evap = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'evap', 'Evaporat', 'kg/(s*m2)', (/ ('', i=1, 6) /))
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_evap_srf     = (/ &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'evap_ter', &
+      "evaporation at surface "//clnsurf(1),"kg/(s*m2)", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'evap_lic', &
+      "evaporation at surface "//clnsurf(2),"kg/(s*m2)", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'evap_oce', &
+      "evaporation at surface "//clnsurf(3),"kg/(s*m2)", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'evap_sic', &
+      "evaporation at surface "//clnsurf(4),"kg/(s*m2)", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE :: o_msnow = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'msnow', 'Surface snow amount', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_fsnow = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'fsnow', 'Surface snow area fraction', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tops = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'tops', 'Solar rad. at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tops0 = ctrl_out((/ 1, 5, 10, 10, 10, 10 /), &
+	'tops0', 'CS Solar rad. at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_topl = ctrl_out((/ 1, 1, 10, 5, 10, 10 /), &
+	'topl', 'IR rad. at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_topl0 = ctrl_out((/ 1, 5, 10, 10, 10, 10 /), &
+	'topl0', 'IR rad. at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWupTOA = ctrl_out((/ 1, 4, 10, 10, 10, 10 /), &
+	'SWupTOA', 'SWup at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWupTOAclr = ctrl_out((/ 1, 4, 10, 10, 10, 10 /), &
+	'SWupTOAclr', 'SWup clear sky at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWdnTOA = ctrl_out((/ 1, 4, 10, 10, 10, 10 /), &
+	'SWdnTOA', 'SWdn at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWdnTOAclr = ctrl_out((/ 1, 4, 10, 10, 10, 10 /), &
+	'SWdnTOAclr', 'SWdn clear sky at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_nettop = ctrl_out((/ 1, 4, 10, 10, 10, 10 /), &
+	'nettop', 'Net dn radiatif flux at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWup200 = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'SWup200', 'SWup at 200mb', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWup200clr = ctrl_out((/ 10, 1, 10, 10, 10, 10 /), &
+	'SWup200clr', 'SWup clear sky at 200mb', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWdn200 = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'SWdn200', 'SWdn at 200mb', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWdn200clr = ctrl_out((/ 10, 1, 10, 10, 10, 10 /), &
+	'SWdn200clr', 'SWdn clear sky at 200mb', 'W/m2', (/ ('', i=1, 6) /))
+
+  ! arajouter
+  !  type(ctrl_out),save :: o_LWupTOA     = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'LWupTOA', &
+  !	(/ ('', i=1, 6) /))
+  !  type(ctrl_out),save :: o_LWupTOAclr  = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'LWupTOAclr', &
+  !	(/ ('', i=1, 6) /))
+  !  type(ctrl_out),save :: o_LWdnTOA     = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'LWdnTOA', &
+  !	(/ ('', i=1, 6) /))
+  !  type(ctrl_out),save :: o_LWdnTOAclr  = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'LWdnTOAclr', &
+  !	(/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_LWup200 = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'LWup200', 'LWup at 200mb', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_LWup200clr = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'LWup200clr', 'LWup clear sky at 200mb', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_LWdn200 = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'LWdn200', 'LWdn at 200mb', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_LWdn200clr = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'LWdn200clr', 'LWdn clear sky at 200mb', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_sols = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'sols', 'Solar rad. at surf.', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_sols0 = ctrl_out((/ 1, 5, 10, 10, 10, 10 /), &
+	'sols0', 'Solar rad. at surf.', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_soll = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'soll', 'IR rad. at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_soll0 = ctrl_out((/ 1, 5, 10, 10, 10, 10 /), &
+	'soll0', 'IR rad. at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_radsol = ctrl_out((/ 1, 7, 10, 10, 10, 10 /), &
+	'radsol', 'Rayonnement au sol', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWupSFC = ctrl_out((/ 1, 4, 10, 10, 5, 10 /), &
+	'SWupSFC', 'SWup at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWupSFCclr = ctrl_out((/ 1, 4, 10, 10, 5, 10 /), &
+	'SWupSFCclr', 'SWup clear sky at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWdnSFC = ctrl_out((/ 1, 1, 10, 10, 5, 10 /), &
+	'SWdnSFC', 'SWdn at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWdnSFCclr = ctrl_out((/ 1, 4, 10, 10, 5, 10 /), &
+	'SWdnSFCclr', 'SWdn clear sky at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_LWupSFC = ctrl_out((/ 1, 4, 10, 10, 5, 10 /), &
+	'LWupSFC', 'Upwd. IR rad. at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_LWupSFCclr = ctrl_out((/ 1, 4, 10, 10, 5, 10 /), &
+	'LWupSFCclr', 'CS Upwd. IR rad. at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_LWdnSFC = ctrl_out((/ 1, 4, 10, 10, 5, 10 /), &
+	'LWdnSFC', 'Down. IR rad. at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_LWdnSFCclr = ctrl_out((/ 1, 4, 10, 10, 5, 10 /), &
+	'LWdnSFCclr', 'Down. CS IR rad. at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_bils = ctrl_out((/ 1, 2, 10, 5, 10, 10 /), &
+	'bils', 'Surf. total heat flux', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_bils_tke = ctrl_out((/ 1, 2, 10, 5, 10, 10 /), &
+	'bils_tke', 'Surf. total heat flux', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_bils_diss = ctrl_out((/ 1, 2, 10, 5, 10, 10 /), &
+	'bils_diss', 'Surf. total heat flux', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_bils_ec = ctrl_out((/ 1, 2, 10, 5, 10, 10 /), &
+	'bils_ec', 'Surf. total heat flux', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_bils_kinetic = ctrl_out((/ 1, 2, 10, 5, 10, 10 /), &
+	'bils_kinetic', 'Surf. total heat flux', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_bils_enthalp = ctrl_out((/ 1, 2, 10, 5, 10, 10 /), &
+	'bils_enthalp', 'Surf. total heat flux', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_bils_latent = ctrl_out((/ 1, 2, 10, 5, 10, 10 /), &
+	'bils_latent', 'Surf. total heat flux', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_sens = ctrl_out((/ 1, 1, 10, 10, 5, 10 /), &
+	'sens', 'Sensible heat flux', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_fder = ctrl_out((/ 1, 2, 10, 10, 10, 10 /), &
+	'fder', 'Heat flux derivation', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ffonte = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'ffonte', 'Thermal flux for snow melting', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_fqcalving = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'fqcalving', 'Ice Calving', 'kg/m2/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_fqfonte = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'fqfonte', 'Land ice melt', 'kg/m2/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_taux = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'taux', 'Zonal wind stress', 'Pa', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tauy = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'tauy', 'Meridional wind stress', 'Pa', (/ ('', i=1, 6) /))
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_taux_srf = (/           &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'taux_ter',             &
+      "Zonal wind stress"//clnsurf(1), "Pa", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'taux_lic',             &
+      "Zonal wind stress"//clnsurf(2), "Pa", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'taux_oce',             &
+      "Zonal wind stress"//clnsurf(3), "Pa", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'taux_sic',             &
+      "Zonal wind stress"//clnsurf(4), "Pa", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_tauy_srf     = (/             &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tauy_ter',                   &
+      "Meridional wind stress "//clnsurf(1),"Pa", (/ ('', i=1, 6) /)),  &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tauy_lic',                   &
+      "Meridional wind stress "//clnsurf(2),"Pa", (/ ('', i=1, 6) /)),  &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tauy_oce',                   &
+      "Meridional wind stress "//clnsurf(3),"Pa", (/ ('', i=1, 6) /)),  &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tauy_sic',                   &
+      "Meridional wind stress "//clnsurf(4),"Pa", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_pourc_srf    = (/ &
+      ctrl_out((/ 1, 7, 10, 10, 10, 10 /),'pourc_ter',      &
+      "% "//clnsurf(1),"%", (/ ('', i=1, 6) /)),            &
+      ctrl_out((/ 1, 7, 10, 10, 10, 10 /),'pourc_lic',      &
+      "% "//clnsurf(2),"%", (/ ('', i=1, 6) /)),            &
+      ctrl_out((/ 1, 7, 10, 10, 10, 10 /),'pourc_oce',      &
+      "% "//clnsurf(3),"%", (/ ('', i=1, 6) /)),            &
+      ctrl_out((/ 1, 7, 10, 10, 10, 10 /),'pourc_sic',      &
+      "% "//clnsurf(4),"%", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_fract_srf    = (/ &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'fract_ter',      &
+      "Fraction "//clnsurf(1),"1", (/ ('', i=1, 6) /)),     &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'fract_lic',      &
+      "Fraction "//clnsurf(2),"1", (/ ('', i=1, 6) /)),     &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'fract_oce',      &
+      "Fraction "//clnsurf(3),"1", (/ ('', i=1, 6) /)),     &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'fract_sic',      &
+      "Fraction "//clnsurf(4),"1", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_tsol_srf     = (/ &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tsol_ter',       &
+      "Temperature "//clnsurf(1),"K", (/ ('', i=1, 6) /)),  &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tsol_lic',       &
+      "Temperature "//clnsurf(2),"K", (/ ('', i=1, 6) /)),  &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tsol_oce',       &
+      "Temperature "//clnsurf(3),"K", (/ ('', i=1, 6) /)),  &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tsol_sic',       &
+      "Temperature "//clnsurf(4),"K", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_evappot_srf  = (/ &
+      ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'evappot_ter',    &
+      "Temperature"//clnsurf(1),"K", (/ ('', i=1, 6) /)),   &
+      ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'evappot_lic',    &
+      "Temperature"//clnsurf(2),"K", (/ ('', i=1, 6) /)),   &
+      ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'evappot_oce',    &
+      "Temperature"//clnsurf(3),"K", (/ ('', i=1, 6) /)),   &
+      ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'evappot_sic',    &
+      "Temperature"//clnsurf(4),"K", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_sens_srf     = (/          &
+      ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'sens_ter',                 &
+      "Sensible heat flux "//clnsurf(1),"W/m2", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'sens_lic',                 &
+      "Sensible heat flux "//clnsurf(2),"W/m2", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'sens_oce',                 &
+      "Sensible heat flux "//clnsurf(3),"W/m2", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'sens_sic',                 &
+      "Sensible heat flux "//clnsurf(4),"W/m2", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_lat_srf      = (/        &
+      ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'lat_ter',                &
+      "Latent heat flux "//clnsurf(1),"W/m2", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'lat_lic',                &
+      "Latent heat flux "//clnsurf(2),"W/m2", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'lat_oce',                &
+      "Latent heat flux "//clnsurf(3),"W/m2", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'lat_sic',                &
+      "Latent heat flux "//clnsurf(4),"W/m2", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_flw_srf      = (/ &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'flw_ter',       &
+      "LW "//clnsurf(1),"W/m2", (/ ('', i=1, 6) /)),        &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'flw_lic',       &
+      "LW "//clnsurf(2),"W/m2", (/ ('', i=1, 6) /)),        &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'flw_oce',       &
+      "LW "//clnsurf(3),"W/m2", (/ ('', i=1, 6) /)),        &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'flw_sic',       &
+      "LW "//clnsurf(4),"W/m2", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_fsw_srf      = (/ &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fsw_ter',       &
+      "SW "//clnsurf(1),"W/m2", (/ ('', i=1, 6) /)),        &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fsw_lic',       &
+      "SW "//clnsurf(2),"W/m2", (/ ('', i=1, 6) /)),        &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fsw_oce',       &
+      "SW "//clnsurf(3),"W/m2", (/ ('', i=1, 6) /)),        &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fsw_sic',       &
+      "SW "//clnsurf(4),"W/m2", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_wbils_srf    = (/ &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbils_ter',     &
+      "Bilan sol "//clnsurf(1),"W/m2", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbils_lic',     &
+      "Bilan sol "//clnsurf(2),"W/m2", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbils_oce',     &
+      "Bilan sol "//clnsurf(3),"W/m2", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbils_sic',     &
+      "Bilan sol "//clnsurf(4),"W/m2", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_wbilo_srf    = (/      &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbilo_ter',          &
+      "Bilan eau "//clnsurf(1),"kg/(m2*s)", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbilo_lic',          &
+      "Bilan eau "//clnsurf(2),"kg/(m2*s)", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbilo_oce',          &
+      "Bilan eau "//clnsurf(3),"kg/(m2*s)", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbilo_sic',          &
+      "Bilan eau "//clnsurf(4),"kg/(m2*s)", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE :: o_cdrm = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'cdrm', 'Momentum drag coef.', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cdrh = ctrl_out((/ 1, 10, 10, 7, 10, 10 /), &
+	'cdrh', 'Heat drag coef.', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cldl = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'cldl', 'Low-level cloudiness', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cldm = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'cldm', 'Mid-level cloudiness', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cldh = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'cldh', 'High-level cloudiness', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cldt = ctrl_out((/ 1, 1, 2, 10, 5, 10 /), &
+	'cldt', 'Total cloudiness', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cldq = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'cldq', 'Cloud liquid water path', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_lwp = ctrl_out((/ 1, 5, 10, 10, 10, 10 /), &
+	'lwp', 'Cloud water path', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_iwp = ctrl_out((/ 1, 5, 10, 10, 10, 10 /), &
+	'iwp', 'Cloud ice water path', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ue = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'ue', 'Zonal energy transport', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ve = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	've', 'Merid energy transport', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_uq = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'uq', 'Zonal humidity transport', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_vq = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'vq', 'Merid humidity transport', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cape = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'cape', 'Conv avlbl pot ener', 'J/kg', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_pbase = ctrl_out((/ 1, 5, 10, 10, 10, 10 /), &
+	'pbase', 'Cld base pressure', 'Pa', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ptop = ctrl_out((/ 1, 5, 10, 10, 10, 10 /), &
+	'ptop', 'Cld top pressure', 'Pa', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_fbase = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'fbase', 'Cld base mass flux', 'kg/m2/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_plcl = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'plcl', 'Lifting Condensation Level', 'hPa', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_plfc = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'plfc', 'Level of Free Convection', 'hPa', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wbeff = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	'wbeff', 'Conv. updraft velocity at LFC (<100)', 'm/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_prw = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'prw', 'Precipitable water', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_s_pblh = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	's_pblh', 'Boundary Layer Height', 'm', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_s_pblt = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	's_pblt', 't at Boundary Layer Height', 'K', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_s_lcl = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	's_lcl', 'Condensation level', 'm', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_s_therm = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	's_therm', 'Exces du thermique', 'K', (/ ('', i=1, 6) /))
+  !IM : Les champs suivants (s_capCL, s_oliqCL, s_cteiCL, s_trmb1, s_trmb2, s_trmb3) ne sont pas definis dans HBTM.F
+  ! type(ctrl_out),save :: o_s_capCL      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_capCL', &
+!	(/ ('', i=1, 6) /))
+  ! type(ctrl_out),save :: o_s_oliqCL     = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_oliqCL', &
+!	(/ ('', i=1, 6) /))
+  ! type(ctrl_out),save :: o_s_cteiCL     = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_cteiCL', &
+!	(/ ('', i=1, 6) /))
+  ! type(ctrl_out),save :: o_s_trmb1      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_trmb1', &
+!	(/ ('', i=1, 6) /))
+  ! type(ctrl_out),save :: o_s_trmb2      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_trmb2', &
+!	(/ ('', i=1, 6) /))
+  ! type(ctrl_out),save :: o_s_trmb3      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_trmb3', &
+	!(/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_slab_bils = ctrl_out((/ 1, 1, 10, 10, 10, 10 /), &
+	'slab_bils_oce', 'Bilan au sol sur ocean slab', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ale_bl = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'ale_bl', 'ALE BL', 'm2/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_alp_bl = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'alp_bl', 'ALP BL', 'm2/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ale_wk = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'ale_wk', 'ALE WK', 'm2/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_alp_wk = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'alp_wk', 'ALP WK', 'm2/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ale = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'ale', 'ALE', 'm2/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_alp = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'alp', 'ALP', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cin = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'cin', 'Convective INhibition', 'm2/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wape = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'wape', '', '', (/ ('', i=1, 6) /))
+
+!!! nrlmd le 10/04/2012
+
+!-------Spectre de thermiques de type 2 au LCL
+  TYPE(ctrl_out), SAVE :: o_n2 = ctrl_out((/ 1, 1, 1, 6, 10, 10 /), &
+	'n2', 'Nombre de panaches de type 2', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_s2 = ctrl_out((/ 1, 1, 1, 6, 10, 10 /), &
+	's2', 'Surface moyenne des panaches de type 2', 'm2', (/ ('', i=1, 6) /))
+                                                                             
+!-------Déclenchement stochastique                                           
+  TYPE(ctrl_out), SAVE :: o_proba_notrig = ctrl_out((/ 1, 1, 1, 6, 10, 10 /), &
+	'proba_notrig', &
+                         'Probabilité de non-déclenchement', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_random_notrig = ctrl_out((/ 1, 1, 1, 6, 10, 10 /), &
+	'random_notrig', &
+                         'Tirage aléatoire de non-déclenchement', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ale_bl_stat = ctrl_out((/ 1, 1, 1, 6, 10, 10 /), &
+	'ale_bl_stat', &
+       'ALE_BL_STAT', 'm2/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ale_bl_trig = ctrl_out((/ 1, 1, 1, 6, 10, 10 /), &
+	'ale_bl_trig', &
+       'ALE_BL_STAT + Condition P>Pseuil', 'm2/s2', (/ ('', i=1, 6) /))
+
+!-------Fermeture statistique
+  TYPE(ctrl_out), SAVE :: o_alp_bl_det = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'alp_bl_det', 'ALP_BL_DET', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_alp_bl_fluct_m = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'alp_bl_fluct_m', 'ALP_BL_FLUCT_M', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_alp_bl_fluct_tke = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'alp_bl_fluct_tke', 'ALP_BL_FLUCT_TKE', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_alp_bl_conv = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'alp_bl_conv', 'ALP_BL_CONV', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_alp_bl_stat = ctrl_out((/ 1, 1, 1, 10, 10, 10 /), &
+	'alp_bl_stat', 'ALP_BL_STAT', 'W/m2', (/ ('', i=1, 6) /))
+
+!!! fin nrlmd le 10/04/2012
+
+  ! Champs interpolles sur des niveaux de pression ??? a faire correctement
+
+  TYPE(ctrl_out), SAVE, DIMENSION(7) :: o_uSTDlevs     = (/                    &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u850', "Zonal wind 1hPa", "m/s",     &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u700', "Zonal wind 2hPa", "m/s",     &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u500', "Zonal wind 3hPa", "m/s",     &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u200', "Zonal wind 4hPa", "m/s",     &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u100', "Zonal wind 5hPa", "m/s",     &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u50', "Zonal wind 6hPa", "m/s",     &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u10', "Zonal wind 7hPa", "m/s",     &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(7) :: o_vSTDlevs     = (/                     &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v850', "Meridional wind 1hPa", "m/s", &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)),  &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v700', "Meridional wind 2hPa", "m/s", &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)),  &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v500', "Meridional wind 3hPa", "m/s", &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)),  &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v200', "Meridional wind 4hPa", "m/s", &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)),  &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v100', "Meridional wind 5hPa", "m/s", &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)),  &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v50', "Meridional wind 6hPa", "m/s",  &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)),  &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v10', "Meridional wind 7hPa", "m/s",  &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(7) :: o_wSTDlevs     = (/                    &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w850', "Vertical wind 1hPa", "Pa/s", &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w700', "Vertical wind 2hPa", "Pa/s", &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w500', "Vertical wind 3hPa", "Pa/s", &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w200', "Vertical wind 4hPa", "Pa/s", &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w100', "Vertical wind 5hPa", "Pa/s", &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w50', "Vertical wind 6hPa", "Pa/s",  &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w10', "Vertical wind 7hPa", "Pa/s",  &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(7) :: o_tSTDlevs     = (/                    &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t850', "Temperature 1hPa", "K",      &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t700', "Temperature 2hPa", "K",      &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t500', "Temperature 3hPa", "K",      &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t200', "Temperature 4hPa", "K",      &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t100', "Temperature 5hPa", "K",      &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t50',  "Temperature 6hPa", "K",      &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t10',  "Temperature 7hPa", "K",      &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(7) :: o_qSTDlevs     = (/                             &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q850', "Specific humidity 1hPa",              &
+      "kg/kg", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q700', "Specific humidity 2hPa",              &
+      "kg/kg", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q500', "Specific humidity 3hPa",              &
+      "kg/kg", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q200', "Specific humidity 4hPa",              &
+      "kg/kg", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q100', "Specific humidity 5hPa",              &
+      "kg/kg", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q50', "Specific humidity 6hPa",               &
+      "kg/kg", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q10', "Specific humidity 7hPa",               &
+      "kg/kg", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(7) :: o_zSTDlevs   = (/                           &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z850', "Geopotential height 1hPa",        &
+      "m", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z700', "Geopotential height 2hPa",        &
+      "m", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z500', "Geopotential height 3hPa",        &
+      "m", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z200', "Geopotential height 4hPa",        &
+      "m", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z100', "Geopotential height 5hPa",        &
+      "m", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z50', "Geopotential height 6hPa",         &
+      "m", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)), &
+      ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z10', "Geopotential height 7hPa",         &
+      "m", (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /)) /)
+
+  TYPE(ctrl_out), SAVE :: o_t_oce_sic = ctrl_out((/ 1, 10, 10, 10, 10, 10 /), &
+	't_oce_sic', 'Temp mixte oce-sic', 'K', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_weakinv = ctrl_out((/ 10, 1, 10, 10, 10, 10 /), &
+	'weakinv', 'Weak inversion', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dthmin = ctrl_out((/ 10, 1, 10, 10, 10, 10 /), &
+	'dthmin', 'dTheta mini', 'K/m', (/ ('', i=1, 6) /))
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_u10_srf      = (/ &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'u10_ter', "", "", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'u10_lic', "", "", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'u10_oce', "", "", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'u10_sic', "", "", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_v10_srf      = (/ &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'v10_ter', "", "", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'v10_lic', "", "", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'v10_oce', "", "", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'v10_sic', "", "", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE :: o_cldtau = ctrl_out((/ 10, 5, 10, 10, 10, 10 /), &
+	'cldtau', 'Cloud optical thickness', '1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cldemi = ctrl_out((/ 10, 5, 10, 10, 10, 10 /), &
+	'cldemi', 'Cloud optical emissivity', '1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rh2m = ctrl_out((/ 5, 5, 10, 10, 10, 10 /), &
+	'rh2m', 'Relative humidity at 2m', '%', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rh2m_min = ctrl_out((/ 10, 5, 10, 10, 10, 10 /), &
+	'rh2m_min', 'Min Relative humidity at 2m', '%',                        &
+      (/ 't_min(X)', 't_min(X)', 't_min(X)', 't_min(X)', 't_min(X)', 't_min(X)' /))
+  TYPE(ctrl_out), SAVE :: o_rh2m_max = ctrl_out((/ 10, 5, 10, 10, 10, 10 /), &
+	'rh2m_max', 'Max Relative humidity at 2m', '%',                        &
+      (/ 't_max(X)', 't_max(X)', 't_max(X)', 't_max(X)', 't_max(X)', 't_max(X)' /))
+  TYPE(ctrl_out), SAVE :: o_qsat2m = ctrl_out((/ 10, 5, 10, 10, 10, 10 /), &
+	'qsat2m', 'Saturant humidity at 2m', '%', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tpot = ctrl_out((/ 10, 5, 10, 10, 10, 10 /), &
+	'tpot', 'Surface air potential temperature', 'K', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tpote = ctrl_out((/ 10, 5, 10, 10, 10, 10 /), &
+	'tpote', &
+      'Surface air equivalent potential temperature', 'K', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tke = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'tke ', 'TKE', 'm2/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tke_max = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'tke_max', 'TKE max', 'm2/s2',                                        &
+      (/ 't_max(X)', 't_max(X)', 't_max(X)', 't_max(X)', 't_max(X)', 't_max(X)' /))
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_tke_srf      = (/             &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_ter',                   &
+      "Max Turb. Kinetic Energy "//clnsurf(1),"-", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_lic',                   &
+      "Max Turb. Kinetic Energy "//clnsurf(2),"-", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_oce',                   &
+      "Max Turb. Kinetic Energy "//clnsurf(3),"-", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_sic',                   &
+      "Max Turb. Kinetic Energy "//clnsurf(4),"-", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_tke_max_srf  = (/                                  &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_max_ter',                                    &
+      "Max Turb. Kinetic Energy "//clnsurf(1),"-",                                           &
+      (/ "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)" /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_max_lic',                                    &
+      "Max Turb. Kinetic Energy "//clnsurf(2),"-",                                           &
+      (/ "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)" /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_max_oce',                                    &
+      "Max Turb. Kinetic Energy "//clnsurf(3),"-",                                           &
+      (/ "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)" /)), &
+      ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_max_sic',                                    &
+      "Max Turb. Kinetic Energy "//clnsurf(4),"-",                                           &
+      (/ "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)" /)) /)
+
+  TYPE(ctrl_out), SAVE :: o_kz = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'kz', 'Kz melange', 'm2/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_kz_max = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'kz_max', 'Kz melange max', 'm2/s',                                  &
+      (/ 't_max(X)', 't_max(X)', 't_max(X)', 't_max(X)', 't_max(X)', 't_max(X)' /))
+  TYPE(ctrl_out), SAVE :: o_SWnetOR = ctrl_out((/ 10, 10, 2, 10, 10, 10 /), &
+	'SWnetOR', 'Sfce net SW radiation OR', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_SWdownOR = ctrl_out((/ 10, 10, 2, 10, 10, 10 /), &
+	'SWdownOR', 'Sfce incident SW radiation OR', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_LWdownOR = ctrl_out((/ 10, 10, 2, 10, 10, 10 /), &
+	'LWdownOR', 'Sfce incident LW radiation OR', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_snowl = ctrl_out((/ 10, 1, 10, 10, 10, 10 /), &
+	'snowl', 'Solid Large-scale Precip.', 'kg/(m2*s)', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cape_max = ctrl_out((/ 10, 1, 10, 10, 10, 10 /), &
+	'cape_max', 'CAPE max.', 'J/kg',                                       &
+      (/ "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)", "t_max(X)" /))
+  TYPE(ctrl_out), SAVE :: o_solldown = ctrl_out((/ 10, 1, 10, 10, 10, 10 /), &
+	'solldown', 'Down. IR rad. at surface', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtsvdfo = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'dtsvdfo', 'Boundary-layer dTs(o)', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtsvdft = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'dtsvdft', 'Boundary-layer dTs(t)', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtsvdfg = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'dtsvdfg', 'Boundary-layer dTs(g)', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtsvdfi = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'dtsvdfi', 'Boundary-layer dTs(g)', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rugs = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'rugs', 'rugosity', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_topswad = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'topswad', 'ADE at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_topswad0 = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'topswad0', 'ADE clear-sky at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_topswai = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'topswai', 'AIE at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_solswad = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'solswad', 'ADE at SRF', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_solswad0 = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'solswad0', 'ADE clear-sky at SRF', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_solswai = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'solswai', 'AIE at SFR', 'W/m2', (/ ('', i=1, 6) /))
+
+!  type(ctrl_out),save,dimension(10) :: o_tausumaero  = (/ ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_ASBCM', &
+!	(/ ('', i=1, 6) /)), &
+  type(ctrl_out),save,dimension(11) :: o_tausumaero  =                           & 
+    (/ ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_ASBCM',                        &
+      "Aerosol Optical depth at 550 nm "//name_aero(1),"1", (/ ('', i=1, 6) /)), &
+       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_ASPOMM',                       &
+      "Aerosol Optical depth at 550 nm "//name_aero(2),"1", (/ ('', i=1, 6) /)), &
+       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_ASSO4M',                       &
+      "Aerosol Optical depth at 550 nm "//name_aero(3),"1", (/ ('', i=1, 6) /)), &
+       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_CSSO4M',                       &
+      "Aerosol Optical depth at 550 nm "//name_aero(4),"1", (/ ('', i=1, 6) /)), &
+       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_SSSSM',                        &
+      "Aerosol Optical depth at 550 nm "//name_aero(5),"1", (/ ('', i=1, 6) /)), &
+       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_ASSSM',                        &
+      "Aerosol Optical depth at 550 nm "//name_aero(6),"1", (/ ('', i=1, 6) /)), &
+       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_CSSSM',                        &
+      "Aerosol Optical depth at 550 nm "//name_aero(7),"1", (/ ('', i=1, 6) /)), &
+       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_CIDUSTM',                      &
+      "Aerosol Optical depth at 550 nm "//name_aero(8),"1", (/ ('', i=1, 6) /)), &
+       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_AIBCM',                        &
+      "Aerosol Optical depth at 550 nm "//name_aero(9),"1", (/ ('', i=1, 6) /)), &
+       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_AIPOMM',                       &
+      "Aerosol Optical depth at 550 nm "//name_aero(10),"1", (/ ('', i=1, 6) /)),&
+       ctrl_out((/ 2, 2, 10, 10, 10, 10 /),'OD550_STRAT',                        &
+      "Aerosol Optical depth at 550 nm "//name_aero(11),"1", (/ ('', i=1, 6) /)) /)
+  TYPE(ctrl_out), SAVE :: o_od550aer = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'od550aer', 'Total aerosol optical depth at 550nm', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_od865aer = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'od865aer', 'Total aerosol optical depth at 870nm', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_absvisaer = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'absvisaer', 'Absorption aerosol visible optical depth', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_od550lt1aer = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'od550lt1aer', 'Fine mode optical depth', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_sconcso4 = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'sconcso4', 'Surface Concentration of Sulfate ', 'kg/m3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_sconcoa = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'sconcoa', 'Surface Concentration of Organic Aerosol ', 'kg/m3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_sconcbc = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'sconcbc', 'Surface Concentration of Black Carbon ', 'kg/m3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_sconcss = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'sconcss', 'Surface Concentration of Sea Salt ', 'kg/m3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_sconcdust = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'sconcdust', 'Surface Concentration of Dust ', 'kg/m3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_concso4 = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'concso4', 'Concentration of Sulfate ', 'kg/m3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_concoa = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'concoa', 'Concentration of Organic Aerosol ', 'kg/m3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_concbc = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'concbc', 'Concentration of Black Carbon ', 'kg/m3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_concss = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'concss', 'Concentration of Sea Salt ', 'kg/m3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_concdust = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'concdust', 'Concentration of Dust ', 'kg/m3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_loadso4 = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'loadso4', 'Column Load of Sulfate ', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_loadoa = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'loadoa', 'Column Load of Organic Aerosol ', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_loadbc = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'loadbc', 'Column Load of Black Carbon ', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_loadss = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'loadss', 'Column Load of Sea Salt ', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_loaddust = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'loaddust', 'Column Load of Dust ', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swtoaas_nat = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swtoaas_nat', 'Natural aerosol radiative forcing all-sky at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swsrfas_nat = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swsrfas_nat', 'Natural aerosol radiative forcing all-sky at SRF', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swtoacs_nat = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swtoacs_nat', 'Natural aerosol radiative forcing clear-sky at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swsrfcs_nat = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swsrfcs_nat', 'Natural aerosol radiative forcing clear-sky at SRF', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swtoaas_ant = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swtoaas_ant', 'Anthropogenic aerosol radiative forcing all-sky at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swsrfas_ant = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swsrfas_ant', 'Anthropogenic aerosol radiative forcing all-sky at SRF', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swtoacs_ant = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swtoacs_ant', 'Anthropogenic aerosol radiative forcing clear-sky at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swsrfcs_ant = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swsrfcs_ant', 'Anthropogenic aerosol radiative forcing clear-sky at SRF', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swtoacf_nat = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swtoacf_nat', 'Natural aerosol impact on cloud radiative forcing at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swsrfcf_nat = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swsrfcf_nat', 'Natural aerosol impact on cloud radiative forcing  at SRF', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swtoacf_ant = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swtoacf_ant', 'Anthropogenic aerosol impact on cloud radiative forcing at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swsrfcf_ant = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swsrfcf_ant', 'Anthropogenic aerosol impact on cloud radiative forcing at SRF', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swtoacf_zero = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swtoacf_zero', 'Cloud radiative forcing (allsky-clearsky fluxes) at TOA', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_swsrfcf_zero = ctrl_out((/ 4, 6, 10, 10, 10, 10 /), &
+	'swsrfcf_zero', 'Cloud radiative forcing (allsky-clearsky fluxes) at SRF', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cldncl = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'cldncl', 'CDNC at top of liquid water cloud', 'm-3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_reffclwtop = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'reffclwtop', 'Droplet effective radius at top of liquid water cloud', 'm', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_cldnvi = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'cldnvi', 'Column Integrated Cloud Droplet Number', 'm-2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_lcc = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'lcc', 'Cloud liquid fraction at top of cloud', '1', (/ ('', i=1, 6) /))
+
+
+!!!!!!!!!!!!!!!!!!!!!! 3D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
+  TYPE(ctrl_out), SAVE :: o_ec550aer = ctrl_out((/ 2, 6, 10, 10, 10, 10 /), &
+	'ec550aer', 'Extinction at 550nm', 'm^-1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_lwcon = ctrl_out((/ 2, 5, 10, 10, 10, 10 /), &
+	'lwcon', 'Cloud liquid water content', 'kg/kg', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_iwcon = ctrl_out((/ 2, 5, 10, 10, 10, 10 /), &
+	'iwcon', 'Cloud ice water content', 'kg/kg', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_temp = ctrl_out((/ 2, 3, 4, 10, 10, 10 /), &
+	'temp', 'Air temperature', 'K', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_theta = ctrl_out((/ 2, 3, 4, 10, 10, 10 /), &
+	'theta', 'Potential air temperature', 'K', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ovap = ctrl_out((/ 2, 3, 4, 10, 10, 10 /), &
+	'ovap', 'Specific humidity', 'kg/kg', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ovapinit = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'ovapinit', 'Specific humidity (begin of timestep)', 'kg/kg', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_oliq = ctrl_out((/ 2, 3, 4, 10, 10, 10 /), &
+	'oliq', 'Condensed water', 'kg/kg', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wvapp = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'wvapp', '', '', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_geop = ctrl_out((/ 2, 3, 10, 10, 10, 10 /), &
+	'geop', 'Geopotential height', 'm2/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_vitu = ctrl_out((/ 2, 3, 4, 6, 10, 10 /), &
+	'vitu', 'Zonal wind', 'm/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_vitv = ctrl_out((/ 2, 3, 4, 6, 10, 10 /), &
+	'vitv', 'Meridional wind', 'm/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_vitw = ctrl_out((/ 2, 3, 10, 6, 10, 10 /), &
+	'vitw', 'Vertical wind', 'Pa/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_pres = ctrl_out((/ 2, 3, 10, 10, 10, 10 /), &
+	'pres', 'Air pressure', 'Pa', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_paprs = ctrl_out((/ 2, 3, 10, 10, 10, 10 /), &
+	'paprs', 'Air pressure Inter-Couches', 'Pa', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_mass = ctrl_out((/ 2, 3, 10, 10, 10, 10 /), &
+	'mass', 'Masse Couches', 'kg/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_zfull = ctrl_out((/ 2, 3, 10, 10, 10, 10 /), &
+	'zfull', 'Altitude of full pressure levels', 'm', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_zhalf = ctrl_out((/ 2, 3, 10, 10, 10, 10 /), &
+	'zhalf', 'Altitude of half pressure levels', 'm', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rneb = ctrl_out((/ 2, 5, 10, 10, 10, 10 /), &
+	'rneb', 'Cloud fraction', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rnebcon = ctrl_out((/ 2, 5, 10, 10, 10, 10 /), &
+	'rnebcon', 'Convective Cloud Fraction', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rnebls = ctrl_out((/ 2, 5, 10, 10, 10, 10 /), &
+	'rnebls', 'LS Cloud fraction', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rhum = ctrl_out((/ 2, 5, 10, 10, 10, 10 /), &
+	'rhum', 'Relative humidity', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ozone = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'ozone', 'Ozone mole fraction', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ozone_light = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'ozone_daylight', 'Daylight ozone mole fraction', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_upwd = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'upwd', 'saturated updraft', 'kg/m2/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtphy = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'dtphy', 'Physics dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dqphy = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'dqphy', 'Physics dQ', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_pr_con_l = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'pr_con_l', 'Convective precipitation lic', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_pr_con_i = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'pr_con_i', 'Convective precipitation ice', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_pr_lsc_l = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'pr_lsc_l', 'Large scale precipitation lic', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_pr_lsc_i = ctrl_out((/ 2, 10, 10, 10, 10, 10 /), &
+	'pr_lsc_i', 'Large scale precipitation ice', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_re = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	're', 'Cloud droplet effective radius', 'um', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_fl = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'fl', 'Denominator of Cloud droplet effective radius', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_scdnc = ctrl_out((/ 2,  6, 10, 10, 10, 10 /), &
+	'scdnc', 'Cloud droplet number concentration', 'm-3', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_reffclws = ctrl_out((/ 2,  6, 10, 10, 10, 10 /), &
+	'reffclws', 'Stratiform Cloud Droplet Effective Radius (aerosol diags.)', 'm', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_reffclwc = ctrl_out((/ 2,  6, 10, 10, 10, 10 /), &
+	'reffclwc', 'Convective Cloud Droplet Effective Radius (aerosol diags.)', 'm', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_lcc3d = ctrl_out((/ 2,  6, 10, 10, 10, 10 /), &
+	'lcc3d', 'Cloud liquid fraction', '1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_lcc3dcon = ctrl_out((/ 2,  6, 10, 10, 10, 10 /), &
+	'lcc3dcon', 'Convective cloud liquid fraction', '1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_lcc3dstra = ctrl_out((/ 2,  6, 10, 10, 10, 10 /), &
+	'lcc3dstra', 'Stratiform cloud liquid fraction', '1', (/ ('', i=1, 6) /))
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_albe_srf     = (/ &
+      ctrl_out((/ 3, 7, 10, 7, 10, 10 /),'albe_ter', "Albedo VIS surf. "//clnsurf(1),"-", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 3, 7, 10, 7, 10, 10 /),'albe_lic', "Albedo VIS surf. "//clnsurf(2),"-", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 3, 7, 10, 7, 10, 10 /),'albe_oce', "Albedo VIS surf. "//clnsurf(3),"-", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 3, 7, 10, 7, 10, 10 /),'albe_sic', "Albedo VIS surf. "//clnsurf(4),"-", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_ages_srf     = (/ &
+      ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'ages_ter', "Snow age", "day", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 3, 10, 10, 10, 10, 10 /),'ages_lic', "Snow age", "day", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'ages_oce',"Snow age", "day", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 3, 10, 10, 10, 10, 10 /),'ages_sic',"Snow age", "day", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE, DIMENSION(4) :: o_rugs_srf     = (/ &
+      ctrl_out((/ 3, 6, 10, 10, 10, 10 /),'rugs_ter', "Surface roughness "//clnsurf(1),"m", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 3, 6, 10, 10, 10, 10 /),'rugs_lic', "Surface roughness "//clnsurf(2),"m", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 3, 6, 10, 10, 10, 10 /),'rugs_oce', "Surface roughness "//clnsurf(3),"m", (/ ('', i=1, 6) /)), &
+      ctrl_out((/ 3, 6, 10, 10, 10, 10 /),'rugs_sic', "Surface roughness "//clnsurf(4),"m", (/ ('', i=1, 6) /)) /)
+
+  TYPE(ctrl_out), SAVE :: o_alb1 = ctrl_out((/ 3, 10, 10, 10, 10, 10 /), &
+	'alb1', 'Surface VIS albedo', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_alb2 = ctrl_out((/ 3, 10, 10, 10, 10, 10 /), &
+	'alb2', 'Surface Near IR albedo', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_clwcon = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'clwcon', 'Convective Cloud Liquid water content', 'kg/kg', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_Ma = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'Ma', 'undilute adiab updraft', 'kg/m2/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dnwd = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dnwd', 'saturated downdraft', 'kg/m2/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dnwd0 = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dnwd0', 'unsat. downdraft', 'kg/m2/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_mc = ctrl_out((/ 4, 5, 10, 10, 10, 10 /), &
+	'mc', 'Convective mass flux', 'kg/m2/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ftime_con = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'ftime_con', 'Fraction of time convection Occurs', ' ',                 &
+      (/ 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)', 'inst(X)' /))
+  TYPE(ctrl_out), SAVE :: o_dtdyn = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtdyn', 'Dynamics dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dqdyn = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dqdyn', 'Dynamics dQ', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dudyn = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dudyn', 'Dynamics dU', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dvdyn = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dvdyn', 'Dynamics dV', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtcon = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtcon', 'Convection dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ducon = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'ducon', 'Convection du', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dvcon = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dvcon', 'Convection dv', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dqcon = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dqcon', 'Convection dQ', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtwak = ctrl_out((/ 4, 5, 10, 10, 10, 10 /), &
+	'dtwak', 'Wake dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dqwak = ctrl_out((/ 4, 5, 10, 10, 10, 10 /), &
+	'dqwak', 'Wake dQ', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wake_h = ctrl_out((/ 4, 5, 10, 10, 10, 10 /), &
+	'wake_h', 'wake_h', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wake_s = ctrl_out((/ 4, 5, 10, 10, 10, 10 /), &
+	'wake_s', 'wake_s', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wake_deltat = ctrl_out((/ 4, 5, 10, 10, 10, 10 /), &
+	'wake_deltat', 'wake_deltat', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wake_deltaq = ctrl_out((/ 4, 5, 10, 10, 10, 10 /), &
+	'wake_deltaq', 'wake_deltaq', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wake_omg = ctrl_out((/ 4, 5, 10, 10, 10, 10 /), &
+	'wake_omg', 'wake_omg', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wdtrainA = ctrl_out((/ 4, 1, 10,  4,  1, 10 /), &
+	'wdtrainA', 'precipitation from AA', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_wdtrainM = ctrl_out((/ 4, 1, 10,  4,  1, 10 /), &
+	'wdtrainM', 'precipitation from mixture', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_Vprecip = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'Vprecip', 'precipitation vertical profile', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ftd = ctrl_out((/ 4, 5, 10, 10, 10, 10 /), &
+	'ftd', 'tend temp due aux descentes precip', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_fqd = ctrl_out((/ 4, 5, 10, 10, 10, 10 /), &
+	'fqd', 'tend vap eau due aux descentes precip', '-', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtlsc = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtlsc', 'Condensation dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtlschr = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtlschr', 'Large-scale condensational heating rate', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dqlsc = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dqlsc', 'Condensation dQ', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_beta_prec = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'beta_prec', 'LS Conversion rate to prec', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtvdf = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtvdf', 'Boundary-layer dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtdis = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtdis', 'TKE dissipation dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dqvdf = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dqvdf', 'Boundary-layer dQ', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dteva = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dteva', 'Reevaporation dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dqeva = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dqeva', 'Reevaporation dQ', '(kg/kg)/s', (/ ('', i=1, 6) /))
+
+!!!!!!!!!!!!!!!! Specifique thermiques
+  TYPE(ctrl_out), SAVE :: o_dqlscth = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'dqlscth', 'dQ therm.', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dqlscst = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'dqlscst', 'dQ strat.', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtlscth = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'dtlscth', 'dQ therm.', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtlscst = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'dtlscst', 'dQ strat.', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_plulth = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'plulth', 'Rainfall therm.', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_plulst = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'plulst', 'Rainfall strat.', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_lmaxth = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'lmaxth', "Upper level thermals", "", (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ptconvth = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'ptconvth', 'POINTS CONVECTIFS therm.', ' ', (/ ('', i=1, 6) /))
+!!!!!!!!!!!!!!!!!!!!!!!!
+  TYPE(ctrl_out), SAVE :: o_ptconv = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'ptconv', 'POINTS CONVECTIFS', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ratqs = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'ratqs', 'RATQS', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtthe = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtthe', 'Thermal dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_f_th = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'f_th', 'Thermal plume mass flux', 'kg/(m2*s)', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_e_th = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'e_th', 'Thermal plume entrainment', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_w_th = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'w_th', 'Thermal plume vertical velocity', 'm/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_lambda_th = ctrl_out((/ 10, 10, 10, 10, 10, 10 /), &
+	'lambda_th', 'Thermal plume vertical velocity', 'm/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ftime_th = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'ftime_th', 'Fraction of time Shallow convection occurs', ' ', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_q_th = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'q_th', 'Thermal plume total humidity', 'kg/kg', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_a_th = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'a_th', "Thermal plume fraction", "", (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_d_th = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'd_th', 'Thermal plume detrainment', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_f0_th = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'f0_th', 'Thermal closure mass flux', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_zmax_th = ctrl_out((/ 4,  4,  4,  5, 10, 10 /), &
+	'zmax_th', 'Thermal plume height', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dqthe = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dqthe', 'Thermal dQ', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtajs = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtajs', 'Dry adjust. dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dqajs = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dqajs', 'Dry adjust. dQ', '(kg/kg)/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtswr = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtswr', 'SW radiation dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtsw0 = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtsw0', 'CS SW radiation dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtlwr = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtlwr', 'LW radiation dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtlw0 = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtlw0', 'CS LW radiation dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtec = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtec', 'Cinetic dissip dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_duvdf = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'duvdf', 'Boundary-layer dU', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dvvdf = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dvvdf', 'Boundary-layer dV', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_duoro = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'duoro', 'Orography dU', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dvoro = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dvoro', 'Orography dV', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dulif = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dulif', 'Orography dU', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dvlif = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dvlif', 'Orography dV', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_duhin = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'duhin', 'Hines GWD dU', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dvhin = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dvhin', 'Hines GWD dV', 'm/s2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtoro = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtoro', 'Orography dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dtlif = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dtlif', 'Orography dT', 'K/s', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dthin = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dthin', 'Hines GWD dT', 'K/s', (/ ('', i=1, 6) /))
+
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_trac(:)
+  TYPE(ctrl_out), SAVE, ALLOCATABLE :: o_trac_cum(:)
+  TYPE(ctrl_out), SAVE :: o_rsu = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'rsu', 'SW upward radiation', 'W m-2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rsd = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'rsd', 'SW downward radiation', 'W m-2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rlu = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'rlu', 'LW upward radiation', 'W m-2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rld = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'rld', 'LW downward radiation', 'W m-2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rsucs = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'rsucs', 'SW CS upward radiation', 'W m-2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rsdcs = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'rsdcs', 'SW CS downward radiation', 'W m-2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rlucs = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'rlucs', 'LW CS upward radiation', 'W m-2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rldcs = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'rldcs', 'LW CS downward radiation', 'W m-2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tnt = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'tnt', 'Tendency of air temperature', 'K s-1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tntc = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'tntc', 'Tendency of air temperature due to Moist Convection', 'K s-1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tntr = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'tntr', 'Air temperature tendency due to Radiative heating', 'K s-1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tntscpbl = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),                  &
+	'tntscpbl', 'Air temperature tendency due to St cloud and precipitation and BL mixing', &
+      'K s-1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tnhus = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'tnhus', 'Tendency of specific humidity', 's-1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tnhusc = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'tnhusc', 'Tendency of specific humidity due to convection', 's-1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_tnhusscpbl = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'tnhusscpbl', 'Tendency of Specific humidity due to ST cl, precip and BL mixing', 's-1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_evu = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'evu', 'Eddy viscosity coefficient for Momentum Variables', 'm2 s-1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_h2o = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'h2o', 'Mass Fraction of Water', '1', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_mcd = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'mcd', 'Downdraft COnvective Mass Flux', 'kg/(m2*s)', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_dmc = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'dmc', 'Deep COnvective Mass Flux', 'kg/(m2*s)', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ref_liq = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'ref_liq', 'Effective radius of convective cloud liquid water particle', 'm', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_ref_ice = ctrl_out((/ 4, 10, 10, 10, 10, 10 /), &
+	'ref_ice', 'Effective radius of startiform cloud ice particle', 'm', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rsut4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rsut4co2', 'TOA Out SW in 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rlut4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rlut4co2', 'TOA Out LW in 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rsutcs4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rsutcs4co2', 'TOA Out CS SW in 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rlutcs4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rlutcs4co2', 'TOA Out CS LW in 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rsu4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rsu4co2', 'Upwelling SW 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rlu4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rlu4co2', 'Upwelling LW 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rsucs4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rsucs4co2', 'Upwelling CS SW 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rlucs4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rlucs4co2', 'Upwelling CS LW 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rsd4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rsd4co2', 'Downwelling SW 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rld4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rld4co2', 'Downwelling LW 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rsdcs4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rsdcs4co2', 'Downwelling CS SW 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+  TYPE(ctrl_out), SAVE :: o_rldcs4co2 = ctrl_out((/ 5, 10, 10, 10, 10, 10 /), &
+	'rldcs4co2', 'Downwelling CS LW 4xCO2 atmosphere', 'W/m2', (/ ('', i=1, 6) /))
+
+END MODULE phys_output_ctrlout_mod
Index: LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/phys_output_mod.F90	(revision 1795)
@@ -11,634 +11,16 @@
 
 MODULE phys_output_mod 
+  USE indice_sol_mod
+  USE phys_output_var_mod
+  USE phys_output_ctrlout_mod
+  USE aero_mod, only : naero_spc,name_aero
 
   IMPLICIT NONE
 
-  private histdef2d, histdef3d, conf_physoutputs
-
-
-  integer, parameter                           :: nfiles = 6
-  logical, dimension(nfiles), save             :: clef_files
-  logical, dimension(nfiles), save             :: clef_stations
-  integer, dimension(nfiles), save             :: lev_files
-  integer, dimension(nfiles), save             :: nid_files
-  integer, dimension(nfiles), save  :: nnid_files
-!!$OMP THREADPRIVATE(clef_files, clef_stations, lev_files,nid_files,nnid_files)
-  integer, dimension(nfiles), private, save :: nnhorim
-
-  integer, dimension(nfiles), private, save :: nhorim, nvertm
-  integer, dimension(nfiles), private, save :: nvertap, nvertbp, nvertAlt
-  !   integer, dimension(nfiles), private, save :: nvertp0
-  real, dimension(nfiles), private, save                :: zoutm
-  real,                    private, save                :: zdtime
-  CHARACTER(len=20), dimension(nfiles), private, save   :: type_ecri
-  !$OMP THREADPRIVATE(nhorim, nvertm, zoutm,zdtime,type_ecri)
- ! swaero_diag : flag indicates if it is necessary to do calculation for some aerosol diagnostics
-  logical, save                                :: swaero_diag=.FALSE.
-
-
-  !   integer, save                     :: nid_hf3d 
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-  !! Definition pour chaque variable du niveau d ecriture dans chaque fichier
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/ histmth, histday, histhf, histins /),'!!!!!!!!!!!!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  integer, private:: levmin(nfiles) = 1
-  integer, private:: levmax(nfiles)
-
-  TYPE ctrl_out
-     integer,dimension(6) :: flag
-     character(len=20)     :: name
-  END TYPE ctrl_out
-
-!!! Comosentes de la coordonnee sigma-hybride
-!!! Ap et Bp
-  type(ctrl_out),save :: o_Ahyb         = ctrl_out((/ 1, 1, 1, 1, 1, 1 /), 'Ap')
-  type(ctrl_out),save :: o_Bhyb         = ctrl_out((/ 1, 1, 1, 1, 1, 1 /), 'Bp')
-  type(ctrl_out),save :: o_Alt          = ctrl_out((/ 1, 1, 1, 1, 1, 1 /), 'Alt')
-
-!!! 1D
-  type(ctrl_out),save :: o_phis         = ctrl_out((/ 1, 1, 10, 5, 1, 1 /), 'phis') 
-  type(ctrl_out),save :: o_aire         = ctrl_out((/ 1, 1, 10,  10, 1, 1 /),'aire')
-  type(ctrl_out),save :: o_contfracATM  = ctrl_out((/ 10, 1,  1, 10, 10, 10 /),'contfracATM')
-  type(ctrl_out),save :: o_contfracOR   = ctrl_out((/ 10, 1,  1, 10, 10, 10 /),'contfracOR')
-  type(ctrl_out),save :: o_aireTER      = ctrl_out((/ 10, 10, 1, 10, 10, 10 /),'aireTER')
-
-!!! 2D
-  type(ctrl_out),save :: o_flat         = ctrl_out((/ 5, 1, 10, 10, 5, 10 /),'flat')
-  type(ctrl_out),save :: o_slp          = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'slp')
-  type(ctrl_out),save :: o_tsol         = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'tsol')
-  type(ctrl_out),save :: o_t2m          = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'t2m')
-  type(ctrl_out),save :: o_t2m_min      = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'t2m_min')
-  type(ctrl_out),save :: o_t2m_max      = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'t2m_max')
-  type(ctrl_out),save,dimension(4) :: o_t2m_srf      = (/ ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'t2m_ter'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'t2m_lic'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'t2m_oce'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'t2m_sic') /)
-
-  type(ctrl_out),save :: o_wind10m      = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'wind10m')
-  type(ctrl_out),save :: o_wind10max    = ctrl_out((/ 10, 1, 10, 10, 10, 10 /),'wind10max')
-  type(ctrl_out),save :: o_sicf         = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'sicf')
-  type(ctrl_out),save :: o_q2m          = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'q2m')
-  type(ctrl_out),save :: o_ustar        = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'ustar')
-  type(ctrl_out),save :: o_u10m         = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'u10m')
-  type(ctrl_out),save :: o_v10m         = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'v10m')
-  type(ctrl_out),save :: o_psol         = ctrl_out((/ 1, 1, 1, 5, 10, 10 /),'psol')
-  type(ctrl_out),save :: o_qsurf        = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'qsurf')
-
-  type(ctrl_out),save,dimension(4) :: o_ustar_srf     = (/ ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_ter'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_lic'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_oce'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'ustar_sic') /)
-  type(ctrl_out),save,dimension(4) :: o_u10m_srf     = (/ ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'u10m_ter'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'u10m_lic'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'u10m_oce'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'u10m_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_v10m_srf     = (/ ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'v10m_ter'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'v10m_lic'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'v10m_oce'), &
-       ctrl_out((/ 10, 6, 10, 10, 10, 10 /),'v10m_sic') /)
-
-  type(ctrl_out),save :: o_qsol         = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'qsol')
-
-  type(ctrl_out),save :: o_ndayrain     = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'ndayrain')
-  type(ctrl_out),save :: o_precip       = ctrl_out((/ 1, 1, 1, 10, 5, 10 /),'precip')
-  type(ctrl_out),save :: o_plul         = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'plul')
-
-  type(ctrl_out),save :: o_pluc         = ctrl_out((/ 1, 1, 1, 10, 5, 10 /),'pluc')
-  type(ctrl_out),save :: o_snow         = ctrl_out((/ 1, 1, 10, 10, 5, 10 /),'snow') 
-  type(ctrl_out),save :: o_evap         = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'evap')
-  type(ctrl_out),save,dimension(4) :: o_evap_srf     = (/ ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'evap_ter'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'evap_lic'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'evap_oce'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'evap_sic') /)
-  type(ctrl_out),save :: o_msnow       = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'msnow')
-  type(ctrl_out),save :: o_fsnow       = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fsnow')
-
-  type(ctrl_out),save :: o_tops         = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'tops')
-  type(ctrl_out),save :: o_tops0        = ctrl_out((/ 1, 5, 10, 10, 10, 10 /),'tops0')
-  type(ctrl_out),save :: o_topl         = ctrl_out((/ 1, 1, 10, 5, 10, 10 /),'topl')
-  type(ctrl_out),save :: o_topl0        = ctrl_out((/ 1, 5, 10, 10, 10, 10 /),'topl0')
-  type(ctrl_out),save :: o_SWupTOA      = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'SWupTOA')
-  type(ctrl_out),save :: o_SWupTOAclr   = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'SWupTOAclr')
-  type(ctrl_out),save :: o_SWdnTOA      = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'SWdnTOA')
-  type(ctrl_out),save :: o_SWdnTOAclr   = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'SWdnTOAclr')
-  type(ctrl_out),save :: o_nettop       = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'nettop')
-
-  type(ctrl_out),save :: o_SWup200      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'SWup200')
-  type(ctrl_out),save :: o_SWup200clr   = ctrl_out((/ 10, 1, 10, 10, 10, 10 /),'SWup200clr')
-  type(ctrl_out),save :: o_SWdn200      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'SWdn200')
-  type(ctrl_out),save :: o_SWdn200clr   = ctrl_out((/ 10, 1, 10, 10, 10, 10 /),'SWdn200clr')
-
-  ! arajouter
-  !  type(ctrl_out),save :: o_LWupTOA     = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'LWupTOA')
-  !  type(ctrl_out),save :: o_LWupTOAclr  = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'LWupTOAclr')
-  !  type(ctrl_out),save :: o_LWdnTOA     = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'LWdnTOA')
-  !  type(ctrl_out),save :: o_LWdnTOAclr  = ctrl_out((/ 1, 4, 10, 10, 10, 10 /),'LWdnTOAclr')
-
-  type(ctrl_out),save :: o_LWup200      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'LWup200')
-  type(ctrl_out),save :: o_LWup200clr   = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'LWup200clr')
-  type(ctrl_out),save :: o_LWdn200      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'LWdn200')
-  type(ctrl_out),save :: o_LWdn200clr   = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'LWdn200clr')
-  type(ctrl_out),save :: o_sols         = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'sols')
-  type(ctrl_out),save :: o_sols0        = ctrl_out((/ 1, 5, 10, 10, 10, 10 /),'sols0')
-  type(ctrl_out),save :: o_soll         = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'soll')
-  type(ctrl_out),save :: o_soll0        = ctrl_out((/ 1, 5, 10, 10, 10, 10 /),'soll0')
-  type(ctrl_out),save :: o_radsol       = ctrl_out((/ 1, 7, 10, 10, 10, 10 /),'radsol')
-  type(ctrl_out),save :: o_SWupSFC      = ctrl_out((/ 1, 4, 10, 10, 5, 10 /),'SWupSFC')
-  type(ctrl_out),save :: o_SWupSFCclr   = ctrl_out((/ 1, 4, 10, 10, 5, 10 /),'SWupSFCclr')
-  type(ctrl_out),save :: o_SWdnSFC      = ctrl_out((/ 1, 1, 10, 10, 5, 10 /),'SWdnSFC') 
-  type(ctrl_out),save :: o_SWdnSFCclr   = ctrl_out((/ 1, 4, 10, 10, 5, 10 /),'SWdnSFCclr')
-  type(ctrl_out),save :: o_LWupSFC      = ctrl_out((/ 1, 4, 10, 10, 5, 10 /),'LWupSFC')
-  type(ctrl_out),save :: o_LWupSFCclr   = ctrl_out((/ 1, 4, 10, 10, 5, 10 /),'LWupSFCclr')
-  type(ctrl_out),save :: o_LWdnSFC      = ctrl_out((/ 1, 4, 10, 10, 5, 10 /),'LWdnSFC')
-  type(ctrl_out),save :: o_LWdnSFCclr   = ctrl_out((/ 1, 4, 10, 10, 5, 10 /),'LWdnSFCclr')
-  type(ctrl_out),save :: o_bils         = ctrl_out((/ 1, 2, 10, 5, 10, 10 /),'bils')
-  type(ctrl_out),save :: o_sens         = ctrl_out((/ 1, 1, 10, 10, 5, 10 /),'sens')
-  type(ctrl_out),save :: o_fder         = ctrl_out((/ 1, 2, 10, 10, 10, 10 /),'fder')
-  type(ctrl_out),save :: o_ffonte       = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'ffonte')
-  type(ctrl_out),save :: o_fqcalving    = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fqcalving')
-  type(ctrl_out),save :: o_fqfonte      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fqfonte')
-
-  type(ctrl_out),save :: o_taux         = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'taux')
-  type(ctrl_out),save :: o_tauy         = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'tauy')
-  type(ctrl_out),save,dimension(4) :: o_taux_srf     = (/ ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'taux_ter'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'taux_lic'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'taux_oce'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'taux_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_tauy_srf     = (/ ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tauy_ter'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tauy_lic'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tauy_oce'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tauy_sic') /)
-
-
-  type(ctrl_out),save,dimension(4) :: o_pourc_srf    = (/ ctrl_out((/ 1, 7, 10, 10, 10, 10 /),'pourc_ter'), &
-       ctrl_out((/ 1, 7, 10, 10, 10, 10 /),'pourc_lic'), &
-       ctrl_out((/ 1, 7, 10, 10, 10, 10 /),'pourc_oce'), &
-       ctrl_out((/ 1, 7, 10, 10, 10, 10 /),'pourc_sic') /)     
-
-  type(ctrl_out),save,dimension(4) :: o_fract_srf    = (/ ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'fract_ter'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'fract_lic'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'fract_oce'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'fract_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_tsol_srf     = (/ ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tsol_ter'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tsol_lic'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tsol_oce'), &
-       ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'tsol_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_evappot_srf  = (/ ctrl_out((/ 1, 6, 10, 10, 10, 10 /),'evappot_ter'), &
-       ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'evappot_lic'), &
-       ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'evappot_oce'), &
-       ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'evappot_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_sens_srf     = (/ ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'sens_ter'), &
-       ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'sens_lic'), &
-       ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'sens_oce'), &
-       ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'sens_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_lat_srf      = (/ ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'lat_ter'), &
-       ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'lat_lic'), &
-       ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'lat_oce'), &
-       ctrl_out((/ 1, 6, 10, 7, 10, 10 /),'lat_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_flw_srf      = (/ ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'flw_ter'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'flw_lic'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'flw_oce'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'flw_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_fsw_srf      = (/ ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fsw_ter'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fsw_lic'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fsw_oce'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fsw_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_wbils_srf    = (/ ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbils_ter'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbils_lic'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbils_oce'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbils_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_wbilo_srf    = (/ ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbilo_ter'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbilo_lic'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbilo_oce'), &
-       ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbilo_sic') /)
-
-
-  type(ctrl_out),save :: o_cdrm         = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'cdrm')
-  type(ctrl_out),save :: o_cdrh         = ctrl_out((/ 1, 10, 10, 7, 10, 10 /),'cdrh')
-  type(ctrl_out),save :: o_cldl         = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'cldl')
-  type(ctrl_out),save :: o_cldm         = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'cldm')
-  type(ctrl_out),save :: o_cldh         = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'cldh')
-  type(ctrl_out),save :: o_cldt         = ctrl_out((/ 1, 1, 2, 10, 5, 10 /),'cldt')
-  type(ctrl_out),save :: o_cldq         = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'cldq')
-  type(ctrl_out),save :: o_lwp          = ctrl_out((/ 1, 5, 10, 10, 10, 10 /),'lwp')
-  type(ctrl_out),save :: o_iwp          = ctrl_out((/ 1, 5, 10, 10, 10, 10 /),'iwp')
-  type(ctrl_out),save :: o_ue           = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'ue')
-  type(ctrl_out),save :: o_ve           = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'ve')
-  type(ctrl_out),save :: o_uq           = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'uq')
-  type(ctrl_out),save :: o_vq           = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'vq')
-
-  type(ctrl_out),save :: o_cape         = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'cape')
-  type(ctrl_out),save :: o_pbase        = ctrl_out((/ 1, 5, 10, 10, 10, 10 /),'pbase')
-  type(ctrl_out),save :: o_ptop         = ctrl_out((/ 1, 5, 10, 10, 10, 10 /),'ptop')
-  type(ctrl_out),save :: o_fbase        = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'fbase')
-  type(ctrl_out),save :: o_plcl        = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'plcl')
-  type(ctrl_out),save :: o_plfc        = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'plfc')
-  type(ctrl_out),save :: o_wbeff        = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'wbeff')
-  type(ctrl_out),save :: o_prw          = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'prw')
-
-  type(ctrl_out),save :: o_s_pblh       = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_pblh')
-  type(ctrl_out),save :: o_s_pblt       = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_pblt')
-  type(ctrl_out),save :: o_s_lcl        = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_lcl')
-  type(ctrl_out),save :: o_s_therm      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_therm')
-  !IM : Les champs suivants (s_capCL, s_oliqCL, s_cteiCL, s_trmb1, s_trmb2, s_trmb3) ne sont pas definis dans HBTM.F
-  ! type(ctrl_out),save :: o_s_capCL      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_capCL')
-  ! type(ctrl_out),save :: o_s_oliqCL     = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_oliqCL')
-  ! type(ctrl_out),save :: o_s_cteiCL     = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_cteiCL')
-  ! type(ctrl_out),save :: o_s_trmb1      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_trmb1')
-  ! type(ctrl_out),save :: o_s_trmb2      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_trmb2')
-  ! type(ctrl_out),save :: o_s_trmb3      = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'s_trmb3')
-
-  type(ctrl_out),save :: o_slab_bils    = ctrl_out((/ 1, 1, 10, 10, 10, 10 /),'slab_bils_oce')
-
-  type(ctrl_out),save :: o_ale_bl       = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'ale_bl')
-  type(ctrl_out),save :: o_alp_bl       = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'alp_bl')
-  type(ctrl_out),save :: o_ale_wk       = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'ale_wk')
-  type(ctrl_out),save :: o_alp_wk       = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'alp_wk')
-
-  type(ctrl_out),save :: o_ale          = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'ale')
-  type(ctrl_out),save :: o_alp          = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'alp')
-  type(ctrl_out),save :: o_cin          = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'cin')
-  type(ctrl_out),save :: o_wape         = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'wape')
-
-!!! nrlmd le 10/04/2012
-
-!-------Spectre de thermiques de type 2 au LCL
-  type(ctrl_out),save :: o_n2                = ctrl_out((/ 1, 1, 1, 6, 10, 10 /),'n2')
-  type(ctrl_out),save :: o_s2                = ctrl_out((/ 1, 1, 1, 6, 10, 10 /),'s2')
-                                                                             
-!-------Déclenchement stochastique                                           
-  type(ctrl_out),save :: o_proba_notrig      = ctrl_out((/ 1, 1, 1, 6, 10, 10 /),'proba_notrig')
-  type(ctrl_out),save :: o_random_notrig     = ctrl_out((/ 1, 1, 1, 6, 10, 10 /),'random_notrig')
-  type(ctrl_out),save :: o_ale_bl_stat       = ctrl_out((/ 1, 1, 1, 6, 10, 10 /),'ale_bl_stat')
-  type(ctrl_out),save :: o_ale_bl_trig       = ctrl_out((/ 1, 1, 1, 6, 10, 10 /),'ale_bl_trig')
-
-!-------Fermeture statistique
-  type(ctrl_out),save :: o_alp_bl_det        = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'alp_bl_det')
-  type(ctrl_out),save :: o_alp_bl_fluct_m    = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'alp_bl_fluct_m')
-  type(ctrl_out),save :: o_alp_bl_fluct_tke  = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'alp_bl_fluct_tke')
-  type(ctrl_out),save :: o_alp_bl_conv       = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'alp_bl_conv')
-  type(ctrl_out),save :: o_alp_bl_stat       = ctrl_out((/ 1, 1, 1, 10, 10, 10 /),'alp_bl_stat')
-
-!!! fin nrlmd le 10/04/2012
-
-  ! Champs interpolles sur des niveaux de pression ??? a faire correctement
-
-  type(ctrl_out),save,dimension(7) :: o_uSTDlevs     = (/ ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u850'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u700'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u500'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u200'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u100'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u50'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'u10') /) 
-
-
-  type(ctrl_out),save,dimension(7) :: o_vSTDlevs     = (/ ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v850'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v700'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v500'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v200'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v100'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v50'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'v10') /)
-
-  type(ctrl_out),save,dimension(7) :: o_wSTDlevs     = (/ ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w850'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w700'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w500'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w200'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w100'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w50'), & 
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'w10') /)
-
-  type(ctrl_out),save,dimension(7) :: o_tSTDlevs     = (/ ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t850'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t700'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t500'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t200'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t100'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t50'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'t10') /)
-
-  type(ctrl_out),save,dimension(7) :: o_qSTDlevs     = (/ ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q850'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q700'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q500'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q200'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q100'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q50'), & 
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'q10') /)
-
-  type(ctrl_out),save,dimension(7) :: o_zSTDlevs   = (/ ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z850'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z700'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z500'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z200'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z100'), &
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z50'), & 
-       ctrl_out((/ 1, 7, 7, 10, 10, 10 /),'z10') /)
-
-
-  type(ctrl_out),save :: o_t_oce_sic    = ctrl_out((/ 1, 10, 10, 10, 10, 10 /),'t_oce_sic')
-
-  type(ctrl_out),save :: o_weakinv      = ctrl_out((/ 10, 1, 10, 10, 10, 10 /),'weakinv')
-  type(ctrl_out),save :: o_dthmin       = ctrl_out((/ 10, 1, 10, 10, 10, 10 /),'dthmin')
-  type(ctrl_out),save,dimension(4) :: o_u10_srf      = (/ ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'u10_ter'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'u10_lic'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'u10_oce'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'u10_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_v10_srf      = (/ ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'v10_ter'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'v10_lic'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'v10_oce'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'v10_sic') /)
-
-  type(ctrl_out),save :: o_cldtau       = ctrl_out((/ 10, 5, 10, 10, 10, 10 /),'cldtau')                     
-  type(ctrl_out),save :: o_cldemi       = ctrl_out((/ 10, 5, 10, 10, 10, 10 /),'cldemi')
-  type(ctrl_out),save :: o_rh2m         = ctrl_out((/ 5, 5, 10, 10, 10, 10 /),'rh2m')
-  type(ctrl_out),save :: o_rh2m_min     = ctrl_out((/ 10, 5, 10, 10, 10, 10 /),'rh2m_min')
-  type(ctrl_out),save :: o_rh2m_max     = ctrl_out((/ 10, 5, 10, 10, 10, 10 /),'rh2m_max')
-  type(ctrl_out),save :: o_qsat2m       = ctrl_out((/ 10, 5, 10, 10, 10, 10 /),'qsat2m')
-  type(ctrl_out),save :: o_tpot         = ctrl_out((/ 10, 5, 10, 10, 10, 10 /),'tpot')
-  type(ctrl_out),save :: o_tpote        = ctrl_out((/ 10, 5, 10, 10, 10, 10 /),'tpote')
-  type(ctrl_out),save :: o_tke          = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'tke ')
-  type(ctrl_out),save :: o_tke_max      = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'tke_max')
-
-  type(ctrl_out),save,dimension(4) :: o_tke_srf      = (/ ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_ter'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_lic'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_oce'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_tke_max_srf  = (/ ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_max_ter'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_max_lic'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_max_oce'), &
-       ctrl_out((/ 10, 4, 10, 10, 10, 10 /),'tke_max_sic') /)
-
-  type(ctrl_out),save :: o_kz           = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'kz')
-  type(ctrl_out),save :: o_kz_max       = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'kz_max')
-  type(ctrl_out),save :: o_SWnetOR      = ctrl_out((/ 10, 10, 2, 10, 10, 10 /),'SWnetOR')
-  type(ctrl_out),save :: o_SWdownOR     = ctrl_out((/ 10, 10, 2, 10, 10, 10 /),'SWdownOR')
-  type(ctrl_out),save :: o_LWdownOR     = ctrl_out((/ 10, 10, 2, 10, 10, 10 /),'LWdownOR')
-
-  type(ctrl_out),save :: o_snowl        = ctrl_out((/ 10, 1, 10, 10, 10, 10 /),'snowl')
-  type(ctrl_out),save :: o_cape_max     = ctrl_out((/ 10, 1, 10, 10, 10, 10 /),'cape_max')
-  type(ctrl_out),save :: o_solldown     = ctrl_out((/ 10, 1, 10, 10, 10, 10 /),'solldown')
-
-  type(ctrl_out),save :: o_dtsvdfo      = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'dtsvdfo')
-  type(ctrl_out),save :: o_dtsvdft      = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'dtsvdft')
-  type(ctrl_out),save :: o_dtsvdfg      = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'dtsvdfg')
-  type(ctrl_out),save :: o_dtsvdfi      = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'dtsvdfi')
-  type(ctrl_out),save :: o_rugs         = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'rugs')
-
-  type(ctrl_out),save :: o_topswad      = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'topswad')
-  type(ctrl_out),save :: o_topswad0     = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'topswad0')
-  type(ctrl_out),save :: o_topswai      = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'topswai')
-  type(ctrl_out),save :: o_solswad      = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'solswad')
-  type(ctrl_out),save :: o_solswad0     = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'solswad0')
-  type(ctrl_out),save :: o_solswai      = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'solswai')
-
-  type(ctrl_out),save,dimension(10) :: o_tausumaero  = (/ ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_ASBCM'), &
-       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_ASPOMM'), &
-       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_ASSO4M'), &
-       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_CSSO4M'), &
-       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_SSSSM'), &
-       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_ASSSM'), &
-       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_CSSSM'), &
-       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_CIDUSTM'), &
-       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_AIBCM'), &
-       ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'OD550_AIPOMM') /)
-
-  type(ctrl_out),save :: o_od550aer     = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'od550aer')
-  type(ctrl_out),save :: o_od865aer     = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'od865aer')
-  type(ctrl_out),save :: o_absvisaer    = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'absvisaer')
-  type(ctrl_out),save :: o_od550lt1aer  = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'od550lt1aer')
-
-  type(ctrl_out),save :: o_sconcso4     = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'sconcso4')
-  type(ctrl_out),save :: o_sconcoa      = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'sconcoa')
-  type(ctrl_out),save :: o_sconcbc      = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'sconcbc')
-  type(ctrl_out),save :: o_sconcss      = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'sconcss')
-  type(ctrl_out),save :: o_sconcdust    = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'sconcdust')
-  type(ctrl_out),save :: o_concso4      = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'concso4')
-  type(ctrl_out),save :: o_concoa       = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'concoa')
-  type(ctrl_out),save :: o_concbc       = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'concbc')
-  type(ctrl_out),save :: o_concss       = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'concss')
-  type(ctrl_out),save :: o_concdust     = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'concdust')
-  type(ctrl_out),save :: o_loadso4      = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'loadso4')
-  type(ctrl_out),save :: o_loadoa       = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'loadoa')
-  type(ctrl_out),save :: o_loadbc       = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'loadbc')
-  type(ctrl_out),save :: o_loadss       = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'loadss')
-  type(ctrl_out),save :: o_loaddust     = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'loaddust')
-
-  type(ctrl_out),save :: o_swtoaas_nat  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swtoaas_nat')
-  type(ctrl_out),save :: o_swsrfas_nat  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swsrfas_nat')
-  type(ctrl_out),save :: o_swtoacs_nat  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swtoacs_nat')
-  type(ctrl_out),save :: o_swsrfcs_nat  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swsrfcs_nat')
-
-  type(ctrl_out),save :: o_swtoaas_ant  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swtoaas_ant')
-  type(ctrl_out),save :: o_swsrfas_ant  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swsrfas_ant')
-  type(ctrl_out),save :: o_swtoacs_ant  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swtoacs_ant')
-  type(ctrl_out),save :: o_swsrfcs_ant  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swsrfcs_ant')
-
-  type(ctrl_out),save :: o_swtoacf_nat  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swtoacf_nat')
-  type(ctrl_out),save :: o_swsrfcf_nat  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swsrfcf_nat')
-  type(ctrl_out),save :: o_swtoacf_ant  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swtoacf_ant')
-  type(ctrl_out),save :: o_swsrfcf_ant  = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swsrfcf_ant')
-  type(ctrl_out),save :: o_swtoacf_zero = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swtoacf_zero')
-  type(ctrl_out),save :: o_swsrfcf_zero = ctrl_out((/ 4, 6, 10, 10, 10, 10 /),'swsrfcf_zero')
-
-  type(ctrl_out),save :: o_cldncl       = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'cldncl')
-  type(ctrl_out),save :: o_reffclwtop   = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'reffclwtop')
-  type(ctrl_out),save :: o_cldnvi       = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'cldnvi')
-  type(ctrl_out),save :: o_lcc          = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'lcc')
-
-
-!!!!!!!!!!!!!!!!!!!!!! 3D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
-  type(ctrl_out),save :: o_ec550aer     = ctrl_out((/ 2, 6, 10, 10, 10, 10 /),'ec550aer')
-  type(ctrl_out),save :: o_lwcon        = ctrl_out((/ 2, 5, 10, 10, 10, 10 /),'lwcon')
-  type(ctrl_out),save :: o_iwcon        = ctrl_out((/ 2, 5, 10, 10, 10, 10 /),'iwcon')
-  type(ctrl_out),save :: o_temp         = ctrl_out((/ 2, 3, 4, 10, 10, 10 /),'temp')
-  type(ctrl_out),save :: o_theta        = ctrl_out((/ 2, 3, 4, 10, 10, 10 /),'theta')
-  type(ctrl_out),save :: o_ovap         = ctrl_out((/ 2, 3, 4, 10, 10, 10 /),'ovap')
-  type(ctrl_out),save :: o_ovapinit     = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'ovapinit')
-  type(ctrl_out),save :: o_oliq         = ctrl_out((/ 2, 3, 4, 10, 10, 10 /),'oliq')
-  type(ctrl_out),save :: o_wvapp        = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'wvapp')
-  type(ctrl_out),save :: o_geop         = ctrl_out((/ 2, 3, 10, 10, 10, 10 /),'geop')
-  type(ctrl_out),save :: o_vitu         = ctrl_out((/ 2, 3, 4, 6, 10, 10 /),'vitu')
-  type(ctrl_out),save :: o_vitv         = ctrl_out((/ 2, 3, 4, 6, 10, 10 /),'vitv')
-  type(ctrl_out),save :: o_vitw         = ctrl_out((/ 2, 3, 10, 6, 10, 10 /),'vitw')
-  type(ctrl_out),save :: o_pres         = ctrl_out((/ 2, 3, 10, 10, 10, 10 /),'pres')
-  type(ctrl_out),save :: o_paprs        = ctrl_out((/ 2, 3, 10, 10, 10, 10 /),'paprs')
-  type(ctrl_out),save :: o_mass        = ctrl_out((/ 2, 3, 10, 10, 10, 10 /),'mass')
-  type(ctrl_out),save :: o_zfull       = ctrl_out((/ 2, 3, 10, 10, 10, 10 /),'zfull')
-  type(ctrl_out),save :: o_zhalf       = ctrl_out((/ 2, 3, 10, 10, 10, 10 /),'zhalf')
-  type(ctrl_out),save :: o_rneb         = ctrl_out((/ 2, 5, 10, 10, 10, 10 /),'rneb')
-  type(ctrl_out),save :: o_rnebcon      = ctrl_out((/ 2, 5, 10, 10, 10, 10 /),'rnebcon')
-  type(ctrl_out),save :: o_rnebls       = ctrl_out((/ 2, 5, 10, 10, 10, 10 /),'rnebls')
-  type(ctrl_out),save :: o_rhum         = ctrl_out((/ 2, 5, 10, 10, 10, 10 /),'rhum')
-  type(ctrl_out),save :: o_ozone        = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'ozone')
-  type(ctrl_out),save :: o_ozone_light  = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'ozone_daylight')
-  type(ctrl_out),save :: o_upwd         = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'upwd')
-  type(ctrl_out),save :: o_dtphy        = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'dtphy')
-  type(ctrl_out),save :: o_dqphy        = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'dqphy')
-  type(ctrl_out),save :: o_pr_con_l     = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'pr_con_l')
-  type(ctrl_out),save :: o_pr_con_i     = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'pr_con_i')
-  type(ctrl_out),save :: o_pr_lsc_l     = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'pr_lsc_l')
-  type(ctrl_out),save :: o_pr_lsc_i     = ctrl_out((/ 2, 10, 10, 10, 10, 10 /),'pr_lsc_i')
-  type(ctrl_out),save :: o_re           = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'re')
-  type(ctrl_out),save :: o_fl           = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'fl')
-  type(ctrl_out),save :: o_scdnc        = ctrl_out((/ 2,  6, 10, 10, 10, 10 /),'scdnc')
-  type(ctrl_out),save :: o_reffclws     = ctrl_out((/ 2,  6, 10, 10, 10, 10 /),'reffclws')
-  type(ctrl_out),save :: o_reffclwc     = ctrl_out((/ 2,  6, 10, 10, 10, 10 /),'reffclwc')
-  type(ctrl_out),save :: o_lcc3d        = ctrl_out((/ 2,  6, 10, 10, 10, 10 /),'lcc3d')
-  type(ctrl_out),save :: o_lcc3dcon     = ctrl_out((/ 2,  6, 10, 10, 10, 10 /),'lcc3dcon')
-  type(ctrl_out),save :: o_lcc3dstra    = ctrl_out((/ 2,  6, 10, 10, 10, 10 /),'lcc3dstra')
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  type(ctrl_out),save,dimension(4) :: o_albe_srf     = (/ ctrl_out((/ 3, 7, 10, 7, 10, 10 /),'albe_ter'), &
-       ctrl_out((/ 3, 7, 10, 7, 10, 10 /),'albe_lic'), &
-       ctrl_out((/ 3, 7, 10, 7, 10, 10 /),'albe_oce'), &
-       ctrl_out((/ 3, 7, 10, 7, 10, 10 /),'albe_sic') /) 
-
-  type(ctrl_out),save,dimension(4) :: o_ages_srf     = (/ ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'ages_ter'), &
-       ctrl_out((/ 3, 10, 10, 10, 10, 10 /),'ages_lic'), &
-       ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'ages_oce'), &
-       ctrl_out((/ 3, 10, 10, 10, 10, 10 /),'ages_sic') /)
-
-  type(ctrl_out),save,dimension(4) :: o_rugs_srf     = (/ ctrl_out((/ 3, 6, 10, 10, 10, 10 /),'rugs_ter'), &
-       ctrl_out((/ 3, 6, 10, 10, 10, 10 /),'rugs_lic'), &
-       ctrl_out((/ 3, 6, 10, 10, 10, 10 /),'rugs_oce'), &
-       ctrl_out((/ 3, 6, 10, 10, 10, 10 /),'rugs_sic') /)
-
-  type(ctrl_out),save :: o_alb1         = ctrl_out((/ 3, 10, 10, 10, 10, 10 /),'alb1')
-  type(ctrl_out),save :: o_alb2       = ctrl_out((/ 3, 10, 10, 10, 10, 10 /),'alb2')
-
-  type(ctrl_out),save :: o_clwcon       = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'clwcon')
-  type(ctrl_out),save :: o_Ma           = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'Ma')
-  type(ctrl_out),save :: o_dnwd         = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dnwd')
-  type(ctrl_out),save :: o_dnwd0        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dnwd0')
-  type(ctrl_out),save :: o_mc           = ctrl_out((/ 4, 5, 10, 10, 10, 10 /),'mc')
-  type(ctrl_out),save :: o_ftime_con    = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'ftime_con')
-  type(ctrl_out),save :: o_dtdyn        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtdyn')
-  type(ctrl_out),save :: o_dqdyn        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dqdyn')
-  type(ctrl_out),save :: o_dudyn        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dudyn')  !AXC
-  type(ctrl_out),save :: o_dvdyn        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dvdyn')  !AXC
-  type(ctrl_out),save :: o_dtcon        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtcon')
-  type(ctrl_out),save :: o_ducon        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'ducon')
-  type(ctrl_out),save :: o_dvcon        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dvcon')
-  type(ctrl_out),save :: o_dqcon        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dqcon')
-  type(ctrl_out),save :: o_dtwak        = ctrl_out((/ 4, 5, 10, 10, 10, 10 /),'dtwak')
-  type(ctrl_out),save :: o_dqwak        = ctrl_out((/ 4, 5, 10, 10, 10, 10 /),'dqwak')
-  type(ctrl_out),save :: o_wake_h       = ctrl_out((/ 4, 5, 10, 10, 10, 10 /),'wake_h')
-  type(ctrl_out),save :: o_wake_s       = ctrl_out((/ 4, 5, 10, 10, 10, 10 /),'wake_s')
-  type(ctrl_out),save :: o_wake_deltat  = ctrl_out((/ 4, 5, 10, 10, 10, 10 /),'wake_deltat')
-  type(ctrl_out),save :: o_wake_deltaq  = ctrl_out((/ 4, 5, 10, 10, 10, 10 /),'wake_deltaq')
-  type(ctrl_out),save :: o_wake_omg     = ctrl_out((/ 4, 5, 10, 10, 10, 10 /),'wake_omg')
-  type(ctrl_out),save :: o_wdtrainA     = ctrl_out((/ 4, 1, 10,  4,  1, 10 /),'wdtrainA') !<<RomP
-  type(ctrl_out),save :: o_wdtrainM     = ctrl_out((/ 4, 1, 10,  4,  1, 10 /),'wdtrainM') !<<RomP
-  type(ctrl_out),save :: o_Vprecip      = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'Vprecip')
-  type(ctrl_out),save :: o_ftd          = ctrl_out((/ 4, 5, 10, 10, 10, 10 /),'ftd')
-  type(ctrl_out),save :: o_fqd          = ctrl_out((/ 4, 5, 10, 10, 10, 10 /),'fqd')
-  type(ctrl_out),save :: o_dtlsc        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtlsc')
-  type(ctrl_out),save :: o_dtlschr      = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtlschr')
-  type(ctrl_out),save :: o_dqlsc        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dqlsc')
-  type(ctrl_out),save :: o_beta_prec    = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'beta_prec')
-  type(ctrl_out),save :: o_dtvdf        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtvdf')
-  type(ctrl_out),save :: o_dqvdf        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dqvdf')
-  type(ctrl_out),save :: o_dteva        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dteva')
-  type(ctrl_out),save :: o_dqeva        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dqeva')
-
-!!!!!!!!!!!!!!!! Specifique thermiques
-  type(ctrl_out),save :: o_dqlscth        = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'dqlscth')
-  type(ctrl_out),save :: o_dqlscst        = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'dqlscst')
-  type(ctrl_out),save :: o_dtlscth        = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'dtlscth')
-  type(ctrl_out),save :: o_dtlscst        = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'dtlscst')
-  type(ctrl_out),save :: o_plulth        = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'plulth')
-  type(ctrl_out),save :: o_plulst        = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'plulst')
-  type(ctrl_out),save :: o_lmaxth        = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'lmaxth')
-  type(ctrl_out),save :: o_ptconvth        = ctrl_out((/ 10, 10, 10, 10, 10, 10 /),'ptconvth')
-!!!!!!!!!!!!!!!!!!!!!!!!
-
-
-  type(ctrl_out),save :: o_ptconv       = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'ptconv')
-  type(ctrl_out),save :: o_ratqs        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'ratqs')
-  type(ctrl_out),save :: o_dtthe        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtthe')
-  type(ctrl_out),save :: o_f_th         = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'f_th')
-  type(ctrl_out),save :: o_e_th         = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'e_th')
-  type(ctrl_out),save :: o_w_th         = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'w_th')
-  type(ctrl_out),save :: o_ftime_th     = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'ftime_th')
-  type(ctrl_out),save :: o_q_th         = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'q_th')
-  type(ctrl_out),save :: o_a_th         = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'a_th')
-  type(ctrl_out),save :: o_d_th         = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'d_th')
-  type(ctrl_out),save :: o_f0_th        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'f0_th')
-  type(ctrl_out),save :: o_zmax_th      = ctrl_out((/ 4,  4,  4,  5, 10, 10 /),'zmax_th')
-  type(ctrl_out),save :: o_dqthe        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dqthe')
-  type(ctrl_out),save :: o_dtajs        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtajs')
-  type(ctrl_out),save :: o_dqajs        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dqajs')
-  type(ctrl_out),save :: o_dtswr        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtswr')
-  type(ctrl_out),save :: o_dtsw0        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtsw0')
-  type(ctrl_out),save :: o_dtlwr        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtlwr')
-  type(ctrl_out),save :: o_dtlw0        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtlw0')
-  type(ctrl_out),save :: o_dtec         = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtec')
-  type(ctrl_out),save :: o_duvdf        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'duvdf')
-  type(ctrl_out),save :: o_dvvdf        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dvvdf')
-  type(ctrl_out),save :: o_duoro        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'duoro')
-  type(ctrl_out),save :: o_dvoro        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dvoro')
-  type(ctrl_out),save :: o_dulif        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dulif')
-  type(ctrl_out),save :: o_dvlif        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dvlif')
-  type(ctrl_out),save :: o_duhin        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'duhin')
-  type(ctrl_out),save :: o_dvhin        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dvhin')
-  type(ctrl_out),save :: o_dtoro        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtoro')
-  type(ctrl_out),save :: o_dtlif        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dtlif')
-  type(ctrl_out),save :: o_dthin        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dthin')
-
-  type(ctrl_out),save,allocatable :: o_trac(:)
-  type(ctrl_out),save,allocatable :: o_trac_cum(:)
-
-  type(ctrl_out),save :: o_rsu        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'rsu')
-  type(ctrl_out),save :: o_rsd        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'rsd')
-  type(ctrl_out),save :: o_rlu        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'rlu')
-  type(ctrl_out),save :: o_rld        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'rld')
-  type(ctrl_out),save :: o_rsucs      = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'rsucs')
-  type(ctrl_out),save :: o_rsdcs      = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'rsdcs')
-  type(ctrl_out),save :: o_rlucs      = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'rlucs')
-  type(ctrl_out),save :: o_rldcs      = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'rldcs')
-
-  type(ctrl_out),save :: o_tnt          = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'tnt')
-  type(ctrl_out),save :: o_tntc         = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'tntc')
-  type(ctrl_out),save :: o_tntr        = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'tntr')
-  type(ctrl_out),save :: o_tntscpbl          = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'tntscpbl')
-
-  type(ctrl_out),save :: o_tnhus          = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'tnhus')
-  type(ctrl_out),save :: o_tnhusc         = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'tnhusc')
-  type(ctrl_out),save :: o_tnhusscpbl     = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'tnhusscpbl')
-
-  type(ctrl_out),save :: o_evu          = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'evu')
-
-  type(ctrl_out),save :: o_h2o          = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'h2o')
-
-  type(ctrl_out),save :: o_mcd          = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'mcd')
-  type(ctrl_out),save :: o_dmc          = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'dmc')
-  type(ctrl_out),save :: o_ref_liq      = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'ref_liq')
-  type(ctrl_out),save :: o_ref_ice      = ctrl_out((/ 4, 10, 10, 10, 10, 10 /),'ref_ice')
-
-  type(ctrl_out),save :: o_rsut4co2     = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rsut4co2')
-  type(ctrl_out),save :: o_rlut4co2     = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rlut4co2')
-  type(ctrl_out),save :: o_rsutcs4co2   = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rsutcs4co2')
-  type(ctrl_out),save :: o_rlutcs4co2   = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rlutcs4co2')
-
-  type(ctrl_out),save :: o_rsu4co2     = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rsu4co2')
-  type(ctrl_out),save :: o_rlu4co2     = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rlu4co2')
-  type(ctrl_out),save :: o_rsucs4co2   = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rsucs4co2')
-  type(ctrl_out),save :: o_rlucs4co2   = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rlucs4co2')
-  type(ctrl_out),save :: o_rsd4co2     = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rsd4co2')
-  type(ctrl_out),save :: o_rld4co2     = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rld4co2')
-  type(ctrl_out),save :: o_rsdcs4co2   = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rsdcs4co2')
-  type(ctrl_out),save :: o_rldcs4co2   = ctrl_out((/ 5, 10, 10, 10, 10, 10 /),'rldcs4co2')
+  PRIVATE histdef2d, histdef3d, conf_physoutputs
+
+  REAL, PRIVATE, SAVE                :: zdtime
+  !$OMP THREADPRIVATE(zdtime)
+
 
 
@@ -656,5 +38,5 @@
        ok_hf,ok_instan,ok_LES,ok_ade,ok_aie, read_climoz, &
        phys_out_filestations, &
-       new_aod, aerosol_couple)   
+       new_aod, aerosol_couple, flag_aerosol_strat)   
 
     USE iophy 
@@ -669,5 +51,4 @@
     include "dimensions.h"
     include "temps.h"
-    include "indicesol.h"
     include "clesphys.h"
     include "thermcell.h"
@@ -677,5 +58,5 @@
     real,dimension(klon),intent(in) :: rlon
     real,dimension(klon),intent(in) :: rlat
-    integer, intent(in)             :: pim
+    INTEGER, intent(in)             :: pim
     INTEGER, DIMENSION(pim)            :: tabij
     INTEGER,dimension(pim), intent(in) :: ipt, jpt
@@ -683,10 +64,10 @@
     REAL,dimension(pim,2) :: plat_bounds, plon_bounds
 
-    integer                               :: jjmp1
-    integer                               :: nbteta, nlevSTD, radpas
-    logical                               :: ok_mensuel, ok_journe, ok_hf, ok_instan
-    logical                               :: ok_LES,ok_ade,ok_aie
-    logical                               :: new_aod, aerosol_couple
-    integer, intent(in)::  read_climoz ! read ozone climatology
+    INTEGER                               :: jjmp1
+    INTEGER                               :: nbteta, nlevSTD, radpas
+    LOGICAL                               :: ok_mensuel, ok_journe, ok_hf, ok_instan
+    LOGICAL                               :: ok_LES,ok_ade,ok_aie,flag_aerosol_strat
+    LOGICAL                               :: new_aod, aerosol_couple
+    INTEGER, intent(in)::  read_climoz ! read ozone climatology
     !     Allowed values are 0, 1 and 2
     !     0: do not read an ozone climatology
@@ -695,44 +76,43 @@
     !     climatology and the daylight climatology
 
-    real                                  :: dtime
-    integer                               :: idayref
-    real                                  :: zjulian
-    real, dimension(klev)                 :: Ahyb, Bhyb, Alt
-    character(len=4), dimension(nlevSTD)  :: clevSTD
-    integer                               :: nsrf, k, iq, iiq, iff, i, j, ilev
-    integer                               :: naero
-    logical                               :: ok_veget
-    integer                               :: iflag_pbl
-    CHARACTER(len=4)                      :: bb2
-    CHARACTER(len=2)                      :: bb3
-    character(len=6)                      :: type_ocean
-    CHARACTER(len=3)                      :: ctetaSTD(nbteta)
-    real, dimension(nfiles)               :: ecrit_files
-    CHARACTER(len=20), dimension(nfiles)  :: phys_out_filenames
-    INTEGER, dimension(iim*jjmp1)         ::  ndex2d
-    INTEGER, dimension(iim*jjmp1*klev)    :: ndex3d
-    integer                               :: imin_ins, imax_ins
-    integer                               :: jmin_ins, jmax_ins
-    integer, dimension(nfiles)            :: phys_out_levmin, phys_out_levmax
-    integer, dimension(nfiles)            :: phys_out_filelevels
-    CHARACTER(len=20), dimension(nfiles)  :: type_ecri_files, phys_out_filetypes
-    character(len=20), dimension(nfiles)  :: chtimestep   = (/ 'DefFreq', 'DefFreq','DefFreq', 'DefFreq', 'DefFreq', 'DefFreq' /)
-    logical, dimension(nfiles)            :: phys_out_filekeys
-    logical, dimension(nfiles)            :: phys_out_filestations
+    REAL                                  :: dtime
+    INTEGER                               :: idayref
+    REAL                                  :: zjulian
+    REAL, DIMENSION(klev)                 :: Ahyb, Bhyb, Alt
+    CHARACTER(LEN=4), DIMENSION(nlevSTD)  :: clevSTD
+    INTEGER                               :: nsrf, k, iq, iiq, iff, i, j, ilev
+    INTEGER                               :: naero
+    LOGICAL                               :: ok_veget
+    INTEGER                               :: iflag_pbl
+    CHARACTER(LEN=4)                      :: bb2
+    CHARACTER(LEN=2)                      :: bb3
+    CHARACTER(LEN=6)                      :: type_ocean
+    CHARACTER(LEN=3)                      :: ctetaSTD(nbteta)
+    REAL, DIMENSION(nfiles)               :: ecrit_files
+    CHARACTER(LEN=20), DIMENSION(nfiles)  :: phys_out_filenames
+    INTEGER, DIMENSION(iim*jjmp1)         ::  ndex2d
+    INTEGER, DIMENSION(iim*jjmp1*klev)    :: ndex3d
+    INTEGER                               :: imin_ins, imax_ins
+    INTEGER                               :: jmin_ins, jmax_ins
+    INTEGER, DIMENSION(nfiles)            :: phys_out_levmin, phys_out_levmax
+    INTEGER, DIMENSION(nfiles)            :: phys_out_filelevels
+    CHARACTER(LEN=20), DIMENSION(nfiles)  :: chtimestep   = (/ 'DefFreq', 'DefFreq','DefFreq', 'DefFreq', 'DefFreq', 'DefFreq' /)
+    LOGICAL, DIMENSION(nfiles)            :: phys_out_filekeys
+    LOGICAL, DIMENSION(nfiles)            :: phys_out_filestations
 
 !!!!!!!!!! stockage dans une region limitee pour chaque fichier !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     !                 entre [phys_out_lonmin,phys_out_lonmax] et [phys_out_latmin,phys_out_latmax]
 
-    logical, dimension(nfiles), save  :: phys_out_regfkey       = (/ .false., .false., .false.,  .false., .false., .false. /)
-    real, dimension(nfiles), save     :: phys_out_lonmin        = (/   -180.,   -180.,   -180.,    -180.,   -180.,   -180. /)
-    real, dimension(nfiles), save     :: phys_out_lonmax        = (/    180.,    180.,    180.,     180.,    180.,    180. /)
-    real, dimension(nfiles), save     :: phys_out_latmin        = (/    -90.,    -90.,    -90.,     -90.,    -90.,    -90. /)
-    real, dimension(nfiles), save     :: phys_out_latmax        = (/     90.,     90.,     90.,     90.,     90.,     90. /)
-
-    write(lunout,*) 'Debut phys_output_mod.F90'
+    LOGICAL, DIMENSION(nfiles), SAVE  :: phys_out_regfkey       = (/ .FALSE., .FALSE., .FALSE.,  .FALSE., .FALSE., .FALSE. /)
+    REAL, DIMENSION(nfiles), SAVE     :: phys_out_lonmin        = (/   -180.,   -180.,   -180.,    -180.,   -180.,   -180. /)
+    REAL, DIMENSION(nfiles), SAVE     :: phys_out_lonmax        = (/    180.,    180.,    180.,     180.,    180.,    180. /)
+    REAL, DIMENSION(nfiles), SAVE     :: phys_out_latmin        = (/    -90.,    -90.,    -90.,     -90.,    -90.,    -90. /)
+    REAL, DIMENSION(nfiles), SAVE     :: phys_out_latmax        = (/     90.,     90.,     90.,     90.,     90.,     90. /)
+
+    WRITE(lunout,*) 'Debut phys_output_mod.F90'
     ! Initialisations (Valeurs par defaut
 
-    if (.not. allocated(o_trac)) ALLOCATE(o_trac(nqtot))
-    if (.not. allocated(o_trac_cum)) ALLOCATE(o_trac_cum(nqtot))
+    IF (.NOT. ALLOCATED(o_trac)) ALLOCATE(o_trac(nqtot))
+    IF (.NOT. ALLOCATED(o_trac_cum)) ALLOCATE(o_trac_cum(nqtot))
 
     levmax = (/ klev, klev, klev, klev, klev, klev /)
@@ -783,35 +163,35 @@
     !! Lectures des parametres de sorties dans physiq.def
 
-    call getin('phys_out_regfkey',phys_out_regfkey)
-    call getin('phys_out_lonmin',phys_out_lonmin)
-    call getin('phys_out_lonmax',phys_out_lonmax)
-    call getin('phys_out_latmin',phys_out_latmin)
-    call getin('phys_out_latmax',phys_out_latmax)
+    CALL getin('phys_out_regfkey',phys_out_regfkey)
+    CALL getin('phys_out_lonmin',phys_out_lonmin)
+    CALL getin('phys_out_lonmax',phys_out_lonmax)
+    CALL getin('phys_out_latmin',phys_out_latmin)
+    CALL getin('phys_out_latmax',phys_out_latmax)
     phys_out_levmin(:)=levmin(:)
-    call getin('phys_out_levmin',levmin)
+    CALL getin('phys_out_levmin',levmin)
     phys_out_levmax(:)=levmax(:)
-    call getin('phys_out_levmax',levmax)
-    call getin('phys_out_filenames',phys_out_filenames)
+    CALL getin('phys_out_levmax',levmax)
+    CALL getin('phys_out_filenames',phys_out_filenames)
     phys_out_filekeys(:)=clef_files(:)
-    call getin('phys_out_filekeys',clef_files)
+    CALL getin('phys_out_filekeys',clef_files)
     phys_out_filestations(:)=clef_stations(:)
-    call getin('phys_out_filestations',clef_stations)
+    CALL getin('phys_out_filestations',clef_stations)
     phys_out_filelevels(:)=lev_files(:)
-    call getin('phys_out_filelevels',lev_files)
-    call getin('phys_out_filetimesteps',chtimestep)
+    CALL getin('phys_out_filelevels',lev_files)
+    CALL getin('phys_out_filetimesteps',chtimestep)
     phys_out_filetypes(:)=type_ecri(:)
-    call getin('phys_out_filetypes',type_ecri)
+    CALL getin('phys_out_filetypes',type_ecri)
 
     type_ecri_files(:)=type_ecri(:)
 
-    write(lunout,*)'phys_out_lonmin=',phys_out_lonmin
-    write(lunout,*)'phys_out_lonmax=',phys_out_lonmax
-    write(lunout,*)'phys_out_latmin=',phys_out_latmin
-    write(lunout,*)'phys_out_latmax=',phys_out_latmax
-    write(lunout,*)'phys_out_filenames=',phys_out_filenames
-    write(lunout,*)'phys_out_filetypes=',type_ecri
-    write(lunout,*)'phys_out_filekeys=',clef_files
-    write(lunout,*)'phys_out_filestations=',clef_stations
-    write(lunout,*)'phys_out_filelevels=',lev_files
+    WRITE(lunout,*)'phys_out_lonmin=',phys_out_lonmin
+    WRITE(lunout,*)'phys_out_lonmax=',phys_out_lonmax
+    WRITE(lunout,*)'phys_out_latmin=',phys_out_latmin
+    WRITE(lunout,*)'phys_out_latmax=',phys_out_latmax
+    WRITE(lunout,*)'phys_out_filenames=',phys_out_filenames
+    WRITE(lunout,*)'phys_out_filetypes=',type_ecri
+    WRITE(lunout,*)'phys_out_filekeys=',clef_files
+    WRITE(lunout,*)'phys_out_filestations=',clef_stations
+    WRITE(lunout,*)'phys_out_filelevels=',lev_files
 
 !!!!!!!!!!!!!!!!!!!!!!! Boucle sur les fichiers !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -823,24 +203,24 @@
 
     ! Calcul des Ahyb, Bhyb et Alt
-    do k=1,klev
+    DO k=1,klev
        Ahyb(k)=(ap(k)+ap(k+1))/2.
        Bhyb(k)=(bp(k)+bp(k+1))/2.
        Alt(k)=log(preff/presnivs(k))*8.
-    enddo
+    ENDDO
     !          if(prt_level.ge.1) then
-    write(lunout,*)'Ap Hybrid = ',Ahyb(1:klev)
-    write(lunout,*)'Bp Hybrid = ',Bhyb(1:klev)
-    write(lunout,*)'Alt approx des couches pour une haut d echelle de 8km = ',Alt(1:klev)
+    WRITE(lunout,*)'Ap Hybrid = ',Ahyb(1:klev)
+    WRITE(lunout,*)'Bp Hybrid = ',Bhyb(1:klev)
+    WRITE(lunout,*)'Alt approx des couches pour une haut d echelle de 8km = ',Alt(1:klev)
     !          endif
     DO iff=1,nfiles
 
        ! Calculate ecrit_files for all files
-       if ( chtimestep(iff).eq.'DefFreq' ) then
+       IF ( chtimestep(iff).eq.'DefFreq' ) then
           ! Par defaut ecrit_files = (ecrit_mensuel ecrit_jour ecrit_hf ...)*86400.
           ecrit_files(iff)=ecrit_files(iff)*86400.
-       else
-          call convers_timesteps(chtimestep(iff),dtime,ecrit_files(iff)) 
-       endif
-       write(lunout,*)'ecrit_files(',iff,')= ',ecrit_files(iff)
+       ELSE
+          CALL convers_timesteps(chtimestep(iff),dtime,ecrit_files(iff)) 
+       ENDIF
+       WRITE(lunout,*)'ecrit_files(',iff,')= ',ecrit_files(iff)
 
        zoutm(iff) = ecrit_files(iff) ! Frequence ou l on ecrit en seconde
@@ -862,5 +242,5 @@
 !!!!!!!!!!!!!!!!! Traitement dans le cas ou l'on veut stocker sur un domaine limite !!
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-          if (phys_out_regfkey(iff)) then
+          IF (phys_out_regfkey(iff)) then
 
              imin_ins=1
@@ -871,18 +251,18 @@
              ! correction abderr        
              do i=1,iim
-                write(lunout,*)'io_lon(i)=',io_lon(i)
-                if (io_lon(i).le.phys_out_lonmin(iff)) imin_ins=i
-                if (io_lon(i).le.phys_out_lonmax(iff)) imax_ins=i+1
+                WRITE(lunout,*)'io_lon(i)=',io_lon(i)
+                IF (io_lon(i).le.phys_out_lonmin(iff)) imin_ins=i
+                IF (io_lon(i).le.phys_out_lonmax(iff)) imax_ins=i+1
              enddo
 
              do j=1,jjmp1
-                write(lunout,*)'io_lat(j)=',io_lat(j)
-                if (io_lat(j).ge.phys_out_latmin(iff)) jmax_ins=j+1
-                if (io_lat(j).ge.phys_out_latmax(iff)) jmin_ins=j
+                WRITE(lunout,*)'io_lat(j)=',io_lat(j)
+                IF (io_lat(j).ge.phys_out_latmin(iff)) jmax_ins=j+1
+                IF (io_lat(j).ge.phys_out_latmax(iff)) jmin_ins=j
              enddo
 
-             write(lunout,*)'On stoke le fichier histoire numero ',iff,' sur ', &
+             WRITE(lunout,*)'On stoke le fichier histoire numero ',iff,' sur ', &
                   imin_ins,imax_ins,jmin_ins,jmax_ins
-             write(lunout,*)'longitudes : ', &
+             WRITE(lunout,*)'longitudes : ', &
                   io_lon(imin_ins),io_lon(imax_ins), &
                   'latitudes : ', &
@@ -895,9 +275,9 @@
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !IM fichiers stations
-          else if (clef_stations(iff)) THEN
-
-             write(lunout,*)'phys_output_mod phys_out_filenames=',phys_out_filenames(iff)
-
-             call histbeg_phy_all(rlon,rlat,pim,tabij,ipt,jpt,plon,plat,plon_bounds,plat_bounds, &
+          else IF (clef_stations(iff)) THEN
+
+             WRITE(lunout,*)'phys_output_mod phys_out_filenames=',phys_out_filenames(iff)
+
+             CALL histbeg_phy_all(rlon,rlat,pim,tabij,ipt,jpt,plon,plat,plon_bounds,plat_bounds, &
                   phys_out_filenames(iff), &
                   itau_phy,zjulian,dtime,nhorim(iff),nid_files(iff))
@@ -935,881 +315,515 @@
           !                 1,preff,nvertp0(iff))
 !!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-          IF (.NOT.clef_stations(iff)) THEN
-             !
-             !IM: there is no way to have one single value in a netcdf file
-             !
-             type_ecri(1) = 'once'
-             type_ecri(2) = 'once'
-             type_ecri(3) = 'once'
-             type_ecri(4) = 'once'
-             type_ecri(5) = 'once'
-             type_ecri(6) = 'once'
-             CALL histdef2d(iff,clef_stations(iff),o_aire%flag,o_aire%name,"Grid area", "-")
-             CALL histdef2d(iff,clef_stations(iff),o_contfracATM%flag,o_contfracATM%name,"% sfce ter+lic", "-")
-          ENDIF
-          type_ecri(:) = type_ecri_files(:)
+    CALL histdef2d(iff,o_aire)
+    CALL histdef2d(iff,o_contfracATM)
 
 !!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-          CALL histdef2d(iff,clef_stations(iff),o_phis%flag,o_phis%name,"Surface geop.height", "m2/s2" )
-          CALL histdef2d(iff,clef_stations(iff),o_contfracOR%flag,o_contfracOR%name,"% sfce terre OR", "-" )
-          CALL histdef2d(iff,clef_stations(iff),o_aireTER%flag,o_aireTER%name,"Grid area CONT", "-" )
-          CALL histdef2d(iff,clef_stations(iff),o_flat%flag,o_flat%name, "Latent heat flux", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_slp%flag,o_slp%name, "Sea Level Pressure", "Pa" )
-          CALL histdef2d(iff,clef_stations(iff),o_tsol%flag,o_tsol%name, "Surface Temperature", "K")
-          CALL histdef2d(iff,clef_stations(iff),o_t2m%flag,o_t2m%name, "Temperature 2m", "K" )
-          IF (.NOT.clef_stations(iff)) THEN 
-             !
-             !IM: there is no way to have one single value in a netcdf file
-             !
-             type_ecri(1) = 't_min(X)'
-             type_ecri(2) = 't_min(X)'
-             type_ecri(3) = 't_min(X)'
-             type_ecri(4) = 't_min(X)'
-             type_ecri(5) = 't_min(X)' 
-             type_ecri(6) = 't_min(X)' 
-             CALL histdef2d(iff,clef_stations(iff),o_t2m_min%flag,o_t2m_min%name, "Temp 2m min", "K" )
-             type_ecri(1) = 't_max(X)'
-             type_ecri(2) = 't_max(X)'
-             type_ecri(3) = 't_max(X)'
-             type_ecri(4) = 't_max(X)'
-             type_ecri(5) = 't_max(X)' 
-             type_ecri(6) = 't_max(X)' 
-             CALL histdef2d(iff,clef_stations(iff),o_t2m_max%flag,o_t2m_max%name, "Temp 2m max", "K" )
-          ENDIF
-          type_ecri(:) = type_ecri_files(:)
-          CALL histdef2d(iff,clef_stations(iff),o_wind10m%flag,o_wind10m%name, "10-m wind speed", "m/s")
-          CALL histdef2d(iff,clef_stations(iff),o_wind10max%flag,o_wind10max%name, "10m wind speed max", "m/s")
-          CALL histdef2d(iff,clef_stations(iff),o_sicf%flag,o_sicf%name, "Sea-ice fraction", "-" )
-          CALL histdef2d(iff,clef_stations(iff),o_q2m%flag,o_q2m%name, "Specific humidity 2m", "kg/kg")
-          CALL histdef2d(iff,clef_stations(iff),o_ustar%flag,o_ustar%name, "Friction velocity", "m/s" )
-          CALL histdef2d(iff,clef_stations(iff),o_u10m%flag,o_u10m%name, "Vent zonal 10m", "m/s" )
-          CALL histdef2d(iff,clef_stations(iff),o_v10m%flag,o_v10m%name, "Vent meridien 10m", "m/s")
-          CALL histdef2d(iff,clef_stations(iff),o_psol%flag,o_psol%name, "Surface Pressure", "Pa" ) 
-          CALL histdef2d(iff,clef_stations(iff),o_qsurf%flag,o_qsurf%name, "Surface Air humidity", "kg/kg")
-
-          if (.not. ok_veget) then
-             CALL histdef2d(iff,clef_stations(iff),o_qsol%flag,o_qsol%name, "Soil watter content", "mm" )
-          endif
-
-             type_ecri(1) = 'inst(X)'
-             type_ecri(2) = 'inst(X)'
-             type_ecri(3) = 'inst(X)'
-             type_ecri(4) = 'inst(X)'
-             type_ecri(5) = 'inst(X)'
-             type_ecri(6) = 'inst(X)'
-          CALL histdef2d(iff,clef_stations(iff),o_ndayrain%flag,o_ndayrain%name, "Number of dayrain(liq+sol)", "-")
-             type_ecri(:) = type_ecri_files(:)
-          CALL histdef2d(iff,clef_stations(iff),o_precip%flag,o_precip%name, "Precip Totale liq+sol", "kg/(s*m2)" )
-          CALL histdef2d(iff,clef_stations(iff),o_plul%flag,o_plul%name, "Large-scale Precip.", "kg/(s*m2)") 
-          CALL histdef2d(iff,clef_stations(iff),o_pluc%flag,o_pluc%name, "Convective Precip.", "kg/(s*m2)")
-          CALL histdef2d(iff,clef_stations(iff),o_snow%flag,o_snow%name, "Snow fall", "kg/(s*m2)" )
-          CALL histdef2d(iff,clef_stations(iff),o_msnow%flag,o_msnow%name, "Surface snow amount", "kg/m2" )
-          CALL histdef2d(iff,clef_stations(iff),o_fsnow%flag,o_fsnow%name, "Surface snow area fraction", "-" )
-          CALL histdef2d(iff,clef_stations(iff),o_evap%flag,o_evap%name, "Evaporat", "kg/(s*m2)" ) 
-          CALL histdef2d(iff,clef_stations(iff),o_tops%flag,o_tops%name, "Solar rad. at TOA", "W/m2") 
-          CALL histdef2d(iff,clef_stations(iff),o_tops0%flag,o_tops0%name, "CS Solar rad. at TOA", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_topl%flag,o_topl%name, "IR rad. at TOA", "W/m2" )
-          CALL histdef2d(iff,clef_stations(iff),o_topl0%flag,o_topl0%name, "IR rad. at TOA", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_SWupTOA%flag,o_SWupTOA%name, "SWup at TOA", "W/m2") 
-          CALL histdef2d(iff,clef_stations(iff),o_SWupTOAclr%flag,o_SWupTOAclr%name, "SWup clear sky at TOA", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_SWdnTOA%flag,o_SWdnTOA%name, "SWdn at TOA", "W/m2" )
-          CALL histdef2d(iff,clef_stations(iff),o_SWdnTOAclr%flag,o_SWdnTOAclr%name, "SWdn clear sky at TOA", "W/m2") 
-          CALL histdef2d(iff,clef_stations(iff),o_nettop%flag,o_nettop%name, "Net dn radiatif flux at TOA", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_SWup200%flag,o_SWup200%name, "SWup at 200mb", "W/m2" ) 
-          CALL histdef2d(iff,clef_stations(iff),o_SWup200clr%flag,o_SWup200clr%name, "SWup clear sky at 200mb", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_SWdn200%flag,o_SWdn200%name, "SWdn at 200mb", "W/m2" )
-          CALL histdef2d(iff,clef_stations(iff),o_SWdn200clr%flag,o_SWdn200clr%name, "SWdn clear sky at 200mb", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_LWup200%flag,o_LWup200%name, "LWup at 200mb", "W/m2") 
-          CALL histdef2d(iff,clef_stations(iff),o_LWup200clr%flag,o_LWup200clr%name, "LWup clear sky at 200mb", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_LWdn200%flag,o_LWdn200%name, "LWdn at 200mb", "W/m2") 
-          CALL histdef2d(iff,clef_stations(iff),o_LWdn200clr%flag,o_LWdn200clr%name, "LWdn clear sky at 200mb", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_sols%flag,o_sols%name, "Solar rad. at surf.", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_sols0%flag,o_sols0%name, "Solar rad. at surf.", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_soll%flag,o_soll%name, "IR rad. at surface", "W/m2")  
-          CALL histdef2d(iff,clef_stations(iff),o_radsol%flag,o_radsol%name, "Rayonnement au sol", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_soll0%flag,o_soll0%name, "IR rad. at surface", "W/m2") 
-          CALL histdef2d(iff,clef_stations(iff),o_SWupSFC%flag,o_SWupSFC%name, "SWup at surface", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_SWupSFCclr%flag,o_SWupSFCclr%name, "SWup clear sky at surface", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_SWdnSFC%flag,o_SWdnSFC%name, "SWdn at surface", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_SWdnSFCclr%flag,o_SWdnSFCclr%name, "SWdn clear sky at surface", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_LWupSFC%flag,o_LWupSFC%name, "Upwd. IR rad. at surface", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_LWdnSFC%flag,o_LWdnSFC%name, "Down. IR rad. at surface", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_LWupSFCclr%flag,o_LWupSFCclr%name, "CS Upwd. IR rad. at surface", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_LWdnSFCclr%flag,o_LWdnSFCclr%name, "Down. CS IR rad. at surface", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_bils%flag,o_bils%name, "Surf. total heat flux", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_sens%flag,o_sens%name, "Sensible heat flux", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_fder%flag,o_fder%name, "Heat flux derivation", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_ffonte%flag,o_ffonte%name, "Thermal flux for snow melting", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_fqcalving%flag,o_fqcalving%name, "Ice Calving", "kg/m2/s") 
-          CALL histdef2d(iff,clef_stations(iff),o_fqfonte%flag,o_fqfonte%name, "Land ice melt", "kg/m2/s") 
-
-          CALL histdef2d(iff,clef_stations(iff),o_taux%flag,o_taux%name, "Zonal wind stress","Pa")
-          CALL histdef2d(iff,clef_stations(iff),o_tauy%flag,o_tauy%name, "Meridional wind stress","Pa")
-
-          DO nsrf = 1, nbsrf
-             CALL histdef2d(iff,clef_stations(iff),o_pourc_srf(nsrf)%flag,o_pourc_srf(nsrf)%name,"% "//clnsurf(nsrf),"%")
-             CALL histdef2d(iff,clef_stations(iff),o_fract_srf(nsrf)%flag,o_fract_srf(nsrf)%name,"Fraction "//clnsurf(nsrf),"1")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_taux_srf(nsrf)%flag,o_taux_srf(nsrf)%name,"Zonal wind stress"//clnsurf(nsrf),"Pa")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_tauy_srf(nsrf)%flag,o_tauy_srf(nsrf)%name,"Meridional wind stress "//clnsurf(nsrf),"Pa")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_tsol_srf(nsrf)%flag,o_tsol_srf(nsrf)%name,"Temperature "//clnsurf(nsrf),"K")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_evappot_srf(nsrf)%flag,o_evappot_srf(nsrf)%name,"Temperature"//clnsurf(nsrf),"K")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_ustar_srf(nsrf)%flag,o_ustar_srf(nsrf)%name,"Friction velocity "//clnsurf(nsrf),"m/s")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_u10m_srf(nsrf)%flag,o_u10m_srf(nsrf)%name,"Vent Zonal 10m "//clnsurf(nsrf),"m/s")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_evap_srf(nsrf)%flag,o_evap_srf(nsrf)%name,"evaporation at surface "//clnsurf(nsrf),"kg/(s*m2)")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_v10m_srf(nsrf)%flag,o_v10m_srf(nsrf)%name,"Vent meredien 10m "//clnsurf(nsrf),"m/s")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_t2m_srf(nsrf)%flag,o_t2m_srf(nsrf)%name,"Temp 2m "//clnsurf(nsrf),"K")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_sens_srf(nsrf)%flag,o_sens_srf(nsrf)%name,"Sensible heat flux "//clnsurf(nsrf),"W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_lat_srf(nsrf)%flag,o_lat_srf(nsrf)%name,"Latent heat flux "//clnsurf(nsrf),"W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_flw_srf(nsrf)%flag,o_flw_srf(nsrf)%name,"LW "//clnsurf(nsrf),"W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_fsw_srf(nsrf)%flag,o_fsw_srf(nsrf)%name,"SW "//clnsurf(nsrf),"W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_wbils_srf(nsrf)%flag,o_wbils_srf(nsrf)%name,"Bilan sol "//clnsurf(nsrf),"W/m2" )
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_wbilo_srf(nsrf)%flag,o_wbilo_srf(nsrf)%name,"Bilan eau "//clnsurf(nsrf),"kg/(m2*s)")
-             if (iflag_pbl>1 .and. lev_files(iff).gt.10 ) then
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_tke_srf(nsrf)%flag,o_tke_srf(nsrf)%name,"Max Turb. Kinetic Energy "//clnsurf(nsrf),"-")
-
-                IF (.NOT.clef_stations(iff)) THEN 
-                   !
-                   !IM: there is no way to have one single value in a netcdf file
-                   !
-                   type_ecri(1) = 't_max(X)'
-                   type_ecri(2) = 't_max(X)'
-                   type_ecri(3) = 't_max(X)'
-                   type_ecri(4) = 't_max(X)'
-                   type_ecri(5) = 't_max(X)'
-                   type_ecri(6) = 't_max(X)'
-                   CALL histdef2d(iff,clef_stations(iff), &
-                        o_tke_max_srf(nsrf)%flag,o_tke_max_srf(nsrf)%name,"Max Turb. Kinetic Energy "//clnsurf(nsrf),"-")
-                   type_ecri(:) = type_ecri_files(:)
-                ENDIF
-
-             endif
-
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_albe_srf(nsrf)%flag,o_albe_srf(nsrf)%name,"Albedo VIS surf. "//clnsurf(nsrf),"-")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_rugs_srf(nsrf)%flag,o_rugs_srf(nsrf)%name,"Surface roughness "//clnsurf(nsrf),"m")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_ages_srf(nsrf)%flag,o_ages_srf(nsrf)%name,"Snow age", "day")
-          END DO
-
-          IF (new_aod .AND. (.NOT. aerosol_couple)) THEN
-             IF (ok_ade.OR.ok_aie) THEN
-
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_od550aer%flag,o_od550aer%name, "Total aerosol optical depth at 550nm", "-")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_od865aer%flag,o_od865aer%name, "Total aerosol optical depth at 870nm", "-")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_absvisaer%flag,o_absvisaer%name, "Absorption aerosol visible optical depth", "-")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_od550lt1aer%flag,o_od550lt1aer%name, "Fine mode optical depth", "-")
-
-
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_sconcso4%flag,o_sconcso4%name,"Surface Concentration of Sulfate ","kg/m3")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_sconcoa%flag,o_sconcoa%name,"Surface Concentration of Organic Aerosol ","kg/m3")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_sconcbc%flag,o_sconcbc%name,"Surface Concentration of Black Carbon ","kg/m3")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_sconcss%flag,o_sconcss%name,"Surface Concentration of Sea Salt ","kg/m3")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_sconcdust%flag,o_sconcdust%name,"Surface Concentration of Dust ","kg/m3")
-                CALL histdef3d(iff,clef_stations(iff), &
-                     o_concso4%flag,o_concso4%name,"Concentration of Sulfate ","kg/m3")
-                CALL histdef3d(iff,clef_stations(iff), &
-                     o_concoa%flag,o_concoa%name,"Concentration of Organic Aerosol ","kg/m3")
-                CALL histdef3d(iff,clef_stations(iff), &
-                     o_concbc%flag,o_concbc%name,"Concentration of Black Carbon ","kg/m3")
-                CALL histdef3d(iff,clef_stations(iff), &
-                     o_concss%flag,o_concss%name,"Concentration of Sea Salt ","kg/m3")
-                CALL histdef3d(iff,clef_stations(iff), &
-                     o_concdust%flag,o_concdust%name,"Concentration of Dust ","kg/m3")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_loadso4%flag,o_loadso4%name,"Column Load of Sulfate ","kg/m2")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_loadoa%flag,o_loadoa%name,"Column Load of Organic Aerosol ","kg/m2")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_loadbc%flag,o_loadbc%name,"Column Load of Black Carbon ","kg/m2")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_loadss%flag,o_loadss%name,"Column Load of Sea Salt ","kg/m2")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_loaddust%flag,o_loaddust%name,"Column Load of Dust ","kg/m2")
-
-                DO naero = 1, naero_spc
-                   CALL histdef2d(iff,clef_stations(iff), &
-                        o_tausumaero(naero)%flag,o_tausumaero(naero)%name,"Aerosol Optical depth at 550 nm "//name_aero(naero),"1")
-                END DO
-             ENDIF
-          ENDIF
-
-          IF (ok_ade) THEN
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_topswad%flag,o_topswad%name, "ADE at TOA", "W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_topswad0%flag,o_topswad0%name, "ADE clear-sky at TOA", "W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_solswad%flag,o_solswad%name, "ADE at SRF", "W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_solswad0%flag,o_solswad0%name, "ADE clear-sky at SRF", "W/m2")
-
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_swtoaas_nat%flag,o_swtoaas_nat%name, "Natural aerosol radiative forcing all-sky at TOA", "W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_swsrfas_nat%flag,o_swsrfas_nat%name, "Natural aerosol radiative forcing all-sky at SRF", "W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_swtoacs_nat%flag,o_swtoacs_nat%name, "Natural aerosol radiative forcing clear-sky at TOA", "W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_swsrfcs_nat%flag,o_swsrfcs_nat%name, "Natural aerosol radiative forcing clear-sky at SRF", "W/m2")
-
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_swtoaas_ant%flag,o_swtoaas_ant%name, "Anthropogenic aerosol radiative forcing all-sky at TOA", "W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_swsrfas_ant%flag,o_swsrfas_ant%name, "Anthropogenic aerosol radiative forcing all-sky at SRF", "W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_swtoacs_ant%flag,o_swtoacs_ant%name, "Anthropogenic aerosol radiative forcing clear-sky at TOA", "W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_swsrfcs_ant%flag,o_swsrfcs_ant%name, "Anthropogenic aerosol radiative forcing clear-sky at SRF", "W/m2")
-
-             IF (.NOT. aerosol_couple) THEN 
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_swtoacf_nat%flag,o_swtoacf_nat%name, "Natural aerosol impact on cloud radiative forcing at TOA", "W/m2")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_swsrfcf_nat%flag,o_swsrfcf_nat%name, "Natural aerosol impact on cloud radiative forcing  at SRF", "W/m2")
-                CALL histdef2d(iff, clef_stations(iff), o_swtoacf_ant%flag, &
-                     o_swtoacf_ant%name, &
-                     "Anthropogenic aerosol impact on cloud radiative forcing at TOA", &
-                     "W/m2")
-                CALL histdef2d(iff, clef_stations(iff), o_swsrfcf_ant%flag, &
-                     o_swsrfcf_ant%name, &
-                     "Anthropogenic aerosol impact on cloud radiative forcing at SRF", &
-                     "W/m2")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_swtoacf_zero%flag,o_swtoacf_zero%name, "Cloud radiative forcing (allsky-clearsky fluxes) at TOA", "W/m2")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_swsrfcf_zero%flag,o_swsrfcf_zero%name, "Cloud radiative forcing (allsky-clearsky fluxes) at SRF", "W/m2")
-             ENDIF
-          ENDIF
-
-          IF (ok_aie) THEN
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_topswai%flag,o_topswai%name, "AIE at TOA", "W/m2")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_solswai%flag,o_solswai%name, "AIE at SFR", "W/m2")
-             !Cloud droplet number concentration
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_scdnc%flag,o_scdnc%name, "Cloud droplet number concentration","m-3")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_cldncl%flag,o_cldncl%name, "CDNC at top of liquid water cloud", "m-3")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_reffclws%flag,o_reffclws%name, "Stratiform Cloud Droplet Effective Radius (aerosol diags.)","m")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_reffclwc%flag,o_reffclwc%name, "Convective Cloud Droplet Effective Radius (aerosol diags.)","m")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_cldnvi%flag,o_cldnvi%name, "Column Integrated Cloud Droplet Number", "m-2")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_lcc3d%flag,o_lcc3d%name, "Cloud liquid fraction","1")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_lcc3dcon%flag,o_lcc3dcon%name, "Convective cloud liquid fraction","1")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_lcc3dstra%flag,o_lcc3dstra%name, "Stratiform cloud liquid fraction","1")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_lcc%flag,o_lcc%name, "Cloud liquid fraction at top of cloud","1")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_reffclwtop%flag,o_reffclwtop%name, "Droplet effective radius at top of liquid water cloud", "m")
-          ENDIF
-
-
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_alb1%flag,o_alb1%name, "Surface VIS albedo", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_alb2%flag,o_alb2%name, "Surface Near IR albedo", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_cdrm%flag,o_cdrm%name, "Momentum drag coef.", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_cdrh%flag,o_cdrh%name, "Heat drag coef.", "-" )
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_cldl%flag,o_cldl%name, "Low-level cloudiness", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_cldm%flag,o_cldm%name, "Mid-level cloudiness", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_cldh%flag,o_cldh%name, "High-level cloudiness", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_cldt%flag,o_cldt%name, "Total cloudiness", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_cldq%flag,o_cldq%name, "Cloud liquid water path", "kg/m2")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_lwp%flag,o_lwp%name, "Cloud water path", "kg/m2")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_iwp%flag,o_iwp%name, "Cloud ice water path", "kg/m2" )
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_ue%flag,o_ue%name, "Zonal energy transport", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_ve%flag,o_ve%name, "Merid energy transport", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_uq%flag,o_uq%name, "Zonal humidity transport", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_vq%flag,o_vq%name, "Merid humidity transport", "-")
-
-          IF(iflag_con.GE.3) THEN ! sb
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_cape%flag,o_cape%name, "Conv avlbl pot ener", "J/kg")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_pbase%flag,o_pbase%name, "Cld base pressure", "Pa")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_ptop%flag,o_ptop%name, "Cld top pressure", "Pa")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_fbase%flag,o_fbase%name, "Cld base mass flux", "kg/m2/s")
-             if (iflag_con /= 30) then
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_plcl%flag,o_plcl%name, "Lifting Condensation Level", "hPa")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_plfc%flag,o_plfc%name, "Level of Free Convection", "hPa")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_wbeff%flag,o_wbeff%name, "Conv. updraft velocity at LFC (<100)", "m/s")
-             end if
-             IF (.NOT.clef_stations(iff)) THEN 
-                !
-                !IM: there is no way to have one single value in a netcdf file
-                !
-                type_ecri(1) = 't_max(X)'
-                type_ecri(2) = 't_max(X)'
-                type_ecri(3) = 't_max(X)'
-                type_ecri(4) = 't_max(X)'
-                type_ecri(5) = 't_max(X)'
-                type_ecri(6) = 't_max(X)'
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_cape_max%flag,o_cape_max%name, "CAPE max.", "J/kg")
-             ENDIF
-             type_ecri(:) = type_ecri_files(:)
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_upwd%flag,o_upwd%name, "saturated updraft", "kg/m2/s")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_Ma%flag,o_Ma%name, "undilute adiab updraft", "kg/m2/s")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_dnwd%flag,o_dnwd%name, "saturated downdraft", "kg/m2/s")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_dnwd0%flag,o_dnwd0%name, "unsat. downdraft", "kg/m2/s")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_mc%flag,o_mc%name, "Convective mass flux", "kg/m2/s")
-             type_ecri(1) = 'inst(X)'
-             type_ecri(2) = 'inst(X)'
-             type_ecri(3) = 'inst(X)'
-             type_ecri(4) = 'inst(X)'
-             type_ecri(5) = 'inst(X)'
-             type_ecri(6) = 'inst(X)'
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_ftime_con%flag,o_ftime_con%name, "Fraction of time convection Occurs", " ")
-             type_ecri(:) = type_ecri_files(:)
-          ENDIF !iflag_con .GE. 3
-
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_prw%flag,o_prw%name, "Precipitable water", "kg/m2")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_s_pblh%flag,o_s_pblh%name, "Boundary Layer Height", "m")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_s_pblt%flag,o_s_pblt%name, "t at Boundary Layer Height", "K")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_s_lcl%flag,o_s_lcl%name, "Condensation level", "m")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_s_therm%flag,o_s_therm%name, "Exces du thermique", "K")
+    CALL histdef2d(iff,o_phis)
+    CALL histdef2d(iff,o_contfracOR)
+    CALL histdef2d(iff,o_aireTER)
+    CALL histdef2d(iff,o_flat)
+    CALL histdef2d(iff,o_slp)
+    CALL histdef2d(iff,o_tsol)
+    CALL histdef2d(iff,o_t2m)
+    CALL histdef2d(iff,o_t2m_min)
+    CALL histdef2d(iff,o_t2m_max)
+    CALL histdef2d(iff,o_wind10m)
+    CALL histdef2d(iff,o_wind10max)
+    CALL histdef2d(iff,o_sicf)
+    CALL histdef2d(iff,o_q2m)
+    CALL histdef2d(iff,o_ustar)
+    CALL histdef2d(iff,o_u10m)
+    CALL histdef2d(iff,o_v10m)
+    CALL histdef2d(iff,o_psol)
+    CALL histdef2d(iff,o_qsurf)
+
+    IF (.NOT. ok_veget) THEN
+      CALL histdef2d(iff,o_qsol)
+    ENDIF
+    CALL histdef2d(iff,o_ndayrain)
+    CALL histdef2d(iff,o_precip)
+    CALL histdef2d(iff,o_plul)
+    CALL histdef2d(iff,o_pluc)
+    CALL histdef2d(iff,o_snow)
+    CALL histdef2d(iff,o_msnow)
+    CALL histdef2d(iff,o_fsnow)
+    CALL histdef2d(iff,o_evap)
+    CALL histdef2d(iff,o_tops)
+    CALL histdef2d(iff,o_tops0)
+    CALL histdef2d(iff,o_topl)
+    CALL histdef2d(iff,o_topl0)
+    CALL histdef2d(iff,o_SWupTOA)
+    CALL histdef2d(iff,o_SWupTOAclr)
+    CALL histdef2d(iff,o_SWdnTOA)
+    CALL histdef2d(iff,o_SWdnTOAclr)
+    CALL histdef2d(iff,o_nettop)
+    CALL histdef2d(iff,o_SWup200)
+    CALL histdef2d(iff,o_SWup200clr)
+    CALL histdef2d(iff,o_SWdn200)
+    CALL histdef2d(iff,o_SWdn200clr)
+    CALL histdef2d(iff,o_LWup200)
+    CALL histdef2d(iff,o_LWup200clr)
+    CALL histdef2d(iff,o_LWdn200)
+    CALL histdef2d(iff,o_LWdn200clr)
+    CALL histdef2d(iff,o_sols)
+    CALL histdef2d(iff,o_sols0)
+    CALL histdef2d(iff,o_soll)
+    CALL histdef2d(iff,o_radsol)
+    CALL histdef2d(iff,o_soll0)
+    CALL histdef2d(iff,o_SWupSFC)
+    CALL histdef2d(iff,o_SWupSFCclr)
+    CALL histdef2d(iff,o_SWdnSFC)
+    CALL histdef2d(iff,o_SWdnSFCclr)
+    CALL histdef2d(iff,o_LWupSFC)
+    CALL histdef2d(iff,o_LWdnSFC)
+    CALL histdef2d(iff,o_LWupSFCclr)
+    CALL histdef2d(iff,o_LWdnSFCclr)
+    CALL histdef2d(iff,o_bils)
+    CALL histdef2d(iff,o_bils_ec)
+    CALL histdef2d(iff,o_bils_tke)
+    CALL histdef2d(iff,o_bils_diss)
+    CALL histdef2d(iff,o_bils_kinetic)
+    CALL histdef2d(iff,o_bils_enthalp)
+    CALL histdef2d(iff,o_bils_latent)
+    CALL histdef2d(iff,o_sens)
+    CALL histdef2d(iff,o_fder)
+    CALL histdef2d(iff,o_ffonte)
+    CALL histdef2d(iff,o_fqcalving)
+    CALL histdef2d(iff,o_fqfonte)
+    CALL histdef2d(iff,o_taux)
+    CALL histdef2d(iff,o_tauy)
+
+    DO nsrf = 1, nbsrf
+      CALL histdef2d(iff,o_pourc_srf(nsrf))
+      CALL histdef2d(iff,o_fract_srf(nsrf))
+      CALL histdef2d(iff, o_taux_srf(nsrf))
+      CALL histdef2d(iff, o_tauy_srf(nsrf))
+      CALL histdef2d(iff, o_tsol_srf(nsrf))
+      CALL histdef2d(iff, o_evappot_srf(nsrf))
+      CALL histdef2d(iff, o_ustar_srf(nsrf))
+      CALL histdef2d(iff, o_u10m_srf(nsrf))
+      CALL histdef2d(iff, o_evap_srf(nsrf))
+      CALL histdef2d(iff, o_v10m_srf(nsrf))
+      CALL histdef2d(iff, o_t2m_srf(nsrf))
+      CALL histdef2d(iff, o_sens_srf(nsrf))
+      CALL histdef2d(iff, o_lat_srf(nsrf))
+      CALL histdef2d(iff, o_flw_srf(nsrf))
+      CALL histdef2d(iff, o_fsw_srf(nsrf))
+      CALL histdef2d(iff, o_wbils_srf(nsrf))
+      CALL histdef2d(iff, o_wbilo_srf(nsrf))
+      IF (iflag_pbl>1 ) then
+            CALL histdef2d(iff, o_tke_srf(nsrf))
+            CALL histdef2d(iff, o_tke_max_srf(nsrf))
+      ENDIF
+
+      CALL histdef2d(iff, o_albe_srf(nsrf))
+      CALL histdef2d(iff, o_rugs_srf(nsrf))
+      CALL histdef2d(iff, o_ages_srf(nsrf))
+    END DO
+
+    IF (new_aod .AND. (.NOT. aerosol_couple)) THEN
+      IF (ok_ade.OR.ok_aie) THEN
+          CALL histdef2d(iff,o_od550aer)
+          CALL histdef2d(iff,o_od865aer)
+          CALL histdef2d(iff,o_absvisaer)
+          CALL histdef2d(iff,o_od550lt1aer)
+          CALL histdef2d(iff,o_sconcso4)
+          CALL histdef2d(iff,o_sconcoa)
+          CALL histdef2d(iff,o_sconcbc)
+          CALL histdef2d(iff,o_sconcss)
+          CALL histdef2d(iff,o_sconcdust)
+          CALL histdef3d(iff,o_concso4)
+          CALL histdef3d(iff,o_concoa)
+          CALL histdef3d(iff,o_concbc)
+          CALL histdef3d(iff,o_concss)
+          CALL histdef3d(iff,o_concdust)
+          CALL histdef2d(iff,o_loadso4)
+          CALL histdef2d(iff,o_loadoa)
+          CALL histdef2d(iff,o_loadbc)
+          CALL histdef2d(iff,o_loadss)
+          CALL histdef2d(iff,o_loaddust)
+!--STRAT AER
+      ENDIF
+      IF (ok_ade.OR.ok_aie.OR.flag_aerosol_strat) THEN
+        DO naero = 1, naero_spc
+          CALL histdef2d(iff, o_tausumaero(naero))
+        END DO
+      ENDIF
+    ENDIF
+
+    IF (ok_ade) THEN
+      CALL histdef2d(iff,o_topswad)
+      CALL histdef2d(iff,o_topswad0)
+      CALL histdef2d(iff,o_solswad)
+      CALL histdef2d(iff,o_solswad0)
+      CALL histdef2d(iff,o_swtoaas_nat)
+      CALL histdef2d(iff,o_swsrfas_nat)
+      CALL histdef2d(iff,o_swtoacs_nat)
+      CALL histdef2d(iff,o_swsrfcs_nat)
+      CALL histdef2d(iff,o_swtoaas_ant)
+      CALL histdef2d(iff,o_swsrfas_ant)
+      CALL histdef2d(iff,o_swtoacs_ant)
+      CALL histdef2d(iff,o_swsrfcs_ant)
+
+      IF (.NOT. aerosol_couple) THEN 
+            CALL histdef2d(iff,o_swtoacf_nat)
+            CALL histdef2d(iff,o_swsrfcf_nat)
+            CALL histdef2d(iff,o_swtoacf_ant)
+            CALL histdef2d(iff,o_swsrfcf_ant)
+            CALL histdef2d(iff,o_swtoacf_zero)
+            CALL histdef2d(iff,o_swsrfcf_zero)
+      ENDIF
+    ENDIF
+
+    IF (ok_aie) THEN
+      CALL histdef2d(iff,o_topswai)
+      CALL histdef2d(iff,o_solswai)
+                  !Cloud droplet number concentration
+      CALL histdef3d(iff,o_scdnc)
+      CALL histdef2d(iff,o_cldncl)
+      CALL histdef3d(iff,o_reffclws)
+      CALL histdef3d(iff,o_reffclwc)
+      CALL histdef2d(iff,o_cldnvi)
+      CALL histdef3d(iff,o_lcc3d)
+      CALL histdef3d(iff,o_lcc3dcon)
+      CALL histdef3d(iff,o_lcc3dstra)
+      CALL histdef2d(iff,o_lcc)
+      CALL histdef2d(iff,o_reffclwtop)
+    ENDIF
+    CALL histdef2d(iff,o_alb1)
+    CALL histdef2d(iff,o_alb2)
+    CALL histdef2d(iff,o_cdrm)
+    CALL histdef2d(iff,o_cdrh)
+    CALL histdef2d(iff,o_cldl)
+    CALL histdef2d(iff,o_cldm)
+    CALL histdef2d(iff,o_cldh)
+    CALL histdef2d(iff,o_cldt)
+    CALL histdef2d(iff,o_cldq)
+    CALL histdef2d(iff,o_lwp)
+    CALL histdef2d(iff,o_iwp)
+    CALL histdef2d(iff,o_ue)
+    CALL histdef2d(iff,o_ve)
+    CALL histdef2d(iff,o_uq)
+    CALL histdef2d(iff,o_vq)
+
+    IF(iflag_con.GE.3) THEN ! sb
+      CALL histdef2d(iff,o_cape)
+      CALL histdef2d(iff,o_pbase)
+      CALL histdef2d(iff,o_ptop)
+      CALL histdef2d(iff,o_fbase)
+      IF (iflag_con /= 30) THEN
+            CALL histdef2d(iff,o_plcl)
+            CALL histdef2d(iff,o_plfc)
+            CALL histdef2d(iff,o_wbeff)
+      ENDIF
+      CALL histdef2d(iff,o_cape_max)
+      CALL histdef3d(iff,o_upwd)
+      CALL histdef3d(iff,o_Ma)
+      CALL histdef3d(iff,o_dnwd)
+      CALL histdef3d(iff,o_dnwd0)
+      CALL histdef3d(iff,o_mc)
+      CALL histdef2d(iff,o_ftime_con)
+    ENDIF !iflag_con .GE. 3
+    CALL histdef2d(iff,o_prw)
+    CALL histdef2d(iff,o_s_pblh)
+    CALL histdef2d(iff,o_s_pblt)
+    CALL histdef2d(iff,o_s_lcl)
+    CALL histdef2d(iff,o_s_therm)
           !IM : Les champs suivants (s_oliqCL, s_cteiCL, s_trmb1, s_trmb2, s_trmb3) ne sont pas definis dans HBTM.F
-          !CALL histdef2d(iff,clef_stations(iff), &
+          !CALL histdef2d(iff, &
           !o_s_capCL%flag,o_s_capCL%name, "Conv avlbl pot enerfor ABL", "J/m2" )
-          !CALL histdef2d(iff,clef_stations(iff), &
+          !CALL histdef2d(iff, &
           !o_s_oliqCL%flag,o_s_oliqCL%name, "Liq Water in BL", "kg/m2")
-          !CALL histdef2d(iff,clef_stations(iff), &
+          !CALL histdef2d(iff, &
           !o_s_cteiCL%flag,o_s_cteiCL%name, "Instability criteria(ABL)", "K")
-          !CALL histdef2d(iff,clef_stations(iff), &
+          !CALL histdef2d(iff, &
           !o_s_trmb1%flag,o_s_trmb1%name, "deep_cape(HBTM2)", "J/m2")
-          !CALL histdef2d(iff,clef_stations(iff), &
+          !CALL histdef2d(iff, &
           !o_s_trmb2%flag,o_s_trmb2%name, "inhibition (HBTM2)", "J/m2")
-          !CALL histdef2d(iff,clef_stations(iff), &
+          !CALL histdef2d(iff, &
           !o_s_trmb3%flag,o_s_trmb3%name, "Point Omega (HBTM2)", "m")
 
           ! Champs interpolles sur des niveaux de pression
 
-          type_ecri(1) = 'inst(X)'
-          type_ecri(2) = 'inst(X)'
-          type_ecri(3) = 'inst(X)'
-          type_ecri(4) = 'inst(X)'
-          type_ecri(5) = 'inst(X)'
-          type_ecri(6) = 'inst(X)'
-
           ! Attention a reverifier
 
-          ilev=0        
-          DO k=1, nlevSTD
-             bb2=clevSTD(k)
-             IF(bb2.EQ."850".OR.bb2.EQ."700".OR.bb2.EQ."500".OR.bb2.EQ."200" &
+    ilev=0        
+    DO k=1, nlevSTD
+      bb2=clevSTD(k)
+      IF(bb2.EQ."850".OR.bb2.EQ."700".OR.bb2.EQ."500".OR.bb2.EQ."200" &
                   .OR.bb2.EQ."100".OR.bb2.EQ."50".OR.bb2.EQ."10")THEN
-                ilev=ilev+1
-                !     print*,'ilev k bb2 flag name ',ilev,k, bb2,o_uSTDlevs(ilev)%flag,o_uSTDlevs(ilev)%name
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_uSTDlevs(ilev)%flag,o_uSTDlevs(ilev)%name,"Zonal wind "//bb2//"hPa", "m/s")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_vSTDlevs(ilev)%flag,o_vSTDlevs(ilev)%name,"Meridional wind "//bb2//"hPa", "m/s")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_wSTDlevs(ilev)%flag,o_wSTDlevs(ilev)%name,"Vertical wind "//bb2//"hPa", "Pa/s")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_zSTDlevs(ilev)%flag,o_zSTDlevs(ilev)%name,"Geopotential height "//bb2//"hPa", "m")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_qSTDlevs(ilev)%flag,o_qSTDlevs(ilev)%name,"Specific humidity "//bb2//"hPa", "kg/kg" )
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_tSTDlevs(ilev)%flag,o_tSTDlevs(ilev)%name,"Temperature "//bb2//"hPa", "K")
-             ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR."500".OR.bb2.EQ."200".OR.bb2.EQ."50".OR.bb2.EQ."10")
-          ENDDO
-          type_ecri(:) = type_ecri_files(:)
-
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_t_oce_sic%flag,o_t_oce_sic%name, "Temp mixte oce-sic", "K")
-
-          IF (type_ocean=='slab') & 
-               CALL histdef2d(iff,clef_stations(iff), &
-               o_slab_bils%flag, o_slab_bils%name,"Bilan au sol sur ocean slab", "W/m2")
-
-          ! Couplage conv-CL
-          IF (iflag_con.GE.3) THEN
-             IF (iflag_coupl>=1) THEN
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_ale_bl%flag,o_ale_bl%name, "ALE BL", "m2/s2") 
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_alp_bl%flag,o_alp_bl%name, "ALP BL", "m2/s2") 
-             ENDIF
-          ENDIF !(iflag_con.GE.3)
-
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_weakinv%flag,o_weakinv%name, "Weak inversion", "-")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_dthmin%flag,o_dthmin%name, "dTheta mini", "K/m")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_rh2m%flag,o_rh2m%name, "Relative humidity at 2m", "%" )
-
-          IF (.NOT.clef_stations(iff)) THEN 
-             !
-             !IM: there is no way to have one single value in a netcdf file
-             !
-             type_ecri(1) = 't_min(X)'
-             type_ecri(2) = 't_min(X)'
-             type_ecri(3) = 't_min(X)'
-             type_ecri(4) = 't_min(X)'
-             type_ecri(5) = 't_min(X)'
-             type_ecri(6) = 't_min(X)'
-             CALL histdef2d(iff,clef_stations(iff),o_rh2m_min%flag,o_rh2m_min%name, "Min Relative humidity at 2m", "%" )
-             type_ecri(1) = 't_max(X)'
-             type_ecri(2) = 't_max(X)'
-             type_ecri(3) = 't_max(X)'
-             type_ecri(4) = 't_max(X)'
-             type_ecri(5) = 't_max(X)'
-             type_ecri(6) = 't_max(X)'
-             CALL histdef2d(iff,clef_stations(iff),o_rh2m_max%flag,o_rh2m_max%name, "Max Relative humidity at 2m", "%" )
-          ENDIF
-
-          type_ecri(:) = type_ecri_files(:)
-          CALL histdef2d(iff,clef_stations(iff),o_qsat2m%flag,o_qsat2m%name, "Saturant humidity at 2m", "%")
-          CALL histdef2d(iff,clef_stations(iff),o_tpot%flag,o_tpot%name, "Surface air potential temperature", "K")
-          CALL histdef2d(iff,clef_stations(iff), &
-               o_tpote%flag,o_tpote%name, "Surface air equivalent potential temperature", "K")
-          CALL histdef2d(iff,clef_stations(iff),o_SWnetOR%flag,o_SWnetOR%name, "Sfce net SW radiation OR", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_SWdownOR%flag,o_SWdownOR%name, "Sfce incident SW radiation OR", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_LWdownOR%flag,o_LWdownOR%name, "Sfce incident LW radiation OR", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_snowl%flag,o_snowl%name, "Solid Large-scale Precip.", "kg/(m2*s)")
-
-          CALL histdef2d(iff,clef_stations(iff),o_solldown%flag,o_solldown%name, "Down. IR rad. at surface", "W/m2")
-          CALL histdef2d(iff,clef_stations(iff),o_dtsvdfo%flag,o_dtsvdfo%name, "Boundary-layer dTs(o)", "K/s")
-          CALL histdef2d(iff,clef_stations(iff),o_dtsvdft%flag,o_dtsvdft%name, "Boundary-layer dTs(t)", "K/s")
-          CALL histdef2d(iff,clef_stations(iff),o_dtsvdfg%flag,o_dtsvdfg%name, "Boundary-layer dTs(g)", "K/s")
-          CALL histdef2d(iff,clef_stations(iff),o_dtsvdfi%flag,o_dtsvdfi%name, "Boundary-layer dTs(g)", "K/s")
-          CALL histdef2d(iff,clef_stations(iff),o_rugs%flag,o_rugs%name, "rugosity", "-" )
+            ilev=ilev+1
+            !     print*,'ilev k bb2 flag name ',ilev,k, bb2,o_uSTDlevs(ilev)%flag,o_uSTDlevs(ilev)%name
+            CALL histdef2d(iff,o_uSTDlevs(ilev))
+            CALL histdef2d(iff,o_vSTDlevs(ilev))
+            CALL histdef2d(iff,o_wSTDlevs(ilev))
+            CALL histdef2d(iff,o_zSTDlevs(ilev))
+            CALL histdef2d(iff,o_qSTDlevs(ilev))
+            CALL histdef2d(iff,o_tSTDlevs(ilev))
+      ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR."500".OR.bb2.EQ."200".OR.bb2.EQ."50".OR.bb2.EQ."10")
+    ENDDO
+
+    CALL histdef2d(iff,o_t_oce_sic)
+
+    IF (type_ocean=='slab') THEN
+      CALL histdef2d(iff,o_slab_bils)
+    ENDIF
+
+    ! Couplage conv-CL
+    IF (iflag_con.GE.3) THEN
+      IF (iflag_coupl>=1) THEN
+            CALL histdef2d(iff,o_ale_bl)
+            CALL histdef2d(iff,o_alp_bl)
+      ENDIF
+    ENDIF !(iflag_con.GE.3)
+
+    CALL histdef2d(iff,o_weakinv)
+    CALL histdef2d(iff,o_dthmin)
+
+    CALL histdef2d(iff,o_rh2m)
+    CALL histdef2d(iff,o_rh2m_min)
+    CALL histdef2d(iff,o_rh2m_max)
+
+    CALL histdef2d(iff,o_qsat2m)
+    CALL histdef2d(iff,o_tpot)
+    CALL histdef2d(iff,o_tpote)
+    CALL histdef2d(iff,o_SWnetOR)
+    CALL histdef2d(iff,o_SWdownOR)
+    CALL histdef2d(iff,o_LWdownOR)
+    CALL histdef2d(iff,o_snowl)
+    CALL histdef2d(iff,o_solldown)
+    CALL histdef2d(iff,o_dtsvdfo)
+    CALL histdef2d(iff,o_dtsvdft)
+    CALL histdef2d(iff,o_dtsvdfg)
+    CALL histdef2d(iff,o_dtsvdfi)
+    CALL histdef2d(iff,o_rugs)
 
           ! Champs 3D:
-          CALL histdef3d(iff,clef_stations(iff),o_ec550aer%flag,o_ec550aer%name, "Extinction at 550nm", "m^-1")
-          CALL histdef3d(iff,clef_stations(iff),o_lwcon%flag,o_lwcon%name, "Cloud liquid water content", "kg/kg")
-          CALL histdef3d(iff,clef_stations(iff),o_iwcon%flag,o_iwcon%name, "Cloud ice water content", "kg/kg")
-          CALL histdef3d(iff,clef_stations(iff),o_temp%flag,o_temp%name, "Air temperature", "K" )
-          CALL histdef3d(iff,clef_stations(iff),o_theta%flag,o_theta%name, "Potential air temperature", "K" )
-          CALL histdef3d(iff,clef_stations(iff),o_ovap%flag,o_ovap%name, "Specific humidity", "kg/kg" )
-          CALL histdef3d(iff,clef_stations(iff),o_oliq%flag,o_oliq%name, "Condensed water", "kg/kg" )
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_ovapinit%flag,o_ovapinit%name, "Specific humidity (begin of timestep)", "kg/kg" )
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_geop%flag,o_geop%name, "Geopotential height", "m2/s2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_vitu%flag,o_vitu%name, "Zonal wind", "m/s" )
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_vitv%flag,o_vitv%name, "Meridional wind", "m/s" )
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_vitw%flag,o_vitw%name, "Vertical wind", "Pa/s" )
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_pres%flag,o_pres%name, "Air pressure", "Pa" )
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_paprs%flag,o_paprs%name, "Air pressure Inter-Couches", "Pa" )
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_mass%flag,o_mass%name, "Masse Couches", "kg/m2" )
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_zfull%flag,o_zfull%name, "Altitude of full pressure levels", "m" )
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_zhalf%flag,o_zhalf%name, "Altitude of half pressure levels", "m" )
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rneb%flag,o_rneb%name, "Cloud fraction", "-")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rnebcon%flag,o_rnebcon%name, "Convective Cloud Fraction", "-")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rnebls%flag,o_rnebls%name, "LS Cloud fraction", "-")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rhum%flag,o_rhum%name, "Relative humidity", "-")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_ozone%flag,o_ozone%name, "Ozone mole fraction", "-")
-          if (read_climoz == 2) &
-               CALL histdef3d(iff,clef_stations(iff), &
-               o_ozone_light%flag,o_ozone_light%name, &
-               "Daylight ozone mole fraction", "-")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dtphy%flag,o_dtphy%name, "Physics dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dqphy%flag,o_dqphy%name, "Physics dQ", "(kg/kg)/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_cldtau%flag,o_cldtau%name, "Cloud optical thickness", "1")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_cldemi%flag,o_cldemi%name, "Cloud optical emissivity", "1")
-          !IM: bug ?? dimensionnement variables (klon,klev+1) pmflxr, pmflxs, prfl, psfl
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_pr_con_l%flag,o_pr_con_l%name, "Convective precipitation lic", " ")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_pr_con_i%flag,o_pr_con_i%name, "Convective precipitation ice", " ")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_pr_lsc_l%flag,o_pr_lsc_l%name, "Large scale precipitation lic", " ")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_pr_lsc_i%flag,o_pr_lsc_i%name, "Large scale precipitation ice", " ")
-          !Cloud droplet effective radius
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_re%flag,o_re%name, "Cloud droplet effective radius","um")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_fl%flag,o_fl%name, "Denominator of Cloud droplet effective radius"," ")
-          !FH Sorties pour la couche limite
-          if (iflag_pbl>1) then
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_tke%flag,o_tke%name, "TKE", "m2/s2")
-             IF (.NOT.clef_stations(iff)) THEN 
-                !
-                !IM: there is no way to have one single value in a netcdf file
-                !
-                type_ecri(1) = 't_max(X)'
-                type_ecri(2) = 't_max(X)'
-                type_ecri(3) = 't_max(X)'
-                type_ecri(4) = 't_max(X)'
-                type_ecri(5) = 't_max(X)'
-                type_ecri(6) = 't_max(X)'
-                CALL histdef3d(iff,clef_stations(iff), &
-                     o_tke_max%flag,o_tke_max%name, "TKE max", "m2/s2")
-             ENDIF
-             type_ecri(:) = type_ecri_files(:)
-          endif
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_kz%flag,o_kz%name, "Kz melange", "m2/s")
-          IF (.NOT.clef_stations(iff)) THEN 
-             !
-             !IM: there is no way to have one single value in a netcdf file
-             !
-             type_ecri(1) = 't_max(X)'
-             type_ecri(2) = 't_max(X)'
-             type_ecri(3) = 't_max(X)'
-             type_ecri(4) = 't_max(X)'
-             type_ecri(5) = 't_max(X)'
-             type_ecri(6) = 't_max(X)'
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_kz_max%flag,o_kz_max%name, "Kz melange max", "m2/s" )
-          ENDIF
-          type_ecri(:) = type_ecri_files(:)
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_clwcon%flag,o_clwcon%name, "Convective Cloud Liquid water content", "kg/kg") 
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dtdyn%flag,o_dtdyn%name, "Dynamics dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dqdyn%flag,o_dqdyn%name, "Dynamics dQ", "(kg/kg)/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dudyn%flag,o_dudyn%name, "Dynamics dU", "m/s2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dvdyn%flag,o_dvdyn%name, "Dynamics dV", "m/s2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dtcon%flag,o_dtcon%name, "Convection dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_ducon%flag,o_ducon%name, "Convection du", "m/s2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dvcon%flag,o_dvcon%name, "Convection dv", "m/s2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dqcon%flag,o_dqcon%name, "Convection dQ", "(kg/kg)/s")
-
-          ! Wakes
-          IF(iflag_con.EQ.3) THEN
-             IF (iflag_wake >= 1) THEN
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_ale_wk%flag,o_ale_wk%name, "ALE WK", "m2/s2")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_alp_wk%flag,o_alp_wk%name, "ALP WK", "m2/s2")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_ale%flag,o_ale%name, "ALE", "m2/s2")
-                CALL histdef2d(iff,clef_stations(iff), &
-                     o_alp%flag,o_alp%name, "ALP", "W/m2")
-                CALL histdef2d(iff,clef_stations(iff),o_cin%flag,o_cin%name, "Convective INhibition", "m2/s2")
-                CALL histdef2d(iff,clef_stations(iff),o_wape%flag,o_WAPE%name, "WAPE", "m2/s2")
-                CALL histdef2d(iff,clef_stations(iff),o_wake_h%flag,o_wake_h%name, "wake_h", "-")
-                CALL histdef2d(iff,clef_stations(iff),o_wake_s%flag,o_wake_s%name, "wake_s", "-")
-                CALL histdef3d(iff,clef_stations(iff),o_dtwak%flag,o_dtwak%name, "Wake dT", "K/s")
-                CALL histdef3d(iff,clef_stations(iff),o_dqwak%flag,o_dqwak%name, "Wake dQ", "(kg/kg)/s")
-                CALL histdef3d(iff,clef_stations(iff),o_wake_deltat%flag,o_wake_deltat%name, "wake_deltat", " ")
-                CALL histdef3d(iff,clef_stations(iff),o_wake_deltaq%flag,o_wake_deltaq%name, "wake_deltaq", " ")
-                CALL histdef3d(iff,clef_stations(iff),o_wake_omg%flag,o_wake_omg%name, "wake_omg", " ")
-             ENDIF
-!!! RomP             CALL histdef3d(iff,clef_stations(iff),o_Vprecip%flag,o_Vprecip%name, "precipitation vertical profile", "-")
-             CALL histdef3d(iff,clef_stations(iff),o_ftd%flag,o_ftd%name, "tend temp due aux descentes precip", "-")
-             CALL histdef3d(iff,clef_stations(iff),o_fqd%flag,o_fqd%name,"tend vap eau due aux descentes precip", "-")
-          ENDIF !(iflag_con.EQ.3)
-
-          IF(iflag_con.GE.3) THEN   !  RomP >>>
-            CALL histdef3d(iff,clef_stations(iff),o_wdtrainA%flag,o_wdtrainA%name, "precipitation from AA", "-")
-            CALL histdef3d(iff,clef_stations(iff),o_wdtrainM%flag,o_wdtrainM%name, "precipitation from mixture", "-")
-            CALL histdef3d(iff,clef_stations(iff),o_Vprecip%flag,o_Vprecip%name, "precipitation vertical profile", "-")
-          ENDIF !(iflag_con.GE.3)   ! <<< RomP
+    CALL histdef3d(iff,o_ec550aer)
+    CALL histdef3d(iff,o_lwcon)
+    CALL histdef3d(iff,o_iwcon)
+    CALL histdef3d(iff,o_temp)
+    CALL histdef3d(iff,o_theta)
+    CALL histdef3d(iff,o_ovap)
+    CALL histdef3d(iff,o_oliq)
+    CALL histdef3d(iff,o_ovapinit)
+    CALL histdef3d(iff,o_geop)
+    CALL histdef3d(iff,o_vitu)
+    CALL histdef3d(iff,o_vitv)
+    CALL histdef3d(iff,o_vitw)
+    CALL histdef3d(iff,o_pres)
+    CALL histdef3d(iff,o_paprs)
+    CALL histdef3d(iff,o_mass)
+    CALL histdef3d(iff,o_zfull)
+    CALL histdef3d(iff,o_zhalf)
+    CALL histdef3d(iff,o_rneb)
+    CALL histdef3d(iff,o_rnebcon)
+    CALL histdef3d(iff,o_rnebls)
+    CALL histdef3d(iff,o_rhum)
+    CALL histdef3d(iff,o_ozone)
+
+    IF (read_climoz == 2) THEN
+      CALL histdef3d(iff,o_ozone_light)
+    END IF
+
+    CALL histdef3d(iff,o_dtphy)
+    CALL histdef3d(iff,o_dqphy)
+    CALL histdef3d(iff,o_cldtau)
+    CALL histdef3d(iff,o_cldemi)
+!IM: bug ?? dimensionnement variables (klon,klev+1) pmflxr, pmflxs, prfl, psfl
+    CALL histdef3d(iff,o_pr_con_l)
+    CALL histdef3d(iff,o_pr_con_i)
+    CALL histdef3d(iff,o_pr_lsc_l)
+    CALL histdef3d(iff,o_pr_lsc_i)
+!Cloud droplet effective radius
+    CALL histdef3d(iff,o_re)
+    CALL histdef3d(iff,o_fl)
+!FH Sorties pour la couche limite
+    IF (iflag_pbl>1) THEN
+      CALL histdef3d(iff,o_tke)
+      CALL histdef3d(iff,o_tke_max)
+    ENDIF
+    CALL histdef3d(iff,o_kz)
+    CALL histdef3d(iff,o_kz_max)
+    CALL histdef3d(iff,o_clwcon)
+    CALL histdef3d(iff,o_dtdyn)
+    CALL histdef3d(iff,o_dqdyn)
+    CALL histdef3d(iff,o_dudyn)
+    CALL histdef3d(iff,o_dvdyn)
+    CALL histdef3d(iff,o_dtcon)
+    CALL histdef3d(iff,o_ducon)
+    CALL histdef3d(iff,o_dvcon)
+    CALL histdef3d(iff,o_dqcon)
+
+! Wakes
+    IF(iflag_con.EQ.3) THEN
+      IF (iflag_wake >= 1) THEN
+            CALL histdef2d(iff,o_ale_wk)
+            CALL histdef2d(iff,o_alp_wk)
+            CALL histdef2d(iff,o_ale)
+            CALL histdef2d(iff,o_alp)
+            CALL histdef2d(iff,o_cin)
+            CALL histdef2d(iff,o_wape)
+            CALL histdef2d(iff,o_wake_h)
+            CALL histdef2d(iff,o_wake_s)
+            CALL histdef3d(iff,o_dtwak)
+            CALL histdef3d(iff,o_dqwak)
+            CALL histdef3d(iff,o_wake_deltat)
+            CALL histdef3d(iff,o_wake_deltaq)
+            CALL histdef3d(iff,o_wake_omg)
+      ENDIF
+!!! RomP             CALL histdef3d(iff,o_Vprecip%flag,o_Vprecip%name, "precipitation vertical profile", "-")
+      CALL histdef3d(iff,o_ftd)
+      CALL histdef3d(iff,o_fqd)
+    ENDIF !(iflag_con.EQ.3)
+
+    IF(iflag_con.GE.3) THEN   !  RomP >>>
+      CALL histdef3d(iff,o_wdtrainA)
+      CALL histdef3d(iff,o_wdtrainM)
+      CALL histdef3d(iff,o_Vprecip)
+    ENDIF !(iflag_con.GE.3)   ! <<< RomP
 
 !!! nrlmd le 10/04/2012
 
-        IF (iflag_trig_bl>=1) THEN
- CALL histdef2d(iff,clef_stations(iff),o_n2%flag,o_n2%name, "Nombre de panaches de type 2", " ")
- CALL histdef2d(iff,clef_stations(iff),o_s2%flag,o_s2%name, "Surface moyenne des panaches de type 2", "m2")
-
- CALL histdef2d(iff,clef_stations(iff),o_proba_notrig%flag,o_proba_notrig%name, "Probabilité de non-déclenchement", " ")
- CALL histdef2d(iff,clef_stations(iff),o_random_notrig%flag,o_random_notrig%name, "Tirage aléatoire de non-déclenchement", " ")
- CALL histdef2d(iff,clef_stations(iff),o_ale_bl_trig%flag,o_ale_bl_trig%name, "ALE_BL_STAT + Condition P>Pseuil", "m2/s2")
- CALL histdef2d(iff,clef_stations(iff),o_ale_bl_stat%flag,o_ale_bl_stat%name, "ALE_BL_STAT", "m2/s2")
-       ENDIF  !(iflag_trig_bl>=1)
-
-        IF (iflag_clos_bl>=1) THEN
- CALL histdef2d(iff,clef_stations(iff),o_alp_bl_det%flag,o_alp_bl_det%name, "ALP_BL_DET", "W/m2")
- CALL histdef2d(iff,clef_stations(iff),o_alp_bl_fluct_m%flag,o_alp_bl_fluct_m%name, "ALP_BL_FLUCT_M", "W/m2")
- CALL histdef2d(iff,clef_stations(iff),o_alp_bl_fluct_tke%flag,o_alp_bl_fluct_tke%name, "ALP_BL_FLUCT_TKE", "W/m2")
- CALL histdef2d(iff,clef_stations(iff),o_alp_bl_conv%flag,o_alp_bl_conv%name, "ALP_BL_CONV", "W/m2")
- CALL histdef2d(iff,clef_stations(iff),o_alp_bl_stat%flag,o_alp_bl_stat%name, "ALP_BL_STAT", "W/m2")
-       ENDIF  !(iflag_clos_bl>=1)
+    IF (iflag_trig_bl>=1) THEN
+      CALL histdef2d(iff,o_n2)
+      CALL histdef2d(iff,o_s2)
+      CALL histdef2d(iff,o_proba_notrig)
+      CALL histdef2d(iff,o_random_notrig)
+      CALL histdef2d(iff,o_ale_bl_trig)
+      CALL histdef2d(iff,o_ale_bl_stat)
+    ENDIF  !(iflag_trig_bl>=1)
+
+    IF (iflag_clos_bl>=1) THEN
+      CALL histdef2d(iff,o_alp_bl_det)
+      CALL histdef2d(iff,o_alp_bl_fluct_m)
+      CALL histdef2d(iff,o_alp_bl_fluct_tke)
+      CALL histdef2d(iff,o_alp_bl_conv)
+      CALL histdef2d(iff,o_alp_bl_stat)
+    ENDIF  !(iflag_clos_bl>=1)
 
 !!! fin nrlmd le 10/04/2012
-
-          CALL histdef3d(iff,clef_stations(iff),o_dtlsc%flag,o_dtlsc%name, "Condensation dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff),o_dtlschr%flag,o_dtlschr%name,"Large-scale condensational heating rate","K/s")
-          CALL histdef3d(iff,clef_stations(iff),o_dqlsc%flag,o_dqlsc%name, "Condensation dQ", "(kg/kg)/s")
-          CALL histdef3d(iff,clef_stations(iff),o_beta_prec%flag,o_beta_prec%name, "LS Conversion rate to prec", "(kg/kg)/s")
-          CALL histdef3d(iff,clef_stations(iff),o_dtvdf%flag,o_dtvdf%name, "Boundary-layer dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff),o_dqvdf%flag,o_dqvdf%name, "Boundary-layer dQ", "(kg/kg)/s") 
-          CALL histdef3d(iff,clef_stations(iff),o_dteva%flag,o_dteva%name, "Reevaporation dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff),o_dqeva%flag,o_dqeva%name, "Reevaporation dQ", "(kg/kg)/s")
-          CALL histdef3d(iff,clef_stations(iff),o_ptconv%flag,o_ptconv%name, "POINTS CONVECTIFS", " ")
-          CALL histdef3d(iff,clef_stations(iff),o_ratqs%flag,o_ratqs%name, "RATQS", " ")
-          CALL histdef3d(iff,clef_stations(iff),o_dtthe%flag,o_dtthe%name, "Thermal dT", "K/s")
-
-          if(iflag_thermals.ge.1) THEN
-             CALL histdef3d(iff,clef_stations(iff),o_dqlscth%flag,o_dqlscth%name, "dQ therm.", "(kg/kg)/s")
-             CALL histdef3d(iff,clef_stations(iff),o_dqlscst%flag,o_dqlscst%name, "dQ strat.", "(kg/kg)/s")
-             CALL histdef3d(iff,clef_stations(iff),o_dtlscth%flag,o_dtlscth%name, "dQ therm.", "K/s")
-             CALL histdef3d(iff,clef_stations(iff),o_dtlscst%flag,o_dtlscst%name, "dQ strat.", "K/s")
-             CALL histdef2d(iff,clef_stations(iff),o_plulth%flag,o_plulth%name, "Rainfall therm.", "K/s")
-             CALL histdef2d(iff,clef_stations(iff),o_plulst%flag,o_plulst%name, "Rainfall strat.", "K/s")
-             CALL histdef2d(iff,clef_stations(iff),o_lmaxth%flag,o_lmaxth%name, "Upper level thermals", "")
-             CALL histdef3d(iff,clef_stations(iff),o_ptconvth%flag,o_ptconvth%name, "POINTS CONVECTIFS therm.", " ")
-             CALL histdef3d(iff,clef_stations(iff),o_f_th%flag,o_f_th%name, "Thermal plume mass flux", "kg/(m2*s)")
-             CALL histdef3d(iff,clef_stations(iff),o_e_th%flag,o_e_th%name,"Thermal plume entrainment","K/s")
-             CALL histdef3d(iff,clef_stations(iff),o_w_th%flag,o_w_th%name,"Thermal plume vertical velocity","m/s")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_ftime_th%flag,o_ftime_th%name,"Fraction of time Shallow convection occurs"," ")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_q_th%flag,o_q_th%name, "Thermal plume total humidity", "kg/kg")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_a_th%flag,o_a_th%name, "Thermal plume fraction", "")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_d_th%flag,o_d_th%name, "Thermal plume detrainment", "K/s")
-
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_f0_th%flag,o_f0_th%name, "Thermal closure mass flux", "K/s")
-             CALL histdef2d(iff,clef_stations(iff), &
-                  o_zmax_th%flag,o_zmax_th%name, "Thermal plume height", "K/s")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_dqthe%flag,o_dqthe%name, "Thermal dQ", "(kg/kg)/s")
-          endif !iflag_thermals.ge.1
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dtajs%flag,o_dtajs%name, "Dry adjust. dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dqajs%flag,o_dqajs%name, "Dry adjust. dQ", "(kg/kg)/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dtswr%flag,o_dtswr%name, "SW radiation dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dtsw0%flag,o_dtsw0%name, "CS SW radiation dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dtlwr%flag,o_dtlwr%name, "LW radiation dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dtlw0%flag,o_dtlw0%name, "CS LW radiation dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dtec%flag,o_dtec%name, "Cinetic dissip dT", "K/s")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_duvdf%flag,o_duvdf%name, "Boundary-layer dU", "m/s2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dvvdf%flag,o_dvvdf%name, "Boundary-layer dV", "m/s2")
-
-          IF (ok_orodr) THEN
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_duoro%flag,o_duoro%name, "Orography dU", "m/s2")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_dvoro%flag,o_dvoro%name, "Orography dV", "m/s2")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_dtoro%flag,o_dtoro%name, "Orography dT", "K/s")
-          ENDIF
-
-          IF (ok_orolf) THEN
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_dulif%flag,o_dulif%name, "Orography dU", "m/s2")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_dvlif%flag,o_dvlif%name, "Orography dV", "m/s2")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_dtlif%flag,o_dtlif%name, "Orography dT", "K/s")
-          ENDIF
-
-          IF (ok_hines) then
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_duhin%flag,o_duhin%name, "Hines GWD dU", "m/s2")
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_dvhin%flag,o_dvhin%name, "Hines GWD dV", "m/s2")
-
-             CALL histdef3d(iff,clef_stations(iff), &
-                  o_dthin%flag,o_dthin%name, "Hines GWD dT", "K/s")
-          ENDIF
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rsu%flag,o_rsu%name, "SW upward radiation", "W m-2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rsd%flag,o_rsd%name, "SW downward radiation", "W m-2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rlu%flag,o_rlu%name, "LW upward radiation", "W m-2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rld%flag,o_rld%name, "LW downward radiation", "W m-2")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rsucs%flag,o_rsucs%name, "SW CS upward radiation", "W m-2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rsdcs%flag,o_rsdcs%name, "SW CS downward radiation", "W m-2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rlucs%flag,o_rlucs%name, "LW CS upward radiation", "W m-2")
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_rldcs%flag,o_rldcs%name, "LW CS downward radiation", "W m-2")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_tnt%flag,o_tnt%name, "Tendency of air temperature", "K s-1")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_tntc%flag,o_tntc%name, "Tendency of air temperature due to Moist Convection", &
-               "K s-1")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_tntr%flag,o_tntr%name, "Air temperature tendency due to Radiative heating", &
-               "K s-1")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_tntscpbl%flag,o_tntscpbl%name, "Air temperature tendency due to St cloud and precipitation and BL mixing", &
-               "K s-1")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_tnhus%flag,o_tnhus%name, "Tendency of specific humidity", "s-1")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_tnhusc%flag,o_tnhusc%name, "Tendency of specific humidity due to convection", "s-1")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_tnhusscpbl%flag,o_tnhusscpbl%name, "Tendency of Specific humidity due to ST cl, precip and BL mixing", &
-               "s-1")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_evu%flag,o_evu%name, "Eddy viscosity coefficient for Momentum Variables", "m2 s-1")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_h2o%flag,o_h2o%name, "Mass Fraction of Water", "1")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_mcd%flag,o_mcd%name, "Downdraft COnvective Mass Flux", "kg/(m2*s)")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_dmc%flag,o_dmc%name, "Deep COnvective Mass Flux", "kg/(m2*s)")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_ref_liq%flag,o_ref_liq%name, "Effective radius of convective cloud liquid water particle", "m")
-
-          CALL histdef3d(iff,clef_stations(iff), &
-               o_ref_ice%flag,o_ref_ice%name, "Effective radius of startiform cloud ice particle", "m")
-
-          if (RCO2_per.NE.RCO2_act.OR.RCH4_per.NE.RCH4_act.OR. &
+    CALL histdef3d(iff,o_dtlsc)
+    CALL histdef3d(iff,o_dtlschr)
+    CALL histdef3d(iff,o_dqlsc)
+    CALL histdef3d(iff,o_beta_prec)
+    CALL histdef3d(iff,o_dtvdf)
+    CALL histdef3d(iff,o_dtdis)
+    CALL histdef3d(iff,o_dqvdf)
+    CALL histdef3d(iff,o_dteva)
+    CALL histdef3d(iff,o_dqeva)
+    CALL histdef3d(iff,o_ptconv)
+    CALL histdef3d(iff,o_ratqs)
+    CALL histdef3d(iff,o_dtthe)
+
+    IF (iflag_thermals.ge.1) THEN
+      CALL histdef3d(iff,o_dqlscth)
+      CALL histdef3d(iff,o_dqlscst)
+      CALL histdef3d(iff,o_dtlscth)
+      CALL histdef3d(iff,o_dtlscst)
+      CALL histdef2d(iff,o_plulth)
+      CALL histdef2d(iff,o_plulst)
+      CALL histdef2d(iff,o_lmaxth)
+      CALL histdef3d(iff,o_ptconvth)
+      CALL histdef3d(iff,o_f_th)
+      CALL histdef3d(iff,o_e_th)
+      CALL histdef3d(iff,o_w_th)
+      CALL histdef3d(iff,o_lambda_th)
+      CALL histdef2d(iff,o_ftime_th)
+      CALL histdef3d(iff,o_q_th)
+      CALL histdef3d(iff,o_a_th)
+      CALL histdef3d(iff,o_d_th)
+      CALL histdef2d(iff,o_f0_th)
+      CALL histdef2d(iff,o_zmax_th)
+      CALL histdef3d(iff,o_dqthe)
+    ENDIF !iflag_thermals.ge.1
+
+    CALL histdef3d(iff,o_dtajs)
+    CALL histdef3d(iff,o_dqajs)
+    CALL histdef3d(iff,o_dtswr)
+    CALL histdef3d(iff,o_dtsw0)
+    CALL histdef3d(iff,o_dtlwr)
+    CALL histdef3d(iff,o_dtlw0)
+    CALL histdef3d(iff,o_dtec)
+    CALL histdef3d(iff,o_duvdf)
+    CALL histdef3d(iff,o_dvvdf)
+
+    IF (ok_orodr) THEN
+      CALL histdef3d(iff,o_duoro)
+      CALL histdef3d(iff,o_dvoro)
+      CALL histdef3d(iff,o_dtoro)
+    ENDIF
+
+    IF (ok_orolf) THEN
+      CALL histdef3d(iff,o_dulif)
+      CALL histdef3d(iff,o_dvlif)
+      CALL histdef3d(iff,o_dtlif)
+    ENDIF
+
+    IF (ok_hines) then
+      CALL histdef3d(iff,o_duhin)
+      CALL histdef3d(iff,o_dvhin)
+      CALL histdef3d(iff,o_dthin)
+    ENDIF
+
+    CALL histdef3d(iff,o_rsu)
+    CALL histdef3d(iff,o_rsd)
+    CALL histdef3d(iff,o_rlu)
+    CALL histdef3d(iff,o_rld)
+    CALL histdef3d(iff,o_rsucs)
+    CALL histdef3d(iff,o_rsdcs)
+    CALL histdef3d(iff,o_rlucs)
+    CALL histdef3d(iff,o_rldcs)
+    CALL histdef3d(iff,o_tnt)
+    CALL histdef3d(iff,o_tntc)
+    CALL histdef3d(iff,o_tntr)
+    CALL histdef3d(iff,o_tntscpbl)
+    CALL histdef3d(iff,o_tnhus)
+    CALL histdef3d(iff,o_tnhusc)
+    CALL histdef3d(iff,o_tnhusscpbl)
+    CALL histdef3d(iff,o_evu)
+    CALL histdef3d(iff,o_h2o)
+    CALL histdef3d(iff,o_mcd)
+    CALL histdef3d(iff,o_dmc)
+    CALL histdef3d(iff,o_ref_liq)
+    CALL histdef3d(iff,o_ref_ice)
+
+    IF (RCO2_per.NE.RCO2_act.OR.RCH4_per.NE.RCH4_act.OR. &
                RN2O_per.NE.RN2O_act.OR.RCFC11_per.NE.RCFC11_act.OR. &
                RCFC12_per.NE.RCFC12_act) THEN
-
-             CALL histdef2d(iff,clef_stations(iff),o_rsut4co2%flag,o_rsut4co2%name, &
-                  "TOA Out SW in 4xCO2 atmosphere", "W/m2") 
-             CALL histdef2d(iff,clef_stations(iff),o_rlut4co2%flag,o_rlut4co2%name, &
-                  "TOA Out LW in 4xCO2 atmosphere", "W/m2") 
-             CALL histdef2d(iff,clef_stations(iff),o_rsutcs4co2%flag,o_rsutcs4co2%name, &
-                  "TOA Out CS SW in 4xCO2 atmosphere", "W/m2") 
-             CALL histdef2d(iff,clef_stations(iff),o_rlutcs4co2%flag,o_rlutcs4co2%name, &
-                  "TOA Out CS LW in 4xCO2 atmosphere", "W/m2") 
-
-             CALL histdef3d(iff,clef_stations(iff),o_rsu4co2%flag,o_rsu4co2%name, &
-                  "Upwelling SW 4xCO2 atmosphere", "W/m2") 
-             CALL histdef3d(iff,clef_stations(iff),o_rlu4co2%flag,o_rlu4co2%name, &
-                  "Upwelling LW 4xCO2 atmosphere", "W/m2") 
-             CALL histdef3d(iff,clef_stations(iff),o_rsucs4co2%flag,o_rsucs4co2%name, &
-                  "Upwelling CS SW 4xCO2 atmosphere", "W/m2") 
-             CALL histdef3d(iff,clef_stations(iff),o_rlucs4co2%flag,o_rlucs4co2%name, &
-                  "Upwelling CS LW 4xCO2 atmosphere", "W/m2") 
-
-             CALL histdef3d(iff,clef_stations(iff),o_rsd4co2%flag,o_rsd4co2%name, &
-                  "Downwelling SW 4xCO2 atmosphere", "W/m2") 
-             CALL histdef3d(iff,clef_stations(iff),o_rld4co2%flag,o_rld4co2%name, &
-                  "Downwelling LW 4xCO2 atmosphere", "W/m2") 
-             CALL histdef3d(iff,clef_stations(iff),o_rsdcs4co2%flag,o_rsdcs4co2%name, &
-                  "Downwelling CS SW 4xCO2 atmosphere", "W/m2") 
-             CALL histdef3d(iff,clef_stations(iff),o_rldcs4co2%flag,o_rldcs4co2%name, &
-                  "Downwelling CS LW 4xCO2 atmosphere", "W/m2") 
-
-          endif
-
-
-          IF (nqtot>=3) THEN
-             DO iq=3,nqtot  
-                iiq=niadv(iq)
-                o_trac(iq-2) = ctrl_out((/ 4, 5, 1, 1, 1, 10 /),tname(iiq))
-                CALL histdef3d (iff,clef_stations(iff), &
-                o_trac(iq-2)%flag,o_trac(iq-2)%name,'Tracer '//ttext(iiq), "-" )
-                o_trac_cum(iq-2) = ctrl_out((/ 3, 4, 10, 10, 10, 10 /),'cum'//tname(iiq))
-                CALL histdef2d (iff,clef_stations(iff), &
-                o_trac_cum(iq-2)%flag,o_trac_cum(iq-2)%name,'Cumulated tracer '//ttext(iiq), "-" )
-             ENDDO
-          ENDIF
-
-          CALL histend(nid_files(iff))
-
-          ndex2d = 0
-          ndex3d = 0
-
-       ENDIF ! clef_files
+      CALL histdef2d(iff,o_rsut4co2)
+      CALL histdef2d(iff,o_rlut4co2)
+      CALL histdef2d(iff,o_rsutcs4co2)
+      CALL histdef2d(iff,o_rlutcs4co2)
+      CALL histdef3d(iff,o_rsu4co2)
+      CALL histdef3d(iff,o_rlu4co2)
+      CALL histdef3d(iff,o_rsucs4co2)
+      CALL histdef3d(iff,o_rlucs4co2)
+      CALL histdef3d(iff,o_rsd4co2)
+      CALL histdef3d(iff,o_rld4co2)
+      CALL histdef3d(iff,o_rsdcs4co2)
+      CALL histdef3d(iff,o_rldcs4co2)
+
+    ENDIF
+
+
+      IF (nqtot>=3) THEN
+            DO iq=3,nqtot  
+            iiq=niadv(iq)
+            o_trac(iq-2) = ctrl_out((/ 4, 5, 1, 1, 1, 10 /),tname(iiq),'Tracer '//ttext(iiq), "-",&
+                  (/ '', '', '', '', '', '' /))
+            CALL histdef3d(iff, o_trac(iq-2))
+            o_trac_cum(iq-2) = ctrl_out((/ 3, 4, 10, 10, 10, 10 /),'cum'//tname(iiq),&
+                  'Cumulated tracer '//ttext(iiq), "-", (/ '', '', '', '', '', '' /))
+            CALL histdef2d(iff, o_trac_cum(iq-2))
+            ENDDO
+      ENDIF
+
+      CALL histend(nid_files(iff))
+
+      ndex2d = 0
+      ndex3d = 0
+
+    ENDIF ! clef_files
 
     ENDDO !  iff
@@ -1824,11 +838,11 @@
     ecrit_ins = ecrit_files(6)
 
-    write(lunout,*)'swaero_diag=',swaero_diag
-    write(lunout,*)'Fin phys_output_mod.F90'
-  end subroutine phys_output_open
-
-  SUBROUTINE histdef2d (iff,lpoint,flag_var,nomvar,titrevar,unitvar)
-
-    use ioipsl
+    WRITE(lunout,*)'swaero_diag=',swaero_diag
+    WRITE(lunout,*)'Fin phys_output_mod.F90'
+  end SUBROUTINE phys_output_open
+
+  SUBROUTINE histdef2d_old (iff,lpoint,flag_var,nomvar,titrevar,unitvar)
+
+    USE ioipsl
     USE dimphy
     USE mod_phys_lmdz_para
@@ -1837,52 +851,51 @@
     IMPLICIT NONE
 
-    include "dimensions.h"
-    include "temps.h"
-    include "indicesol.h"
-    include "clesphys.h"
-
-    integer                          :: iff
-    logical                          :: lpoint
-    integer, dimension(nfiles)       :: flag_var
-    character(len=20)                 :: nomvar
-    character(len=*)                 :: titrevar
-    character(len=*)                 :: unitvar
-
-    real zstophym
-
-    if (type_ecri(iff)=='inst(X)'.OR.type_ecri(iff)=='once') then
+    INCLUDE "dimensions.h"
+    INCLUDE "temps.h"
+    INCLUDE "clesphys.h"
+
+    INTEGER                          :: iff
+    LOGICAL                          :: lpoint
+    INTEGER, DIMENSION(nfiles)       :: flag_var
+    CHARACTER(LEN=20)                 :: nomvar
+    CHARACTER(LEN=*)                 :: titrevar
+    CHARACTER(LEN=*)                 :: unitvar
+
+    REAL zstophym
+
+    IF (type_ecri(iff)=='inst(X)'.OR.type_ecri(iff)=='once') THEN
        zstophym=zoutm(iff)
-    else
+    ELSE
        zstophym=zdtime
-    endif
+    ENDIF
 
     ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
-    call conf_physoutputs(nomvar,flag_var)
-
-    if(.NOT.lpoint) THEN  
-       if ( flag_var(iff)<=lev_files(iff) ) then
-          call histdef (nid_files(iff),nomvar,titrevar,unitvar, &
+    CALL conf_physoutputs(nomvar,flag_var)
+
+    IF(.NOT.lpoint) THEN  
+       IF ( flag_var(iff)<=lev_files(iff) ) THEN
+          CALL histdef (nid_files(iff),nomvar,titrevar,unitvar, &
                iim,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
                type_ecri(iff), zstophym,zoutm(iff))                
-       endif
-    else
-       if ( flag_var(iff)<=lev_files(iff) ) then
-          call histdef (nid_files(iff),nomvar,titrevar,unitvar, &
+       ENDIF
+    ELSE
+       IF ( flag_var(iff)<=lev_files(iff) ) THEN
+          CALL histdef (nid_files(iff),nomvar,titrevar,unitvar, &
                npstn,1,nhorim(iff), 1,1,1, -99, 32, &
                type_ecri(iff), zstophym,zoutm(iff))                
-       endif
-    endif
+       ENDIF
+    ENDIF
 
     ! Set swaero_diag=true if at least one of the concerned variables are defined 
-    if (nomvar=='topswad' .OR. nomvar=='topswai' .OR. nomvar=='solswad' .OR. nomvar=='solswai' ) THEN
-       if  ( flag_var(iff)<=lev_files(iff) ) then
+    IF (nomvar=='topswad' .OR. nomvar=='topswai' .OR. nomvar=='solswad' .OR. nomvar=='solswai' ) THEN
+       IF  ( flag_var(iff)<=lev_files(iff) ) THEN
           swaero_diag=.TRUE.
-       end if
-    end if
-  end subroutine histdef2d
-
-  SUBROUTINE histdef3d (iff,lpoint,flag_var,nomvar,titrevar,unitvar)
-
-    use ioipsl
+       END IF
+    END IF
+  END SUBROUTINE histdef2d_old
+
+  SUBROUTINE histdef2d (iff,var)
+
+    USE ioipsl
     USE dimphy
     USE mod_phys_lmdz_para
@@ -1891,43 +904,167 @@
     IMPLICIT NONE
 
-    include "dimensions.h"
-    include "temps.h"
-    include "indicesol.h"
-    include "clesphys.h"
-
-    integer                          :: iff
-    logical                          :: lpoint
-    integer, dimension(nfiles)       :: flag_var
-    character(len=20)                 :: nomvar
-    character(len=*)                 :: titrevar
-    character(len=*)                 :: unitvar
-
-    real zstophym
+    INCLUDE "dimensions.h"
+    INCLUDE "temps.h"
+    INCLUDE "clesphys.h"
+
+    INTEGER                          :: iff
+    TYPE(ctrl_out)                   :: var
+
+    REAL zstophym
+    CHARACTER(LEN=20) :: typeecrit
+
+    ! ug On récupère le type écrit de la structure:
+    !       Assez moche, à refaire si meilleure méthode...
+    IF (INDEX(var%type_ecrit(iff), "once") > 0) THEN
+       typeecrit = 'once'
+    ELSE IF(INDEX(var%type_ecrit(iff), "t_min") > 0) THEN
+       typeecrit = 't_min(X)'
+    ELSE IF(INDEX(var%type_ecrit(iff), "t_max") > 0) THEN
+       typeecrit = 't_max(X)'
+    ELSE IF(INDEX(var%type_ecrit(iff), "inst") > 0) THEN
+       typeecrit = 'inst(X)'
+    ELSE
+       typeecrit = type_ecri_files(iff)
+    ENDIF
+
+    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
+       zstophym=zoutm(iff)
+    ELSE
+       zstophym=zdtime
+    ENDIF
 
     ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
-    call conf_physoutputs(nomvar,flag_var)
-
-    if (type_ecri(iff)=='inst(X)'.OR.type_ecri(iff)=='once') then
+    CALL conf_physoutputs(var%name, var%flag)
+
+    IF(.NOT.clef_stations(iff)) THEN  
+       IF ( var%flag(iff)<=lev_files(iff) ) THEN
+          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
+               iim,jj_nb,nhorim(iff), 1,1,1, -99, 32, &
+               typeecrit, zstophym,zoutm(iff))                
+       ENDIF
+    ELSE
+       IF ( var%flag(iff)<=lev_files(iff)) THEN
+          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
+               npstn,1,nhorim(iff), 1,1,1, -99, 32, &
+               typeecrit, zstophym,zoutm(iff))                
+       ENDIF
+    ENDIF
+
+    ! Set swaero_diag=true if at least one of the concerned variables are defined 
+    IF (var%name=='topswad' .OR. var%name=='topswai' .OR. var%name=='solswad' .OR. var%name=='solswai' ) THEN
+       IF  ( var%flag(iff)<=lev_files(iff) ) THEN
+          swaero_diag=.TRUE.
+       END IF
+    END IF
+  END SUBROUTINE histdef2d
+
+  SUBROUTINE histdef3d_old (iff,lpoint,flag_var,nomvar,titrevar,unitvar)
+
+    USE ioipsl
+    USE dimphy
+    USE mod_phys_lmdz_para
+    USE iophy
+
+    IMPLICIT NONE
+
+    INCLUDE "dimensions.h"
+    INCLUDE "temps.h"
+!    INCLUDE "indicesol.h"
+    INCLUDE "clesphys.h"
+
+    INTEGER                          :: iff
+    LOGICAL                          :: lpoint
+    INTEGER, DIMENSION(nfiles)       :: flag_var
+    CHARACTER(LEN=20)                 :: nomvar
+    CHARACTER(LEN=*)                 :: titrevar
+    CHARACTER(LEN=*)                 :: unitvar
+
+    REAL zstophym
+
+    ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
+    CALL conf_physoutputs(nomvar,flag_var)
+
+    IF (type_ecri(iff)=='inst(X)'.OR.type_ecri(iff)=='once') THEN
        zstophym=zoutm(iff)
-    else
+    ELSE
        zstophym=zdtime
-    endif
-
-    if(.NOT.lpoint) THEN
-       if ( flag_var(iff)<=lev_files(iff) ) then
-          call histdef (nid_files(iff), nomvar, titrevar, unitvar, &
+    ENDIF
+
+    IF(.NOT.lpoint) THEN
+       IF ( flag_var(iff)<=lev_files(iff) ) THEN
+          CALL histdef (nid_files(iff), nomvar, titrevar, unitvar, &
                iim, jj_nb, nhorim(iff), klev, levmin(iff), &
                levmax(iff)-levmin(iff)+1, nvertm(iff), 32, type_ecri(iff), &
                zstophym, zoutm(iff))
-       endif
-    else
-       if ( flag_var(iff)<=lev_files(iff) ) then
-          call histdef (nid_files(iff), nomvar, titrevar, unitvar, &
+       ENDIF
+    ELSE
+       IF ( flag_var(iff)<=lev_files(iff) ) THEN
+          CALL histdef (nid_files(iff), nomvar, titrevar, unitvar, &
                npstn,1,nhorim(iff), klev, levmin(iff), &
                levmax(iff)-levmin(iff)+1, nvertm(iff), 32, &
                type_ecri(iff), zstophym,zoutm(iff))
-       endif
-    endif
-  end subroutine histdef3d
+       ENDIF
+    ENDIF
+  END SUBROUTINE histdef3d_old
+
+  SUBROUTINE histdef3d (iff,var)
+
+    USE ioipsl
+    USE dimphy
+    USE mod_phys_lmdz_para
+    USE iophy
+
+    IMPLICIT NONE
+
+    INCLUDE "dimensions.h"
+    INCLUDE "temps.h"
+    INCLUDE "clesphys.h"
+
+    INTEGER                          :: iff
+    TYPE(ctrl_out)                   :: var
+
+    REAL zstophym
+    CHARACTER(LEN=20) :: typeecrit
+
+    ! ug On récupère le type écrit de la structure:
+    !       Assez moche, à refaire si meilleure méthode...
+    IF (INDEX(var%type_ecrit(iff), "once") > 0) THEN
+       typeecrit = 'once'
+    ELSE IF(INDEX(var%type_ecrit(iff), "t_min") > 0) THEN
+       typeecrit = 't_min(X)'
+    ELSE IF(INDEX(var%type_ecrit(iff), "t_max") > 0) THEN
+       typeecrit = 't_max(X)'
+    ELSE IF(INDEX(var%type_ecrit(iff), "inst") > 0) THEN
+       typeecrit = 'inst(X)'
+    ELSE
+       typeecrit = type_ecri_files(iff)
+    ENDIF
+
+
+    ! Appel a la lecture des noms et niveau d'ecriture des variables dans output.def
+    CALL conf_physoutputs(var%name,var%flag)
+
+    IF (typeecrit=='inst(X)'.OR.typeecrit=='once') THEN
+       zstophym=zoutm(iff)
+    ELSE
+       zstophym=zdtime
+    ENDIF
+
+    IF(.NOT.clef_stations(iff)) THEN
+       IF ( var%flag(iff)<=lev_files(iff) ) THEN
+          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
+               iim, jj_nb, nhorim(iff), klev, levmin(iff), &
+               levmax(iff)-levmin(iff)+1, nvertm(iff), 32, typeecrit, &
+               zstophym, zoutm(iff))
+       ENDIF
+    ELSE
+       IF ( var%flag(iff)<=lev_files(iff)) THEN
+          CALL histdef (nid_files(iff), var%name, var%description, var%unit, &
+               npstn,1,nhorim(iff), klev, levmin(iff), &
+               levmax(iff)-levmin(iff)+1, nvertm(iff), 32, &
+               typeecrit, zstophym,zoutm(iff))
+       ENDIF
+    ENDIF
+  END SUBROUTINE histdef3d
 
   SUBROUTINE conf_physoutputs(nam_var,flag_var)
@@ -1940,10 +1077,10 @@
     include 'iniprint.h'
 
-    character(len=20)                :: nam_var
-    integer, dimension(nfiles)      :: flag_var
+    CHARACTER(LEN=20)                :: nam_var
+    INTEGER, DIMENSION(nfiles)      :: flag_var
 
     IF(prt_level>10) WRITE(lunout,*)'Avant getin: nam_var flag_var ',nam_var,flag_var(:)
-    call getin('flag_'//nam_var,flag_var)
-    call getin('name_'//nam_var,nam_var)
+    CALL getin('flag_'//nam_var,flag_var)
+    CALL getin('name_'//nam_var,nam_var)
     IF(prt_level>10) WRITE(lunout,*)'Apres getin: nam_var flag_var ',nam_var,flag_var(:)
 
@@ -1957,7 +1094,7 @@
     IMPLICIT NONE
 
-    character(len=20)   :: str
-    character(len=10)   :: type
-    integer             :: ipos,il
+    CHARACTER(LEN=20)   :: str
+    CHARACTER(LEN=10)   :: type
+    INTEGER             :: ipos,il
     real                :: ttt,xxx,timestep,dayseconde,dtime
     parameter (dayseconde=86400.)
@@ -1966,30 +1103,30 @@
     include "iniprint.h"
 
-    ipos=scan(str,'0123456789.',.true.)
+    ipos=scan(str,'0123456789.',.TRUE.)
     !  
     il=len_trim(str)
-    write(lunout,*)ipos,il
+    WRITE(lunout,*)ipos,il
     read(str(1:ipos),*) ttt
-    write(lunout,*)ttt
+    WRITE(lunout,*)ttt
     type=str(ipos+1:il)
 
 
-    if ( il == ipos ) then
+    IF ( il == ipos ) then
        type='day'
     endif
 
-    if ( type == 'day'.or.type == 'days'.or.type == 'jours'.or.type == 'jour' ) timestep = ttt * dayseconde
-    if ( type == 'mounths'.or.type == 'mth'.or.type == 'mois' ) then
-       write(lunout,*)'annee_ref,day_ref mon_len',annee_ref,day_ref,mth_len
+    IF ( type == 'day'.or.type == 'days'.or.type == 'jours'.or.type == 'jour' ) timestep = ttt * dayseconde
+    IF ( type == 'mounths'.or.type == 'mth'.or.type == 'mois' ) then
+       WRITE(lunout,*)'annee_ref,day_ref mon_len',annee_ref,day_ref,mth_len
        timestep = ttt * dayseconde * mth_len
     endif
-    if ( type == 'hours'.or.type == 'hr'.or.type == 'heurs') timestep = ttt * dayseconde / 24.
-    if ( type == 'mn'.or.type == 'minutes'  ) timestep = ttt * 60.
-    if ( type == 's'.or.type == 'sec'.or.type == 'secondes'   ) timestep = ttt
-    if ( type == 'TS' ) timestep = ttt * dtime
-
-    write(lunout,*)'type =      ',type
-    write(lunout,*)'nb j/h/m =  ',ttt
-    write(lunout,*)'timestep(s)=',timestep
+    IF ( type == 'hours'.or.type == 'hr'.or.type == 'heurs') timestep = ttt * dayseconde / 24.
+    IF ( type == 'mn'.or.type == 'minutes'  ) timestep = ttt * 60.
+    IF ( type == 's'.or.type == 'sec'.or.type == 'secondes'   ) timestep = ttt
+    IF ( type == 'TS' ) timestep = ttt * dtime
+
+    WRITE(lunout,*)'type =      ',type
+    WRITE(lunout,*)'nb j/h/m =  ',ttt
+    WRITE(lunout,*)'timestep(s)=',timestep
 
   END SUBROUTINE convers_timesteps
Index: LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/phys_output_var_mod.F90	(revision 1795)
@@ -14,7 +14,47 @@
       REAL, SAVE, ALLOCATABLE :: snow_o(:), zfra_o(:)
 !$OMP THREADPRIVATE(snow_o, zfra_o)
-      INTEGER, save, ALLOCATABLE ::  itau_con(:)       ! Nombre de pas ou rflag <= 1
+      INTEGER, SAVE, ALLOCATABLE ::  itau_con(:)       ! Nombre de pas ou rflag <= 1
 !$OMP THREADPRIVATE(itau_con)
+      REAL, ALLOCATABLE :: bils_ec(:) ! Contribution of energy conservation
+      REAL, ALLOCATABLE :: bils_tke(:) ! Contribution of energy conservation
+      REAL, ALLOCATABLE :: bils_diss(:) ! Contribution of energy conservation
+      REAL, ALLOCATABLE :: bils_kinetic(:) ! bilan de chaleur au sol, kinetic
+      REAL, ALLOCATABLE :: bils_enthalp(:) ! bilan de chaleur au sol
+      REAL, ALLOCATABLE :: bils_latent(:) ! bilan de chaleur au sol
+!$OMP THREADPRIVATE(bils_ec,bils_tke,bils_diss,bils_kinetic,bils_enthalp,bils_latent)
 
+! ug Plein de variables venues de phys_output_mod
+      INTEGER, PARAMETER                           :: nfiles = 6
+      LOGICAL, DIMENSION(nfiles), SAVE             :: clef_files
+      LOGICAL, DIMENSION(nfiles), SAVE             :: clef_stations
+      INTEGER, DIMENSION(nfiles), SAVE             :: lev_files
+      INTEGER, DIMENSION(nfiles), SAVE             :: nid_files
+      INTEGER, DIMENSION(nfiles), SAVE  :: nnid_files
+!$OMP THREADPRIVATE(clef_files, clef_stations, lev_files,nid_files,nnid_files)
+      INTEGER, DIMENSION(nfiles), SAVE :: nnhorim
+
+      INTEGER, DIMENSION(nfiles), SAVE :: nhorim, nvertm
+      INTEGER, DIMENSION(nfiles), SAVE :: nvertap, nvertbp, nvertAlt
+      REAL, DIMENSION(nfiles), SAVE                :: zoutm
+      CHARACTER(LEN=20), DIMENSION(nfiles), SAVE   :: type_ecri
+!$OMP THREADPRIVATE(nnhorim, nhorim, nvertm, zoutm,type_ecri)
+      CHARACTER(LEN=20), DIMENSION(nfiles), SAVE  :: type_ecri_files, phys_out_filetypes
+!$OMP THREADPRIVATE(type_ecri_files, phys_out_filetypes)
+
+ ! swaero_diag : flag indicates if it is necessary to do calculation for some aerosol diagnostics
+      LOGICAL, SAVE                                :: swaero_diag=.FALSE.
+!$OMP THREADPRIVATE(swaero_diag)
+
+      INTEGER, SAVE:: levmin(nfiles) = 1
+      INTEGER, SAVE:: levmax(nfiles)
+!$OMP THREADPRIVATE(levmin, levmax)
+
+  TYPE ctrl_out
+     INTEGER,DIMENSION(nfiles)            :: flag
+     CHARACTER(len=20)                    :: name
+     CHARACTER(len=150)                   :: description
+     CHARACTER(len=20)                    :: unit
+     CHARACTER(len=20),DIMENSION(nfiles)  :: type_ecrit
+  END TYPE ctrl_out
 CONTAINS
 
@@ -27,4 +67,5 @@
       allocate(snow_o(klon), zfra_o(klon))
       allocate(itau_con(klon))
+      allocate (bils_ec(klon),bils_tke(klon),bils_diss(klon),bils_kinetic(klon),bils_enthalp(klon),bils_latent(klon))
 
 END SUBROUTINE phys_output_var_init
@@ -36,4 +77,5 @@
 
       deallocate(snow_o,zfra_o,itau_con)
+      deallocate (bils_ec,bils_tke,bils_diss,bils_kinetic,bils_enthalp,bils_latent)
 
 END SUBROUTINE phys_output_var_end
Index: LMDZ5/branches/testing/libf/phylmd/phys_output_write.h
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phys_output_write.h	(revision 1750)
+++ 	(revision )
@@ -1,2317 +1,0 @@
-      itau_w = itau_phy + itap + start_time * day_step / iphysiq
-
-      DO iff=1,nfiles
-
-       IF (clef_files(iff)) THEN
-             ndex2d = 0
-             ndex3d = 0
-
-!!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-       IF (o_phis%flag(iff)<=lev_files(iff)) THEN 
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                  o_phis%name,itau_w,pphis)
-       ENDIF
-
-       IF (.NOT.clef_stations(iff)) THEN
-       IF (o_aire%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_aire%name,itau_w,airephy)
-       ENDIF
-
-       IF (o_contfracATM%flag(iff)<=lev_files(iff)) THEN
-      DO i=1, klon
-       zx_tmp_fi2d(i)=pctsrf(i,is_ter)+pctsrf(i,is_lic)
-      ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $             o_contfracATM%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-       ENDIF
-
-       IF (o_contfracOR%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                  o_contfracOR%name,itau_w,pctsrf(:,is_ter))
-       ENDIF
-
-       IF (o_aireTER%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                  o_aireTER%name,itau_w,paire_ter)
-       ENDIF
-
-!!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-       IF (o_flat%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                  o_flat%name,itau_w,zxfluxlat)
-       ENDIF
-
-       IF (o_slp%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                  o_slp%name,itau_w,slp)
-       ENDIF
-
-       IF (o_tsol%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                  o_tsol%name,itau_w,zxtsol)
-       ENDIF
-
-       IF (o_t2m%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                  o_t2m%name,itau_w,zt2m)
-       ENDIF
-
-      IF (.NOT.clef_stations(iff)) THEN
-       IF (o_t2m_min%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_t2m_min%name,itau_w,zt2m)
-       ENDIF
-
-       IF (o_t2m_max%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_t2m_max%name,itau_w,zt2m)
-       ENDIF
-       ENDIF
-
-       IF (o_wind10m%flag(iff)<=lev_files(iff)) THEN
-      DO i=1, klon
-       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
-      ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                  o_wind10m%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-      IF (.NOT.clef_stations(iff)) THEN
-       IF (o_wind10max%flag(iff)<=lev_files(iff)) THEN
-      DO i=1, klon
-       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
-      ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_wind10max%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-      ENDIF
-
-       IF (o_sicf%flag(iff)<=lev_files(iff)) THEN
-      DO i = 1, klon
-         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
-      ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_sicf%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_q2m%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_q2m%name,itau_w,zq2m)
-       ENDIF
-
-       IF (o_ustar%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ustar%name,itau_w,zustar)
-       ENDIF
-
-       IF (o_u10m%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_u10m%name,itau_w,zu10m)
-       ENDIF
-
-       IF (o_v10m%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_v10m%name,itau_w,zv10m)
-       ENDIF
-
-       IF (o_psol%flag(iff)<=lev_files(iff)) THEN
-      DO i = 1, klon
-         zx_tmp_fi2d(i) = paprs(i,1)
-      ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_psol%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_mass%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_mass%name,itau_w,zmasse)
-        ENDIF
-
-
-       IF (o_qsurf%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_qsurf%name,itau_w,zxqsurf)
-       ENDIF
-
-       if (.not. ok_veget) then
-         IF (o_qsol%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_qsol%name,itau_w,qsol)
-         ENDIF
-       endif
-
-      IF (o_precip%flag(iff)<=lev_files(iff)) THEN
-       DO i = 1, klon
-         zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
-       ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_precip%name,itau_w,zx_tmp_fi2d)
-      ENDIF
-
-       IF (o_ndayrain%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ndayrain%name,itau_w,nday_rain)
-       ENDIF
-
-      IF (o_plul%flag(iff)<=lev_files(iff)) THEN
-       DO i = 1, klon
-         zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
-       ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_plul%name,itau_w,zx_tmp_fi2d)
-      ENDIF
-
-      IF (o_pluc%flag(iff)<=lev_files(iff)) THEN
-      DO i = 1, klon
-         zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
-      ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_pluc%name,itau_w,zx_tmp_fi2d)
-      ENDIF
-
-       IF (o_snow%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_snow%name,itau_w,snow_fall)
-       ENDIF
-
-       IF (o_msnow%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_msnow%name,itau_w,snow_o)
-       ENDIF
-
-       IF (o_fsnow%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_fsnow%name,itau_w,zfra_o)
-       ENDIF
-
-       IF (o_evap%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_evap%name,itau_w,evap)
-       ENDIF
-
-       IF (o_tops%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tops%name,itau_w,topsw)
-       ENDIF
-
-       IF (o_tops0%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tops0%name,itau_w,topsw0)
-       ENDIF
-
-       IF (o_topl%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_topl%name,itau_w,toplw)
-       ENDIF
-
-       IF (o_topl0%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_topl0%name,itau_w,toplw0)
-       ENDIF
-
-       IF (o_SWupTOA%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_SWupTOA%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_SWupTOAclr%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
-     $                  o_SWupTOAclr%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_SWdnTOA%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                  o_SWdnTOA%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_SWdnTOAclr%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
-     $                  o_SWdnTOAclr%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_nettop%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(:) = topsw(:)-toplw(:)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                  o_nettop%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_SWup200%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_SWup200%name,itau_w,SWup200)
-       ENDIF
-
-       IF (o_SWup200clr%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_SWup200clr%name,itau_w,SWup200clr)
-       ENDIF
-
-       IF (o_SWdn200%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_SWdn200%name,itau_w,SWdn200)
-       ENDIF
-
-       IF (o_SWdn200clr%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                o_SWdn200clr%name,itau_w,SWdn200clr)
-       ENDIF
-
-       IF (o_LWup200%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_LWup200%name,itau_w,LWup200)
-       ENDIF
-
-       IF (o_LWup200clr%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_LWup200clr%name,itau_w,LWup200clr)
-       ENDIF
-
-       IF (o_LWdn200%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_LWdn200%name,itau_w,LWdn200)
-       ENDIF
-
-       IF (o_LWdn200clr%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                  o_LWdn200clr%name,itau_w,LWdn200clr)
-       ENDIF
-
-       IF (o_sols%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_sols%name,itau_w,solsw)
-       ENDIF
-
-       IF (o_sols0%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_sols0%name,itau_w,solsw0)
-       ENDIF
-
-       IF (o_soll%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_soll%name,itau_w,sollw)
-       ENDIF
-
-       IF (o_radsol%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_radsol%name,itau_w,radsol)
-       ENDIF
-
-       IF (o_soll0%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_soll0%name,itau_w,sollw0)
-       ENDIF
-
-       IF (o_SWupSFC%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s               o_SWupSFC%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_SWupSFCclr%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
-     $                   o_SWupSFCclr%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_SWdnSFC%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
-     $                   o_SWdnSFC%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_SWdnSFCclr%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
-     $                  o_SWdnSFCclr%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_LWupSFC%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                    o_LWupSFC%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_LWdnSFC%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_LWdnSFC%name,itau_w,sollwdown)
-       ENDIF
-
-       sollwdownclr(1:klon) = -1.*lwdn0(1:klon,1)
-       IF (o_LWupSFCclr%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_LWupSFCclr%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_LWdnSFCclr%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_LWdnSFCclr%name,itau_w,sollwdownclr)
-       ENDIF
-
-       IF (o_bils%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_bils%name,itau_w,bils)
-       ENDIF
-
-       IF (o_sens%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_sens%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_fder%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_fder%name,itau_w,fder)
-       ENDIF
-
-       IF (o_ffonte%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ffonte%name,itau_w,zxffonte)
-       ENDIF
-
-       IF (o_fqcalving%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                    o_fqcalving%name,itau_w,zxfqcalving)
-       ENDIF
-
-       IF (o_fqfonte%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_fqfonte%name,itau_w,zxfqfonte)
-       ENDIF
-
-       IF (o_taux%flag(iff)<=lev_files(iff)) THEN
-         zx_tmp_fi2d=0.
-         do nsrf=1,nbsrf
-          zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxu(:,1,nsrf)
-         enddo
-         CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_taux%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_tauy%flag(iff)<=lev_files(iff)) THEN
-         zx_tmp_fi2d=0.
-         do nsrf=1,nbsrf
-          zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxv(:,1,nsrf)
-         enddo
-         CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_tauy%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-         DO nsrf = 1, nbsrf
-!           IF(nsrf.GE.2) THEN
-            IF (o_pourc_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-            zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
-            CALL histwrite_phy(nid_files(iff),
-     $                     clef_stations(iff),
-     $                     o_pourc_srf(nsrf)%name,itau_w,
-     $                     zx_tmp_fi2d)
-            ENDIF
-
-          IF (o_fract_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-          zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
-          CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                  o_fract_srf(nsrf)%name,itau_w,
-     $                  zx_tmp_fi2d)
-          ENDIF
-!         ENDIF !nsrf.GT.2
-
-        IF (o_taux_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                     o_taux_srf(nsrf)%name,itau_w,
-     $                     zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_tauy_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN           
-        zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                    o_tauy_srf(nsrf)%name,itau_w,
-     $                    zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_tsol_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_tsol_srf(nsrf)%name,itau_w,
-     $      zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_evappot_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi2d(1 : klon) = evap_pot( 1 : klon, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_evappot_srf(nsrf)%name,itau_w,
-     $      zx_tmp_fi2d)
-        ENDIF
-
-      IF (o_ustar_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = ustar(1 : klon, nsrf)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ustar_srf(nsrf)%name,
-     $                 itau_w,zx_tmp_fi2d)
-      ENDIF
-
-      IF (o_u10m_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, nsrf)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_u10m_srf(nsrf)%name,
-     $                 itau_w,zx_tmp_fi2d)
-      ENDIF
-
-      IF (o_v10m_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, nsrf)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_v10m_srf(nsrf)%name,
-     $              itau_w,zx_tmp_fi2d)
-      ENDIF
- 
-      IF (o_t2m_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, nsrf)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_t2m_srf(nsrf)%name,
-     $           itau_w,zx_tmp_fi2d)
-      ENDIF
-
-      IF (o_evap_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = fevap(1 : klon, nsrf)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_evap_srf(nsrf)%name,
-     $           itau_w,zx_tmp_fi2d)
-      ENDIF
-
-       IF (o_sens_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-       zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                    o_sens_srf(nsrf)%name,itau_w,
-     $      zx_tmp_fi2d)
-       ENDIF
-
-        IF (o_lat_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                 o_lat_srf(nsrf)%name,itau_w,
-     $                                   zx_tmp_fi2d)
-          ENDIF
-
-        IF (o_flw_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                     o_flw_srf(nsrf)%name,itau_w,
-     $      zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_fsw_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_fsw_srf(nsrf)%name,itau_w,
-     $      zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_wbils_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_wbils_srf(nsrf)%name,itau_w,
-     $      zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_wbilo_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi2d(1 : klon) = wfbilo( 1 : klon, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                    o_wbilo_srf(nsrf)%name,itau_w,
-     $      zx_tmp_fi2d)
-        ENDIF
-
-       if (iflag_pbl>1 .and. lev_files(iff).gt.10 ) then
-        IF (o_tke_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_tke_srf(nsrf)%name,itau_w,
-     $                    pbl_tke(:,1:klev,nsrf))
-       ENDIF
-
-      IF (.NOT.clef_stations(iff)) THEN
-        IF (o_tke_max_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                    o_tke_max_srf(nsrf)%name,itau_w,
-     $      pbl_tke(:,1:klev,nsrf))
-        ENDIF
-      ENDIF
-       endif
-      ENDDO
-
-        IF (o_cdrm%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cdrm%name,itau_w,cdragm)
-        ENDIF
-
-        IF (o_cdrh%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cdrh%name,itau_w,cdragh)
-        ENDIF
-
-        IF (o_cldl%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cldl%name,itau_w,cldl)
-        ENDIF
-
-        IF (o_cldm%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cldm%name,itau_w,cldm)
-        ENDIF
-
-        IF (o_cldh%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cldh%name,itau_w,cldh)
-        ENDIF
-
-        IF (o_cldt%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cldt%name, 
-     &                   itau_w,cldt)
-        ENDIF
-
-        IF (o_cldq%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cldq%name,itau_w,cldq)
-        ENDIF
-
-        IF (o_lwp%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1:klon) = flwp(1:klon)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_lwp%name,itau_w,zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_iwp%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1:klon) = fiwp(1:klon)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                    o_iwp%name,itau_w,zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_ue%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ue%name,itau_w,ue)
-        ENDIF
-
-        IF (o_ve%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ve%name,itau_w,ve)
-        ENDIF
-
-        IF (o_uq%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_uq%name,itau_w,uq)
-        ENDIF
-
-        IF (o_vq%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_vq%name,itau_w,vq)
-        ENDIF
-
-      IF(iflag_con.GE.3) THEN ! sb
-        IF (o_cape%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cape%name,itau_w,cape)
-        ENDIF
-
-        IF (o_pbase%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_pbase%name,itau_w,ema_pcb)
-        ENDIF
-
-        IF (o_ptop%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ptop%name,itau_w,ema_pct)
-        ENDIF
-
-        IF (o_fbase%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_fbase%name,itau_w,ema_cbmf)
-        ENDIF
-
-        if (iflag_con /= 30) then
-           if (o_plcl%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $             o_plcl%name,itau_w,plcl)
-           ENDIF
-
-           IF (o_plfc%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $             o_plfc%name,itau_w,plfc)
-           ENDIF
-
-           IF (o_wbeff%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $             o_wbeff%name,itau_w,wbeff)
-           ENDIF
-        end if
-
-      IF (.NOT.clef_stations(iff)) THEN
-      IF (o_cape_max%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cape_max%name,itau_w,cape)
-      ENDIF
-      ENDIF
-
-       IF (o_upwd%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_upwd%name,itau_w,upwd)
-       ENDIF
-
-       IF (o_Ma%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_Ma%name,itau_w,Ma)
-       ENDIF
-
-       IF (o_dnwd%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dnwd%name,itau_w,dnwd)
-       ENDIF
-
-       IF (o_dnwd0%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dnwd0%name,itau_w,dnwd0)
-       ENDIF
-
-       IF (o_ftime_con%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi2d=float(itau_con)/float(itap)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ftime_con%name,
-     s                   itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_mc%flag(iff)<=lev_files(iff)) THEN
-        if(iflag_thermals>=1)then
-         zx_tmp_fi3d=dnwd+dnwd0+upwd+fm_therm(:,1:klev)
-        else
-         zx_tmp_fi3d=dnwd+dnwd0+upwd
-        endif 
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_mc%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-      
-      ENDIF !iflag_con .GE. 3
-
-        IF (o_prw%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_prw%name,itau_w,prw)
-        ENDIF
-
-        IF (o_s_pblh%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_s_pblh%name,itau_w,s_pblh)
-        ENDIF
-
-        IF (o_s_pblt%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_s_pblt%name,itau_w,s_pblt)
-        ENDIF
-
-        IF (o_s_lcl%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_s_lcl%name,itau_w,s_lcl)
-        ENDIF
-
-        IF (o_s_therm%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_s_therm%name,itau_w,s_therm)
-        ENDIF
-
-!IM : Les champs suivants (s_capCL, s_oliqCL, s_cteiCL, s_trmb1, s_trmb2, s_trmb3) ne sont pas definis dans HBTM.F
-!       IF (o_s_capCL%flag(iff)<=lev_files(iff)) THEN
-!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-!    $o_s_capCL%name,itau_w,s_capCL)
-!       ENDIF
-
-!       IF (o_s_oliqCL%flag(iff)<=lev_files(iff)) THEN
-!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-!    $o_s_oliqCL%name,itau_w,s_oliqCL)
-!       ENDIF
-
-!       IF (o_s_cteiCL%flag(iff)<=lev_files(iff)) THEN
-!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-!    $o_s_cteiCL%name,itau_w,s_cteiCL)
-!       ENDIF
-
-!       IF (o_s_trmb1%flag(iff)<=lev_files(iff)) THEN
-!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-!    $o_s_trmb1%name,itau_w,s_trmb1)
-!       ENDIF
-
-!       IF (o_s_trmb2%flag(iff)<=lev_files(iff)) THEN
-!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-!    $o_s_trmb2%name,itau_w,s_trmb2)
-!       ENDIF
-
-!       IF (o_s_trmb3%flag(iff)<=lev_files(iff)) THEN
-!     CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-!    $o_s_trmb3%name,itau_w,s_trmb3)
-!       ENDIF
-
-! Champs interpolles sur des niveaux de pression
-
-        ll=0
-        DO k=1, nlevSTD
-         bb2=clevSTD(k) 
-         IF(bb2.EQ."850".OR.bb2.EQ."700".OR.
-     $      bb2.EQ."500".OR.bb2.EQ."200".OR.
-     $      bb2.EQ."100".OR.
-     $      bb2.EQ."50".OR.bb2.EQ."10") THEN
-
-! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-          ll=ll+1
-       IF (o_uSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_uSTDlevs(ll)%name,
-     &                    itau_w,uwriteSTD(:,k,iff))
-       ENDIF
-
-       IF (o_vSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_vSTDlevs(ll)%name,  
-     &                   itau_w,vwriteSTD(:,k,iff))
-       ENDIF
-
-       IF (o_wSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_wSTDlevs(ll)%name,
-     &                    itau_w,wwriteSTD(:,k,iff))
-       ENDIF
-
-       IF (o_zSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_zSTDlevs(ll)%name,
-     &               itau_w,phiwriteSTD(:,k,iff))
-       ENDIF
-
-       IF (o_qSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_qSTDlevs(ll)%name,
-     &                   itau_w, qwriteSTD(:,k,iff))
-       ENDIF
-
-       IF (o_tSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tSTDlevs(ll)%name,
-     &                   itau_w, twriteSTD(:,k,iff))
-       ENDIF
-
-       ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
-       ENDDO
-
-      IF (o_t_oce_sic%flag(iff)<=lev_files(iff)) THEN
-      DO i=1, klon
-       IF (pctsrf(i,is_oce).GT.epsfra.OR.
-     $     pctsrf(i,is_sic).GT.epsfra) THEN
-        zx_tmp_fi2d(i) = (ftsol(i, is_oce) * pctsrf(i,is_oce)+
-     $                   ftsol(i, is_sic) * pctsrf(i,is_sic))/
-     $                   (pctsrf(i,is_oce)+pctsrf(i,is_sic))
-       ELSE
-        zx_tmp_fi2d(i) = 273.15
-       ENDIF
-      ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_t_oce_sic%name,itau_w,zx_tmp_fi2d)
-      ENDIF
-
-! Couplage convection-couche limite
-      IF (iflag_con.GE.3) THEN
-      IF (iflag_coupl>=1) THEN
-       IF (o_ale_bl%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ale_bl%name,itau_w,ale_bl)
-       ENDIF
-       IF (o_alp_bl%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_alp_bl%name,itau_w,alp_bl)
-       ENDIF
-      ENDIF !iflag_coupl>=1
-      ENDIF !(iflag_con.GE.3)
-
-! Wakes
-      IF (iflag_con.EQ.3) THEN
-      IF (iflag_wake>=1) THEN
-       IF (o_ale_wk%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ale_wk%name,itau_w,ale_wake)
-       ENDIF
-       IF (o_alp_wk%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_alp_wk%name,itau_w,alp_wake)
-       ENDIF
-
-       IF (o_ale%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ale%name,itau_w,ale)
-       ENDIF
-       IF (o_alp%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_alp%name,itau_w,alp)
-       ENDIF
-       IF (o_cin%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cin%name,itau_w,cin)
-       ENDIF
-       IF (o_wape%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_WAPE%name,itau_w,wake_pe)
-       ENDIF
-       IF (o_wake_h%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_wake_h%name,itau_w,wake_h)
-       ENDIF
-
-       IF (o_wake_s%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_wake_s%name,itau_w,wake_s)
-       ENDIF
-
-        IF (o_wake_deltat%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_wake_deltat%name,
-     $                     itau_w,wake_deltat)
-        ENDIF
-
-        IF (o_wake_deltaq%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_wake_deltaq%name,
-     $                    itau_w,wake_deltaq)
-        ENDIF
-
-        IF (o_wake_omg%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                    o_wake_omg%name,itau_w,wake_omg)
-        ENDIF
-
-         IF (o_dtwak%flag(iff)<=lev_files(iff)) THEN
-           zx_tmp_fi3d(1:klon,1:klev)=d_t_wake(1:klon,1:klev)
-     &                                        /pdtphys
-           CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     &                       o_dtwak%name,itau_w,zx_tmp_fi3d)
-         ENDIF
-
-        IF (o_dqwak%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi3d(1:klon,1:klev)=d_q_wake(1:klon,1:klev)/pdtphys
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     &                     o_dqwak%name,itau_w,zx_tmp_fi3d)
-        ENDIF
-      ENDIF ! iflag_wake>=1
-
-        IF (o_Vprecip%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_Vprecip%name,itau_w,Vprecip)
-        ENDIF
-
-        IF (o_ftd%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ftd%name,itau_w,ftd)
-        ENDIF
-
-        IF (o_fqd%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_fqd%name,itau_w,fqd)
-        ENDIF
-
-      ELSEIF (iflag_con.EQ.30) THEN
-! sortie RomP convection descente insaturee iflag_con=30
-       IF (o_Vprecip%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_Vprecip%name,itau_w,Vprecip)
-       ENDIF
-      IF (o_wdtrainA%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_wdtrainA%name,itau_w,wdtrainA)
-      ENDIF
-      IF (o_wdtrainM%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_wdtrainM%name,itau_w,wdtrainM)
-      ENDIF
-
-      ENDIF !(iflag_con.EQ.3.or.iflag_con.EQ.30)
- 
-!!! nrlmd le 10/04/2012
-
-        IF (iflag_trig_bl>=1) THEN
-          IF (o_n2%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_n2%name,itau_w,n2)
-         ENDIF
-
-         IF (o_s2%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_s2%name,itau_w,s2)
-         ENDIF
-
-          IF (o_proba_notrig%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_proba_notrig%name,itau_w,proba_notrig)
-         ENDIF
-
-         IF (o_random_notrig%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_random_notrig%name,itau_w,random_notrig)
-         ENDIF
-
-         IF (o_ale_bl_stat%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_ale_bl_stat%name,itau_w,ale_bl_stat)
-         ENDIF
-
-         IF (o_ale_bl_trig%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_ale_bl_trig%name,itau_w,ale_bl_trig)
-         ENDIF
-       ENDIF  !(iflag_trig_bl>=1)
-
-        IF (iflag_clos_bl>=1) THEN
-         IF (o_alp_bl_det%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_alp_bl_det%name,itau_w,alp_bl_det)
-         ENDIF
-
-         IF (o_alp_bl_fluct_m%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_alp_bl_fluct_m%name,itau_w,alp_bl_fluct_m)
-         ENDIF
-
-         IF (o_alp_bl_fluct_tke%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                o_alp_bl_fluct_tke%name,itau_w,alp_bl_fluct_tke)
-         ENDIF
-
-         IF (o_alp_bl_conv%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_alp_bl_conv%name,itau_w,alp_bl_conv)
-         ENDIF
-
-         IF (o_alp_bl_stat%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_alp_bl_stat%name,itau_w,alp_bl_stat)
-         ENDIF
-       ENDIF  !(iflag_clos_bl>=1)
-
-!!! fin nrlmd le 10/04/2012
-
-      IF (type_ocean=='slab ') THEN
-      IF ( o_slab_bils%flag(iff)<=lev_files(iff)) 
-     $     CALL histwrite_phy(
-     $     nid_files(iff),clef_stations(iff),
-     $o_slab_bils%name,itau_w,slab_wfbils)
-
-      ENDIF !type_ocean == force/slab
-
-      IF (o_weakinv%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                  o_weakinv%name,itau_w,weak_inversion)
-      ENDIF
-
-      IF (o_dthmin%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dthmin%name,itau_w,dthmin)
-      ENDIF
-
-       IF (o_cldtau%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cldtau%name,itau_w,cldtau)
-       ENDIF
-
-       IF (o_cldemi%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_cldemi%name,itau_w,cldemi)
-       ENDIF
-
-      IF (o_pr_con_l%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s         o_pr_con_l%name,itau_w,pmflxr(:,1:klev))
-      ENDIF
-
-      IF (o_pr_con_i%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s         o_pr_con_i%name,itau_w,pmflxs(:,1:klev))
-      ENDIF
-
-      IF (o_pr_lsc_l%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s        o_pr_lsc_l%name,itau_w,prfl(:,1:klev))
-      ENDIF
-
-      IF (o_pr_lsc_i%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s        o_pr_lsc_i%name,itau_w,psfl(:,1:klev))
-      ENDIF
-
-      IF (o_re%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_re%name,itau_w,re)
-      ENDIF
-
-      IF (o_fl%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_fl%name,itau_w,fl)
-      ENDIF
-
-
-
-      IF (o_rh2m%flag(iff)<=lev_files(iff)) THEN
-      DO i=1, klon
-       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
-      ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rh2m%name,itau_w,zx_tmp_fi2d)
-      ENDIF
-
-      IF (.NOT.clef_stations(iff)) THEN
-      IF (o_rh2m_min%flag(iff)<=lev_files(iff)) THEN
-      DO i=1, klon
-       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
-      ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rh2m_min%name,
-     s               itau_w,zx_tmp_fi2d)
-      ENDIF
-
-      IF (o_rh2m_max%flag(iff)<=lev_files(iff)) THEN
-      DO i=1, klon
-       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
-      ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rh2m_max%name,
-     s              itau_w,zx_tmp_fi2d)
-      ENDIF
-      ENDIF
-
-
-      IF (o_qsat2m%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_qsat2m%name,itau_w,qsat2m)
-      ENDIF
-
-      IF (o_tpot%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tpot%name,itau_w,tpot)
-      ENDIF
-
-       IF (o_tpote%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tpote%name,itau_w,tpote)
-       ENDIF
-
-      IF (o_SWnetOR%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, is_ter)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_SWnetOR%name,itau_w, zx_tmp_fi2d)
-      ENDIF
-
-      IF (o_SWdownOR%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1:klon) = solsw(1:klon)/(1.-albsol1(1:klon))
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_SWdownOR%name,itau_w, zx_tmp_fi2d)
-      ENDIF
-
-      IF (o_LWdownOR%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                  o_LWdownOR%name,itau_w,sollwdown)
-      ENDIF
-
-      IF (o_snowl%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_snowl%name,itau_w,snow_lsc)
-      ENDIF
-
-      IF (o_solldown%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_solldown%name,itau_w,sollwdown)
-      ENDIF
-
-      IF (o_dtsvdfo%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                 o_dtsvdfo%name,itau_w,d_ts(:,is_oce))
-      ENDIF
-
-      IF (o_dtsvdft%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_dtsvdft%name,itau_w,d_ts(:,is_ter))
-      ENDIF
-
-       IF (o_dtsvdfg%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_dtsvdfg%name,itau_w, d_ts(:,is_lic))
-       ENDIF
-
-       IF (o_dtsvdfi%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_dtsvdfi%name,itau_w,d_ts(:,is_sic))
-       ENDIF
-
-       IF (o_rugs%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rugs%name,itau_w,zxrugs)
-       ENDIF
-
-! OD550 per species
-      IF (new_aod .and. (.not. aerosol_couple)) THEN
-          IF (ok_ade.OR.ok_aie) THEN
-
-          IF (o_od550aer%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_od550aer%name,itau_w,
-     $            od550aer)
-          ENDIF
-          IF (o_od865aer%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_od865aer%name,itau_w,
-     $            od865aer)
-          ENDIF
-          IF (o_absvisaer%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_absvisaer%name,itau_w,
-     $            absvisaer)
-          ENDIF
-          IF (o_od550lt1aer%flag(iff)<=lev_files(iff)) THEN
-            CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_od550lt1aer%name,itau_w,
-     $            od550lt1aer)
-          ENDIF
-
-          IF (o_sconcso4%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_sconcso4%name,itau_w,
-     $            sconcso4)
-          ENDIF
-          IF (o_sconcoa%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_sconcoa%name,itau_w,
-     $            sconcoa)
-          ENDIF
-          IF (o_sconcbc%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_sconcbc%name,itau_w,
-     $            sconcbc)
-          ENDIF
-          IF (o_sconcss%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_sconcss%name,itau_w,
-     $            sconcss)
-          ENDIF
-          IF (o_sconcdust%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_sconcdust%name,itau_w,
-     $            sconcdust)
-          ENDIF
-          
-          IF (o_concso4%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_concso4%name,itau_w,
-     $            concso4)
-          ENDIF
-          IF (o_concoa%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_concoa%name,itau_w,
-     $            concoa)
-          ENDIF
-          IF (o_concbc%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_concbc%name,itau_w,
-     $            concbc)
-          ENDIF
-          IF (o_concss%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_concss%name,itau_w,
-     $            concss)
-          ENDIF
-          IF (o_concdust%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_concdust%name,itau_w,
-     $            concdust)
-          ENDIF
-          
-          IF (o_loadso4%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_loadso4%name,itau_w,
-     $            loadso4)
-          ENDIF
-          IF (o_loadoa%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_loadoa%name,itau_w,
-     $            loadoa)
-          ENDIF
-          IF (o_loadbc%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_loadbc%name,itau_w,
-     $            loadbc)
-          ENDIF
-          IF (o_loadss%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_loadss%name,itau_w,
-     $            loadss)
-          ENDIF
-          IF (o_loaddust%flag(iff)<=lev_files(iff)) THEN
-              CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_loaddust%name,itau_w,
-     $            loaddust)
-          ENDIF
-          
-          DO naero = 1, naero_spc
-            IF (o_tausumaero(naero)%flag(iff)<=lev_files(iff)) THEN
-                CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $              o_tausumaero(naero)%name,itau_w,
-     $              tausum_aero(:,2,naero) )
-            ENDIF
-          END DO
-          endif
-      ENDIF
-      
-       IF (ok_ade) THEN
-          IF (o_topswad%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_topswad%name,itau_w,
-     $            topswad_aero)
-          ENDIF
-          IF (o_topswad0%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_topswad0%name,itau_w,
-     $            topswad0_aero)
-          ENDIF
-          IF (o_solswad%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_solswad%name,itau_w,
-     $            solswad_aero)
-          ENDIF
-          IF (o_solswad0%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_solswad0%name,itau_w,
-     $            solswad0_aero)
-          ENDIF
-
-!====MS forcing diagnostics
-        if (new_aod) then	       
-        IF (o_swtoaas_nat%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swtoaas_nat%name,itau_w,
-     $      topsw_aero(:,1))
-        ENDIF
-
-        IF (o_swsrfas_nat%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swsrfas_nat%name,itau_w,
-     $      solsw_aero(:,1))
-        ENDIF
-
-        IF (o_swtoacs_nat%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swtoacs_nat%name,itau_w,
-     $      topsw0_aero(:,1))
-        ENDIF
-
-        IF (o_swsrfcs_nat%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swsrfcs_nat%name,itau_w,
-     $      solsw0_aero(:,1))
-        ENDIF
-  
-!ant
-        IF (o_swtoaas_ant%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swtoaas_ant%name,itau_w,
-     $      topsw_aero(:,2))
-        ENDIF
-
-        IF (o_swsrfas_ant%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swsrfas_ant%name,itau_w,
-     $      solsw_aero(:,2))
-        ENDIF
-
-        IF (o_swtoacs_ant%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swtoacs_ant%name,itau_w,
-     $      topsw0_aero(:,2))
-        ENDIF
-
-        IF (o_swsrfcs_ant%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swsrfcs_ant%name,itau_w,
-     $      solsw0_aero(:,2))
-        ENDIF
-
-!cf
-
-        if (.not. aerosol_couple) then
-        IF (o_swtoacf_nat%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swtoacf_nat%name,itau_w,
-     $      topswcf_aero(:,1))
-        ENDIF
-
-        IF (o_swsrfcf_nat%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swsrfcf_nat%name,itau_w,
-     $      solswcf_aero(:,1))
-        ENDIF
-
-        IF (o_swtoacf_ant%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swtoacf_ant%name,itau_w,
-     $      topswcf_aero(:,2))
-        ENDIF
-
-        IF (o_swsrfcf_ant%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swsrfcf_ant%name,itau_w,
-     $      solswcf_aero(:,2))
-        ENDIF
-
-        IF (o_swtoacf_zero%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swtoacf_zero%name,itau_w,
-     $      topswcf_aero(:,3))
-        ENDIF
-
-        IF (o_swsrfcf_zero%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_swsrfcf_zero%name,itau_w,
-     $      solswcf_aero(:,3))
-        ENDIF
-        endif
-
-	endif ! new_aod
-!====MS forcing diagnostics
-
-       ENDIF
-
-       IF (ok_aie) THEN
-          IF (o_topswai%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_topswai%name,itau_w,
-     $            topswai_aero)
-          ENDIF
-          IF (o_solswai%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_solswai%name,itau_w,
-     $            solswai_aero)
-          ENDIF
-          IF (o_scdnc%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_scdnc%name,itau_w,
-     $            scdnc)
-          ENDIF
-          IF (o_cldncl%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_cldncl%name,itau_w,
-     $            cldncl)
-          ENDIF
-         IF (o_reffclws%flag(iff)<=lev_files(iff)) THEN
-            CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_reffclws%name,itau_w,
-     $            reffclws)
-         ENDIF
-         IF (o_reffclwc%flag(iff)<=lev_files(iff)) THEN
-            CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_reffclwc%name,itau_w,
-     $            reffclwc)
-         ENDIF
-          IF (o_cldnvi%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_cldnvi%name,itau_w,
-     $            cldnvi)
-          ENDIF
-          IF (o_lcc%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_lcc%name,itau_w,
-     $            lcc)
-          ENDIF
-          IF (o_lcc3d%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_lcc3d%name,itau_w,
-     $            lcc3d)
-          ENDIF
-          IF (o_lcc3dcon%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_lcc3dcon%name,itau_w,
-     $            lcc3dcon)
-          ENDIF
-          IF (o_lcc3dstra%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_lcc3dstra%name,itau_w,
-     $            lcc3dstra)
-          ENDIF
-          IF (o_reffclwtop%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_reffclwtop%name,itau_w,
-     $            reffclwtop)
-          ENDIF
-       ENDIF
-
-! Champs 3D:
-       IF (ok_ade .OR. ok_aie) then
-          IF (o_ec550aer%flag(iff)<=lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff),
-     $clef_stations(iff),
-     $o_ec550aer%name,itau_w,
-     &            ec550aer)
-          ENDIF
-       ENDIF
-
-       IF (o_lwcon%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_lwcon%name,itau_w,flwc)
-       ENDIF
-
-       IF (o_iwcon%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_iwcon%name,itau_w,fiwc)
-       ENDIF
-
-       IF (o_temp%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_temp%name,itau_w,t_seri)
-       ENDIF
-
-       IF (o_theta%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_theta%name,itau_w,theta)
-       ENDIF
-
-       IF (o_ovapinit%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ovapinit%name,itau_w,
-     $ qx(:,:,ivap))
-       ENDIF
-
-       IF (o_ovap%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $                   o_ovap%name,itau_w,q_seri)
-       ENDIF
-                                                               
-       IF (o_oliq%flag(iff)<=lev_files(iff)) THEN              
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),    
-     $                   o_oliq%name,itau_w,ql_seri)            
-       ENDIF
-
-       IF (o_geop%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_geop%name,itau_w,zphi)
-       ENDIF
-
-       IF (o_vitu%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_vitu%name,itau_w,u_seri)
-       ENDIF
-
-       IF (o_vitv%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_vitv%name,itau_w,v_seri)
-       ENDIF
-
-       IF (o_vitw%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_vitw%name,itau_w,omega)
-       ENDIF
-
-        IF (o_pres%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_pres%name,itau_w,pplay)
-        ENDIF
-
-        IF (o_paprs%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_paprs%name,
-     s                    itau_w,paprs(:,1:klev))
-        ENDIF
-
-        IF (o_zfull%flag(iff)<=lev_files(iff)) THEN
-         DO i=1, klon
-          zx_tmp_fi3d1(i,1)= pphis(i)/RG
-!020611   zx_tmp_fi3d(i,1)= pphis(i)/RG
-         ENDDO
-         DO k=1, klev
-!020611        DO k=1, klev-1
-         DO i=1, klon
-!020611         zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - (t_seri(i,k) *RD * 
-          zx_tmp_fi3d1(i,k+1)= zx_tmp_fi3d1(i,k) - (t_seri(i,k) *RD * 
-     $    (paprs(i,k+1) - paprs(i,k))) / ( pplay(i,k) * RG ) 
-         ENDDO
-         ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_zfull%name,itau_w,zx_tmp_fi3d1(:,2:klevp1))
-!020611    $o_zfull%name,itau_w,zx_tmp_fi3d)
-        ENDIF
-
-        IF (o_zhalf%flag(iff)<=lev_files(iff)) THEN
-         DO i=1, klon
-          zx_tmp_fi3d(i,1)= pphis(i)/RG - (
-     $    (t_seri(i,1)+zxtsol(i))/2. *RD *
-     $    (pplay(i,1) - paprs(i,1)))/( (paprs(i,1)+pplay(i,1))/2. * RG)
-         ENDDO
-         DO k=1, klev-1
-         DO i=1, klon
-          zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - (
-     $    (t_seri(i,k)+t_seri(i,k+1))/2. *RD * 
-     $    (pplay(i,k+1) - pplay(i,k))) / ( paprs(i,k) * RG ) 
-         ENDDO
-         ENDDO
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_zhalf%name,itau_w,zx_tmp_fi3d)
-        ENDIF
-
-       IF (o_rneb%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rneb%name,itau_w,cldfra)
-       ENDIF
-
-       IF (o_rnebcon%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rnebcon%name,itau_w,rnebcon)
-       ENDIF
-
-       IF (o_rnebls%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rnebls%name,itau_w,rneb)
-       ENDIF
-
-       IF (o_rhum%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rhum%name,itau_w,zx_rh)
-       ENDIF
-
-      IF (o_ozone%flag(iff)<=lev_files(iff)) THEN
-         CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
-     $o_ozone%name, itau_w,
-     $        wo(:, :, 1) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
-      ENDIF
-
-      IF (o_ozone_light%flag(iff)<=lev_files(iff) .and.
-     $     read_climoz == 2) THEN
-         CALL histwrite_phy(nid_files(iff),clef_stations(iff), 
-     $o_ozone_light%name, itau_w,
-     $        wo(:, :, 2) * dobson_u * 1e3 / zmasse / rmo3 * rmd)
-      ENDIF
-
-       IF (o_dtphy%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtphy%name,itau_w,d_t)
-       ENDIF
-
-       IF (o_dqphy%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                  o_dqphy%name,itau_w, d_qx(:,:,ivap))
-       ENDIF
-
-        DO nsrf=1, nbsrf
-        IF (o_albe_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN 
-        zx_tmp_fi2d(1 : klon) = falb1( 1 : klon, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                    o_albe_srf(nsrf)%name,itau_w,
-     $                     zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_rugs_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN  
-        zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_rugs_srf(nsrf)%name,itau_w,
-     $      zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_ages_srf(nsrf)%flag(iff)<=lev_files(iff)) THEN
-        zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                     o_ages_srf(nsrf)%name,itau_w
-     $    ,zx_tmp_fi2d)
-        ENDIF
-        ENDDO !nsrf=1, nbsrf
-
-       IF (o_alb1%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_alb1%name,itau_w,albsol1)
-       ENDIF
-
-       IF (o_alb2%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_alb2%name,itau_w,albsol2)
-       ENDIF
-
-!FH Sorties pour la couche limite
-      if (iflag_pbl>1) then
-      zx_tmp_fi3d=0.
-      do nsrf=1,nbsrf
-         do k=1,klev
-          zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k)
-     $    +pctsrf(:,nsrf)*pbl_tke(:,k,nsrf)
-         enddo
-      enddo
-       IF (o_tke%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tke%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-      IF (.NOT.clef_stations(iff)) THEN
-       IF (o_tke_max%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_tke_max%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-      ENDIF
-      endif
-
-       IF (o_kz%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_kz%name,itau_w,coefh)
-       ENDIF
-
-      IF (.NOT.clef_stations(iff)) THEN
-       IF (o_kz_max%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_kz_max%name,itau_w,coefh)
-       ENDIF
-      ENDIF
-
-       IF (o_clwcon%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_clwcon%name,itau_w,clwcon0)
-       ENDIF
-
-       IF (o_dtdyn%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtdyn%name,itau_w,d_t_dyn)
-       ENDIF
-
-       IF (o_dqdyn%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dqdyn%name,itau_w,d_q_dyn)
-       ENDIF
-
-       IF (o_dudyn%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dudyn%name,itau_w,d_u_dyn)
-       ENDIF                                                    
-
-       IF (o_dvdyn%flag(iff)<=lev_files(iff)) THEN                 
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dvdyn%name,itau_w,d_v_dyn)  
-       ENDIF                                                     
-
-       IF (o_dtcon%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtcon%name,itau_w,zx_tmp_fi3d)
-      ENDIF                                                     
-
-      if(iflag_thermals.eq.1)then
-      IF (o_tntc%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys +
-     $                           d_t_ajsb(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tntc%name,itau_w,zx_tmp_fi3d)
-      ENDIF
-      else if(iflag_thermals.gt.1.and.iflag_wake.EQ.1)then
-      IF (o_tntc%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys +
-     $                           d_t_ajs(1:klon,1:klev)/pdtphys +
-     $                           d_t_wake(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tntc%name,itau_w,zx_tmp_fi3d)
-      ENDIF
-      endif
-
-       IF (o_ducon%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_u_con(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ducon%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dvcon%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_v_con(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dvcon%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dqcon%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dqcon%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-      if(iflag_thermals.eq.1)then
-       IF (o_tnhusc%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tnhusc%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-      else if(iflag_thermals.gt.1.and.iflag_wake.EQ.1)then
-      IF (o_tnhusc%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys +
-     $                           d_q_ajs(1:klon,1:klev)/pdtphys +
-     $                           d_q_wake(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tnhusc%name,itau_w,zx_tmp_fi3d)
-      ENDIF
-      endif
-
-       IF (o_dtlsc%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_lsc(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtlsc%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dtlschr%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+
-     $                           d_t_eva(1:klon,1:klev))/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                   o_dtlschr%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dqlsc%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dqlsc%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_beta_prec%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=beta_prec(1:klon,1:klev)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_beta_prec%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-! Sorties specifiques a la separation thermiques/non thermiques
-       if (iflag_thermals>=1) then
-
-       IF (o_dtlscth%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_lscth(1:klon,1:klev)/pdtphys
-      CALL 
-     s histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtlscth%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dtlscst%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_lscst(1:klon,1:klev)/pdtphys
-      CALL 
-     s histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtlscst%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dqlscth%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
-      CALL 
-     s histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dqlscth%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dqlscst%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
-      CALL 
-     s histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dqlscst%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_plulth%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_plulth%name,itau_w,plul_th)
-       ENDIF
-
-       IF (o_plulst%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_plulst%name,itau_w,plul_st)
-       ENDIF
-
-      do k=1,klev
-      do i=1,klon
-          if (ptconvth(i,k)) then
-           zx_tmp_fi3d(i,k)=1.
-          else
-           zx_tmp_fi3d(i,k)=0.
-          endif
-      enddo
-      enddo
-       IF (o_ptconvth%flag(iff)<=lev_files(iff)) THEN
-      CALL 
-     s  histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ptconvth%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-      do i=1,klon
-           zx_tmp_fi2d(1:klon)=lmax_th(:)
-      enddo
-       IF (o_ptconvth%flag(iff)<=lev_files(iff)) THEN
-      CALL 
-     s histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_lmaxth%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-      endif ! iflag_thermals>=1
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-       IF (o_dtvdf%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtvdf%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dqvdf%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dqvdf%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dteva%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dteva%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dqeva%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dqeva%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_ptconv%flag(iff)<=lev_files(iff)) THEN
-      zpt_conv = 0.
-      where (ptconv) zpt_conv = 1.
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ptconv%name,itau_w,zpt_conv)
-       ENDIF
-
-       IF (o_ratqs%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ratqs%name,itau_w,ratqs)
-       ENDIF
-
-       IF (o_dtthe%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajs(1:klon,1:klev)/pdtphys -
-     $                           d_t_ajsb(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtthe%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (iflag_thermals>=1) THEN
-        IF (o_ftime_th%flag(iff)<=lev_files(iff)) THEN
-! Pour l instant 0 a y reflichir pour les thermiques
-         zx_tmp_fi2d=0. 
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ftime_th%name,
-     s                     itau_w,zx_tmp_fi2d)
-        ENDIF
-
-        IF (o_f_th%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_f_th%name,itau_w,fm_therm)
-        ENDIF
-
-        IF (o_e_th%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_e_th%name,itau_w,entr_therm)
-        ENDIF
-
-        IF (o_w_th%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_w_th%name,itau_w,zw2)
-        ENDIF
-
-        IF (o_q_th%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_q_th%name,itau_w,zqasc)
-        ENDIF
-
-
-        IF (o_a_th%flag(iff)<=lev_files(iff)) THEN
-        CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_a_th%name,itau_w,fraca)
-        ENDIF
-
-       IF (o_d_th%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_d_th%name,itau_w,detr_therm)
-       ENDIF
-
-       IF (o_f0_th%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_f0_th%name,itau_w,f0)
-       ENDIF
-
-       IF (o_zmax_th%flag(iff)<=lev_files(iff)) THEN
-       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_zmax_th%name,itau_w,zmax_th)
-       ENDIF
-
-       IF (o_dqthe%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys -
-     $                           d_q_ajsb(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dqthe%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-      ENDIF !iflag_thermals
-
-       IF (o_dtajs%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajsb(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtajs%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dqajs%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dqajs%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dtswr%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtswr%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dtsw0%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtsw0%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dtlwr%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtlwr%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dtlw0%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtlw0%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dtec%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtec%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_duvdf%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_duvdf%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_dvvdf%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dvvdf%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (ok_orodr) THEN
-      IF (o_duoro%flag(iff)<=lev_files(iff)) THEN 
-      zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_duoro%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-      IF (o_dvoro%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dvoro%name,itau_w,zx_tmp_fi3d)
-      ENDIF
-
-      IF (o_dtoro%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_oro(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtoro%name,itau_w,zx_tmp_fi3d)
-      ENDIF
-       ENDIF
-
-        IF (ok_orolf) THEN
-       IF (o_dulif%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dulif%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-        IF (o_dvlif%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dvlif%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-        IF (o_dtlif%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_lif(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dtlif%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-        ENDIF
-
-       IF (ok_hines) THEN
-       IF (o_duhin%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_u_hin(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_duhin%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-
-        IF (o_dvhin%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_v_hin(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dvhin%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-        IF (o_dthin%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t_hin(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_dthin%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-        ENDIF
-
-       IF (o_rsu%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rsu%name,itau_w,swup)
-       ENDIF
-       IF (o_rsd%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rsd%name,itau_w,swdn)
-       ENDIF
-       IF (o_rlu%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rlu%name,itau_w,lwup)
-       ENDIF
-       IF (o_rld%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rld%name,itau_w,lwdn)
-       ENDIF
-
-       IF (o_rsucs%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rsucs%name,itau_w,swup0)
-       ENDIF
-       IF (o_rsdcs%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rsdcs%name,itau_w,swdn0)
-       ENDIF
-       IF (o_rlucs%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rlucs%name,itau_w,lwup0)
-       ENDIF
-       IF (o_rldcs%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rldcs%name,itau_w,lwdn0)
-       ENDIF
-
-       IF (o_tnt%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_t(1:klon,1:klev)+
-     $d_t_dyn(1:klon,1:klev)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tnt%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_tntr%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY -
-     $cool(1:klon,1:klev)/RDAY
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tntr%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_tntscpbl%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)= (d_t_lsc(1:klon,1:klev)+
-     $                             d_t_eva(1:klon,1:klev)+
-     $                             d_t_vdf(1:klon,1:klev))/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tntscpbl%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_tnhus%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_qx(1:klon,1:klev,ivap)+
-     $d_q_dyn(1:klon,1:klev)
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tnhus%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_tnhusscpbl%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys+
-     $                           d_q_eva(1:klon,1:klev)/pdtphys
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_tnhusscpbl%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       IF (o_evu%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_evu%name,itau_w,coefm)
-       ENDIF
-
-       IF (o_h2o%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi3d(1:klon,1:klev)=q_seri(1:klon,1:klev)+
-     $                           ql_seri(1:klon,1:klev) 
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_h2o%name,itau_w,zx_tmp_fi3d)
-       ENDIF
-
-       if (iflag_con >= 3) then
-          IF (o_mcd%flag(iff)<=lev_files(iff)) THEN
-             zx_tmp_fi3d(1:klon,1:klev)=-1 * (dnwd(1:klon,1:klev)+
-     $            dnwd0(1:klon,1:klev)) 
-             CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $            o_mcd%name,itau_w,zx_tmp_fi3d)
-          ENDIF
-
-          IF (o_dmc%flag(iff)<=lev_files(iff)) THEN
-             zx_tmp_fi3d(1:klon,1:klev)=upwd(1:klon,1:klev) +
-     $            dnwd(1:klon,1:klev)+ dnwd0(1:klon,1:klev) 
-             CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $            o_dmc%name,itau_w,zx_tmp_fi3d)
-          ENDIF
-       else if (iflag_con == 2) then
-          IF (o_mcd%flag(iff) <= lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff), clef_stations(iff),
-     $            o_mcd%name, itau_w, pmfd)
-          ENDIF
-
-          IF (o_dmc%flag(iff) <= lev_files(iff)) THEN
-             CALL histwrite_phy(nid_files(iff), clef_stations(iff),
-     $            o_dmc%name, itau_w, pmfu + pmfd)
-          ENDIF
-       end if
-
-       IF (o_ref_liq%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ref_liq%name,itau_w,ref_liq)
-       ENDIF
-
-       IF (o_ref_ice%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_ref_ice%name,itau_w,ref_ice)
-       ENDIF
-
-      if (RCO2_per.NE.RCO2_act.OR.RCH4_per.NE.RCH4_act.OR.
-     $ RN2O_per.NE.RN2O_act.OR.RCFC11_per.NE.RCFC11_act.OR.
-     $ RCFC12_per.NE.RCFC12_act) THEN
-
-       IF (o_rsut4co2%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = swupp ( 1 : klon, klevp1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rsut4co2%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_rlut4co2%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = lwupp ( 1 : klon, klevp1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rlut4co2%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_rsutcs4co2%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = swup0p ( 1 : klon, klevp1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rsutcs4co2%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_rlutcs4co2%flag(iff)<=lev_files(iff)) THEN
-      zx_tmp_fi2d(1 : klon) = lwup0p ( 1 : klon, klevp1 )
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rlutcs4co2%name,itau_w,zx_tmp_fi2d)
-       ENDIF
-
-       IF (o_rsu4co2%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rsu4co2%name,itau_w,swupp)
-       ENDIF
-
-       IF (o_rlu4co2%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rlu4co2%name,itau_w,lwupp)
-       ENDIF
-
-       IF (o_rsucs4co2%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rsucs4co2%name,itau_w,swup0p)
-       ENDIF
-
-       IF (o_rlucs4co2%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rlucs4co2%name,itau_w,lwup0p)
-       ENDIF
-
-       IF (o_rsd4co2%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rsd4co2%name,itau_w,swdnp)
-       ENDIF
-
-       IF (o_rld4co2%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rld4co2%name,itau_w,lwdnp)
-       ENDIF
-
-       IF (o_rsdcs4co2%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rsdcs4co2%name,itau_w,swdn0p)
-       ENDIF
-
-       IF (o_rldcs4co2%flag(iff)<=lev_files(iff)) THEN
-      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     $o_rldcs4co2%name,itau_w,lwdn0p)
-       ENDIF
-
-      endif
-
-        if (nqtot.GE.3) THEN
-         DO iq=3,nqtot
-       IF (o_trac(iq-2)%flag(iff)<=lev_files(iff)) THEN
-         CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                  o_trac(iq-2)%name,itau_w,qx(:,:,iq))
-       ENDIF
-         ENDDO
-         DO iq=3,nqtot
-       IF (o_trac_cum(iq-2)%flag(iff)<=lev_files(iff)) THEN
-         zx_tmp_fi2d=0.
-         do k=1,klev
-            zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*qx(:,k,iq)
-         enddo
-         CALL histwrite_phy(nid_files(iff),clef_stations(iff),
-     s                  o_trac_cum(iq-2)%name,itau_w,zx_tmp_fi2d)
-
-       ENDIF
-         ENDDO
-        endif
-
-      if (ok_sync) then
-c$OMP MASTER
-      call histsync(nid_files(iff))
-c$OMP END MASTER
-      endif
-
-       ENDIF ! clef_files
-
-      ENDDO ! iff=1,nfiles
Index: LMDZ5/branches/testing/libf/phylmd/phys_output_write_new.h
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phys_output_write_new.h	(revision 1795)
+++ LMDZ5/branches/testing/libf/phylmd/phys_output_write_new.h	(revision 1795)
@@ -0,0 +1,788 @@
+      itau_w = itau_phy + itap + start_time * day_step / iphysiq
+      ! ug On transmet le pas de temps à iophy pour que les méthodes histwrite y aient accès:
+      itau_iophy = itau_w
+
+             ndex2d = 0
+             ndex3d = 0
+!!! Champs 1D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+      CALL histwrite_phy(o_phis, pphis)
+      CALL histwrite_phy(o_aire, airephy)
+
+      DO i=1, klon
+            zx_tmp_fi2d(i)=pctsrf(i,is_ter)+pctsrf(i,is_lic)
+      ENDDO
+      CALL histwrite_phy(o_contfracATM, zx_tmp_fi2d)
+      CALL histwrite_phy(o_contfracOR, pctsrf(:,is_ter))
+      CALL histwrite_phy(o_aireTER, paire_ter)
+!!! Champs 2D !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+      CALL histwrite_phy(o_flat, zxfluxlat)
+      CALL histwrite_phy(o_slp, slp)
+      CALL histwrite_phy(o_tsol, zxtsol)
+      CALL histwrite_phy(o_t2m, zt2m)
+      CALL histwrite_phy(o_t2m_min, zt2m)
+      CALL histwrite_phy(o_t2m_max, zt2m)
+
+      DO i=1, klon
+       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
+      ENDDO
+      CALL histwrite_phy(o_wind10m, zx_tmp_fi2d)
+
+      DO i=1, klon
+       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
+      ENDDO
+      CALL histwrite_phy(o_wind10max, zx_tmp_fi2d)
+
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
+      ENDDO
+      CALL histwrite_phy(o_sicf, zx_tmp_fi2d)
+      CALL histwrite_phy(o_q2m, zq2m)
+      CALL histwrite_phy(o_ustar, zustar)
+      CALL histwrite_phy(o_u10m, zu10m)
+      CALL histwrite_phy(o_v10m, zv10m)
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = paprs(i,1)
+      ENDDO
+      CALL histwrite_phy(o_psol, zx_tmp_fi2d)
+      CALL histwrite_phy(o_mass, zmasse)
+      CALL histwrite_phy(o_qsurf, zxqsurf)
+
+      IF (.NOT. ok_veget) THEN
+            CALL histwrite_phy(o_qsol, qsol)
+      ENDIF
+
+       DO i = 1, klon
+         zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
+       ENDDO
+      CALL histwrite_phy(o_precip, zx_tmp_fi2d)
+      CALL histwrite_phy(o_ndayrain, nday_rain)
+       DO i = 1, klon
+         zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
+       ENDDO
+      CALL histwrite_phy(o_plul, zx_tmp_fi2d)
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
+      ENDDO
+      CALL histwrite_phy(o_pluc, zx_tmp_fi2d)
+      CALL histwrite_phy(o_snow, snow_fall)
+      CALL histwrite_phy(o_msnow, snow_o)
+      CALL histwrite_phy(o_fsnow, zfra_o)
+      CALL histwrite_phy(o_evap, evap)
+      CALL histwrite_phy(o_tops, topsw)
+      CALL histwrite_phy(o_tops0, topsw0)
+      CALL histwrite_phy(o_topl, toplw)
+      CALL histwrite_phy(o_topl0, toplw0)
+      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
+      CALL histwrite_phy(o_SWupTOA, zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
+      CALL histwrite_phy(o_SWupTOAclr, zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
+      CALL histwrite_phy(o_SWdnTOA, zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
+      CALL histwrite_phy(o_SWdnTOAclr, zx_tmp_fi2d)
+      zx_tmp_fi2d(:) = topsw(:)-toplw(:)
+      CALL histwrite_phy(o_nettop, zx_tmp_fi2d)
+      CALL histwrite_phy(o_SWup200, SWup200)
+      CALL histwrite_phy(o_SWup200clr, SWup200clr)
+      CALL histwrite_phy(o_SWdn200, SWdn200)
+      CALL histwrite_phy(o_SWdn200clr, SWdn200clr)
+      CALL histwrite_phy(o_LWup200, LWup200)
+      CALL histwrite_phy(o_LWup200clr, LWup200clr)
+      CALL histwrite_phy(o_LWdn200, LWdn200)
+      CALL histwrite_phy(o_LWdn200clr, LWdn200clr)
+      CALL histwrite_phy(o_sols, solsw)
+      CALL histwrite_phy(o_sols0, solsw0)
+      CALL histwrite_phy(o_soll, sollw)
+      CALL histwrite_phy(o_radsol, radsol)
+      CALL histwrite_phy(o_soll0, sollw0)
+      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
+      CALL histwrite_phy(o_SWupSFC, zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 1 )
+      CALL histwrite_phy(o_SWupSFCclr, zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
+      CALL histwrite_phy(o_SWdnSFC, zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 1 )
+      CALL histwrite_phy(o_SWdnSFCclr, zx_tmp_fi2d)
+      zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
+      CALL histwrite_phy(o_LWupSFC, zx_tmp_fi2d)
+      CALL histwrite_phy(o_LWdnSFC, sollwdown)
+
+       sollwdownclr(1:klon) = -1.*lwdn0(1:klon,1)
+      zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
+      CALL histwrite_phy(o_LWupSFCclr, zx_tmp_fi2d)
+      CALL histwrite_phy(o_LWdnSFCclr, sollwdownclr)
+
+      CALL histwrite_phy(o_bils, bils)
+      CALL histwrite_phy(o_bils_diss, bils_diss)
+      CALL histwrite_phy(o_bils_ec, bils_ec)
+      CALL histwrite_phy(o_bils_tke, bils_tke)
+      CALL histwrite_phy(o_bils_kinetic, bils_kinetic)
+      CALL histwrite_phy(o_bils_latent, bils_latent)
+      CALL histwrite_phy(o_bils_enthalp, bils_enthalp)
+
+      zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
+      CALL histwrite_phy(o_sens, zx_tmp_fi2d)
+      CALL histwrite_phy(o_fder, fder)
+      CALL histwrite_phy(o_ffonte, zxffonte)
+      CALL histwrite_phy(o_fqcalving, zxfqcalving)
+      CALL histwrite_phy(o_fqfonte, zxfqfonte)
+         zx_tmp_fi2d=0.
+         do nsrf=1,nbsrf
+          zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxu(:,1,nsrf)
+         enddo
+      CALL histwrite_phy(o_taux, zx_tmp_fi2d)
+         zx_tmp_fi2d=0.
+         do nsrf=1,nbsrf
+          zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+pctsrf(:,nsrf)*fluxv(:,1,nsrf)
+         enddo
+      CALL histwrite_phy(o_tauy, zx_tmp_fi2d)
+         DO nsrf = 1, nbsrf
+!           IF(nsrf.GE.2) THEN
+            zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
+      CALL histwrite_phy(o_pourc_srf(nsrf), zx_tmp_fi2d)
+          zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
+      CALL histwrite_phy(o_fract_srf(nsrf), zx_tmp_fi2d)
+!         ENDIF !nsrf.GT.2
+        zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
+      CALL histwrite_phy(o_taux_srf(nsrf), zx_tmp_fi2d)
+        zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
+      CALL histwrite_phy(o_tauy_srf(nsrf), zx_tmp_fi2d)
+        zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
+      CALL histwrite_phy(o_tsol_srf(nsrf), zx_tmp_fi2d)
+        zx_tmp_fi2d(1 : klon) = evap_pot( 1 : klon, nsrf)
+      CALL histwrite_phy(o_evappot_srf(nsrf), zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = ustar(1 : klon, nsrf)
+      CALL histwrite_phy(o_ustar_srf(nsrf), zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, nsrf)
+      CALL histwrite_phy(o_u10m_srf(nsrf), zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, nsrf)
+      CALL histwrite_phy(o_v10m_srf(nsrf), zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, nsrf)
+      CALL histwrite_phy(o_t2m_srf(nsrf), zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = fevap(1 : klon, nsrf)
+      CALL histwrite_phy(o_evap_srf(nsrf), zx_tmp_fi2d)
+       zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
+      CALL histwrite_phy(o_sens_srf(nsrf), zx_tmp_fi2d)
+        zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
+      CALL histwrite_phy(o_lat_srf(nsrf), zx_tmp_fi2d)
+        zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
+      CALL histwrite_phy(o_flw_srf(nsrf), zx_tmp_fi2d)
+        zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
+      CALL histwrite_phy(o_fsw_srf(nsrf), zx_tmp_fi2d)
+        zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
+      CALL histwrite_phy(o_wbils_srf(nsrf), zx_tmp_fi2d)
+        zx_tmp_fi2d(1 : klon) = wfbilo( 1 : klon, nsrf)
+      CALL histwrite_phy(o_wbilo_srf(nsrf), zx_tmp_fi2d)
+
+      IF (iflag_pbl>1) THEN
+       CALL histwrite_phy(o_tke_srf(nsrf), pbl_tke(:,1:klev,nsrf))
+       CALL histwrite_phy(o_tke_max_srf(nsrf), pbl_tke(:,1:klev,nsrf))
+      ENDIF
+
+      ENDDO
+      CALL histwrite_phy(o_cdrm, cdragm)
+      CALL histwrite_phy(o_cdrh, cdragh)
+      CALL histwrite_phy(o_cldl, cldl)
+      CALL histwrite_phy(o_cldm, cldm)
+      CALL histwrite_phy(o_cldh, cldh)
+      CALL histwrite_phy(o_cldt, cldt)
+      CALL histwrite_phy(o_cldq, cldq)
+      zx_tmp_fi2d(1:klon) = flwp(1:klon)
+      CALL histwrite_phy(o_lwp, zx_tmp_fi2d)
+      zx_tmp_fi2d(1:klon) = fiwp(1:klon)
+      CALL histwrite_phy(o_iwp, zx_tmp_fi2d)
+      CALL histwrite_phy(o_ue, ue)
+      CALL histwrite_phy(o_ve, ve)
+      CALL histwrite_phy(o_uq, uq)
+      CALL histwrite_phy(o_vq, vq)
+      IF(iflag_con.GE.3) THEN ! sb
+            CALL histwrite_phy(o_cape, cape)
+            CALL histwrite_phy(o_pbase, ema_pcb)
+            CALL histwrite_phy(o_ptop, ema_pct)
+            CALL histwrite_phy(o_fbase, ema_cbmf)
+
+            IF (iflag_con /= 30) THEN
+                  CALL histwrite_phy(o_plcl, plcl)
+                  CALL histwrite_phy(o_plfc, plfc)
+                  CALL histwrite_phy(o_wbeff, wbeff)
+            ENDIF
+
+            CALL histwrite_phy(o_cape_max, cape)
+            CALL histwrite_phy(o_upwd, upwd)
+            CALL histwrite_phy(o_Ma, Ma)
+            CALL histwrite_phy(o_dnwd, dnwd)
+            CALL histwrite_phy(o_dnwd0, dnwd0)
+              zx_tmp_fi2d=float(itau_con)/float(itap)
+            CALL histwrite_phy(o_ftime_con, zx_tmp_fi2d)
+
+            IF (iflag_thermals>=1) THEN
+               zx_tmp_fi3d=dnwd+dnwd0+upwd+fm_therm(:,1:klev)
+            ELSE
+               zx_tmp_fi3d=dnwd+dnwd0+upwd
+            ENDIF
+            CALL histwrite_phy(o_mc, zx_tmp_fi3d)
+      ENDIF !iflag_con .GE. 3
+
+      CALL histwrite_phy(o_prw, prw)
+      CALL histwrite_phy(o_s_pblh, s_pblh)
+      CALL histwrite_phy(o_s_pblt, s_pblt)
+      CALL histwrite_phy(o_s_lcl, s_lcl)
+      CALL histwrite_phy(o_s_therm, s_therm)
+
+
+! ANCIENNE METHODE
+        DO iff=1,nfiles
+              ll=0
+        DO k=1, nlevSTD
+         bb2=clevSTD(k) 
+         IF(bb2.EQ."850".OR.bb2.EQ."700".OR.
+     $      bb2.EQ."500".OR.bb2.EQ."200".OR.
+     $      bb2.EQ."100".OR.
+     $      bb2.EQ."50".OR.bb2.EQ."10") THEN
+
+! a refaire correctement !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+          ll=ll+1
+      CALL histwrite_phy(o_uSTDlevs(ll),uwriteSTD(:,k,iff), iff)
+      CALL histwrite_phy(o_vSTDlevs(ll),vwriteSTD(:,k,iff), iff)
+      CALL histwrite_phy(o_wSTDlevs(ll),wwriteSTD(:,k,iff), iff)
+      CALL histwrite_phy(o_zSTDlevs(ll),phiwriteSTD(:,k,iff), iff)
+      CALL histwrite_phy(o_qSTDlevs(ll),qwriteSTD(:,k,iff), iff)
+      CALL histwrite_phy(o_tSTDlevs(ll),twriteSTD(:,k,iff), iff)
+!       IF (o_uSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
+!       CALL histwrite_phy(nid_files(iff),clef_stations(iff),
+!     $o_uSTDlevs(ll)%name,
+!     &                    itau_w,uwriteSTD(:,k,iff))
+!       ENDIF
+
+ !      IF (o_vSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
+!      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
+!     $o_vSTDlevs(ll)%name,  
+!     &                   itau_w,vwriteSTD(:,k,iff))
+!       ENDIF
+
+!       IF (o_wSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
+!      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
+!     $o_wSTDlevs(ll)%name,
+!     &                    itau_w,wwriteSTD(:,k,iff))
+!       ENDIF
+
+!       IF (o_zSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
+!      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
+!     $o_zSTDlevs(ll)%name,
+!     &               itau_w,phiwriteSTD(:,k,iff))
+!      ENDIF
+
+ !      IF (o_qSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
+!      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
+!     $o_qSTDlevs(ll)%name,
+!     &                   itau_w, qwriteSTD(:,k,iff))
+!       ENDIF
+
+ !      IF (o_tSTDlevs(ll)%flag(iff)<=lev_files(iff)) THEN
+!      CALL histwrite_phy(nid_files(iff),clef_stations(iff),
+!     $o_tSTDlevs(ll)%name,
+!     &                   itau_w, twriteSTD(:,k,iff))
+ !      ENDIF
+
+       ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
+       ENDDO
+   	   ENDDO
+! /ANCIENNE METHODE       
+
+
+      DO i=1, klon
+       IF (pctsrf(i,is_oce).GT.epsfra.OR.
+     $     pctsrf(i,is_sic).GT.epsfra) THEN
+        zx_tmp_fi2d(i) = (ftsol(i, is_oce) * pctsrf(i,is_oce)+
+     $                   ftsol(i, is_sic) * pctsrf(i,is_sic))/
+     $                   (pctsrf(i,is_oce)+pctsrf(i,is_sic))
+       ELSE
+        zx_tmp_fi2d(i) = 273.15
+       ENDIF
+      ENDDO
+      CALL histwrite_phy(o_t_oce_sic, zx_tmp_fi2d)
+! Couplage convection-couche limite
+      IF (iflag_con.GE.3) THEN
+            IF (iflag_coupl>=1) THEN
+                  CALL histwrite_phy(o_ale_bl, ale_bl)
+                  CALL histwrite_phy(o_alp_bl, alp_bl)
+            ENDIF !iflag_coupl>=1
+      ENDIF !(iflag_con.GE.3)
+! Wakes
+      IF (iflag_con.EQ.3) THEN
+            IF (iflag_wake>=1) THEN
+            CALL histwrite_phy(o_ale_wk, ale_wake)
+            CALL histwrite_phy(o_alp_wk, alp_wake)
+            CALL histwrite_phy(o_ale, ale)
+            CALL histwrite_phy(o_alp, alp)
+            CALL histwrite_phy(o_cin, cin)
+            CALL histwrite_phy(o_WAPE, wake_pe)
+            CALL histwrite_phy(o_wake_h, wake_h)
+            CALL histwrite_phy(o_wake_s, wake_s)
+            CALL histwrite_phy(o_wake_deltat, wake_deltat)
+            CALL histwrite_phy(o_wake_deltaq, wake_deltaq)
+            CALL histwrite_phy(o_wake_omg, wake_omg)
+                  zx_tmp_fi3d(1:klon,1:klev)=d_t_wake(1:klon,1:klev)
+     &                                        /pdtphys
+            CALL histwrite_phy(o_dtwak, zx_tmp_fi3d)
+                  zx_tmp_fi3d(1:klon,1:klev)=d_q_wake(1:klon,1:klev)
+     &                                        /pdtphys
+            CALL histwrite_phy(o_dqwak, zx_tmp_fi3d)
+            ENDIF ! iflag_wake>=1
+            CALL histwrite_phy(o_Vprecip, Vprecip)
+            CALL histwrite_phy(o_ftd, ftd)
+            CALL histwrite_phy(o_fqd, fqd)
+      ELSEIF (iflag_con.EQ.30) THEN
+! sortie RomP convection descente insaturee iflag_con=30
+            CALL histwrite_phy(o_Vprecip, Vprecip)
+            CALL histwrite_phy(o_wdtrainA, wdtrainA)
+            CALL histwrite_phy(o_wdtrainM, wdtrainM)
+      ENDIF !(iflag_con.EQ.3.or.iflag_con.EQ.30)
+
+!!! nrlmd le 10/04/2012
+      IF (iflag_trig_bl>=1) THEN
+            CALL histwrite_phy(o_n2, n2)
+            CALL histwrite_phy(o_s2, s2)
+            CALL histwrite_phy(o_proba_notrig, proba_notrig)
+            CALL histwrite_phy(o_random_notrig, random_notrig)
+            CALL histwrite_phy(o_ale_bl_stat, ale_bl_stat)
+            CALL histwrite_phy(o_ale_bl_trig, ale_bl_trig)
+      ENDIF  !(iflag_trig_bl>=1)
+      
+      IF (iflag_clos_bl>=1) THEN
+            CALL histwrite_phy(o_alp_bl_det, alp_bl_det)
+            CALL histwrite_phy(o_alp_bl_fluct_m, alp_bl_fluct_m)
+            CALL histwrite_phy(o_alp_bl_fluct_tke, alp_bl_fluct_tke)
+            CALL histwrite_phy(o_alp_bl_conv, alp_bl_conv)
+            CALL histwrite_phy(o_alp_bl_stat, alp_bl_stat)
+      ENDIF  !(iflag_clos_bl>=1)
+!!! fin nrlmd le 10/04/2012
+
+      IF (type_ocean=='slab ') THEN
+            CALL histwrite_phy(o_slab_bils, slab_wfbils)
+      ENDIF !type_ocean == force/slab
+
+      CALL histwrite_phy(o_weakinv, weak_inversion)
+      CALL histwrite_phy(o_dthmin, dthmin)
+      CALL histwrite_phy(o_cldtau, cldtau)
+      CALL histwrite_phy(o_cldemi, cldemi)
+      CALL histwrite_phy(o_pr_con_l, pmflxr(:,1:klev))
+      CALL histwrite_phy(o_pr_con_i, pmflxs(:,1:klev))
+      CALL histwrite_phy(o_pr_lsc_l, prfl(:,1:klev))
+      CALL histwrite_phy(o_pr_lsc_i, psfl(:,1:klev))
+      CALL histwrite_phy(o_re, re)
+      CALL histwrite_phy(o_fl, fl)
+      DO i=1, klon
+       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
+      ENDDO
+      CALL histwrite_phy(o_rh2m, zx_tmp_fi2d)
+
+      DO i=1, klon
+       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
+      ENDDO
+      CALL histwrite_phy(o_rh2m_min, zx_tmp_fi2d)
+      DO i=1, klon
+       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
+      ENDDO
+      CALL histwrite_phy(o_rh2m_max, zx_tmp_fi2d)
+
+      CALL histwrite_phy(o_qsat2m, qsat2m)
+      CALL histwrite_phy(o_tpot, tpot)
+      CALL histwrite_phy(o_tpote, tpote)
+      zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, is_ter)
+      CALL histwrite_phy(o_SWnetOR,  zx_tmp_fi2d)
+      zx_tmp_fi2d(1:klon) = solsw(1:klon)/(1.-albsol1(1:klon))
+      CALL histwrite_phy(o_SWdownOR,  zx_tmp_fi2d)
+      CALL histwrite_phy(o_LWdownOR, sollwdown)
+      CALL histwrite_phy(o_snowl, snow_lsc)
+      CALL histwrite_phy(o_solldown, sollwdown)
+      CALL histwrite_phy(o_dtsvdfo, d_ts(:,is_oce))
+      CALL histwrite_phy(o_dtsvdft, d_ts(:,is_ter))
+      CALL histwrite_phy(o_dtsvdfg,  d_ts(:,is_lic))
+      CALL histwrite_phy(o_dtsvdfi, d_ts(:,is_sic))
+      CALL histwrite_phy(o_rugs, zxrugs)
+! OD550 per species
+      IF (new_aod .and. (.not. aerosol_couple)) THEN
+          IF (ok_ade.OR.ok_aie) THEN
+      CALL histwrite_phy(o_od550aer, od550aer)
+      CALL histwrite_phy(o_od865aer, od865aer)
+      CALL histwrite_phy(o_absvisaer, absvisaer)
+      CALL histwrite_phy(o_od550lt1aer, od550lt1aer)
+      CALL histwrite_phy(o_sconcso4, sconcso4)
+      CALL histwrite_phy(o_sconcoa, sconcoa)
+      CALL histwrite_phy(o_sconcbc, sconcbc)
+      CALL histwrite_phy(o_sconcss, sconcss)
+      CALL histwrite_phy(o_sconcdust, sconcdust)
+      CALL histwrite_phy(o_concso4, concso4)
+      CALL histwrite_phy(o_concoa, concoa)
+      CALL histwrite_phy(o_concbc, concbc)
+      CALL histwrite_phy(o_concss, concss)
+      CALL histwrite_phy(o_concdust, concdust)
+      CALL histwrite_phy(o_loadso4, loadso4)
+      CALL histwrite_phy(o_loadoa, loadoa)
+      CALL histwrite_phy(o_loadbc, loadbc)
+      CALL histwrite_phy(o_loadss, loadss)
+      CALL histwrite_phy(o_loaddust, loaddust)
+          DO naero = 1, naero_spc
+      CALL histwrite_phy(o_tausumaero(naero),
+     & tausum_aero(:,2,naero) )
+          END DO
+          endif
+      ENDIF
+       IF (ok_ade) THEN
+      CALL histwrite_phy(o_topswad, topswad_aero)
+      CALL histwrite_phy(o_topswad0, topswad0_aero)
+      CALL histwrite_phy(o_solswad, solswad_aero)
+      CALL histwrite_phy(o_solswad0, solswad0_aero)
+!====MS forcing diagnostics
+        if (new_aod) then	       
+      CALL histwrite_phy(o_swtoaas_nat, topsw_aero(:,1))
+      CALL histwrite_phy(o_swsrfas_nat, solsw_aero(:,1))
+      CALL histwrite_phy(o_swtoacs_nat, topsw0_aero(:,1))
+      CALL histwrite_phy(o_swsrfcs_nat, solsw0_aero(:,1))
+!ant
+      CALL histwrite_phy(o_swtoaas_ant, topsw_aero(:,2))
+      CALL histwrite_phy(o_swsrfas_ant, solsw_aero(:,2))
+      CALL histwrite_phy(o_swtoacs_ant, topsw0_aero(:,2))
+      CALL histwrite_phy(o_swsrfcs_ant, solsw0_aero(:,2))
+!cf
+        if (.not. aerosol_couple) then
+      CALL histwrite_phy(o_swtoacf_nat, topswcf_aero(:,1))
+      CALL histwrite_phy(o_swsrfcf_nat, solswcf_aero(:,1))
+      CALL histwrite_phy(o_swtoacf_ant, topswcf_aero(:,2))
+      CALL histwrite_phy(o_swsrfcf_ant, solswcf_aero(:,2))
+      CALL histwrite_phy(o_swtoacf_zero,topswcf_aero(:,3))
+      CALL histwrite_phy(o_swsrfcf_zero,solswcf_aero(:,3))
+        endif
+	endif ! new_aod
+!====MS forcing diagnostics
+       ENDIF
+       IF (ok_aie) THEN
+      CALL histwrite_phy(o_topswai, topswai_aero)
+      CALL histwrite_phy(o_solswai, solswai_aero)
+      CALL histwrite_phy(o_scdnc, scdnc)
+      CALL histwrite_phy(o_cldncl, cldncl)
+      CALL histwrite_phy(o_reffclws, reffclws)
+      CALL histwrite_phy(o_reffclwc, reffclwc)
+      CALL histwrite_phy(o_cldnvi, cldnvi)
+      CALL histwrite_phy(o_lcc, lcc)
+      CALL histwrite_phy(o_lcc3d, lcc3d)
+      CALL histwrite_phy(o_lcc3dcon, lcc3dcon)
+      CALL histwrite_phy(o_lcc3dstra, lcc3dstra)
+      CALL histwrite_phy(o_reffclwtop, reffclwtop)
+       ENDIF
+! Champs 3D:
+       IF (ok_ade .OR. ok_aie) then
+      CALL histwrite_phy(o_ec550aer, ec550aer)
+       ENDIF
+      CALL histwrite_phy(o_lwcon, flwc)
+      CALL histwrite_phy(o_iwcon, fiwc)
+      CALL histwrite_phy(o_temp, t_seri)
+      CALL histwrite_phy(o_theta, theta)
+      CALL histwrite_phy(o_ovapinit, qx(:,:,ivap))
+      CALL histwrite_phy(o_ovap, q_seri)
+      CALL histwrite_phy(o_oliq, ql_seri)
+      CALL histwrite_phy(o_geop, zphi)
+      CALL histwrite_phy(o_vitu, u_seri)
+      CALL histwrite_phy(o_vitv, v_seri)
+      CALL histwrite_phy(o_vitw, omega)
+      CALL histwrite_phy(o_pres, pplay)
+      CALL histwrite_phy(o_paprs, paprs(:,1:klev))
+         DO i=1, klon
+          zx_tmp_fi3d1(i,1)= pphis(i)/RG
+!020611   zx_tmp_fi3d(i,1)= pphis(i)/RG
+         ENDDO
+         DO k=1, klev
+!020611        DO k=1, klev-1
+         DO i=1, klon
+!020611         zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - (t_seri(i,k) *RD * 
+          zx_tmp_fi3d1(i,k+1)= zx_tmp_fi3d1(i,k) - (t_seri(i,k) *RD * 
+     $    (paprs(i,k+1) - paprs(i,k))) / ( pplay(i,k) * RG ) 
+         ENDDO
+         ENDDO
+      CALL histwrite_phy(o_zfull,zx_tmp_fi3d1(:,2:klevp1))
+!020611    $o_zfull%name,itau_w,zx_tmp_fi3d)
+         DO i=1, klon
+          zx_tmp_fi3d(i,1)= pphis(i)/RG - (
+     $    (t_seri(i,1)+zxtsol(i))/2. *RD *
+     $    (pplay(i,1) - paprs(i,1)))/((paprs(i,1)+pplay(i,1))/2. * RG)
+         ENDDO
+         DO k=1, klev-1
+         DO i=1, klon
+          zx_tmp_fi3d(i,k+1)= zx_tmp_fi3d(i,k) - (
+     $    (t_seri(i,k)+t_seri(i,k+1))/2. *RD * 
+     $    (pplay(i,k+1) - pplay(i,k))) / ( paprs(i,k) * RG ) 
+         ENDDO
+         ENDDO
+      CALL histwrite_phy(o_zhalf, zx_tmp_fi3d)
+      CALL histwrite_phy(o_rneb, cldfra)
+      CALL histwrite_phy(o_rnebcon, rnebcon)
+      CALL histwrite_phy(o_rnebls, rneb)
+      CALL histwrite_phy(o_rhum, zx_rh)
+      CALL histwrite_phy(o_ozone, wo(:, :, 1)
+     & * dobson_u * 1e3 / zmasse / rmo3 * rmd)
+      IF (read_climoz == 2) THEN
+      CALL histwrite_phy(o_ozone_light, wo(:, :, 2)
+     & * dobson_u * 1e3 / zmasse / rmo3 * rmd)
+      ENDIF
+      CALL histwrite_phy(o_dtphy, d_t)
+      CALL histwrite_phy(o_dqphy,  d_qx(:,:,ivap))
+        DO nsrf=1, nbsrf
+        zx_tmp_fi2d(1 : klon) = falb1( 1 : klon, nsrf)
+      CALL histwrite_phy(o_albe_srf(nsrf), zx_tmp_fi2d)
+        zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
+      CALL histwrite_phy(o_rugs_srf(nsrf), zx_tmp_fi2d)
+        zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
+      CALL histwrite_phy(o_ages_srf(nsrf), zx_tmp_fi2d)
+        ENDDO !nsrf=1, nbsrf
+      CALL histwrite_phy(o_alb1, albsol1)
+      CALL histwrite_phy(o_alb2, albsol2)
+!FH Sorties pour la couche limite
+      if (iflag_pbl>1) then
+      zx_tmp_fi3d=0.
+      do nsrf=1,nbsrf
+         do k=1,klev
+          zx_tmp_fi3d(:,k)=zx_tmp_fi3d(:,k)
+     $    +pctsrf(:,nsrf)*pbl_tke(:,k,nsrf)
+         enddo
+      enddo
+      CALL histwrite_phy(o_tke, zx_tmp_fi3d)
+
+      CALL histwrite_phy(o_tke_max, zx_tmp_fi3d)
+
+      endif
+      CALL histwrite_phy(o_kz, coefh(:,:,is_ave))
+
+      CALL histwrite_phy(o_kz_max, coefh(:,:,is_ave))
+
+      CALL histwrite_phy(o_clwcon, clwcon0)
+      CALL histwrite_phy(o_dtdyn, d_t_dyn)
+      CALL histwrite_phy(o_dqdyn, d_q_dyn)
+      CALL histwrite_phy(o_dudyn, d_u_dyn)
+      CALL histwrite_phy(o_dvdyn, d_v_dyn)
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtcon, zx_tmp_fi3d)
+      if(iflag_thermals.eq.1)then
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys +
+     $                           d_t_ajsb(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_tntc, zx_tmp_fi3d)
+      else if(iflag_thermals.gt.1.and.iflag_wake.EQ.1)then
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys +
+     $                           d_t_ajs(1:klon,1:klev)/pdtphys +
+     $                           d_t_wake(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_tntc, zx_tmp_fi3d)
+      endif
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_con(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_ducon, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_con(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dvcon, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dqcon, zx_tmp_fi3d)
+      if(iflag_thermals.eq.1)then
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_tnhusc, zx_tmp_fi3d)
+      else if(iflag_thermals.gt.1.and.iflag_wake.EQ.1)then
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys +
+     $                           d_q_ajs(1:klon,1:klev)/pdtphys +
+     $                           d_q_wake(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_tnhusc, zx_tmp_fi3d)
+      endif
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_lsc(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtlsc, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+
+     $                           d_t_eva(1:klon,1:klev))/pdtphys
+      CALL histwrite_phy(o_dtlschr, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dqlsc, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=beta_prec(1:klon,1:klev)
+      CALL histwrite_phy(o_beta_prec, zx_tmp_fi3d)
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Sorties specifiques a la separation thermiques/non thermiques
+       if (iflag_thermals>=1) then
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_lscth(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtlscth, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_lscst(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtlscst, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_lscth(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dqlscth, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_lscst(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dqlscst, zx_tmp_fi3d)
+      CALL histwrite_phy(o_plulth, plul_th)
+      CALL histwrite_phy(o_plulst, plul_st)
+      do k=1,klev
+      do i=1,klon
+          if (ptconvth(i,k)) then
+           zx_tmp_fi3d(i,k)=1.
+          else
+           zx_tmp_fi3d(i,k)=0.
+          endif
+      enddo
+      enddo
+      CALL histwrite_phy(o_ptconvth, zx_tmp_fi3d)
+      do i=1,klon
+           zx_tmp_fi2d(1:klon)=lmax_th(:)
+      enddo
+      CALL histwrite_phy(o_lmaxth, zx_tmp_fi2d)
+      endif ! iflag_thermals>=1
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtvdf, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_diss(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtdis, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dqvdf, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dteva, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dqeva, zx_tmp_fi3d)
+      zpt_conv = 0.
+      where (ptconv) zpt_conv = 1.
+      CALL histwrite_phy(o_ptconv, zpt_conv)
+      CALL histwrite_phy(o_ratqs, ratqs)
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajs(1:klon,1:klev)/pdtphys -
+     $                           d_t_ajsb(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtthe, zx_tmp_fi3d)
+       IF (iflag_thermals>=1) THEN
+! Pour l instant 0 a y reflichir pour les thermiques
+         zx_tmp_fi2d=0. 
+      CALL histwrite_phy(o_ftime_th, zx_tmp_fi2d)
+      CALL histwrite_phy(o_f_th, fm_therm)
+      CALL histwrite_phy(o_e_th, entr_therm)
+      CALL histwrite_phy(o_w_th, zw2)
+      CALL histwrite_phy(o_q_th, zqasc)
+      CALL histwrite_phy(o_a_th, fraca)
+      CALL histwrite_phy(o_d_th, detr_therm)
+      CALL histwrite_phy(o_f0_th, f0)
+      CALL histwrite_phy(o_zmax_th, zmax_th)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys -
+     $                           d_q_ajsb(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dqthe, zx_tmp_fi3d)
+      ENDIF !iflag_thermals
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajsb(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtajs, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajsb(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dqajs, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY
+      CALL histwrite_phy(o_dtswr, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
+      CALL histwrite_phy(o_dtsw0, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
+      CALL histwrite_phy(o_dtlwr, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
+      CALL histwrite_phy(o_dtlw0, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtec, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_duvdf, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dvvdf, zx_tmp_fi3d)
+       IF (ok_orodr) THEN
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_duoro, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dvoro, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_oro(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtoro, zx_tmp_fi3d)
+       ENDIF
+       
+        IF (ok_orolf) THEN
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dulif, zx_tmp_fi3d)
+       ENDIF
+       
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dvlif, zx_tmp_fi3d)
+      
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_lif(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dtlif, zx_tmp_fi3d)
+      
+       IF (ok_hines) THEN
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_hin(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_duhin, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_hin(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dvhin, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_hin(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_dthin, zx_tmp_fi3d)
+        ENDIF
+      CALL histwrite_phy(o_rsu, swup)
+      CALL histwrite_phy(o_rsd, swdn)
+      CALL histwrite_phy(o_rlu, lwup)
+      CALL histwrite_phy(o_rld, lwdn)
+      CALL histwrite_phy(o_rsucs, swup0)
+      CALL histwrite_phy(o_rsdcs, swdn0)
+      CALL histwrite_phy(o_rlucs, lwup0)
+      CALL histwrite_phy(o_rldcs, lwdn0)
+      zx_tmp_fi3d(1:klon,1:klev)=d_t(1:klon,1:klev)+
+     $d_t_dyn(1:klon,1:klev)
+      CALL histwrite_phy(o_tnt, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY -
+     $cool(1:klon,1:klev)/RDAY
+      CALL histwrite_phy(o_tntr, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)= (d_t_lsc(1:klon,1:klev)+
+     $                             d_t_eva(1:klon,1:klev)+
+     $                             d_t_vdf(1:klon,1:klev))/pdtphys
+      CALL histwrite_phy(o_tntscpbl, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_qx(1:klon,1:klev,ivap)+
+     $d_q_dyn(1:klon,1:klev)
+      CALL histwrite_phy(o_tnhus, zx_tmp_fi3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys+
+     $                           d_q_eva(1:klon,1:klev)/pdtphys
+      CALL histwrite_phy(o_tnhusscpbl, zx_tmp_fi3d)
+      CALL histwrite_phy(o_evu, coefm(:,:,is_ave))
+      zx_tmp_fi3d(1:klon,1:klev)=q_seri(1:klon,1:klev)+
+     $                           ql_seri(1:klon,1:klev) 
+      CALL histwrite_phy(o_h2o, zx_tmp_fi3d)
+       if (iflag_con >= 3) then
+             zx_tmp_fi3d(1:klon,1:klev)=-1 * (dnwd(1:klon,1:klev)+
+     $            dnwd0(1:klon,1:klev)) 
+      CALL histwrite_phy(o_mcd, zx_tmp_fi3d)
+             zx_tmp_fi3d(1:klon,1:klev)=upwd(1:klon,1:klev) +
+     $            dnwd(1:klon,1:klev)+ dnwd0(1:klon,1:klev) 
+      CALL histwrite_phy(o_dmc, zx_tmp_fi3d)
+       else if (iflag_con == 2) then
+      CALL histwrite_phy(o_mcd,  pmfd)
+      CALL histwrite_phy(o_dmc,  pmfu + pmfd)
+       end if
+      CALL histwrite_phy(o_ref_liq, ref_liq)
+      CALL histwrite_phy(o_ref_ice, ref_ice)
+      if (RCO2_per.NE.RCO2_act.OR.RCH4_per.NE.RCH4_act.OR.
+     $ RN2O_per.NE.RN2O_act.OR.RCFC11_per.NE.RCFC11_act.OR.
+     $ RCFC12_per.NE.RCFC12_act) THEN
+      zx_tmp_fi2d(1 : klon) = swupp ( 1 : klon, klevp1 )
+      CALL histwrite_phy(o_rsut4co2, zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = lwupp ( 1 : klon, klevp1 )
+      CALL histwrite_phy(o_rlut4co2, zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = swup0p ( 1 : klon, klevp1 )
+      CALL histwrite_phy(o_rsutcs4co2, zx_tmp_fi2d)
+      zx_tmp_fi2d(1 : klon) = lwup0p ( 1 : klon, klevp1 )
+      CALL histwrite_phy(o_rlutcs4co2, zx_tmp_fi2d)
+      CALL histwrite_phy(o_rsu4co2, swupp)
+      CALL histwrite_phy(o_rlu4co2, lwupp)
+      CALL histwrite_phy(o_rsucs4co2, swup0p)
+      CALL histwrite_phy(o_rlucs4co2, lwup0p)
+      CALL histwrite_phy(o_rsd4co2, swdnp)
+      CALL histwrite_phy(o_rld4co2, lwdnp)
+      CALL histwrite_phy(o_rsdcs4co2, swdn0p)
+      CALL histwrite_phy(o_rldcs4co2, lwdn0p)
+      endif
+        if (nqtot.GE.3) THEN
+         DO iq=3,nqtot
+      CALL histwrite_phy(o_trac(iq-2), qx(:,:,iq))
+         ENDDO
+         DO iq=3,nqtot
+         zx_tmp_fi2d=0.
+         do k=1,klev
+            zx_tmp_fi2d(:)=zx_tmp_fi2d(:)+zmasse(:,k)*qx(:,k,iq)
+         enddo
+      CALL histwrite_phy(o_trac_cum(iq-2), zx_tmp_fi2d)
+         ENDDO
+        endif
+!       ENDIF ! clef_files
+
+      DO iff=1,nfiles
+          IF (ok_sync .AND. clef_files(iff)) THEN
+c$OMP MASTER
+              CALL histsync(nid_files(iff))
+c$OMP END MASTER
+          ENDIF
+      END DO
Index: LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/phys_state_var_mod.F90	(revision 1795)
@@ -63,5 +63,7 @@
 !$OMP THREADPRIVATE(ratqs)
       REAL, ALLOCATABLE, SAVE :: pbl_tke(:,:,:) ! turb kinetic energy
-!$OMP THREADPRIVATE(pbl_tke)
+      REAL, ALLOCATABLE, SAVE :: coefh(:,:,:) ! Kz enthalpie
+      REAL, ALLOCATABLE, SAVE :: coefm(:,:,:) ! Kz momentum
+!$OMP THREADPRIVATE(pbl_tke, coefh,coefm)
       REAL, ALLOCATABLE, SAVE :: zmax0(:), f0(:) ! 
 !$OMP THREADPRIVATE(zmax0,f0)
@@ -359,8 +361,9 @@
 !======================================================================
 SUBROUTINE phys_state_var_init(read_climoz)
-use dimphy
+USE dimphy
 USE control_mod
-use aero_mod
-use infotrac, ONLY : nbtr
+USE aero_mod
+USE infotrac, ONLY : nbtr
+USE indice_sol_mod
 IMPLICIT NONE
 
@@ -373,5 +376,4 @@
 ! climatology and the daylight climatology
 
-#include "indicesol.h"
       ALLOCATE(rlat(klon), rlon(klon))
       ALLOCATE(pctsrf(klon,nbsrf))
@@ -394,5 +396,7 @@
       ALLOCATE(clwcon(klon,klev),rnebcon(klon,klev))
       ALLOCATE(ratqs(klon,klev))
-      ALLOCATE(pbl_tke(klon,klev+1,nbsrf))
+      ALLOCATE(pbl_tke(klon,klev+1,nbsrf+1))
+      ALLOCATE(coefh(klon,klev+1,nbsrf+1))
+      ALLOCATE(coefm(klon,klev+1,nbsrf+1))
       ALLOCATE(zmax0(klon), f0(klon))
       ALLOCATE(ema_work1(klon,klev), ema_work2(klon,klev))
@@ -518,8 +522,8 @@
 !======================================================================
 SUBROUTINE phys_state_var_end
-use dimphy
-use control_mod
+USE dimphy
+USE control_mod
+USE indice_sol_mod
 IMPLICIT NONE
-#include "indicesol.h"
 
       deallocate(rlat, rlon, pctsrf, ftsol, falb1, falb2)
@@ -530,5 +534,5 @@
       deallocate(        u_ancien, v_ancien                 )
       deallocate(        tr_ancien)                           !RomP
-      deallocate(ratqs, pbl_tke)
+      deallocate(ratqs, pbl_tke,coefh,coefm)
       deallocate(zmax0, f0)
       deallocate(ema_work1, ema_work2)
Index: LMDZ5/branches/testing/libf/phylmd/physiq.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/physiq.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/physiq.F	(revision 1795)
@@ -31,9 +31,12 @@
       USE fonte_neige_mod, ONLY  : fonte_neige_get_vars
       USE phys_output_mod
+      USE phys_output_ctrlout_mod
+      USE iophy
       use open_climoz_m, only: open_climoz ! ozone climatology from a file
       use regr_pr_av_m, only: regr_pr_av
       use netcdf95, only: nf95_close
 cIM for NMC files
-      use netcdf, only: nf90_fill_real
+c     use netcdf, only: nf90_fill_real
+      use netcdf
       use mod_phys_lmdz_mpi_data, only: is_mpi_root
       USE aero_mod
@@ -45,55 +48,55 @@
       USE CHEM_REP, ONLY : Init_chem_rep_xjour
 #endif
-
+      USE indice_sol_mod
 
 !IM stations CFMIP
       USE CFMIP_point_locations
       IMPLICIT none
-c======================================================================
-c
-c Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
-c
-c Objet: Moniteur general de la physique du modele
-cAA      Modifications quant aux traceurs :
-cAA                  -  uniformisation des parametrisations ds phytrac
-cAA                  -  stockage des moyennes des champs necessaires
-cAA                     en mode traceur off-line 
-c======================================================================
-c   CLEFS CPP POUR LES IO
-c   =====================
+!>======================================================================
+!!
+!! Auteur(s) Z.X. Li (LMD/CNRS) date: 19930818
+!!
+!! Objet: Moniteur general de la physique du modele
+!!AA      Modifications quant aux traceurs :
+!!AA                  -  uniformisation des parametrisations ds phytrac
+!!AA                  -  stockage des moyennes des champs necessaires
+!!AA                     en mode traceur off-line 
+!!======================================================================
+!!   CLEFS CPP POUR LES IO
+!!   =====================
 #define histNMC
 c#define histISCCP
-c======================================================================
-c    modif   ( P. Le Van ,  12/10/98 )
-c
-c  Arguments:
-c
-c nlon----input-I-nombre de points horizontaux
-c nlev----input-I-nombre de couches verticales, doit etre egale a klev
-c debut---input-L-variable logique indiquant le premier passage
-c lafin---input-L-variable logique indiquant le dernier passage
-c jD_cur       -R-jour courant a l'appel de la physique (jour julien)
-c jH_cur       -R-heure courante a l'appel de la physique (jour julien)
-c pdtphys-input-R-pas d'integration pour la physique (seconde)
-c paprs---input-R-pression pour chaque inter-couche (en Pa)
-c pplay---input-R-pression pour le mileu de chaque couche (en Pa)
-c pphi----input-R-geopotentiel de chaque couche (g z) (reference sol)
-c pphis---input-R-geopotentiel du sol
-c presnivs-input_R_pressions approximat. des milieux couches ( en PA)
-c u-------input-R-vitesse dans la direction X (de O a E) en m/s
-c v-------input-R-vitesse Y (de S a N) en m/s
-c t-------input-R-temperature (K)
-c qx------input-R-humidite specifique (kg/kg) et d'autres traceurs
-c d_t_dyn-input-R-tendance dynamique pour "t" (K/s)
-c d_q_dyn-input-R-tendance dynamique pour "q" (kg/kg/s)
-c flxmass_w -input-R- flux de masse verticale
-c d_u-----output-R-tendance physique de "u" (m/s/s)
-c d_v-----output-R-tendance physique de "v" (m/s/s)
-c d_t-----output-R-tendance physique de "t" (K/s)
-c d_qx----output-R-tendance physique de "qx" (kg/kg/s)
-c d_ps----output-R-tendance physique de la pression au sol
-cIM
-c PVteta--output-R-vorticite potentielle a des thetas constantes
-c======================================================================
+!!======================================================================
+!!    modif   ( P. Le Van ,  12/10/98 )
+!!
+!!  Arguments:
+!!
+!! nlon----input-I-nombre de points horizontaux
+!! nlev----input-I-nombre de couches verticales, doit etre egale a klev
+!! debut---input-L-variable logique indiquant le premier passage
+!! lafin---input-L-variable logique indiquant le dernier passage
+!! jD_cur       -R-jour courant a l'appel de la physique (jour julien)
+!! jH_cur       -R-heure courante a l'appel de la physique (jour julien)
+!! pdtphys-input-R-pas d'integration pour la physique (seconde)
+!! paprs---input-R-pression pour chaque inter-couche (en Pa)
+!! pplay---input-R-pression pour le mileu de chaque couche (en Pa)
+!! pphi----input-R-geopotentiel de chaque couche (g z) (reference sol)
+!! pphis---input-R-geopotentiel du sol
+!! presnivs-input_R_pressions approximat. des milieux couches ( en PA)
+!! u-------input-R-vitesse dans la direction X (de O a E) en m/s
+!! v-------input-R-vitesse Y (de S a N) en m/s
+!! t-------input-R-temperature (K)
+!! qx------input-R-humidite specifique (kg/kg) et d'autres traceurs
+!! d_t_dyn-input-R-tendance dynamique pour "t" (K/s)
+!! d_q_dyn-input-R-tendance dynamique pour "q" (kg/kg/s)
+!! flxmass_w -input-R- flux de masse verticale
+!! d_u-----output-R-tendance physique de "u" (m/s/s)
+!! d_v-----output-R-tendance physique de "v" (m/s/s)
+!! d_t-----output-R-tendance physique de "t" (K/s)
+!! d_qx----output-R-tendance physique de "qx" (kg/kg/s)
+!! d_ps----output-R-tendance physique de la pression au sol
+!!IM
+!! PVteta--output-R-vorticite potentielle a des thetas constantes
+!!======================================================================
 #include "dimensions.h"
       integer jjmp1
@@ -103,5 +106,4 @@
 
 #include "regdim.h"
-#include "indicesol.h"
 #include "dimsoil.h"
 #include "clesphys.h"
@@ -218,5 +220,9 @@
       REAL u(klon,klev)
       REAL v(klon,klev)
-      REAL t(klon,klev),theta(klon,klev)
+      REAL t(klon,klev),theta(klon,klev),thetal(klon,klev)
+c thetal: ligne suivante a decommenter si vous avez les fichiers     MPL 20130625
+c fth_fonctions.F90 et parkind1.F90
+c sinon thetal=theta
+c     REAL fth_thetae,fth_thetav,fth_thetal
       REAL qx(klon,klev,nqtot)
       REAL flxmass_w(klon,klev)
@@ -642,7 +648,7 @@
       REAL zw2(klon,klev+1)
       REAL fraca(klon,klev+1)        
-      REAL ztv(klon,klev) 
+      REAL ztv(klon,klev),ztva(klon,klev)
       REAL zpspsk(klon,klev)
-      REAL ztla(klon,klev) 
+      REAL ztla(klon,klev),zqla(klon,klev) 
       REAL zthl(klon,klev)
 
@@ -655,4 +661,5 @@
       real w0(klon)                                          ! Vitesse des thermiques au LCL
       real w_conv(klon)                                      ! Vitesse verticale de grande \'echelle au LCL
+      real tke0(klon,klev+1)                                 ! TKE au début du pas de temps
       real therm_tke_max0(klon)                              ! TKE dans les thermiques au LCL 
       real env_tke_max0(klon)                                ! TKE dans l'environnement au LCL 
@@ -694,7 +701,4 @@
 cAA
 cAA  Pour phytrac 
-cAA
-      REAL coefh(klon,klev)     ! coef d'echange pour phytrac, valable pour 2<=k<=klev
-      REAL coefm(klon,klev)     ! coef d'echange pour U, V
       REAL u1(klon)             ! vents dans la premiere couche U
       REAL v1(klon)             ! vents dans la premiere couche V
@@ -722,4 +726,5 @@
 
       REAL bils(klon) ! bilan de chaleur au sol
+
       REAL wfbilo(klon,nbsrf) ! bilan d'eau, pour chaque
 C                             ! type de sous-surface et pondere par la fraction
@@ -751,5 +756,5 @@
       SAVE lmt_pas                ! frequence de mise a jour
 c$OMP THREADPRIVATE(lmt_pas) 
-      real zmasse(klon, llm) 
+      real zmasse(klon, llm),exner(klon, llm) 
 C     (column-density of mass of air in a cell, in kg m-2)
       real, parameter:: dobson_u = 2.1415e-05 ! Dobson unit, in kg m-2
@@ -1058,5 +1063,5 @@
      .           prof2d_av = 3, prof3d_av = 4)
       character*30 nom_fichier
-      character*10 varname
+      character*40 varname
       character*40 vartitle
       character*20 varunits
@@ -1121,5 +1126,9 @@
       LOGICAL, SAVE :: new_aod
 c$OMP THREADPRIVATE(new_aod) 
-   
+c
+c--STRAT AEROSOL
+      LOGICAL, SAVE :: flag_aerosol_strat
+c$OMP THREADPRIVATE(flag_aerosol_strat)
+cc-fin STRAT AEROSOL
 c
 c Declaration des constantes et des fonctions thermodynamiques
@@ -1271,5 +1280,5 @@
      .     iflag_cldcon,iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,
      .     ok_ade, ok_aie, ok_cdnc, aerosol_couple, 
-     .     flag_aerosol, new_aod,
+     .     flag_aerosol, flag_aerosol_strat, new_aod,
      .     bl95_b0, bl95_b1,
 c     nv flags pour la convection et les poches froides
@@ -1287,6 +1296,4 @@
           pbase=0
 cIM 180608
-c         pmflxr=0.
-c         pmflxs=0.
 
         itau_con=0
@@ -1395,4 +1402,9 @@
 
          CALL phyetat0 ("startphy.nc",clesphy0,tabcntr0)
+         IF (klon_glo==1) THEN
+         coefh=0. ; coefm=0. ; pbl_tke=0.
+         coefh(:,2,:)=1.e-2 ; coefm(:,2,:)=1.e-2 ; pbl_tke(:,2,:)=1.e-2
+         PRINT*,'FH WARNING : lignes a supprimer'
+         ENDIF
 cIM begin
           print*,'physiq: clwcon rnebcon ratqs',clwcon(1,1),rnebcon(1,1)
@@ -1593,6 +1605,6 @@
      &                       ok_hf,ok_instan,ok_LES,ok_ade,ok_aie, 
      &                       read_climoz, phys_out_filestations,
-     &                       new_aod, aerosol_couple
-     &                        )
+     &                       new_aod, aerosol_couple,
+     &                       flag_aerosol_strat )
 c$OMP END MASTER
 c$OMP BARRIER
@@ -1769,4 +1781,6 @@
       d1a(:,:)=0.
       dam(:,:)=0.
+          pmflxr=0.
+          pmflxs=0.
 ! RomP <<<
 
@@ -1784,4 +1798,5 @@
       ENDDO
       ENDDO
+      tke0(:,:)=pbl_tke(:,:,is_ave)
       IF (nqtot.GE.3) THEN
       DO iq = 3, nqtot
@@ -2072,5 +2087,5 @@
      s     albsol1,   albsol2,   sens,    evap,  
      s     zxtsol,    zxfluxlat, zt2m,    qsat2m, 
-     s     d_t_vdf,   d_q_vdf,   d_u_vdf, d_v_vdf,
+     s     d_t_vdf,   d_q_vdf,   d_u_vdf, d_v_vdf, d_t_diss,
      s     coefh,     coefm,     slab_wfbils,                
      d     qsol,      zq2m,      s_pblh,  s_lcl,
@@ -2088,5 +2103,6 @@
 !-----------------------------------------------------------------------------------------
 ! ajout des tendances de la diffusion turbulente
-      CALL add_phys_tend(d_u_vdf,d_v_vdf,d_t_vdf,d_q_vdf,dql0,'vdf')
+      CALL add_phys_tend
+     s     (d_u_vdf,d_v_vdf,d_t_vdf+d_t_diss,d_q_vdf,dql0,'vdf')
 !-----------------------------------------------------------------------------------------
 
@@ -2658,5 +2674,5 @@
      s      ,alp_bl_conv,alp_bl_stat
 ccc fin nrlmd le 10/04/2012
-     s                 )
+     s      ,zqla,ztva )
 
 ccc nrlmd le 10/04/2012
@@ -2966,4 +2982,12 @@
          cg_aero(:,:,:,:)  = 0.
       ENDIF
+c
+c--STRAT AEROSOL
+c--updates tausum_aero,tau_aero,piz_aero,cg_aero
+      IF (flag_aerosol_strat) THEN
+         PRINT *,'appel a readaerosolstrat', mth_cur
+         CALL readaerosolstrato(debut)
+      ENDIF
+c--fin STRAT AEROSOL
 
 cIM calcul nuages par le simulateur ISCCP
@@ -3174,5 +3198,5 @@
      $                          paprs,
      $                          pplay,
-     $                          coefh,
+     $                          coefh(:,:,is_ave),
      $                          pphi,
      $                          t_seri,
@@ -3353,5 +3377,6 @@
      e        t_seri,q_seri,wo,
      e        cldfrarad, cldemirad, cldtaurad,
-     e        ok_ade, ok_aie, flag_aerosol,
+     e        ok_ade.OR.flag_aerosol_strat, ok_aie, flag_aerosol,
+     e        flag_aerosol_strat,
      e        tau_aero, piz_aero, cg_aero,
      e        cldtaupirad,new_aod,
@@ -3395,5 +3420,6 @@
      e        t_seri,q_seri,wo,
      e        cldfra, cldemi, cldtau,
-     e        ok_ade, ok_aie, flag_aerosol,
+     e        ok_ade.OR.flag_aerosol_strat, ok_aie, flag_aerosol,
+     e        flag_aerosol_strat,
      e        tau_aero, piz_aero, cg_aero,
      e        cldtaupi,new_aod,
@@ -3431,4 +3457,12 @@
          solsw=0.
          radsol=0.
+         swup=0.    ! MPL 27102011 pour les fichiers AMMA_profiles et AMMA_scalars
+         swup0=0.
+         swdn=0.
+         swdn0=0.
+         lwup=0.
+         lwup0=0.
+         lwdn=0.
+         lwdn0=0.
       END IF
 
@@ -3695,5 +3729,5 @@
      I     paprs,    pplay,     pmfu,     pmfd,
      I     pen_u,    pde_u,     pen_d,    pde_d,
-     I     cdragh,   coefh,     fm_therm, entr_therm,
+     I     cdragh,   coefh(:,:,is_ave),     fm_therm, entr_therm,
      I     u1,       v1,        ftsol,    pctsrf,
      I     ustar,     u10m,      v10m,
@@ -3722,5 +3756,5 @@
      I                   t,pmfu, pmfd, pen_u, pde_u, pen_d, pde_d,
      I                   fm_therm,entr_therm,
-     I                   cdragh,coefh,u1,v1,ftsol,pctsrf,
+     I                   cdragh,coefh(:,:,is_ave),u1,v1,ftsol,pctsrf,
      I                   frac_impa, frac_nucl,
      I                   pphis,airephy,dtime,itap,
@@ -3748,20 +3782,17 @@
 c Accumuler les variables a stocker dans les fichiers histoire:
 c
-c+jld ec_conser
-      DO k = 1, klev
-      DO i = 1, klon
-        ZRCPD = RCPD*(1.0+RVTMP2*q_seri(i,k))
-        d_t_ec(i,k)=0.5/ZRCPD
-     $      *(u(i,k)**2+v(i,k)**2-u_seri(i,k)**2-v_seri(i,k)**2)
-      ENDDO
-      ENDDO
-
-      DO k = 1, klev
-      DO i = 1, klon
-        t_seri(i,k)=t_seri(i,k)+d_t_ec(i,k)
-        d_t_ec(i,k) = d_t_ec(i,k)/dtime
-       END DO 
-      END DO 
-c-jld ec_conser
+
+!================================================================
+! Conversion of kinetic and potential energy into heat, for
+! parameterisation of subgrid-scale motions
+!================================================================
+
+      d_t_ec(:,:)=0.
+      forall (k=1: llm) exner(:, k) = (pplay(:, k)/paprs(:,1))**RKAPPA
+      CALL ener_conserv(klon,klev,pdtphys,u,v,t,qx(:,:,ivap),
+     s        u_seri,v_seri,t_seri,q_seri,pbl_tke(:,:,is_ave)-tke0(:,:),
+     s        zmasse,exner,d_t_ec)
+      t_seri(:,:)=t_seri(:,:)+d_t_ec(:,:)
+
 cIM
       IF (ip_ebil_phy.ge.1) THEN 
@@ -3833,5 +3864,5 @@
       END IF
 
-c=============================================================
+
 c
 c Convertir les incrementations en tendances
@@ -3946,4 +3977,10 @@
 cJYG/IM theta en fin de pas de temps de physique
         theta(i,k)=t_seri(i,k)*(100000./pplay(i,k))**(RD/RCPD)
+c thetal: 2 lignes suivantes a decommenter si vous avez les fichiers     MPL 20130625
+c fth_fonctions.F90 et parkind1.F90
+c sinon thetal=theta
+c       thetal(i,k)=fth_thetal(pplay(i,k),t_seri(i,k),q_seri(i,k),
+c    :         ql_seri(i,k))
+        thetal(i,k)=theta(i,k)
       ENDDO
       ENDDO
@@ -3962,4 +3999,5 @@
       CALL fonte_neige_get_vars(pctsrf, 
      .     zxfqcalving, zxfqfonte, zxffonte)
+
 
 
@@ -3993,6 +4031,8 @@
       endif
 
- 
-#include "phys_output_write.h"
+#include "phys_output_write_new.h"
+
+
+
 
 #ifdef histISCCP
@@ -4072,5 +4112,4 @@
          ENDIF !if callstats
      
-
       IF (lafin) THEN
          itau_phy = itau_phy + itap
Index: LMDZ5/branches/testing/libf/phylmd/phystokenc.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phystokenc.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/phystokenc.F90	(revision 1795)
@@ -12,4 +12,5 @@
   USE iophy
   USE control_mod
+  USE indice_sol_mod
   
   IMPLICIT NONE
@@ -22,5 +23,4 @@
   INCLUDE "dimensions.h"
   INCLUDE "tracstoke.h"
-  INCLUDE "indicesol.h"
   INCLUDE "iniprint.h"
 !======================================================================
Index: LMDZ5/branches/testing/libf/phylmd/phytrac.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/phytrac.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/phytrac.F90	(revision 1795)
@@ -45,4 +45,5 @@
   USE tracreprobus_mod
   USE control_mod
+  USE indice_sol_mod
 
   IMPLICIT NONE
@@ -50,5 +51,4 @@
   INCLUDE "YOMCST.h"
   INCLUDE "dimensions.h"
-  INCLUDE "indicesol.h"
   INCLUDE "clesphys.h"
   INCLUDE "temps.h"
@@ -203,6 +203,6 @@
   INTEGER                   :: itau_w      ! pas de temps ecriture = nstep + itau_phy
   LOGICAL,PARAMETER         :: ok_sync=.TRUE.
-  CHARACTER(len=20)         :: chtratimestep 
-
+  CHARACTER(len=20),save    :: chtratimestep,chtratimestep_omp
+!$OMP THREADPRIVATE(chtratimestep)
 !
 ! Nature du traceur
@@ -264,6 +264,6 @@
   CHARACTER(len=8),DIMENSION(nbtr) :: solsym
 !RomP >>>
-  INTEGER,SAVE  :: iflag_lscav
-  LOGICAL,SAVE  :: convscav
+  INTEGER,SAVE  :: iflag_lscav_omp,iflag_lscav
+  LOGICAL,SAVE  :: convscav_omp,convscav
 !$OMP THREADPRIVATE(iflag_lscav,convscav)
 !RomP <<<
@@ -309,6 +309,10 @@
   IF (debutphy) THEN
 !!jyg
-   chtratimestep='DefFreq'
-   CALL getin('tra_time_step',chtratimestep)
+!$OMP MASTER
+   chtratimestep_omp='DefFreq'
+   CALL getin('tra_time_step',chtratimestep_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+   chtratimestep=chtratimestep_omp
    IF (chtratimestep .NE. 'DefFreq') THEN
      call convers_timesteps(chtratimestep,pdtphys,ecrit_tra)
@@ -321,6 +325,10 @@
 !Config Help = 
 !
-  convscav=.false.
-  call getin('convscav', convscav)
+!$OMP MASTER
+  convscav_omp=.false.
+  call getin('convscav', convscav_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+  convscav=convscav_omp
   print*,'phytrac passage dans routine conv avec lessivage', convscav
 !
@@ -331,6 +339,10 @@
 !Config Help = 
 !
-  iflag_lscav=1
-  call getin('iflag_lscav', iflag_lscav)
+!$OMP MASTER
+  iflag_lscav_omp=1
+  call getin('iflag_lscav', iflag_lscav_omp)
+!$OMP END MASTER
+!$OMP BARRIER
+  iflag_lscav=iflag_lscav_omp
 !
   SELECT CASE(iflag_lscav)
@@ -371,5 +383,5 @@
      INCLUDE "ini_histrac.h"
 #endif
-  END IF
+  END IF ! of IF (debutphy)
 !############################################ END INITIALIZATION #######
 
Index: LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/radlwsw_m.F90	(revision 1795)
@@ -11,4 +11,5 @@
    cldfra, cldemi, cldtaupd,&
    ok_ade, ok_aie, flag_aerosol,&
+   flag_aerosol_strat,&
    tau_aero, piz_aero, cg_aero,&
    cldtaupi, new_aod, &
@@ -57,4 +58,5 @@
   ! ok_aie---input-L- apply the Aerosol Indirect Effect or not?
   ! flag_aerosol-input-I- aerosol flag from 0 to 6
+  ! flag_aerosol_strat-input-I- use stratospheric aerosols flag (T/F)
   ! tau_ae, piz_ae, cg_ae-input-R- aerosol optical properties (calculated in aeropt.F)
   ! cldtaupi-input-R- epaisseur optique des nuages dans le visible
@@ -121,4 +123,5 @@
   LOGICAL, INTENT(in)  :: ok_ade, ok_aie                                 ! switches whether to use aerosol direct (indirect) effects or not
   INTEGER, INTENT(in)  :: flag_aerosol                                   ! takes value 0 (no aerosol) or 1 to 6 (aerosols)
+  LOGICAL, INTENT(in)  :: flag_aerosol_strat                             ! use stratospheric aerosols
   REAL,    INTENT(in)  :: cldfra(KLON,KLEV), cldemi(KLON,KLEV), cldtaupd(KLON,KLEV)
   REAL,    INTENT(in)  :: tau_aero(KLON,KLEV,9,2)                        ! aerosol optical properties (see aeropt.F)
@@ -360,5 +363,5 @@
                ztopswadaero,zsolswadaero,&
                ztopswaiaero,zsolswaiaero,& 
-               ok_ade, ok_aie, flag_aerosol) 
+               ok_ade, ok_aie) 
           
        ELSE ! new_aod=T         
@@ -379,5 +382,5 @@
                zsolsw_aero,zsolsw0_aero,&
                ztopswcf_aero,zsolswcf_aero, & 
-               ok_ade, ok_aie, flag_aerosol) 
+               ok_ade, ok_aie, flag_aerosol,flag_aerosol_strat) 
        ENDIF
 
Index: LMDZ5/branches/testing/libf/phylmd/read_pstoke.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/read_pstoke.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/read_pstoke.F	(revision 1795)
@@ -21,4 +21,5 @@
       USE dimphy
       USE control_mod
+      USE indice_sol_mod
 
        IMPLICIT NONE
@@ -34,5 +35,4 @@
 #include "description.h"
 #include "serre.h"
-#include "indicesol.h"
 cccc#include "dimphy.h"
 	
Index: LMDZ5/branches/testing/libf/phylmd/read_pstoke0.F
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/read_pstoke0.F	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/read_pstoke0.F	(revision 1795)
@@ -17,7 +17,8 @@
 C******************************************************************************
 
-	use netcdf
+	 USE netcdf
        USE dimphy
        USE control_mod
+       USE indice_sol_mod
 
        IMPLICIT NONE
@@ -33,5 +34,4 @@
 #include "description.h"
 #include "serre.h"
-#include "indicesol.h"
 cccc#include "dimphy.h"
 	  
Index: LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90	(revision 1795)
+++ LMDZ5/branches/testing/libf/phylmd/readaerosolstrato.F90	(revision 1795)
@@ -0,0 +1,172 @@
+subroutine readaerosolstrato(debut)
+
+    use netcdf95, only: nf95_close, nf95_gw_var, nf95_inq_dimid, & 
+                        nf95_inq_varid, nf95_open
+    use netcdf, only: nf90_get_var, nf90_noerr, nf90_nowrite
+
+    USE phys_cal_mod, ONLY : mth_cur
+    USE mod_grid_phy_lmdz
+    USE mod_phys_lmdz_mpi_data, ONLY :  is_mpi_root
+    USE mod_phys_lmdz_para 
+    USE phys_state_var_mod
+    USE phys_local_var_mod
+    USE aero_mod
+    USE dimphy
+
+    implicit none
+
+    include "YOMCST.h"
+    include "dimensions.h"
+
+! Variable input
+    logical debut
+
+! Variables locales
+    integer n_lat   ! number of latitudes in the input data
+    integer n_lon   ! number of longitudes in the input data
+    integer n_lev   ! number of levels in the input data
+    integer n_month ! number of months in the input data
+    real, pointer:: latitude(:)
+    real, pointer:: longitude(:)
+    real, pointer:: time(:)
+    real, pointer:: lev(:)
+    integer i, k, band, wave
+    integer, save :: mth_pre
+
+    real, allocatable, dimension(:,:), save :: tau_aer_strat
+!$OMP THREADPRIVATE(tau_aer_strat)
+
+! Champs reconstitues
+    real, allocatable:: tauaerstrat(:, :, :, :)
+    real, allocatable:: tauaerstrat_mois(:, :, :)
+    real, allocatable:: tauaerstrat_mois_glo(:, :)
+    real, allocatable:: tauaerstrat_mois_glo_bands(:,:,:)
+
+! For NetCDF:
+    integer ncid_in  ! IDs for input files
+    integer varid, ncerr
+
+! Stratospheric aerosols optical properties
+! alpha_strat over the 2 bands is normalised by the 550 nm extinction coefficient
+! alpha_strat_wave is *not* normalised by the 550 nm extinction coefficient
+    real, dimension(nbands) :: alpha_strat, piz_strat, cg_strat
+    data alpha_strat/0.9922547, 0.7114912 /
+    data piz_strat  /0.9999998, 0.99762493/
+    data cg_strat   /0.73107845,0.73229635/
+    real, dimension(nwave) :: alpha_strat_wave
+    data alpha_strat_wave/3.36780953,3.34667683,3.20444202,3.0293026,2.82108808/
+
+!--------------------------------------------------------
+
+    IF (.not.ALLOCATED(tau_aer_strat)) ALLOCATE(tau_aer_strat(klon,klev))
+
+    IF (is_mpi_root) THEN
+
+    IF (debut.OR.mth_cur.NE.mth_pre) THEN
+
+    IF (nbands.NE.2) THEN 
+        print *,'nbands doit etre egal a 2 dans readaerosolstrat'
+        STOP
+    ENDIF
+
+    CALL nf95_open("taustrat.nc", nf90_nowrite, ncid_in)
+
+    CALL nf95_inq_varid(ncid_in, "LEV", varid)
+    CALL nf95_gw_var(ncid_in, varid, lev)
+    n_lev = size(lev)
+    IF (n_lev.NE.klev) THEN 
+       print *,'Le nombre de niveaux n est pas egal a klev'
+       STOP
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "LAT", varid)
+    CALL nf95_gw_var(ncid_in, varid, latitude)
+    n_lat = size(latitude)
+    print *, 'LAT aerosol strato=', n_lat, latitude
+    IF (n_lat.NE.jjm+1) THEN 
+       print *,'Le nombre de lat n est pas egal a jjm+1'
+       STOP
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "LON", varid)
+    CALL nf95_gw_var(ncid_in, varid, longitude)
+    n_lon = size(longitude)
+    print *, 'LON aerosol strato=', n_lon, longitude
+    IF (n_lon.NE.iim) THEN 
+       print *,'Le nombre de lon n est pas egal a iim'
+       STOP
+    ENDIF
+
+    CALL nf95_inq_varid(ncid_in, "TIME", varid)
+    CALL nf95_gw_var(ncid_in, varid, time)
+    n_month = size(time)
+    print *, 'TIME aerosol strato=', n_month, time
+    IF (n_month.NE.12) THEN 
+       print *,'Le nombre de month n est pas egal a 12'
+       STOP
+    ENDIF
+
+    ALLOCATE(tauaerstrat(n_lon, n_lat, n_lev, n_month))
+    ALLOCATE(tauaerstrat_mois(n_lon, n_lat, n_lev))
+    ALLOCATE(tauaerstrat_mois_glo(klon_glo, n_lev))
+    ALLOCATE(tauaerstrat_mois_glo_bands(klon_glo, n_lev,nbands))
+
+!--reading stratospheric AOD at 550 nm
+    CALL nf95_inq_varid(ncid_in, "TAUSTRAT", varid)
+    ncerr = nf90_get_var(ncid_in, varid, tauaerstrat)
+    print *,'code erreur readaerosolstrato=', ncerr, varid
+
+    CALL nf95_close(ncid_in)
+
+!---select the correct month
+    IF (mth_cur.LT.1.OR.mth_cur.GT.12) THEN
+      print *,'probleme avec le mois dans readaerosolstrat =', mth_cur
+    ENDIF
+    tauaerstrat_mois(:,:,:) = tauaerstrat(:,:,:,mth_cur)
+
+!---reduce to a klon_glo grid 
+    CALL grid2dTo1d_glo(tauaerstrat_mois,tauaerstrat_mois_glo)
+
+!--scatter on all proc
+    CALL scatter(tauaerstrat_mois_glo,tau_aer_strat)
+
+    DEALLOCATE(tauaerstrat)
+    DEALLOCATE(tauaerstrat_mois)
+    DEALLOCATE(tauaerstrat_mois_glo)
+  
+    mth_pre=mth_cur
+
+    ENDIF !--debut ou nouveau mois
+
+    ENDIF !--is_mpi_root
+
+!--total vertical aod at the 5 wavelengths
+    DO wave=1, nwave
+    DO k=1, klev
+    tausum_aero(:,wave,id_strat)=tausum_aero(:,wave,id_strat)+tau_aer_strat(:,k)*alpha_strat_wave(wave)/alpha_strat_wave(2)
+    ENDDO
+    ENDDO
+
+!--weighted average for cg, piz and tau, adding strat aerosols on top of tropospheric ones
+    DO band=1, nbands
+!--anthropogenic aerosols bands 1 and 2
+    cg_aero(:,:,3,band)  = ( cg_aero(:,:,3,band)*piz_aero(:,:,3,band)*tau_aero(:,:,3,band) +          &
+                             cg_strat(band)*piz_strat(band)*alpha_strat(band)*tau_aer_strat(:,:) ) /  &
+                             MAX( piz_aero(:,:,3,band)*tau_aero(:,:,3,band) +                         &
+                                  piz_strat(band)*alpha_strat(band)*tau_aer_strat(:,:), 1.e-15 )
+    piz_aero(:,:,3,band)  = ( piz_aero(:,:,3,band)*tau_aero(:,:,3,band) +                             &
+                              piz_strat(band)*alpha_strat(band)*tau_aer_strat(:,:) ) /                &
+                              MAX( tau_aero(:,:,3,band) + alpha_strat(band)*tau_aer_strat(:,:), 1.e-15 )
+    tau_aero(:,:,3,band)  = tau_aero(:,:,3,band) + alpha_strat(band)*tau_aer_strat(:,:)
+!--natural aerosols bands 1 and 2
+    cg_aero(:,:,2,band)  = ( cg_aero(:,:,2,band)*piz_aero(:,:,2,band)*tau_aero(:,:,2,band) +          &
+                             cg_strat(band)*piz_strat(band)*alpha_strat(band)*tau_aer_strat(:,:) ) /  &
+                             MAX( piz_aero(:,:,2,band)*tau_aero(:,:,2,band) +                         &
+                                  piz_strat(band)*alpha_strat(band)*tau_aer_strat(:,:), 1.e-15 )
+    piz_aero(:,:,2,band)  = ( piz_aero(:,:,2,band)*tau_aero(:,:,2,band) +                             & 
+                              piz_strat(band)*alpha_strat(band)*tau_aer_strat(:,:) ) /                &
+                              MAX( tau_aero(:,:,2,band) + alpha_strat(band)*tau_aer_strat(:,:),1.e-15 )
+    tau_aero(:,:,2,band)  = tau_aero(:,:,2,band) + alpha_strat(band)*tau_aer_strat(:,:)
+    ENDDO
+
+end subroutine readaerosolstrato
Index: LMDZ5/branches/testing/libf/phylmd/screenc.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/screenc.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/screenc.F90	(revision 1795)
@@ -22,5 +22,5 @@
 ! klon----input-I- dimension de la grille physique (= nb_pts_latitude X nb_pts_longitude)
 ! knon----input-I- nombre de points pour un type de surface
-! nsrf----input-I- indice pour le type de surface; voir indicesol.h
+! nsrf----input-I- indice pour le type de surface; voir indice_sol_mod.F90
 ! zxli----input-L- TRUE si calcul des cdrags selon Laurent Li
 ! speed---input-R- module du vent au 1er niveau du modele
Index: LMDZ5/branches/testing/libf/phylmd/screenp.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/screenp.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/screenp.F90	(revision 1795)
@@ -22,5 +22,5 @@
 ! klon----input-I- dimension de la grille physique (= nb_pts_latitude X nb_pts_longitude)
 ! knon----input-I- nombre de points pour un type de surface
-! nsrf----input-I- indice pour le type de surface; voir indicesol.h
+! nsrf----input-I- indice pour le type de surface; voir indice_sol_mod.F90
 ! speed---input-R- module du vent au 1er niveau du modele
 ! tair----input-R- temperature de l'air au 1er niveau du modele
Index: LMDZ5/branches/testing/libf/phylmd/soil.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/soil.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/soil.F90	(revision 1795)
@@ -7,4 +7,6 @@
   USE dimphy
   USE mod_phys_lmdz_para
+  USE indice_sol_mod
+
   IMPLICIT NONE
 
@@ -52,5 +54,4 @@
   INCLUDE "YOMCST.h"
   INCLUDE "dimsoil.h"
-  INCLUDE "indicesol.h"
   INCLUDE "comsoil.h"
   INCLUDE "iniprint.h"
Index: LMDZ5/branches/testing/libf/phylmd/stdlevvar.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/stdlevvar.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/stdlevvar.F90	(revision 1795)
@@ -23,5 +23,5 @@
 ! klon----input-I- dimension de la grille physique (= nb_pts_latitude X nb_pts_longitude)
 ! knon----input-I- nombre de points pour un type de surface
-! nsrf----input-I- indice pour le type de surface; voir indicesol.h
+! nsrf----input-I- indice pour le type de surface; voir indice_sol_mod.F90
 ! zxli----input-L- TRUE si calcul des cdrags selon Laurent Li
 ! u1------input-R- vent zonal au 1er niveau du modele
Index: LMDZ5/branches/testing/libf/phylmd/stratocu_if.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/stratocu_if.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/stratocu_if.F90	(revision 1795)
@@ -1,5 +1,8 @@
   SUBROUTINE stratocu_if(klon,klev,pctsrf,paprs, pplay,t &
 ,seuil_inversion,weak_inversion,dthmin)
-implicit none
+
+  USE indice_sol_mod
+
+IMPLICIT NONE
 
 !======================================================================
@@ -39,5 +42,4 @@
     REAL dthmin(klon), zdthdp
 
-    INCLUDE "indicesol.h"
     INCLUDE "YOMCST.h"
 
Index: LMDZ5/branches/testing/libf/phylmd/surf_land_bucket_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/surf_land_bucket_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/surf_land_bucket_mod.F90	(revision 1795)
@@ -27,9 +27,9 @@
     USE mod_grid_phy_lmdz
     USE mod_phys_lmdz_para
+    USE indice_sol_mod
 !****************************************************************************************
 ! Bucket calculations for surface. 
 !
     INCLUDE "clesphys.h"
-    INCLUDE "indicesol.h"
     INCLUDE "dimsoil.h"
     INCLUDE "YOMCST.h"
Index: LMDZ5/branches/testing/libf/phylmd/surf_land_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/surf_land_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/surf_land_mod.F90	(revision 1795)
@@ -31,6 +31,6 @@
     USE surf_land_bucket_mod
     USE calcul_fluxs_mod
+    USE indice_sol_mod
 
-    INCLUDE "indicesol.h"
     INCLUDE "dimsoil.h"
     INCLUDE "YOMCST.h"
Index: LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_mod.F90	(revision 1795)
@@ -44,4 +44,5 @@
     USE mod_synchro_omp
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl
+    USE indice_sol_mod
 
 !    
@@ -97,5 +98,4 @@
 !   qsurf        air moisture at surface
 !
-    INCLUDE "indicesol.h"
     INCLUDE "temps.h"
     INCLUDE "YOMCST.h"
@@ -551,5 +551,5 @@
     USE mod_grid_phy_lmdz
     USE mod_surf_para    
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
 
 #ifdef CPP_MPI
Index: LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noopenmp_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noopenmp_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/surf_land_orchidee_noopenmp_mod.F90	(revision 1795)
@@ -97,7 +97,7 @@
 !
     USE carbon_cycle_mod, ONLY : carbon_cycle_cpl, fco2_land_inst, fco2_lu_inst
+    USE indice_sol_mod
     IMPLICIT NONE
 
-    INCLUDE "indicesol.h"
     INCLUDE "temps.h"
     INCLUDE "YOMCST.h"
@@ -634,5 +634,6 @@
   SUBROUTINE Init_neighbours(knon,neighbours,ktindex,pctsrf)
     
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "dimensions.h"
 #ifdef CPP_MPI
Index: LMDZ5/branches/testing/libf/phylmd/surf_landice_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/surf_landice_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/surf_landice_mod.F90	(revision 1795)
@@ -25,6 +25,7 @@
     USE calcul_fluxs_mod
     USE phys_output_var_mod
-
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
+!    INCLUDE "indicesol.h"
     INCLUDE "dimsoil.h"
     INCLUDE "YOMCST.h"
Index: LMDZ5/branches/testing/libf/phylmd/surf_ocean_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/surf_ocean_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/surf_ocean_mod.F90	(revision 1795)
@@ -25,10 +25,11 @@
   USE ocean_slab_mod, ONLY   : ocean_slab_noice
   USE ocean_cpl_mod, ONLY    : ocean_cpl_noice
+  USE indice_sol_mod
 !
 ! This subroutine will make a call to ocean_XXX_noice according to the ocean mode (force, 
 ! slab or couple). The calculations of albedo and rugosity for the ocean surface are 
 ! done in here because they are identical for the different modes of ocean. 
-!
-    INCLUDE "indicesol.h"
+
+
     INCLUDE "YOMCST.h"
 
Index: LMDZ5/branches/testing/libf/phylmd/surf_seaice_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/surf_seaice_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/surf_seaice_mod.F90	(revision 1795)
@@ -25,4 +25,5 @@
   USE ocean_forced_mod, ONLY : ocean_forced_ice
   USE ocean_cpl_mod, ONLY    : ocean_cpl_ice
+  USE indice_sol_mod
 
 !
@@ -31,5 +32,4 @@
 ! in here because it is the same calculation for the different modes of ocean.
 !
-    INCLUDE "indicesol.h"
     INCLUDE "dimsoil.h"
 
Index: LMDZ5/branches/testing/libf/phylmd/sw_aeroAR4.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/sw_aeroAR4.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/sw_aeroAR4.F90	(revision 1795)
@@ -18,5 +18,5 @@
      PSOLSWAERO,PSOLSW0AERO,&
      PTOPSWCFAERO,PSOLSWCFAERO,&
-     ok_ade, ok_aie, flag_aerosol )
+     ok_ade, ok_aie, flag_aerosol, flag_aerosol_strat )
 
   USE dimphy
@@ -138,4 +138,5 @@
 
   LOGICAL ok_ade, ok_aie    ! use aerosol forcings or not?
+  LOGICAL flag_aerosol_strat ! use stratospehric aerosols
   INTEGER flag_aerosol      ! global flag for aerosol 0 (no aerosol) or 1-5 (aerosols)
   REAL(KIND=8) tauaero(kdlon,kflev,9,2)  ! aerosol optical properties
@@ -307,5 +308,5 @@
      ENDIF ! swaero_diag .or. .not. AEROSOLFEEDBACK_ACTIVE
 
-     IF (flag_aerosol .GT. 0 ) THEN
+     IF (flag_aerosol .GT. 0 .OR. flag_aerosol_strat) THEN
 
      IF (ok_ade.and.swaero_diag .or. .not. ok_ade) THEN
@@ -498,5 +499,5 @@
      ENDIF ! ok_aie      
 
-     ENDIF !--if flag_aerosol GT 0
+     ENDIF !--if flag_aerosol GT 0 OR flag_aerosol_strat
 
      itapsw = 0
@@ -504,5 +505,5 @@
   itapsw = itapsw + 1
 
-  IF  ( AEROSOLFEEDBACK_ACTIVE .AND. flag_aerosol .GT. 0 ) THEN
+  IF  ( AEROSOLFEEDBACK_ACTIVE .AND. (flag_aerosol .GT. 0 .OR. flag_aerosol_strat) ) THEN
   IF ( ok_ade .and. ok_aie  ) THEN
     ZFSUP(:,:) =    ZFSUP_AERO(:,:,4)
Index: LMDZ5/branches/testing/libf/phylmd/thermcell_main.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/thermcell_main.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/thermcell_main.F90	(revision 1795)
@@ -19,9 +19,10 @@
      &                  ,alp_bl_conv,alp_bl_stat &
 !!! fin nrlmd le 10/04/2012
-     &                         )
+     &                  ,ztva  )
 
       USE dimphy
       USE ioipsl
       USE comgeomphy , ONLY:rlond,rlatd
+      USE indice_sol_mod
       IMPLICIT NONE
 
@@ -67,7 +68,4 @@
 #include "iniprint.h"
 #include "thermcell.h"
-!!! nrlmd le 10/04/2012
-#include "indicesol.h"
-!!! fin nrlmd le 10/04/2012
 
 !   arguments:
Index: LMDZ5/branches/testing/libf/phylmd/tracinca_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/tracinca_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/tracinca_mod.F90	(revision 1795)
@@ -46,9 +46,9 @@
     USE comgeomphy
     USE control_mod
+    USE indice_sol_mod
 
     
     IMPLICIT NONE
     
-    INCLUDE "indicesol.h"
     INCLUDE "dimensions.h"
     INCLUDE "paramet.h"
Index: LMDZ5/branches/testing/libf/phylmd/traclmdz_mod.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/traclmdz_mod.F90	(revision 1750)
+++ LMDZ5/branches/testing/libf/phylmd/traclmdz_mod.F90	(revision 1795)
@@ -95,6 +95,6 @@
     USE mod_grid_phy_lmdz
     USE mod_phys_lmdz_para
-
-    INCLUDE "indicesol.h"
+    USE indice_sol_mod
+
     INCLUDE "iniprint.h"
 ! Input variables
@@ -346,6 +346,7 @@
     USE o3_chem_m, ONLY: o3_chem
     USE carbon_cycle_mod, ONLY : carbon_cycle, carbon_cycle_tr, carbon_cycle_cpl
+    USE indice_sol_mod
+
     INCLUDE "YOMCST.h"
-    INCLUDE "indicesol.h"
 
 !==========================================================================
Index: LMDZ5/branches/testing/libf/phylmd/yamada_c.F90
===================================================================
--- LMDZ5/branches/testing/libf/phylmd/yamada_c.F90	(revision 1795)
+++ LMDZ5/branches/testing/libf/phylmd/yamada_c.F90	(revision 1795)
@@ -0,0 +1,712 @@
+!
+! $Header$
+!
+      SUBROUTINE yamada_c(ngrid,timestep,plev,play &
+     &   ,pu,pv,pt,d_u,d_v,d_t,cd,q2,km,kn,kq,d_t_diss,ustar &
+     &   ,iflag_pbl,okiophys)
+      use dimphy
+      IMPLICIT NONE
+#include "iniprint.h"
+#include "YOMCST.h"
+!.......................................................................
+!ym#include "dimensions.h"
+!ym#include "dimphy.h"
+!.......................................................................
+!
+! timestep : pas de temps
+! g  : g
+! zlev : altitude a chaque niveau (interface inferieure de la couche
+!        de meme indice)
+! zlay : altitude au centre de chaque couche
+! u,v : vitesse au centre de chaque couche
+!       (en entree : la valeur au debut du pas de temps)
+! teta : temperature potentielle au centre de chaque couche
+!        (en entree : la valeur au debut du pas de temps)
+! cd : cdrag
+!      (en entree : la valeur au debut du pas de temps)
+! q2 : $q^2$ au bas de chaque couche
+!      (en entree : la valeur au debut du pas de temps)
+!      (en sortie : la valeur a la fin du pas de temps)
+! km : diffusivite turbulente de quantite de mouvement (au bas de chaque
+!      couche)
+!      (en sortie : la valeur a la fin du pas de temps)
+! kn : diffusivite turbulente des scalaires (au bas de chaque couche)
+!      (en sortie : la valeur a la fin du pas de temps)
+!
+!  iflag_pbl doit valoir entre 6 et 9
+!      l=6, on prend  systematiquement une longueur d'equilibre
+!    iflag_pbl=6 : MY 2.0
+!    iflag_pbl=7 : MY 2.0.Fournier
+!    iflag_pbl=8/9 : MY 2.5
+!       iflag_pbl=8 with special obsolete treatments for convergence
+!       with Cmpi5 NPv3.1 simulations
+!    iflag_pbl=10/11 :  New scheme M2 and N2 explicit and dissiptation exact
+!    iflag_pbl=12 = 11 with vertical diffusion off q2
+!
+!  2013/04/01 (FH hourdin@lmd.jussieu.fr)
+!     Correction for very stable PBLs (iflag_pbl=10 and 11)
+!     iflag_pbl=8 converges numerically with NPv3.1
+!     iflag_pbl=11 -> the model starts with NP from start files created by ce0l
+!                  -> the model can run with longer time-steps.
+!.......................................................................
+
+      REAL, DIMENSION(klon,klev) :: d_u,d_v,d_t
+      REAL, DIMENSION(klon,klev) :: pu,pv,pt
+      REAL, DIMENSION(klon,klev) :: d_t_diss
+      INTEGER okiophys
+
+      REAL timestep
+      real plev(klon,klev+1)
+      real play(klon,klev)
+      real ustar(klon)
+      real kmin,qmin,pblhmin(klon),coriol(klon)
+      REAL zlev(klon,klev+1)
+      REAL zlay(klon,klev)
+      REAL zu(klon,klev)
+      REAL zv(klon,klev)
+      REAL zt(klon,klev)
+      REAL teta(klon,klev)
+      REAL cd(klon)
+      REAL q2(klon,klev+1),qpre
+      REAL unsdz(klon,klev)
+      REAL unsdzdec(klon,klev+1)
+
+      REAL km(klon,klev+1)
+      REAL kmpre(klon,klev+1),tmp2
+      REAL mpre(klon,klev+1)
+      REAL kn(klon,klev+1)
+      REAL kq(klon,klev+1)
+      real ff(klon,klev+1),delta(klon,klev+1)
+      real aa(klon,klev+1),aa0,aa1
+      integer iflag_pbl,ngrid
+      integer nlay,nlev
+
+      logical first
+      integer ipas
+      save first,ipas
+!FH/IM     data first,ipas/.true.,0/
+      data first,ipas/.false.,0/
+!$OMP THREADPRIVATE( first,ipas)
+
+      integer ig,k
+
+
+      real ri,zrif,zalpha,zsm,zsn
+      real rif(klon,klev+1),sm(klon,klev+1),alpha(klon,klev)
+
+      real m2(klon,klev+1),dz(klon,klev+1),zq,n2(klon,klev+1)
+      REAL, DIMENSION(klon,klev+1) :: km2,kn2,sqrtq
+      real dtetadz(klon,klev+1)
+      real m2cstat,mcstat,kmcstat
+      real l(klon,klev+1)
+      real leff(klon,klev+1)
+      real,allocatable,save :: l0(:)
+!$OMP THREADPRIVATE(l0)      
+      real sq(klon),sqz(klon),zz(klon,klev+1)
+      integer iter
+
+      real ric,rifc,b1,kap
+      save ric,rifc,b1,kap
+      data ric,rifc,b1,kap/0.195,0.191,16.6,0.4/
+!$OMP THREADPRIVATE(ric,rifc,b1,kap)
+      real frif,falpha,fsm
+      real fl,zzz,zl0,zq2,zn2
+
+      real rino(klon,klev+1),smyam(klon,klev),styam(klon,klev)
+      real lyam(klon,klev),knyam(klon,klev)
+      real w2yam(klon,klev),t2yam(klon,klev)
+      logical,save :: firstcall=.true.
+
+REAL, DIMENSION(klon,klev+1) :: fluxu,fluxv,fluxt
+REAL, DIMENSION(klon,klev+1) :: dddu,dddv,dddt
+REAL, DIMENSION(klon,klev) :: exner,masse
+REAL, DIMENSION(klon,klev+1) :: masseb,q2old,q2neg
+
+!$OMP THREADPRIVATE(firstcall)       
+      frif(ri)=0.6588*(ri+0.1776-sqrt(ri*ri-0.3221*ri+0.03156))
+      falpha(ri)=1.318*(0.2231-ri)/(0.2341-ri)
+      fsm(ri)=1.96*(0.1912-ri)*(0.2341-ri)/((1.-ri)*(0.2231-ri))
+      fl(zzz,zl0,zq2,zn2)= &
+     &     max(min(l0(ig)*kap*zlev(ig,k)/(kap*zlev(ig,k)+l0(ig)) &
+     &     ,0.5*sqrt(q2(ig,k))/sqrt(max(n2(ig,k),1.e-10))) ,1.)
+
+
+      if (firstcall) then
+        allocate(l0(klon))
+#ifdef IOPHYS
+        call iophys_ini
+#endif
+        firstcall=.false.
+      endif
+
+
+#ifdef IOPHYS
+if (okiophys==1) then
+call iophys_ecrit('q2i',klev,'q2 debut my','m2/s2',q2(:,1:klev))
+call iophys_ecrit('kmi',klev,'Kz debut my','m/s2',km(:,1:klev))
+endif
+#endif
+
+      nlay=klev
+      nlev=klev+1
+
+!-------------------------------------------------------------------------
+! Computation of conservative source terms from the turbulent tendencies
+!-------------------------------------------------------------------------
+
+
+   zu(:,:)=pu(:,:)+0.5*d_u(:,:)
+   zv(:,:)=pv(:,:)+0.5*d_v(:,:)
+   zt(:,:)=pt(:,:)+0.5*d_t(:,:)
+   do k=1,klev
+      exner(:,k)=(play(:,k)/plev(:,1))**RKAPPA
+      masse(:,k)=(plev(:,k)-plev(:,k+1))/RG
+   enddo
+   teta(:,:)=zt(:,:)/exner(:,:)
+
+! Atmospheric mass at layer interfaces, where the TKE is computed
+   masseb(:,:)=0.
+   do k=1,klev
+      masseb(:,k)=masseb(:,k)+masse(:,k)
+      masseb(:,k+1)=masseb(:,k+1)+masse(:,k)
+    enddo
+    masseb(:,:)=0.5*masseb(:,:)
+
+
+
+   zlev(:,1)=0.
+   zlay(:,1)=RCPD*teta(:,1)*(1.-exner(:,1))
+   do k=1,klev-1
+      zlay(:,k+1)=zlay(:,k)+0.5*RCPD*(teta(:,k)+teta(:,k+1))*(exner(:,k)-exner(:,k+1))/RG
+      zlev(:,k)=0.5*(zlay(:,k)+zlay(:,k+1)) ! PASBO
+   enddo
+
+   fluxu(:,klev+1)=0.
+   fluxv(:,klev+1)=0.
+   fluxt(:,klev+1)=0.
+
+   do k=klev,1,-1
+      fluxu(:,k)=fluxu(:,k+1)+masse(:,k)*d_u(:,k)
+      fluxv(:,k)=fluxv(:,k+1)+masse(:,k)*d_v(:,k)
+      fluxt(:,k)=fluxt(:,k+1)+masse(:,k)*d_t(:,k)/exner(:,k) ! Flux de theta
+   enddo
+
+   dddu(:,1)=2*zu(:,1)*fluxu(:,1)
+   dddv(:,1)=2*zv(:,1)*fluxv(:,1)
+   dddt(:,1)=(exner(:,1)-1.)*fluxt(:,1)
+
+   do k=2,klev
+      dddu(:,k)=(zu(:,k)-zu(:,k-1))*fluxu(:,k)
+      dddv(:,k)=(zv(:,k)-zv(:,k-1))*fluxv(:,k)
+      dddt(:,k)=(exner(:,k)-exner(:,k-1))*fluxt(:,k)
+   enddo
+   dddu(:,klev+1)=0.
+   dddv(:,klev+1)=0.
+   dddt(:,klev+1)=0.
+
+#ifdef IOPHYS
+if (okiophys==1) then
+      call iophys_ecrit('zlay',klev,'Geop','m',zlay)
+      call iophys_ecrit('teta',klev,'teta','K',teta)
+      call iophys_ecrit('temp',klev,'temp','K',zt)
+      call iophys_ecrit('pt',klev,'temp','K',pt)
+      call iophys_ecrit('d_u',klev,'d_u','m/s2',d_u)
+      call iophys_ecrit('d_v',klev,'d_v','m/s2',d_v)
+      call iophys_ecrit('d_t',klev,'d_t','K/s',d_t)
+      call iophys_ecrit('exner',klev,'exner','',exner)
+      call iophys_ecrit('masse',klev,'masse','',masse)
+      call iophys_ecrit('masseb',klev,'masseb','',masseb)
+      call iophys_ecrit('Cm2',klev,'m2 conserv','m/s',(dddu(:,1:klev)+dddv(:,1:klev))/(masseb(:,1:klev)*timestep))
+      call iophys_ecrit('Cn2',klev,'m2 conserv','m/s',(rcpd*dddt(:,1:klev)/masseb(:,1:klev))/timestep)
+      call iophys_ecrit('rifc',klev,'rif conservative','',rcpd*dddt(:,1:klev)/min(dddu(:,1:klev)+dddv(:,1:klev),-1.e-20))
+endif
+#endif
+
+
+
+      ipas=ipas+1
+
+
+!.......................................................................
+!  les increments verticaux
+!.......................................................................
+!
+!!!!!! allerte !!!!!c
+!!!!!! zlev n'est pas declare a nlev !!!!!c
+!!!!!! ---->
+                                                      DO ig=1,ngrid
+            zlev(ig,nlev)=zlay(ig,nlay) &
+     &             +( zlay(ig,nlay) - zlev(ig,nlev-1) )
+                                                      ENDDO
+!!!!!! <----
+!!!!!! allerte !!!!!c
+!
+      DO k=1,nlay
+                                                      DO ig=1,ngrid
+        unsdz(ig,k)=1.E+0/(zlev(ig,k+1)-zlev(ig,k))
+                                                      ENDDO
+      ENDDO
+                                                      DO ig=1,ngrid
+      unsdzdec(ig,1)=1.E+0/(zlay(ig,1)-zlev(ig,1))
+                                                      ENDDO
+      DO k=2,nlay
+                                                      DO ig=1,ngrid
+        unsdzdec(ig,k)=1.E+0/(zlay(ig,k)-zlay(ig,k-1))
+                                                     ENDDO
+      ENDDO
+                                                      DO ig=1,ngrid
+      unsdzdec(ig,nlay+1)=1.E+0/(zlev(ig,nlay+1)-zlay(ig,nlay))
+                                                     ENDDO
+!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Computing M^2, N^2, Richardson numbers, stability functions
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+
+      do k=2,klev
+                                                          do ig=1,ngrid
+         dz(ig,k)=zlay(ig,k)-zlay(ig,k-1)
+         m2(ig,k)=((zu(ig,k)-zu(ig,k-1))**2+(zv(ig,k)-zv(ig,k-1))**2)/(dz(ig,k)*dz(ig,k))
+         dtetadz(ig,k)=(teta(ig,k)-teta(ig,k-1))/dz(ig,k)
+         n2(ig,k)=RG*2.*dtetadz(ig,k)/(teta(ig,k-1)+teta(ig,k))
+!        n2(ig,k)=0.
+         ri=n2(ig,k)/max(m2(ig,k),1.e-10)
+         if (ri.lt.ric) then
+            rif(ig,k)=frif(ri)
+         else
+            rif(ig,k)=rifc
+         endif
+         if(rif(ig,k).lt.0.16) then
+            alpha(ig,k)=falpha(rif(ig,k))
+            sm(ig,k)=fsm(rif(ig,k))
+         else
+            alpha(ig,k)=1.12
+            sm(ig,k)=0.085
+         endif
+         zz(ig,k)=b1*m2(ig,k)*(1.-rif(ig,k))*sm(ig,k)
+                                                          enddo
+      enddo
+
+
+
+!====================================================================
+!  Computing the mixing length
+!====================================================================
+
+!   Mise a jour de l0
+      if (iflag_pbl==8.or.iflag_pbl==10) then
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Iterative computation of l0
+! This version is kept for iflag_pbl only for convergence
+! with NPv3.1 Cmip5 simulations
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+                                                          do ig=1,ngrid
+      sq(ig)=1.e-10
+      sqz(ig)=1.e-10
+                                                          enddo
+      do k=2,klev-1
+                                                          do ig=1,ngrid
+        zq=sqrt(q2(ig,k))
+        sqz(ig)=sqz(ig)+zq*zlev(ig,k)*(zlay(ig,k)-zlay(ig,k-1))
+        sq(ig)=sq(ig)+zq*(zlay(ig,k)-zlay(ig,k-1))
+                                                          enddo
+      enddo
+                                                          do ig=1,ngrid
+      l0(ig)=0.2*sqz(ig)/sq(ig)
+                                                          enddo
+      do k=2,klev
+                                                          do ig=1,ngrid
+         l(ig,k)=fl(zlev(ig,k),l0(ig),q2(ig,k),n2(ig,k))
+                                                          enddo
+      enddo
+!     print*,'L0 cas 8 ou 10 ',l0
+
+      else
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! In all other case, the assymptotic mixing length l0 is imposed (100m)
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+          l0(:)=150.
+          do k=2,klev
+                                                          do ig=1,ngrid
+             l(ig,k)=fl(zlev(ig,k),l0(ig),q2(ig,k),n2(ig,k))
+                                                          enddo
+          enddo
+!     print*,'L0 cas autres ',l0
+
+      endif
+
+
+#ifdef IOPHYS
+if (okiophys==1) then
+call iophys_ecrit('rif',klev,'Flux Richardson','m',rif(:,1:klev))
+call iophys_ecrit('m2',klev,'m2 ','m/s',m2(:,1:klev))
+call iophys_ecrit('Km2',klev,'m2 conserv','m/s',km(:,1:klev)*m2(:,1:klev))
+call iophys_ecrit('Km',klev,'Km','m2/s',km(:,1:klev))
+endif
+#endif
+
+
+IF (iflag_pbl<20) then
+      ! For diagnostics only
+      RETURN
+
+ELSE
+
+!  print*,'OK1'
+
+! Evolution of TKE under source terms K M2 and K N2
+   leff(:,:)=max(l(:,:),1.)
+   IF (iflag_pbl==29) THEN
+      km2(:,:)=km(:,:)*m2(:,:)
+      kn2(:,:)=kn2(:,:)*rif(:,:)
+   ELSEIF (iflag_pbl==25) THEN
+      DO k=1,klev
+         km2(:,k)=-0.5*(dddu(:,k)+dddv(:,k)+dddu(:,k+1)+dddv(:,k+1)) &
+         &        /(masse(:,k)*timestep)
+         kn2(:,k)=rcpd*0.5*(dddt(:,k)+dddt(:,k+1))/(masse(:,k)*timestep)
+         leff(:,k)=0.5*(leff(:,k)+leff(:,k+1))
+      ENDDO
+      km2(:,klev+1)=0. ; kn2(:,klev+1)=0.
+   ELSE
+      km2(:,:)=-(dddu(:,:)+dddv(:,:))/(masseb(:,:)*timestep)
+      kn2(:,:)=rcpd*dddt(:,:)/(masseb(:,:)*timestep)
+   ENDIF
+   q2neg(:,:)=q2(:,:)+timestep*(km2(:,:)-kn2(:,:))
+   q2(:,:)=min(max(q2neg(:,:),1.e-10),1.e4)
+
+! Dissipation of TKE
+   q2old(:,:)=q2(:,:)
+   q2(:,:)=1./(1./sqrt(q2(:,:))+timestep/(2*leff(:,:)*b1))
+   q2(:,:)=q2(:,:)*q2(:,:)
+   IF (iflag_pbl<=24) THEN
+      DO k=1,klev
+         d_t_diss(:,k)=(masseb(:,k)*(q2neg(:,k)-q2(:,k))+masseb(:,k+1)*(q2neg(:,k+1)-q2(:,k+1)))/(2.*rcpd*masse(:,k))
+      ENDDO
+   ELSE IF (iflag_pbl<=27) THEN
+      DO k=1,klev
+         d_t_diss(:,k)=(q2neg(:,k)-q2(:,k))/rcpd
+      ENDDO
+   ENDIF
+!  print*,'iflag_pbl ',d_t_diss
+
+
+! Compuation of stability functions
+   IF (iflag_pbl/=29) THEN
+      DO k=1,klev
+      DO ig=1,ngrid
+         IF (ABS(km2(ig,k))<=1.e-20) THEN
+            rif(ig,k)=0.
+         ELSE
+            rif(ig,k)=min(kn2(ig,k)/km2(ig,k),rifc)
+         ENDIF
+         IF (rif(ig,k).lt.0.16) THEN
+            alpha(ig,k)=falpha(rif(ig,k))
+            sm(ig,k)=fsm(rif(ig,k))
+         else
+            alpha(ig,k)=1.12
+            sm(ig,k)=0.085
+         endif
+      ENDDO
+      ENDDO
+    ENDIF
+
+! Computation of turbulent diffusivities
+   IF (25<=iflag_pbl.and.iflag_pbl<=28) THEN
+     DO k=2,klev
+        sqrtq(:,k)=sqrt(0.5*(q2(:,k)+q2(:,k-1)))
+     ENDDO
+   ELSE
+     DO k=2,klev
+        sqrtq(:,k)=sqrt(q2(:,k))
+     ENDDO
+   ENDIF
+   DO k=2,klev
+   DO ig=1,ngrid
+      km(ig,k)=leff(ig,k)*sqrtq(ig,k)*sm(ig,k)
+      kn(ig,k)=km(ig,k)*alpha(ig,k)
+      kq(ig,k)=leff(ig,k)*zq*0.2
+!         print*,q2(ig,k),zq,km(ig,k)
+   ENDDO
+   ENDDO
+
+
+
+#ifdef IOPHYS
+if (okiophys==1) then
+call iophys_ecrit('mixingl',klev,'Mixing length','m',leff(:,1:klev))
+call iophys_ecrit('rife',klev,'Flux Richardson','m',rif(:,1:klev))
+call iophys_ecrit('q2f',klev,'KTE finale','m2/s',q2(:,1:klev))
+call iophys_ecrit('q2neg',klev,'KTE non bornee','m2/s',q2neg(:,1:klev))
+call iophys_ecrit('alpha',klev,'alpha','',alpha(:,1:klev))
+call iophys_ecrit('sm',klev,'sm','',sm(:,1:klev))
+call iophys_ecrit('q2f',klev,'KTE finale','m2/s',q2(:,1:klev))
+call iophys_ecrit('kmf',klev,'Kz final','m2/s',km(:,1:klev))
+call iophys_ecrit('knf',klev,'Kz final','m2/s',kn(:,1:klev))
+call iophys_ecrit('kqf',klev,'Kz final','m2/s',kq(:,1:klev))
+endif
+#endif
+
+ENDIF
+
+
+!  print*,'OK2'
+      RETURN
+!====================================================================
+!   Yamada 2.0
+!====================================================================
+      if (iflag_pbl.eq.6) then
+
+      do k=2,klev
+         q2(:,k)=l(:,k)**2*zz(:,k)
+      enddo
+
+
+      else if (iflag_pbl.eq.7) then
+!====================================================================
+!   Yamada 2.Fournier
+!====================================================================
+
+!  Calcul de l,  km, au pas precedent
+      do k=2,klev
+                                                          do ig=1,ngrid
+!        print*,'SMML=',sm(ig,k),l(ig,k)
+         delta(ig,k)=q2(ig,k)/(l(ig,k)**2*sm(ig,k))
+         kmpre(ig,k)=l(ig,k)*sqrt(q2(ig,k))*sm(ig,k)
+         mpre(ig,k)=sqrt(m2(ig,k))
+!        print*,'0L=',k,l(ig,k),delta(ig,k),km(ig,k)
+                                                          enddo
+      enddo
+
+      do k=2,klev-1
+                                                          do ig=1,ngrid
+        m2cstat=max(alpha(ig,k)*n2(ig,k)+delta(ig,k)/b1,1.e-12)
+        mcstat=sqrt(m2cstat)
+
+!        print*,'M2 L=',k,mpre(ig,k),mcstat
+!
+!  -----{puis on ecrit la valeur de q qui annule l'equation de m
+!        supposee en q3}
+!
+        IF (k.eq.2) THEN
+          kmcstat=1.E+0 / mcstat &
+     &    *( unsdz(ig,k)*kmpre(ig,k+1) &
+     &                        *mpre(ig,k+1) &
+     &      +unsdz(ig,k-1) &
+     &              *cd(ig) &
+     &              *( sqrt(zu(ig,3)**2+zv(ig,3)**2) &
+     &                -mcstat/unsdzdec(ig,k) &
+     &                -mpre(ig,k+1)/unsdzdec(ig,k+1) )**2) &
+     &      /( unsdz(ig,k)+unsdz(ig,k-1) )
+        ELSE
+          kmcstat=1.E+0 / mcstat &
+     &    *( unsdz(ig,k)*kmpre(ig,k+1) &
+     &                        *mpre(ig,k+1) &
+     &      +unsdz(ig,k-1)*kmpre(ig,k-1) &
+     &                          *mpre(ig,k-1) ) &
+     &      /( unsdz(ig,k)+unsdz(ig,k-1) )
+        ENDIF
+!       print*,'T2 L=',k,tmp2
+        tmp2=kmcstat &
+     &      /( sm(ig,k)/q2(ig,k) ) &
+     &      /l(ig,k)
+        q2(ig,k)=max(tmp2,1.e-12)**(2./3.)
+!       print*,'Q2 L=',k,q2(ig,k)
+!
+                                                          enddo
+      enddo
+
+      else if (iflag_pbl==8.or.iflag_pbl==9) then
+!====================================================================
+!   Yamada 2.5 a la Didi
+!====================================================================
+
+
+!  Calcul de l,  km, au pas precedent
+      do k=2,klev
+                                                          do ig=1,ngrid
+!        print*,'SMML=',sm(ig,k),l(ig,k)
+         delta(ig,k)=q2(ig,k)/(l(ig,k)**2*sm(ig,k))
+         if (delta(ig,k).lt.1.e-20) then
+!     print*,'ATTENTION   L=',k,'   Delta=',delta(ig,k)
+            delta(ig,k)=1.e-20
+         endif
+         km(ig,k)=l(ig,k)*sqrt(q2(ig,k))*sm(ig,k)
+         aa0=(m2(ig,k)-alpha(ig,k)*n2(ig,k)-delta(ig,k)/b1)
+         aa1=(m2(ig,k)*(1.-rif(ig,k))-delta(ig,k)/b1)
+! abder      print*,'AA L=',k,aa0,aa1,aa1/max(m2(ig,k),1.e-20)
+         aa(ig,k)=aa1*timestep/(delta(ig,k)*l(ig,k))
+!     print*,'0L=',k,l(ig,k),delta(ig,k),km(ig,k)
+         qpre=sqrt(q2(ig,k))
+!        if (iflag_pbl.eq.8 ) then
+            if (aa(ig,k).gt.0.) then
+               q2(ig,k)=(qpre+aa(ig,k)*qpre*qpre)**2
+            else
+               q2(ig,k)=(qpre/(1.-aa(ig,k)*qpre))**2
+            endif
+!        else ! iflag_pbl=9
+!           if (aa(ig,k)*qpre.gt.0.9) then
+!              q2(ig,k)=(qpre*10.)**2
+!           else
+!              q2(ig,k)=(qpre/(1.-aa(ig,k)*qpre))**2
+!           endif
+!        endif
+         q2(ig,k)=min(max(q2(ig,k),1.e-10),1.e4)
+!     print*,'Q2 L=',k,q2(ig,k),qpre*qpre
+                                                          enddo
+      enddo
+
+      else if (iflag_pbl>=10) then
+
+!        print*,'Schema mixte D'
+!        print*,'Longueur ',l(:,:)
+         do k=2,klev-1
+            l(:,k)=max(l(:,k),1.)
+            km(:,k)=l(:,k)*sqrt(q2(:,k))*sm(:,k)
+            q2(:,k)=q2(:,k)+timestep*km(:,k)*m2(:,k)*(1.-rif(:,k))
+            q2(:,k)=min(max(q2(:,k),1.e-10),1.e4)
+            q2(:,k)=1./(1./sqrt(q2(:,k))+timestep/(2*l(:,k)*b1))
+            q2(:,k)=q2(:,k)*q2(:,k)
+         enddo
+
+
+      else
+         stop'Cas nom prevu dans yamada4'
+
+      endif ! Fin du cas 8
+
+!     print*,'OK8'
+
+!====================================================================
+!   Calcul des coefficients de m�ange
+!====================================================================
+      do k=2,klev
+!     print*,'k=',k
+                                                          do ig=1,ngrid
+!abde      print*,'KML=',l(ig,k),q2(ig,k),sm(ig,k)
+         zq=sqrt(q2(ig,k))
+         km(ig,k)=l(ig,k)*zq*sm(ig,k)
+         kn(ig,k)=km(ig,k)*alpha(ig,k)
+         kq(ig,k)=l(ig,k)*zq*0.2
+!     print*,'KML=',km(ig,k),kn(ig,k)
+                                                          enddo
+      enddo
+
+! Transport diffusif vertical de la TKE.
+      if (iflag_pbl.ge.12) then
+!       print*,'YAMADA VDIF'
+        q2(:,1)=q2(:,2)
+        call vdif_q2(timestep,RG,RD,ngrid,plev,zt,kq,q2)
+      endif
+
+!   Traitement des cas noctrunes avec l'introduction d'une longueur
+!   minilale.
+
+!====================================================================
+!   Traitement particulier pour les cas tres stables.
+!   D'apres Holtslag Boville.
+
+      if (prt_level>1) THEN
+       print*,'YAMADA4 0'
+      endif !(prt_level>1) THEN
+                                                          do ig=1,ngrid
+      coriol(ig)=1.e-4
+      pblhmin(ig)=0.07*ustar(ig)/max(abs(coriol(ig)),2.546e-5)
+                                                          enddo
+
+!     print*,'pblhmin ',pblhmin
+!Test a remettre 21 11 02
+! test abd 13 05 02      if(0.eq.1) then
+      if(1==1) then
+      if(iflag_pbl==8.or.iflag_pbl==10) then
+
+      do k=2,klev
+         do ig=1,ngrid
+            if (teta(ig,2).gt.teta(ig,1)) then
+               qmin=ustar(ig)*(max(1.-zlev(ig,k)/pblhmin(ig),0.))**2
+               kmin=kap*zlev(ig,k)*qmin
+            else
+               kmin=-1. ! kmin n'est utilise que pour les SL stables.
+            endif 
+            if (kn(ig,k).lt.kmin.or.km(ig,k).lt.kmin) then
+!               print*,'Seuil min Km K=',k,kmin,km(ig,k),kn(ig,k)
+!     s           ,sqrt(q2(ig,k)),pblhmin(ig),qmin/sm(ig,k)
+               kn(ig,k)=kmin
+               km(ig,k)=kmin
+               kq(ig,k)=kmin
+!   la longueur de melange est suposee etre l= kap z
+!   K=l q Sm d'ou q2=(K/l Sm)**2
+               q2(ig,k)=(qmin/sm(ig,k))**2
+            endif
+         enddo
+      enddo
+
+      else
+
+      do k=2,klev
+         do ig=1,ngrid
+            if (teta(ig,2).gt.teta(ig,1)) then
+               qmin=ustar(ig)*(max(1.-zlev(ig,k)/pblhmin(ig),0.))**2
+               kmin=kap*zlev(ig,k)*qmin
+            else
+               kmin=-1. ! kmin n'est utilise que pour les SL stables.
+            endif 
+            if (kn(ig,k).lt.kmin.or.km(ig,k).lt.kmin) then
+!               print*,'Seuil min Km K=',k,kmin,km(ig,k),kn(ig,k)
+!     s           ,sqrt(q2(ig,k)),pblhmin(ig),qmin/sm(ig,k)
+               kn(ig,k)=kmin
+               km(ig,k)=kmin
+               kq(ig,k)=kmin
+!   la longueur de melange est suposee etre l= kap z
+!   K=l q Sm d'ou q2=(K/l Sm)**2
+               sm(ig,k)=1.
+               alpha(ig,k)=1.
+               q2(ig,k)=min((qmin/sm(ig,k))**2,10.)
+               zq=sqrt(q2(ig,k))
+               km(ig,k)=l(ig,k)*zq*sm(ig,k)
+               kn(ig,k)=km(ig,k)*alpha(ig,k)
+               kq(ig,k)=l(ig,k)*zq*0.2
+            endif
+         enddo
+      enddo
+      endif
+
+      endif
+
+      if (prt_level>1) THEN
+       print*,'YAMADA4 1'
+      endif !(prt_level>1) THEN
+!   Diagnostique pour stokage
+
+      if(1.eq.0)then
+      rino=rif
+      smyam(1:ngrid,1)=0.
+      styam(1:ngrid,1)=0.
+      lyam(1:ngrid,1)=0.
+      knyam(1:ngrid,1)=0.
+      w2yam(1:ngrid,1)=0.
+      t2yam(1:ngrid,1)=0.
+
+      smyam(1:ngrid,2:klev)=sm(1:ngrid,2:klev)
+      styam(1:ngrid,2:klev)=sm(1:ngrid,2:klev)*alpha(1:ngrid,2:klev)
+      lyam(1:ngrid,2:klev)=l(1:ngrid,2:klev)
+      knyam(1:ngrid,2:klev)=kn(1:ngrid,2:klev)
+
+!   Estimations de w'2 et T'2 d'apres Abdela et McFarlane
+
+      w2yam(1:ngrid,2:klev)=q2(1:ngrid,2:klev)*0.24 &
+     &    +lyam(1:ngrid,2:klev)*5.17*kn(1:ngrid,2:klev) &
+     &    *n2(1:ngrid,2:klev)/sqrt(q2(1:ngrid,2:klev))
+
+      t2yam(1:ngrid,2:klev)=9.1*kn(1:ngrid,2:klev) &
+     &    *dtetadz(1:ngrid,2:klev)**2 &
+     &    /sqrt(q2(1:ngrid,2:klev))*lyam(1:ngrid,2:klev)
+      endif
+
+!     print*,'OKFIN'
+      first=.false.
+      return
+      end
