Index: /LMDZ4/trunk/libf/dyn3d/PVteta.F
===================================================================
--- /LMDZ4/trunk/libf/dyn3d/PVteta.F	(revision 644)
+++ /LMDZ4/trunk/libf/dyn3d/PVteta.F	(revision 644)
@@ -0,0 +1,194 @@
+      SUBROUTINE PVtheta(ilon,ilev,pucov,pvcov,pteta,
+     $           ztfi,zplay,zplev,
+     $           nbteta,theta,PVteta)
+      IMPLICIT none
+
+c=======================================================================
+c
+c   Auteur:  I. Musat
+c   -------
+c
+c   Objet:
+c   ------
+c
+c    *******************************************************************
+c    Calcul de la vorticite potentielle PVteta sur des iso-theta selon
+c    la methodologie du NCEP/NCAR :
+c    1) on calcule la stabilite statique N**2=g/T*(dT/dz+g/cp) sur les
+c       niveaux du modele => N2
+c    2) on interpole les vents, la temperature et le N**2 sur des isentropes
+c       (en fait sur des iso-theta) lineairement en log(theta) =>
+c       ucovteta, vcovteta, N2teta
+c    3) on calcule la vorticite absolue sur des iso-theta => vorateta
+c    4) on calcule la densite rho sur des iso-theta => rhoteta 
+c
+c       rhoteta = (T/theta)**(cp/R)*p0/(R*T)
+c
+c    5) on calcule la vorticite potentielle sur des iso-theta => PVteta
+c
+c       PVteta = (vorateta * N2 * theta)/(g * rhoteta) ! en PVU
+c
+c       NB: 1PVU=10**(-6) K*m**2/(s * kg)
+c
+c       PVteta =  vorateta * N2/(g**2 * rhoteta) ! en 1/(Pa*s)
+c
+c
+c    *******************************************************************
+c
+c
+c     Variables d'entree : ilon,ilev,pucov,pvcov,pteta,ztfi,zplay,zplev,nbteta,theta
+c                       -> sur la grille dynamique
+c     Variable de sortie : PVteta
+c                       -> sur la grille physique 
+c=======================================================================
+
+#include "dimensions.h"
+#include "paramet.h"
+c
+c variables Input
+c
+      INTEGER ilon, ilev
+      REAL pvcov(iip1,jjm,ilev)
+      REAL pucov(iip1,jjp1,ilev)
+      REAL pteta(iip1,jjp1,ilev)
+      REAL ztfi(ilon,ilev)
+      REAL zplay(ilon,ilev), zplev(ilon,ilev+1)
+      INTEGER nbteta
+      REAL theta(nbteta)
+c
+c variable Output
+c
+      REAL PVteta(ilon,nbteta)
+c
+c variables locales
+c
+      INTEGER i, j, l, ig0
+      REAL SSUM
+      REAL teta(ilon, ilev)
+      REAL ptetau(ip1jmp1, ilev), ptetav(ip1jm, ilev)
+      REAL ucovteta(ip1jmp1,ilev), vcovteta(ip1jm,ilev)
+      REAL N2(ilon,ilev-1), N2teta(ilon,nbteta)
+      REAL ztfiteta(ilon,nbteta)
+      REAL rhoteta(ilon,nbteta)
+      REAL vorateta(iip1,jjm,ilev)
+      REAL voratetafi(ilon,ilev), vorpol(iim)
+c
+#include "comgeom2.h"
+#include "comconst.h"
+#include "comvert.h"
+c
+c projection teta sur la grille physique
+c
+      DO l=1,llm
+       teta(1,l)   =  pteta(1,1,l)
+       ig0         = 2
+       DO j = 2, jjm
+        DO i = 1, iim
+         teta(ig0,l)    = pteta(i,j,l)
+         ig0            = ig0 + 1
+        ENDDO
+       ENDDO
+       teta(ig0,l)    = pteta(1,jjp1,l)
+      ENDDO
+c
+c calcul pteta sur les grilles U et V
+c
+      DO l=1, llm
+       DO j=1, jjp1
+        DO i=1, iip1
+         ig0=i+(j-1)*iip1
+         ptetau(ig0,l)=pteta(i,j,l)
+        ENDDO !i
+       ENDDO !j
+       DO j=1, jjm
+        DO i=1, iip1
+         ig0=i+(j-1)*iip1
+         ptetav(ig0,l)=0.5*(pteta(i,j,l)+pteta(i,j+1,l))
+        ENDDO !i
+       ENDDO !j
+      ENDDO !l
+c
+c projection pucov, pvcov sur une surface de theta constante
+c
+      DO l=1, nbteta
+       CALL tetaleveli1j1(ip1jmp1,llm,.true.,ptetau,theta(l),
+     .                    pucov,ucovteta(:,l))
+       CALL tetaleveli1j(ip1jm,llm,.true.,ptetav,theta(l),
+     .                   pvcov,vcovteta(:,l))
+      ENDDO !l
+c
+c calcul vorticite absolue sur une iso-theta : vorateta
+c
+      CALL tourabs(nbteta,vcovteta,ucovteta,vorateta)
+c
+c projection vorateta sur la grille physique => voratetafi
+c
+      DO l=1,llm
+       DO j=2,jjm
+        ig0=1+(j-2)*iim
+        DO i=1,iim
+         voratetafi(ig0+i+1,l) = vorateta( i ,j-1,l) * alpha4(i+1,j) +
+     $                           vorateta(i+1,j-1,l) * alpha1(i+1,j) +
+     $                           vorateta(i  ,j  ,l) * alpha3(i+1,j) +
+     $                           vorateta(i+1,j  ,l) * alpha2(i+1,j)
+        ENDDO
+        voratetafi(ig0 +1,l) = voratetafi(ig0 +1+ iim,l)
+       ENDDO
+      ENDDO
+c
+      DO l=1,llm
+       DO i=1,iim
+        vorpol(i)  = vorateta(i,1,l)*aire(i,1)
+       ENDDO
+       voratetafi(1,l)= SSUM(iim,vorpol,1)/apoln
+      ENDDO
+c
+      DO l=1,llm
+       DO i=1,iim
+        vorpol(i)  = vorateta(i,jjm,l)* aire(i,jjm +1)
+       ENDDO
+       voratetafi(ilon,l)= SSUM(iim,vorpol,1)/apols
+      ENDDO
+c 
+c calcul N**2 sur la grille physique => N2
+c
+      DO l=1, llm-1 
+       DO i=1, ilon
+        N2(i,l) = (g**2 * zplay(i,l) * 
+     $            (ztfi(i,l+1)-ztfi(i,l)) )/
+     $            (R*ztfi(i,l)*ztfi(i,l)*
+     $            (zplev(i,l)-zplev(i,l+1)) )+
+     $            (g**2)/(ztfi(i,l)*CPP)
+       ENDDO !i
+      ENDDO !l
+c
+c calcul N2 sur une iso-theta => N2teta 
+c
+      DO l=1, nbteta
+       CALL tetalevel(ilon,llm-1,.true.,teta,theta(l),
+     $                N2,N2teta(:,l))
+       CALL tetalevel(ilon,llm,.true.,teta,theta(l),
+     $                ztfi,ztfiteta(:,l))
+      ENDDO !l=1, nbteta
+c
+c calcul rho et PV sur une iso-theta : rhoteta, PVteta
+c
+      DO l=1, nbteta
+       DO i=1, ilon
+        rhoteta(i,l)=(ztfiteta(i,l)/theta(l))**(CPP/R)*
+     $  (preff/(R*ztfiteta(i,l)))
+c
+c PVteta en PVU
+c
+        PVteta(i,l)=(theta(l)*g*voratetafi(i,l)*N2teta(i,l))/
+     $              (g**2*rhoteta(i,l))
+c
+c PVteta en 1/(Pa*s)
+c
+        PVteta(i,l)=(voratetafi(i,l)*N2teta(i,l))/
+     $              (g**2*rhoteta(i,l))
+       ENDDO !i
+      ENDDO !l
+c
+      RETURN
+      END 
Index: /LMDZ4/trunk/libf/dyn3d/advx.F
===================================================================
--- /LMDZ4/trunk/libf/dyn3d/advx.F	(revision 643)
+++ /LMDZ4/trunk/libf/dyn3d/advx.F	(revision 644)
@@ -106,5 +106,6 @@
          DO j = 1,jjp1
             DO i = 1,iim
-               sqi = sqi + S0(i,j,l,9)
+cIM 240305            sqi = sqi + S0(i,j,l,9)
+               sqi = sqi + S0(i,j,l,ntra)
             ENDDO
          ENDDO
@@ -483,5 +484,6 @@
         DO j = 1, jjp1
           DO i = 1, iim
-             sqf = sqf + S0(i,j,l,9)
+cIM 240405          sqf = sqf + S0(i,j,l,9)
+             sqf = sqf + S0(i,j,l,ntra)
           END DO  
         END DO
Index: /LMDZ4/trunk/libf/dyn3d/advz.F
===================================================================
--- /LMDZ4/trunk/libf/dyn3d/advz.F	(revision 643)
+++ /LMDZ4/trunk/libf/dyn3d/advz.F	(revision 644)
@@ -105,5 +105,6 @@
          DO j = 1,jjp1
             DO i = 1,iim
-               sqi = sqi + S0(i,j,l,9)
+cIM 240305            sqi = sqi + S0(i,j,l,9)
+               sqi = sqi + S0(i,j,l,ntra)
             ENDDO
          ENDDO
@@ -307,5 +308,6 @@
          DO j = 1,jjp1
             DO i = 1,iim
-               sqf = sqf + S0(i,j,l,9)
+cIM 240305            sqf = sqf + S0(i,j,l,9)
+               sqf = sqf + S0(i,j,l,ntra)
             ENDDO
          ENDDO
Index: /LMDZ4/trunk/libf/dyn3d/calfis.F
===================================================================
--- /LMDZ4/trunk/libf/dyn3d/calfis.F	(revision 643)
+++ /LMDZ4/trunk/libf/dyn3d/calfis.F	(revision 644)
@@ -162,5 +162,12 @@
       REAL zsinbis(iim),zcosbis(iim),z1bis(iim)
       REAL unskap, pksurcp
-
+c
+cIM diagnostique PVteta, Amip2
+      INTEGER ntetaSTD
+      PARAMETER(ntetaSTD=3)
+      REAL rtetaSTD(ntetaSTD)
+      DATA rtetaSTD/350., 380., 405./
+      REAL PVteta(ngridmx,ntetaSTD)
+c
 #ifdef INCA
       REAL flxw(iip1,jjp1,llm)
@@ -430,6 +437,10 @@
 
       ENDDO
-
-
+c
+cIM calcul PV a teta=350, 380, 405K
+      CALL PVtheta(ngridmx,llm,pucov,pvcov,pteta,
+     $           ztfi,zplay,zplev,
+     $           ntetaSTD,rtetaSTD,PVteta)
+c
 #ifdef INCA
       CALL gr_dyn_fi(llm,iip1,jjp1,ngridmx,flxw,flxwfi)
@@ -468,5 +479,8 @@
      .             zdtfi,
      .             zdqfi,
-     .             zdpsrf)
+     .             zdpsrf,
+cIM diagnostique PVteta, Amip2          
+     .             pducov,
+     .             PVteta)
 
 500   CONTINUE
Index: /LMDZ4/trunk/libf/dyn3d/etat0_netcdf.F
===================================================================
--- /LMDZ4/trunk/libf/dyn3d/etat0_netcdf.F	(revision 643)
+++ /LMDZ4/trunk/libf/dyn3d/etat0_netcdf.F	(revision 644)
@@ -43,5 +43,7 @@
       REAL :: radsol(klon),rain_fall(klon), snow_fall(klon)
       REAL :: solsw(klon), sollw(klon), fder(klon)
-      REAL :: deltat(klon), frugs(klon,nbsrf), agesno(klon,nbsrf)
+cIM "slab" ocean
+      REAL :: tslab(klon), seaice(klon)
+      REAL :: frugs(klon,nbsrf), agesno(klon,nbsrf)
       REAL :: rugmer(klon)
       REAL :: zmea(iip1*jjp1), zstd(iip1*jjp1)
@@ -365,7 +367,13 @@
      .    jjm, rlonu, rlatv , interbar )
       !
-      varname = 'deltat'
-      deltat(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,deltat,0.0,
+cIM "slab" ocean
+      varname = 'tslab'
+      tslab(:) = 0.0
+      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,tslab,0.0,
+     .     jjm, rlonu, rlatv , interbar )
+c
+      varname = 'seaice'
+      seaice(:) = 0.0
+      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,seaice,0.0,
      .     jjm, rlonu, rlatv , interbar )
       !
@@ -651,5 +659,8 @@
       q_ancien = 0.
       agesno = 0.
-      deltat = 0.
+cIM "slab" ocean
+      tslab(1:klon) = tsolsrf(1:klon,is_oce)
+      seaice = 0. !kg m-2
+c
       frugs(1:klon,is_oce) = rugmer(1:klon)
       frugs(1:klon,is_ter) = MAX(1.0e-05, zstd(1:klon)*zsig(1:klon)/2.0)
@@ -664,5 +675,6 @@
 cIM   call phyredem("startphy.nc",phystep,radpas, co2_ppm, solaire,
       call phyredem("startphy.nc",phystep,radpas,
-     $    latfi, lonfi, pctsrf, tsolsrf, tsoil, deltat, qsolsrf, qsol, 
+     $    latfi, lonfi, pctsrf, tsolsrf, tsoil, tslab, seaice, 
+     $    qsolsrf, qsol,
      $    snsrf, 
      $    albe, alblw, evap, rain_fall, snow_fall, solsw, sollw, fder,
Index: /LMDZ4/trunk/libf/dyn3d/guide.F
===================================================================
--- /LMDZ4/trunk/libf/dyn3d/guide.F	(revision 643)
+++ /LMDZ4/trunk/libf/dyn3d/guide.F	(revision 644)
@@ -81,4 +81,5 @@
       INTEGER step_rea,count_no_rea
 
+cIM 180305   real aire_min,aire_max
       integer ilon,ilat
       real factt,ztau(ip1jmp1)
Index: /LMDZ4/trunk/libf/dyn3d/startvar.F
===================================================================
--- /LMDZ4/trunk/libf/dyn3d/startvar.F	(revision 643)
+++ /LMDZ4/trunk/libf/dyn3d/startvar.F	(revision 644)
@@ -521,5 +521,8 @@
             CASE ('snow')
                   champ(:) = 0.0
-            CASE ('deltat')
+cIM "slab" ocean
+            CASE ('tslab')
+                   champ(:) = 0.0
+            CASE ('seaice')
                   champ(:) = 0.0
             CASE ('rugmer')
Index: /LMDZ4/trunk/libf/dyn3d/tetaleveli1j.F
===================================================================
--- /LMDZ4/trunk/libf/dyn3d/tetaleveli1j.F	(revision 644)
+++ /LMDZ4/trunk/libf/dyn3d/tetaleveli1j.F	(revision 644)
@@ -0,0 +1,137 @@
+c================================================================
+c================================================================
+      SUBROUTINE tetaleveli1j(ilon,ilev,lnew,pgcm,pres,Qgcm,Qpres)
+c================================================================
+c================================================================
+
+      IMPLICIT none
+
+#include "dimensions.h"
+#include "dimphy.h"
+
+c================================================================
+c
+c Interpoler des champs 3-D u, v et g du modele a un niveau de
+c pression donnee (pres)
+c
+c INPUT:  ilon ----- nombre de points
+c         ilev ----- nombre de couches
+c         lnew ----- true si on doit reinitialiser les poids
+c         pgcm ----- pressions modeles
+c         pres ----- pression vers laquelle on interpolle
+c         Qgcm ----- champ GCM
+c         Qpres ---- champ interpolle au niveau pres
+c
+c================================================================
+c
+c   arguments :
+c   -----------
+
+      INTEGER ilon, ilev
+      logical lnew
+
+      REAL pgcm(ilon,ilev)
+      REAL Qgcm(ilon,ilev)
+      real pres
+      REAL Qpres(ilon)
+
+c   local :
+c   -------
+
+cIM 211004
+c     INTEGER lt(klon), lb(klon)
+c     REAL ptop, pbot, aist(klon), aisb(klon)
+c
+#include "paramet.h"
+c
+      INTEGER lt(ip1jm), lb(ip1jm)
+      REAL ptop, pbot, aist(ip1jm), aisb(ip1jm)
+cMI 211004
+      save lt,lb,ptop,pbot,aist,aisb
+
+      INTEGER i, k
+c
+c     PRINT*,'tetalevel pres=',pres
+c=====================================================================
+      if (lnew) then
+c   on réinitialise les réindicages et les poids
+c=====================================================================
+
+
+c Chercher les 2 couches les plus proches du niveau a obtenir
+c
+c Eventuellement, faire l'extrapolation a partir des deux couches
+c les plus basses ou les deux couches les plus hautes:
+      DO 130 i = 1, ilon
+cIM      IF ( ABS(pres-pgcm(i,ilev) ) .LT.
+         IF ( ABS(pres-pgcm(i,ilev) ) .GT.
+     .        ABS(pres-pgcm(i,1)) ) THEN
+            lt(i) = ilev     ! 2
+            lb(i) = ilev-1   ! 1
+         ELSE
+            lt(i) = 2
+            lb(i) = 1
+         ENDIF
+cIM   PRINT*,'i, ABS(pres-pgcm),ABS(pres-pgcm)',
+cIM  .i, ABS(pres-pgcm(i,ilev)),ABS(pres-pgcm(i,1))
+  130 CONTINUE
+      DO 150 k = 1, ilev-1
+         DO 140 i = 1, ilon
+            pbot = pgcm(i,k)
+            ptop = pgcm(i,k+1)
+cIM         IF (ptop.LE.pres .AND. pbot.GE.pres) THEN
+            IF (ptop.GE.pres .AND. pbot.LE.pres) THEN
+               lt(i) = k+1
+               lb(i) = k
+            ENDIF
+  140    CONTINUE
+  150 CONTINUE
+c
+c Interpolation lineaire:
+c
+      DO i = 1, ilon
+c interpolation en logarithme de pression:
+c
+c ...   Modif . P. Le Van    ( 20/01/98) ....
+c       Modif Frédéric Hourdin (3/01/02)
+
+        IF(pgcm(i,lb(i)).EQ.0.OR.
+     $     pgcm(i,lt(i)).EQ.0.) THEN
+c
+        PRINT*,'i,lb,lt,2pgcm,pres',i,lb(i),
+     .  lt(i),pgcm(i,lb(i)),pgcm(i,lt(i)),pres
+c
+        ENDIF 
+c
+        aist(i) = LOG( pgcm(i,lb(i))/ pres )
+     .       / LOG( pgcm(i,lb(i))/ pgcm(i,lt(i)) )
+        aisb(i) = LOG( pres / pgcm(i,lt(i)) )
+     .       / LOG( pgcm(i,lb(i))/ pgcm(i,lt(i)))
+      enddo
+
+
+      endif ! lnew
+
+c======================================================================
+c    inteprollation
+c======================================================================
+
+      do i=1,ilon
+         Qpres(i)= Qgcm(i,lb(i))*aisb(i)+Qgcm(i,lt(i))*aist(i)
+cIM      PRINT*,'i,Qgcm,Qpres',i,Qgcm(i,lb(i)),aisb(i),
+cIM  $   Qgcm(i,lt(i)),aist(i),Qpres(i)
+      enddo
+c
+c Je mets les vents a zero quand je rencontre une montagne
+      do i = 1, ilon
+cIM      if (pgcm(i,1).LT.pres) THEN
+         if (pgcm(i,1).GT.pres) THEN
+c           Qpres(i)=1e33
+            Qpres(i)=1e+20
+cIM         PRINT*,'i,pgcm(i,1),pres =',i,pgcm(i,1),pres
+         endif
+      enddo
+
+c
+      RETURN
+      END
Index: /LMDZ4/trunk/libf/dyn3d/tetaleveli1j1.F
===================================================================
--- /LMDZ4/trunk/libf/dyn3d/tetaleveli1j1.F	(revision 644)
+++ /LMDZ4/trunk/libf/dyn3d/tetaleveli1j1.F	(revision 644)
@@ -0,0 +1,137 @@
+c================================================================
+c================================================================
+      SUBROUTINE tetaleveli1j1(ilon,ilev,lnew,pgcm,pres,Qgcm,Qpres)
+c================================================================
+c================================================================
+
+      IMPLICIT none
+
+#include "dimensions.h"
+#include "dimphy.h"
+
+c================================================================
+c
+c Interpoler des champs 3-D u, v et g du modele a un niveau de
+c pression donnee (pres)
+c
+c INPUT:  ilon ----- nombre de points
+c         ilev ----- nombre de couches
+c         lnew ----- true si on doit reinitialiser les poids
+c         pgcm ----- pressions modeles
+c         pres ----- pression vers laquelle on interpolle
+c         Qgcm ----- champ GCM
+c         Qpres ---- champ interpolle au niveau pres
+c
+c================================================================
+c
+c   arguments :
+c   -----------
+
+      INTEGER ilon, ilev
+      logical lnew
+
+      REAL pgcm(ilon,ilev)
+      REAL Qgcm(ilon,ilev)
+      real pres
+      REAL Qpres(ilon)
+
+c   local :
+c   -------
+
+cIM 211004
+c     INTEGER lt(klon), lb(klon)
+c     REAL ptop, pbot, aist(klon), aisb(klon)
+c
+#include "paramet.h"
+c
+      INTEGER lt(ip1jmp1), lb(ip1jmp1)
+      REAL ptop, pbot, aist(ip1jmp1), aisb(ip1jmp1)
+cMI 211004
+      save lt,lb,ptop,pbot,aist,aisb
+
+      INTEGER i, k
+c
+c     PRINT*,'tetalevel pres=',pres
+c=====================================================================
+      if (lnew) then
+c   on réinitialise les réindicages et les poids
+c=====================================================================
+
+
+c Chercher les 2 couches les plus proches du niveau a obtenir
+c
+c Eventuellement, faire l'extrapolation a partir des deux couches
+c les plus basses ou les deux couches les plus hautes:
+      DO 130 i = 1, ilon
+cIM      IF ( ABS(pres-pgcm(i,ilev) ) .LT.
+         IF ( ABS(pres-pgcm(i,ilev) ) .GT.
+     .        ABS(pres-pgcm(i,1)) ) THEN
+            lt(i) = ilev     ! 2
+            lb(i) = ilev-1   ! 1
+         ELSE
+            lt(i) = 2
+            lb(i) = 1
+         ENDIF
+cIM   PRINT*,'i, ABS(pres-pgcm),ABS(pres-pgcm)',
+cIM  .i, ABS(pres-pgcm(i,ilev)),ABS(pres-pgcm(i,1))
+  130 CONTINUE
+      DO 150 k = 1, ilev-1
+         DO 140 i = 1, ilon
+            pbot = pgcm(i,k)
+            ptop = pgcm(i,k+1)
+cIM         IF (ptop.LE.pres .AND. pbot.GE.pres) THEN
+            IF (ptop.GE.pres .AND. pbot.LE.pres) THEN
+               lt(i) = k+1
+               lb(i) = k
+            ENDIF
+  140    CONTINUE
+  150 CONTINUE
+c
+c Interpolation lineaire:
+c
+      DO i = 1, ilon
+c interpolation en logarithme de pression:
+c
+c ...   Modif . P. Le Van    ( 20/01/98) ....
+c       Modif Frédéric Hourdin (3/01/02)
+
+        IF(pgcm(i,lb(i)).EQ.0.OR.
+     $     pgcm(i,lt(i)).EQ.0.) THEN
+c
+        PRINT*,'i,lb,lt,2pgcm,pres',i,lb(i),
+     .  lt(i),pgcm(i,lb(i)),pgcm(i,lt(i)),pres
+c
+        ENDIF 
+c
+        aist(i) = LOG( pgcm(i,lb(i))/ pres )
+     .       / LOG( pgcm(i,lb(i))/ pgcm(i,lt(i)) )
+        aisb(i) = LOG( pres / pgcm(i,lt(i)) )
+     .       / LOG( pgcm(i,lb(i))/ pgcm(i,lt(i)))
+      enddo
+
+
+      endif ! lnew
+
+c======================================================================
+c    inteprollation
+c======================================================================
+
+      do i=1,ilon
+         Qpres(i)= Qgcm(i,lb(i))*aisb(i)+Qgcm(i,lt(i))*aist(i)
+cIM      PRINT*,'i,Qgcm,Qpres',i,Qgcm(i,lb(i)),aisb(i),
+cIM  $   Qgcm(i,lt(i)),aist(i),Qpres(i)
+      enddo
+c
+c Je mets les vents a zero quand je rencontre une montagne
+      do i = 1, ilon
+cIM      if (pgcm(i,1).LT.pres) THEN
+         if (pgcm(i,1).GT.pres) THEN
+c           Qpres(i)=1e33
+            Qpres(i)=1e+20
+cIM         PRINT*,'i,pgcm(i,1),pres =',i,pgcm(i,1),pres
+         endif
+      enddo
+
+c
+      RETURN
+      END
Index: /LMDZ4/trunk/libf/dyn3d/tourabs.F
===================================================================
--- /LMDZ4/trunk/libf/dyn3d/tourabs.F	(revision 644)
+++ /LMDZ4/trunk/libf/dyn3d/tourabs.F	(revision 644)
@@ -0,0 +1,98 @@
+      SUBROUTINE tourabs ( ntetaSTD,vcov, ucov, vorabs )
+      IMPLICIT NONE
+
+c=======================================================================
+c
+c   Modif:  I. Musat (28/10/04)
+c   -------
+c   adaptation du code tourpot.F pour le calcul de la vorticite absolue
+c   cf. P. Le Van
+c
+c   Objet: 
+c   ------
+c
+c    *******************************************************************
+c    .............  calcul de la vorticite absolue     .................
+c    *******************************************************************
+c
+c     ntetaSTD, vcov,ucov      sont des argum. d'entree pour le s-pg .
+c             vorabs            est  un argum.de sortie pour le s-pg .
+c
+c=======================================================================
+
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom.h"
+#include "logic.h"
+#include "comconst.h"
+c
+      INTEGER ntetaSTD
+      REAL vcov( ip1jm,ntetaSTD ), ucov( ip1jmp1,ntetaSTD )
+      REAL vorabs( ip1jm,ntetaSTD )
+c
+c variables locales
+      INTEGER l, ij, i, j
+      REAL  rot( ip1jm,ntetaSTD )
+
+
+
+c  ... vorabs = ( Filtre( d(vcov)/dx - d(ucov)/dy ) + fext ) ..
+
+
+
+c    ........  Calcul du rotationnel du vent V  puis filtrage  ........
+
+      DO 5 l = 1,ntetaSTD
+
+      DO 2 i = 1, iip1
+      DO 2 j = 1, jjm
+c
+       ij=i+(j-1)*iip1
+       IF(ij.LE.ip1jm - 1) THEN
+c
+        IF(cv(ij).EQ.0..OR.cv(ij+1).EQ.0..OR.
+     $     cu(ij).EQ.0..OR.cu(ij+iip1).EQ.0.) THEN
+         rot( ij,l ) = 0.
+         continue
+        ELSE
+         rot( ij,l ) = (vcov(ij+1,l)/cv(ij+1)-vcov(ij,l)/cv(ij))/
+     $                 (2.*pi*RAD*cos(rlatv(j)))*float(iim)
+     $                +(ucov(ij+iip1,l)/cu(ij+iip1)-ucov(ij,l)/cu(ij))/
+     $                 (pi*RAD)*(float(jjm)-1.)
+c
+        ENDIF
+       ENDIF !(ij.LE.ip1jm - 1) THEN
+   2  CONTINUE
+
+c    ....  correction pour  rot( iip1,j,l )  .....
+c    ....     rot(iip1,j,l) = rot(1,j,l)    .....
+
+CDIR$ IVDEP
+
+      DO 3 ij = iip1, ip1jm, iip1
+      rot( ij,l ) = rot( ij -iim, l )
+   3  CONTINUE
+
+   5  CONTINUE
+
+
+      CALL  filtreg( rot, jjm, ntetaSTD, 2, 1, .FALSE., 1 )
+
+
+      DO 10 l = 1, ntetaSTD
+
+      DO 6 ij = 1, ip1jm - 1
+      vorabs( ij,l ) = ( rot(ij,l) + fext(ij)*unsairez(ij) )
+   6  CONTINUE
+
+c    ..... correction pour  vorabs( iip1,j,l)  .....
+c    ....   vorabs(iip1,j,l)= vorabs(1,j,l) ....
+CDIR$ IVDEP
+      DO 8 ij = iip1, ip1jm, iip1
+      vorabs( ij,l ) = vorabs( ij -iim,l )
+   8  CONTINUE
+
+  10  CONTINUE
+
+      RETURN
+      END
Index: /LMDZ4/trunk/libf/phylmd/aaam_bud.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/aaam_bud.F	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/aaam_bud.F	(revision 644)
@@ -0,0 +1,361 @@
+      subroutine aaam_bud (iam,nlon,nlev,rjour,rsec,
+     i                   rea,rg,ome,      
+     i                   plat,plon,phis,
+     i                   dragu,liftu,phyu,
+     i                   dragv,liftv,phyv,
+     i                   p, u, v,
+     o                   aam, torsfc)
+c
+      implicit none
+c======================================================================
+c Auteur(s): F.Lott (LMD/CNRS) date: 20031020
+c Object: Compute different terms of the axial AAAM Budget.
+C No outputs, every AAM quantities are written on the IAM
+C File. 
+c
+c Modif : I.Musat (LMD/CNRS) date : 20041020
+c Outputs : axial components of wind AAM "aam" and total surface torque "torsfc",
+c but no write in the iam file.
+c
+C WARNING: Only valid for regular rectangular grids.
+C REMARK: CALL DANS PHYSIQ AFTER lift_noro:
+C        CALL aaam_bud (27,klon,klev,rjourvrai,gmtime,
+C    C               ra,rg,romega,
+C    C               rlat,rlon,pphis,
+C    C               zustrdr,zustrli,zustrph,
+C    C               zvstrdr,zvstrli,zvstrph,
+C    C               paprs,u,v)
+C
+C======================================================================
+c Explicit Arguments:
+c ==================
+c iam-----input-I-File number where AAMs and torques are written
+c                 It is a formatted file that has been opened
+c                 in physiq.F
+c nlon----input-I-Total number of horizontal points that get into physics
+c nlev----input-I-Number of vertical levels
+c rjour---input-R-Jour compte depuis le debut de la simu (run.def)
+c rsec----input-R-Seconde de la journee
+c rea-----input-R-Earth radius
+c rg------input-R-gravity constant
+c ome-----input-R-Earth rotation rate
+c plat ---input-R-Latitude en degres
+c plon ---input-R-Longitude en degres
+c phis ---input-R-Geopotential at the ground
+c dragu---input-R-orodrag stress (zonal)
+c liftu---input-R-orolift stress (zonal)
+c phyu----input-R-Stress total de la physique (zonal)
+c dragv---input-R-orodrag stress (Meridional)
+c liftv---input-R-orolift stress (Meridional)
+c phyv----input-R-Stress total de la physique (Meridional)
+c p-------input-R-Pressure (Pa) at model half levels
+c u-------input-R-Horizontal wind (m/s)
+c v-------input-R-Meridional wind (m/s)
+c aam-----output-R-Axial Wind AAM (=raam(3))
+c torsfc--output-R-Total surface torque (=tmou(3)+tsso(3)+tbls(3))
+c
+c Implicit Arguments:
+c ===================
+c
+c iim--common-I: Number of longitude intervals
+c jjm--common-I: Number of latitude intervals
+c klon-common-I: Number of points seen by the physics
+c                iim*(jjm-1)+2 for instance
+c klev-common-I: Number of vertical layers
+c======================================================================
+c Local Variables:
+c ================
+c dlat-----R: Latitude increment (Radians)
+c dlon-----R: Longitude increment (Radians)
+c raam  ---R: Wind AAM (3 Components, 1 & 2 Equatoriales; 3 Axiale)
+c oaam  ---R: Mass AAM (3 Components, 1 & 2 Equatoriales; 3 Axiale)
+c tmou-----R: Resolved Mountain torque (3 components)
+c tsso-----R: Parameterised Moutain drag torque (3 components)
+c tbls-----R: Parameterised Boundary layer torque (3 components)
+c
+c LOCAL ARRAY:
+c ===========
+c zs    ---R: Topographic height
+c ps    ---R: Surface Pressure  
+c ub    ---R: Barotropic wind zonal
+c vb    ---R: Barotropic wind meridional
+c zlat  ---R: Latitude in radians
+c zlon  ---R: Longitude in radians
+c======================================================================
+
+#include "dimensions.h"
+#include "dimphy.h"
+c
+c ARGUMENTS
+c
+      INTEGER iam,nlon,nlev
+      REAL rjour,rsec,rea,rg,ome
+      REAL plat(nlon),plon(nlon),phis(nlon)
+      REAL dragu(nlon),liftu(nlon),phyu(nlon)             
+      REAL dragv(nlon),liftv(nlon),phyv(nlon)             
+      REAL p(nlon,nlev+1), u(nlon,nlev), v(nlon,nlev)
+c
+c Variables locales:
+c
+      INTEGER i,j,k,l
+      REAL xpi,hadley,hadday
+      REAL dlat,dlon
+      REAL raam(3),oaam(3),tmou(3),tsso(3),tbls(3)
+      integer iax
+cIM ajout aam, torsfc
+c aam = composante axiale du Wind AAM raam
+c torsfc = composante axiale de (tmou+tsso+tbls)
+      REAL aam, torsfc
+
+      REAL ZS(801,401),PS(801,401)
+      REAL UB(801,401),VB(801,401)
+      REAL SSOU(801,401),SSOV(801,401)
+      REAL BLSU(801,401),BLSV(801,401)
+      REAL ZLON(801),ZLAT(401)
+C
+C  PUT AAM QUANTITIES AT ZERO:
+C
+      if(iim+1.gt.801.or.jjm+1.gt.401)then
+      print *,' Pb de dimension dans aaam_bud'
+      stop
+      endif
+
+      xpi=acos(-1.)
+      hadley=1.e18
+      hadday=1.e18*24.*3600.
+      dlat=xpi/float(jjm)
+      dlon=2.*xpi/float(iim) 
+      
+      do iax=1,3
+      oaam(iax)=0.
+      raam(iax)=0.
+      tmou(iax)=0.
+      tsso(iax)=0.
+      tbls(iax)=0.
+      enddo
+
+C MOUNTAIN HEIGHT, PRESSURE AND BAROTROPIC WIND:
+
+C North pole values (j=1):
+ 
+      l=1
+
+        ub(1,1)=0.
+        vb(1,1)=0.
+        do k=1,nlev
+          ub(1,1)=ub(1,1)+u(l,k)*(p(l,k)-p(l,k+1))/rg
+          vb(1,1)=vb(1,1)+v(l,k)*(p(l,k)-p(l,k+1))/rg
+        enddo
+
+          zlat(1)=plat(l)*xpi/180.
+
+        do i=1,iim+1
+
+          zs(i,1)=phis(l)/rg
+          ps(i,1)=p(l,1)
+          ub(i,1)=ub(1,1)                             
+          vb(i,1)=vb(1,1)                             
+          ssou(i,1)=dragu(l)+liftu(l)
+          ssov(i,1)=dragv(l)+liftv(l)
+          blsu(i,1)=phyu(l)-dragu(l)-liftu(l)
+          blsv(i,1)=phyv(l)-dragv(l)-liftv(l)
+
+        enddo
+
+
+      do j = 2,jjm
+
+C Values at Greenwich (Periodicity)
+
+      zs(iim+1,j)=phis(l+1)/rg
+      ps(iim+1,j)=p(l+1,1)
+          ssou(iim+1,j)=dragu(l+1)+liftu(l+1)
+          ssov(iim+1,j)=dragv(l+1)+liftv(l+1)
+          blsu(iim+1,j)=phyu(l+1)-dragu(l+1)-liftu(l+1)
+          blsv(iim+1,j)=phyv(l+1)-dragv(l+1)-liftv(l+1)
+      zlon(iim+1)=-plon(l+1)*xpi/180.
+      zlat(j)=plat(l+1)*xpi/180.
+
+      ub(iim+1,j)=0.
+      vb(iim+1,j)=0.
+         do k=1,nlev
+         ub(iim+1,j)=ub(iim+1,j)+u(l+1,k)*(p(l+1,k)-p(l+1,k+1))/rg
+         vb(iim+1,j)=vb(iim+1,j)+v(l+1,k)*(p(l+1,k)-p(l+1,k+1))/rg
+         enddo
+      
+
+      do i=1,iim
+
+      l=l+1
+      zs(i,j)=phis(l)/rg
+      ps(i,j)=p(l,1)
+          ssou(i,j)=dragu(l)+liftu(l)
+          ssov(i,j)=dragv(l)+liftv(l)
+          blsu(i,j)=phyu(l)-dragu(l)-liftu(l)
+          blsv(i,j)=phyv(l)-dragv(l)-liftv(l)
+      zlon(i)=plon(l)*xpi/180.
+
+      ub(i,j)=0.
+      vb(i,j)=0.
+         do k=1,nlev
+         ub(i,j)=ub(i,j)+u(l,k)*(p(l,k)-p(l,k+1))/rg
+         vb(i,j)=vb(i,j)+v(l,k)*(p(l,k)-p(l,k+1))/rg
+         enddo
+
+      enddo
+
+      enddo
+
+
+C South Pole
+
+      l=l+1
+      ub(1,jjm+1)=0.
+      vb(1,jjm+1)=0.
+      do k=1,nlev
+         ub(1,jjm+1)=ub(1,jjm+1)+u(l,k)*(p(l,k)-p(l,k+1))/rg
+         vb(1,jjm+1)=vb(1,jjm+1)+v(l,k)*(p(l,k)-p(l,k+1))/rg
+      enddo
+      zlat(jjm+1)=plat(l)*xpi/180.
+
+      do i=1,iim+1
+      zs(i,jjm+1)=phis(l)/rg
+      ps(i,jjm+1)=p(l,1)
+          ssou(i,jjm+1)=dragu(l)+liftu(l)
+          ssov(i,jjm+1)=dragv(l)+liftv(l)
+          blsu(i,jjm+1)=phyu(l)-dragu(l)-liftu(l)
+          blsv(i,jjm+1)=phyv(l)-dragv(l)-liftv(l)
+      ub(i,jjm+1)=ub(1,jjm+1)                               
+      vb(i,jjm+1)=vb(1,jjm+1)                                
+      enddo
+
+C
+C  MOMENT ANGULAIRE 
+C
+        DO j=1,jjm    
+        DO i=1,iim
+
+           raam(1)=raam(1)-rea**3*dlon*dlat*0.5*
+     c    (cos(zlon(i  ))*sin(zlat(j  ))*cos(zlat(j  ))*ub(i  ,j  )
+     c    +cos(zlon(i  ))*sin(zlat(j+1))*cos(zlat(j+1))*ub(i  ,j+1))
+     c                    +rea**3*dlon*dlat*0.5*
+     c    (sin(zlon(i  ))*cos(zlat(j  ))*vb(i  ,j  )
+     c    +sin(zlon(i  ))*cos(zlat(j+1))*vb(i  ,j+1))
+
+           oaam(1)=oaam(1)-ome*rea**4*dlon*dlat/rg*0.5*
+     c   (cos(zlon(i  ))*cos(zlat(j  ))**2*sin(zlat(j  ))*ps(i  ,j  )
+     c   +cos(zlon(i  ))*cos(zlat(j+1))**2*sin(zlat(j+1))*ps(i  ,j+1))
+
+           raam(2)=raam(2)-rea**3*dlon*dlat*0.5*
+     c    (sin(zlon(i  ))*sin(zlat(j  ))*cos(zlat(j  ))*ub(i  ,j  )
+     c    +sin(zlon(i  ))*sin(zlat(j+1))*cos(zlat(j+1))*ub(i  ,j+1))
+     c                    -rea**3*dlon*dlat*0.5*
+     c    (cos(zlon(i  ))*cos(zlat(j  ))*vb(i  ,j  )
+     c    +cos(zlon(i  ))*cos(zlat(j+1))*vb(i  ,j+1))
+
+           oaam(2)=oaam(2)-ome*rea**4*dlon*dlat/rg*0.5*
+     c   (sin(zlon(i  ))*cos(zlat(j  ))**2*sin(zlat(j  ))*ps(i  ,j  )
+     c   +sin(zlon(i  ))*cos(zlat(j+1))**2*sin(zlat(j+1))*ps(i  ,j+1))
+
+           raam(3)=raam(3)+rea**3*dlon*dlat*0.5*
+     c           (cos(zlat(j))**2*ub(i,j)+cos(zlat(j+1))**2*ub(i,j+1))
+
+           oaam(3)=oaam(3)+ome*rea**4*dlon*dlat/rg*0.5*
+     c        (cos(zlat(j))**3*ps(i,j)+cos(zlat(j+1))**3*ps(i,j+1))
+
+        ENDDO
+        ENDDO
+
+C
+C COUPLE DES MONTAGNES:
+C
+
+        DO j=1,jjm
+        DO i=1,iim
+           tmou(1)=tmou(1)-rea**2*dlon*0.5*sin(zlon(i))
+     c  *(zs(i,j)-zs(i,j+1))
+     c  *(cos(zlat(j+1))*ps(i,j+1)+cos(zlat(j))*ps(i,j)) 
+           tmou(2)=tmou(2)+rea**2*dlon*0.5*cos(zlon(i))
+     c  *(zs(i,j)-zs(i,j+1))
+     c  *(cos(zlat(j+1))*ps(i,j+1)+cos(zlat(j))*ps(i,j)) 
+        ENDDO
+        ENDDO
+           
+        DO j=2,jjm 
+        DO i=1,iim
+           tmou(1)=tmou(1)+rea**2*dlat*0.5*sin(zlat(j))
+     c  *(zs(i+1,j)-zs(i,j))
+     c  *(cos(zlon(i+1))*ps(i+1,j)+cos(zlon(i))*ps(i,j))
+           tmou(2)=tmou(2)+rea**2*dlat*0.5*sin(zlat(j))
+     c  *(zs(i+1,j)-zs(i,j))
+     c  *(sin(zlon(i+1))*ps(i+1,j)+sin(zlon(i))*ps(i,j))
+           tmou(3)=tmou(3)-rea**2*dlat*0.5*
+     c  cos(zlat(j))*(zs(i+1,j)-zs(i,j))*(ps(i+1,j)+ps(i,j))
+        ENDDO
+        ENDDO
+
+C
+C COUPLES DES DIFFERENTES FRICTION AU SOL:
+C
+        l=1
+        DO j=2,jjm
+        DO i=1,iim
+        l=l+1
+           tsso(1)=tsso(1)-rea**3*cos(zlat(j))*dlon*dlat*
+     c     ssou(i,j)          *sin(zlat(j))*cos(zlon(i))
+     c                    +rea**3*cos(zlat(j))*dlon*dlat*
+     c     ssov(i,j)          *sin(zlon(i))
+
+           tsso(2)=tsso(2)-rea**3*cos(zlat(j))*dlon*dlat*
+     c     ssou(i,j)          *sin(zlat(j))*sin(zlon(i))
+     c                    -rea**3*cos(zlat(j))*dlon*dlat*
+     c     ssov(i,j)          *cos(zlon(i))
+
+           tsso(3)=tsso(3)+rea**3*cos(zlat(j))*dlon*dlat*
+     c     ssou(i,j)          *cos(zlat(j))
+
+           tbls(1)=tbls(1)-rea**3*cos(zlat(j))*dlon*dlat*
+     c     blsu(i,j)          *sin(zlat(j))*cos(zlon(i))
+     c                    +rea**3*cos(zlat(j))*dlon*dlat*
+     c     blsv(i,j)          *sin(zlon(i))
+
+           tbls(2)=tbls(2)-rea**3*cos(zlat(j))*dlon*dlat*
+     c     blsu(i,j)          *sin(zlat(j))*sin(zlon(i))
+     c                    -rea**3*cos(zlat(j))*dlon*dlat*
+     c     blsv(i,j)          *cos(zlon(i))
+
+           tbls(3)=tbls(3)+rea**3*cos(zlat(j))*dlon*dlat*
+     c     blsu(i,j)          *cos(zlat(j))
+
+        ENDDO
+        ENDDO
+            
+
+c     write(*,*) 'AAM',rsec,
+c     write(*,*) 'AAM',rjour+rsec/86400.,
+c    c      raam(3)/hadday,oaam(3)/hadday,
+c    c      tmou(3)/hadley,tsso(3)/hadley,tbls(3)/hadley
+
+c     write(iam,100)rjour+rsec/86400.,
+c    c      raam(1)/hadday,oaam(1)/hadday,
+c    c      tmou(1)/hadley,tsso(1)/hadley,tbls(1)/hadley,
+c    c      raam(2)/hadday,oaam(2)/hadday,
+c    c      tmou(2)/hadley,tsso(2)/hadley,tbls(2)/hadley,
+c    c      raam(3)/hadday,oaam(3)/hadday,
+c    c      tmou(3)/hadley,tsso(3)/hadley,tbls(3)/hadley 
+100   format(F12.5,15(1x,F12.5))
+
+c     write(iam+1,*)((zs(i,j),i=1,iim),j=1,jjm+1)
+c     write(iam+1,*)((ps(i,j),i=1,iim),j=1,jjm+1)
+c     write(iam+1,*)((ub(i,j),i=1,iim),j=1,jjm+1)
+c     write(iam+1,*)((vb(i,j),i=1,iim),j=1,jjm+1)
+c     write(iam+1,*)((ssou(i,j),i=1,iim),j=1,jjm+1)
+c     write(iam+1,*)((ssov(i,j),i=1,iim),j=1,jjm+1)
+c     write(iam+1,*)((blsu(i,j),i=1,iim),j=1,jjm+1)
+c     write(iam+1,*)((blsv(i,j),i=1,iim),j=1,jjm+1)
+c
+      aam=raam(3)
+      torsfc= tmou(3)+tsso(3)+tbls(3)
+c
+      RETURN
+      END
Index: /LMDZ4/trunk/libf/phylmd/calcul_REGDYN.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/calcul_REGDYN.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/calcul_REGDYN.h	(revision 644)
@@ -0,0 +1,22 @@
+c
+c $Header$
+c
+c calculs statistiques distribution nuage ftion du regime dynamique 
+c
+c Ce calcul doit etre fait a partir de valeurs mensuelles ??
+      CALL histo_o500_pctau(nbregdyn,pct_ocean,o500,fq_isccp,
+     &histoW,nhistoW)
+c
+c nhistoWt = somme de toutes les nhistoW
+      DO nreg=1, nbregdyn
+       DO k = 1, kmaxm1
+        DO l = 1, lmaxm1
+         DO iw = 1, iwmax
+          nhistoWt(k,l,iw,nreg)=nhistoWt(k,l,iw,nreg)+
+     &    nhistoW(k,l,iw,nreg)
+         ENDDO
+        ENDDO
+       ENDDO
+      ENDDO
+c
+cIM 190504 END
Index: /LMDZ4/trunk/libf/phylmd/calcul_STDlev.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/calcul_STDlev.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/calcul_STDlev.h	(revision 644)
@@ -0,0 +1,324 @@
+c
+c $Header$
+c
+c
+cIM on initialise les champs en debut du jour ou du mois 
+c
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,tsumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,usumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,vsumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,wsumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,phisumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,qsumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,rhsumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,uvsumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,vqsumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,vTsumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,wqsumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,vphisumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,wTsumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,u2sumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,v2sumSTD)
+        CALL ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $                    tnondef,T2sumSTD)
+c
+cIM on interpole sur les niveaux STD de pression a chaque pas de temps de la physique
+c
+       DO k=1, nlevSTD
+c
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .              t_seri,tlevSTD(:,k))
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             u_seri,ulevSTD(:,k))
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             v_seri,vlevSTD(:,k))
+c
+        DO l=1, klev
+        DO i=1, klon
+         zx_tmp_fi3d(i,l)=paprs(i,l)
+        ENDDO !i
+        ENDDO !l
+        CALL plevel(klon,klev,.true.,zx_tmp_fi3d,rlevSTD(k),
+     .             omega,wlevSTD(:,k))
+c
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zphi/RG,philevSTD(:,k))
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             qx(:,:,ivap),qlevSTD(:,k))
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zx_rh*100.,rhlevSTD(:,k))
+c
+        DO l=1, klev
+         DO i=1, klon
+          zx_tmp_fi3d(i,l)=u_seri(i,l)*v_seri(i,l)
+         ENDDO !i
+        ENDDO !l
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zx_tmp_fi3d,uvSTD(:,k))
+c
+        DO l=1, klev
+         DO i=1, klon
+          zx_tmp_fi3d(i,l)=v_seri(i,l)*q_seri(i,l)
+         ENDDO !i
+        ENDDO !l
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zx_tmp_fi3d,vqSTD(:,k))
+c
+        DO l=1, klev
+         DO i=1, klon
+          zx_tmp_fi3d(i,l)=v_seri(i,l)*t_seri(i,l)
+         ENDDO !i
+        ENDDO !l
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zx_tmp_fi3d,vTSTD(:,k))
+c
+        DO l=1, klev
+         DO i=1, klon
+          zx_tmp_fi3d(i,l)=omega(i,l)*qx(i,l,ivap)
+         ENDDO !i 
+        ENDDO !l
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zx_tmp_fi3d,wqSTD(:,k))
+c
+        DO l=1, klev
+         DO i=1, klon
+          zx_tmp_fi3d(i,l)=v_seri(i,l)*zphi(i,l)/RG
+         ENDDO !i
+        ENDDO !l
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zx_tmp_fi3d,vphiSTD(:,k))
+c
+        DO l=1, klev
+         DO i=1, klon
+          zx_tmp_fi3d(i,l)=omega(i,l)*t_seri(i,l)
+         ENDDO !i
+        ENDDO !l
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zx_tmp_fi3d,wTSTD(:,k))
+c
+        DO l=1, klev
+         DO i=1, klon
+          zx_tmp_fi3d(i,l)=u_seri(i,l)*u_seri(i,l)
+         ENDDO !i
+        ENDDO !l
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zx_tmp_fi3d,u2STD(:,k))
+c
+        DO l=1, klev
+         DO i=1, klon
+          zx_tmp_fi3d(i,l)=v_seri(i,l)*v_seri(i,l)
+         ENDDO !i
+        ENDDO !l
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zx_tmp_fi3d,v2STD(:,k))
+c
+        DO l=1, klev
+         DO i=1, klon
+          zx_tmp_fi3d(i,l)=t_seri(i,l)*t_seri(i,l)
+         ENDDO !i
+        ENDDO !l
+        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
+     .             zx_tmp_fi3d,T2STD(:,k))
+c
+       ENDDO !k=1,nlevSTD
+c
+cIM on somme les valeurs definies a chaque pas de temps de la physique ou 
+cIM toutes les 6 heures
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.TRUE.
+       CALL undefSTD(nlevSTD,itap,tlevSTD,
+     $               ecrit_hf,
+     $               oknondef,tnondef,tsumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,ulevSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,usumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,vlevSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,vsumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,wlevSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,wsumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,philevSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,phisumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,qlevSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,qsumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,rhlevSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,rhsumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,uvSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,uvsumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,vqSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,vqsumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,vTSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,vTsumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,wqSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,wqsumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,vphiSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,vphisumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,wTSTD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,wTsumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,u2STD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,u2sumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,v2STD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,v2sumSTD)
+c
+       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
+       CALL undefSTD(nlevSTD,itap,T2STD,
+     $           ecrit_hf,
+     $               oknondef,tnondef,T2sumSTD)
+c
+cIM on moyenne a la fin du jour ou du mois 
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,tsumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,usumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,vsumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,wsumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,phisumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,qsumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,rhsumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,uvsumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,vqsumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,vTsumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,wqsumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,vphisumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,wTsumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,u2sumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,v2sumSTD)
+c
+       CALL moy_undefSTD(nlevSTD,itap,
+     $      ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $                   tnondef,T2sumSTD)
+c
+cIM interpolation a chaque pas de temps du SWup(clr) et SWdn(clr) a 200 hPa
+c
+      CALL plevel(klon,klevp1,.true.,paprs,20000.,
+     $     swdn0,SWdn200clr)
+      CALL plevel(klon,klevp1,.false.,paprs,20000.,
+     $     swdn,SWdn200)
+      CALL plevel(klon,klevp1,.false.,paprs,20000.,
+     $     swup0,SWup200clr)
+      CALL plevel(klon,klevp1,.false.,paprs,20000.,
+     $     swup,SWup200)
+c
+      CALL plevel(klon,klevp1,.false.,paprs,20000.,
+     $     lwdn0,LWdn200clr)
+      CALL plevel(klon,klevp1,.false.,paprs,20000.,
+     $     lwdn,LWdn200)
+      CALL plevel(klon,klevp1,.false.,paprs,20000.,
+     $     lwup0,LWup200clr)
+      CALL plevel(klon,klevp1,.false.,paprs,20000.,
+     $     lwup,LWup200)
+c
Index: /LMDZ4/trunk/libf/phylmd/calcul_divers.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/calcul_divers.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/calcul_divers.h	(revision 644)
@@ -0,0 +1,29 @@
+c
+c $Header$
+c
+c
+c initialisations diverses au "debut" du mois
+c
+      IF(MOD(itap,ecrit_mth).EQ.1) THEN
+         DO i=1, klon
+          nday_rain(i)=0.
+         ENDDO !i
+c
+c surface terre
+       DO i=1, klon
+         IF(pctsrf_new(i,is_ter).GT.0.) THEN
+            paire_ter(i)=airephy(i)*pctsrf_new(i,is_ter)
+         ENDIF 
+       ENDDO
+c
+      ENDIF !MOD(itap,ecrit_mth).EQ.1
+c
+      IF(MOD(itap,ecrit_day).EQ.0) THEN
+c
+cIM calcul total_rain, nday_rain
+c
+       DO i = 1, klon
+        total_rain(i)=rain_fall(i)+snow_fall(i)  
+        IF(total_rain(i).GT.0.) nday_rain(i)=nday_rain(i)+1.
+       ENDDO
+      ENDIF !itap.EQ.ecrit_mth
Index: /LMDZ4/trunk/libf/phylmd/calcul_simulISCCP.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/calcul_simulISCCP.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/calcul_simulISCCP.h	(revision 644)
@@ -0,0 +1,160 @@
+c
+c $Header$
+c
+cIM 090704 BEG
+c     nbapp_isccp=48
+c     nbapp_isccp=8
+c     nbapp_isccp=6
+c     nbapp_isccp=4 !CPU < 30min pour  9pdt/jour
+      nbapp_isccp=3 !CPU ??           10pdt/jour
+c     nbapp_isccp=2
+c     nbapp_isccp=1
+      isccppas=NINT(86400./dtime/nbapp_isccp)
+cIM 010904 BEG
+cIM   IF (MOD(itap,isccppas).EQ.0) THEN
+c      PRINT*,'itap,isccppas,xjour',itap,isccppas,xjour
+c
+cIM initialisation nbsunlit pour calculs simulateur ISCCP pdt la journee
+c
+      DO i=1, klon
+       sunlit(i)=1 
+       IF(rmu0(i).EQ.0.) sunlit(i)=0
+       nbsunlit(1,i)=FLOAT(sunlit(i))
+      ENDDO
+c
+cIM calcul tau, emissivite nuages convectifs
+c
+      convfra(:,:)=rnebcon(:,:)
+      convliq(:,:)=rnebcon(:,:)*clwcon(:,:)
+cIM Amip2 beg
+c
+      CALL newmicro (paprs, pplay,ok_newmicro,
+     .            t_seri, convliq, convfra, dtau_c, dem_c,
+     .            cldh_c, cldl_c, cldm_c, cldt_c, cldq_c,
+     .            flwp_c, fiwp_c, flwc_c, fiwc_c,
+     e            ok_aie,
+     e            sulfate, sulfate_pi,
+     e            bl95_b0, bl95_b1,
+     s            cldtaupi, re, fl)
+c
+cIM Amip2 end
+
+c
+cIM calcul tau, emissivite nuages startiformes
+c
+cIM Amip2 beg
+c
+      CALL newmicro (paprs, pplay,ok_newmicro,
+     .            t_seri, cldliq, cldfra, dtau_s, dem_s,
+     .            cldh_s, cldl_s, cldm_s, cldt_s, cldq_s,
+     .            flwp_s, fiwp_s, flwc_s, fiwc_s,
+     e            ok_aie,
+     e            sulfate, sulfate_pi,
+     e            bl95_b0, bl95_b1,
+     s            cldtaupi, re, fl)
+c
+cIM Amip2 end
+c
+      cldtot(:,:)=min(max(cldfra(:,:),rnebcon(:,:)),1.)
+c
+cIM inversion des niveaux de pression ==> de haut en bas
+c
+      CALL haut2bas(klon, klev, pplay, pfull)
+      CALL haut2bas(klon, klev, q_seri, qv)
+      CALL haut2bas(klon, klev, cldtot, cc)
+      CALL haut2bas(klon, klev, rnebcon, conv)
+      CALL haut2bas(klon, klev, dtau_s, dtau_sH2B)
+      CALL haut2bas(klon, klev, dtau_c, dtau_cH2B)
+      CALL haut2bas(klon, klev, t_seri, at)
+      CALL haut2bas(klon, klev, dem_s, dem_sH2B)
+      CALL haut2bas(klon, klev, dem_c, dem_cH2B)
+      CALL haut2bas(klon, klevp1, paprs, phalf)
+c
+cIM lecture invtau, tautab des fichiers formattes
+c
+      IF (debut) THEN
+c     open(99,file='tautab.bin',access='sequential',
+c    $     form='unformatted',status='old')
+c     read(99) tautab
+c
+      open(99,file='tautab.formatted', FORM='FORMATTED')
+      read(99,'(f30.20)') tautab
+      close(99)
+c
+      open(99,file='invtau.formatted',form='FORMATTED')
+      read(99,'(i10)') invtau
+      close(99)
+c
+cIM: calcul coordonnees regions pour statistiques distribution 
+cIM: nuages en ftion du regime dynamique pour regions oceaniques
+c
+      IF (ok_regdyn) THEN !histREGDYN
+c
+#include "ini_coord_REGDYN.h"
+c
+      ENDIF !ok_regdyn
+c 
+      ENDIF !debut
+c
+cIM: initialisation de seed
+        DO i=1, klon
+          seed(i)=i+100
+        ENDDO
+c     
+cIM: pas de debug, debugcol
+      debug=0
+      debugcol=0
+c
+cIM o500 ==> distribution nuage ftion du regime dynamique (vit. verticale a 500 hPa)
+c
+        DO k=1, klevm1
+        kp1=k+1
+c       PRINT*,'k, presnivs',k,presnivs(k), presnivs(kp1)
+        if(presnivs(k).GT.50000.AND.presnivs(kp1).LT.50000.) THEN
+         DO i=1, klon
+          o500(i)=omega(i,k)*RDAY/100.
+c         if(i.EQ.1) print*,' 500hPa lev',k,presnivs(k),presnivs(kp1)
+         ENDDO
+         GOTO 1000
+        endif 
+1000  continue
+      ENDDO
+c
+cIM recalcule les nuages vus par satellite, via le simulateur ISCCP
+c
+      CALL ISCCP_CLOUD_TYPES(
+     &     debug,
+     &     debugcol,
+cIM 300704    &     itap, debut,
+cIM 300604 klon !BAD
+     &     klon,
+     &     sunlit,
+     &     klev,
+     &     ncol,
+     &     seed,
+     &     pfull,
+     &     phalf,
+     &     qv, cc, conv, dtau_sH2B, dtau_cH2B,
+     &     top_height,
+     &     overlap,
+     &     tautab,
+     &     invtau,
+     &     ztsol,
+     &     emsfc_lw,
+     &     at, dem_sH2B, dem_cH2B,
+     &     fq_isccp,
+     &     totalcldarea,
+     &     meanptop,
+     &     meantaucld,
+     &     boxtau,
+     &     boxptop)
+c
+c calcul regime dynamique sur les regions fixees
+c
+       IF (ok_regdyn) THEN !histREGDYN
+c
+#include "calcul_REGDYN.h"
+c
+       ENDIF !(ok_regdyn) THEN !histREGDYN
+cIM    ENDIF !(MOD(itaprad,radpas).EQ.0) THEN
+cIM 010904 END
Index: /LMDZ4/trunk/libf/phylmd/clesphys.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/clesphys.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/clesphys.h	(revision 644)
@@ -22,4 +22,9 @@
 cIM lev_histmth : niveau sorties mensuelles
        INTEGER lev_histhf, lev_histday, lev_histmth
+       CHARACTER*4 type_run
+       LOGICAL ok_isccp, ok_regdyn
+       REAL lonmin_ins, lonmax_ins, latmin_ins, latmax_ins
+       INTEGER ecrit_ins, ecrit_hf, ecrit_hf2mth, ecrit_day
+       INTEGER ecrit_mth, ecrit_tra, ecrit_reg 
 
        COMMON/clesphys/cycle_diurne, soil_model, new_oliq,
@@ -29,2 +34,6 @@
      ,     , top_height, overlap, cdmmax, cdhmax, ksta, ksta_ter
      ,     , ok_kzmin, lev_histhf, lev_histday, lev_histmth
+     ,     , type_run, ok_isccp, ok_regdyn
+     ,     , lonmin_ins, lonmax_ins, latmin_ins, latmax_ins
+     ,     , ecrit_ins, ecrit_hf, ecrit_hf2mth, ecrit_day
+     ,     , ecrit_mth, ecrit_tra, ecrit_reg
Index: /LMDZ4/trunk/libf/phylmd/clesphys.inc
===================================================================
--- /LMDZ4/trunk/libf/phylmd/clesphys.inc	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/clesphys.inc	(revision 644)
@@ -15,4 +15,9 @@
        LOGICAL :: ok_kzmin
        INTEGER :: lev_histhf, lev_histday, lev_histmth
+       CHARACTER (len=4) type_run
+       LOGICAL ok_isccp, ok_regdyn
+       REAL lonmin_ins, lonmax_ins, latmin_ins, latmax_ins
+       INTEGER ecrit_ins, ecrit_hf, ecrit_hf2mth, ecrit_day
+       INTEGER ecrit_mth, ecrit_tra, ecrit_reg
 
        COMMON/clesphys/cycle_diurne, soil_model, new_oliq, &
@@ -21,3 +26,7 @@
      &     , CH4_ppb, N2O_ppb, CFC11_ppt, CFC12_ppt &
      &     , top_height, overlap, cdmmax, cdhmax, ksta, ksta_ter &
-     &     , ok_kzmin, lev_histhf, lev_histday, lev_histmth
+     &     , ok_kzmin, lev_histhf, lev_histday, lev_histmth &
+     &     , type_run, ok_isccp, ok_regdyn &
+     &     , lonmin_ins, lonmax_ins, latmin_ins, latmax_ins &
+     &     , ecrit_ins, ecrit_hf, ecrit_hf2mth, ecrit_day &
+     &     , ecrit_mth, ecrit_tra, ecrit_reg
Index: /LMDZ4/trunk/libf/phylmd/clmain.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/clmain.F	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/clmain.F	(revision 644)
@@ -10,5 +10,6 @@
      .                  soil_model,cdmmax, cdhmax,
      .                  ksta, ksta_ter, ok_kzmin, ftsoil,qsol,
-     .                  paprs,pplay,radsol,snow,qsurf,evap,albe,alblw,
+cIM BAD .                  paprs,pplay,radsol,snow,qsurf,evap,albe,alblw,
+     .                  paprs,pplay,snow,qsurf,evap,albe,alblw,
      .                  fluxlat,
      .                  rain_f, snow_f, solsw, sollw, sollwdown, fder,
@@ -20,5 +21,10 @@
      .                  dflux_t,dflux_q,
      .                  zcoefh,zu1,zv1, t2m, q2m, u10m, v10m,
-     .                  fqcalving,ffonte, run_off_lic_0)
+cIM cf. AM : pbl
+     .                  pblh,capCL,oliqCL,cteiCL,pblT,
+     .                  therm,trmb1,trmb2,trmb3,plcl,
+     .                  fqcalving,ffonte, run_off_lic_0,
+cIM "slab" ocean
+     .                  flux_o, flux_g, tslab, seaice)
 cAA .                  itr, tr, flux_surf, d_tr)
 cAA REM:
@@ -72,4 +78,10 @@
 c dflux_t derive du flux sensible
 c dflux_q derive du flux latent
+cIM "slab" ocean
+c flux_g---output-R-  flux glace (pour OCEAN='slab  ')
+c flux_o---output-R-  flux ocean (pour OCEAN='slab  ')
+c tslab-in/output-R temperature du slab ocean (en Kelvin) ! uniqmnt pour slab
+c seaice---output-R-  glace de mer (kg/m2) (pour OCEAN='slab  ')
+ccc
 c ffonte----Flux thermique utilise pour fondre la neige
 c fqcalving-Flux d'eau "perdue" par la surface et necessaire pour limiter la
@@ -82,4 +94,14 @@
 c flux_surf--input-R- flux de traceurs a la surface
 c d_tr-------output-R tendance de traceurs
+cIM cf. AM : PBL
+c trmb1-------deep_cape
+c trmb2--------inhibition 
+c trmb3-------Point Omega
+c Cape(klon)-------Cape du thermique
+c EauLiq(klon)-------Eau liqu integr du thermique
+c ctei(klon)-------Critere d'instab d'entrainmt des nuages de CL
+c lcl------- Niveau de condensation
+c pblh------- HCL
+c pblT------- T au nveau HCL
 c======================================================================
 #include "dimensions.h"
@@ -96,5 +118,6 @@
       REAL t(klon,klev), q(klon,klev)
       REAL u(klon,klev), v(klon,klev)
-      REAL paprs(klon,klev+1), pplay(klon,klev), radsol(klon)
+cIM 230604 BAD  REAL radsol(klon) ??? 
+      REAL paprs(klon,klev+1), pplay(klon,klev)
       REAL rlon(klon), rlat(klon), cufi(klon), cvfi(klon)
       REAL d_t(klon, klev), d_q(klon, klev)
@@ -102,4 +125,9 @@
       REAL flux_t(klon,klev, nbsrf), flux_q(klon,klev, nbsrf)
       REAL dflux_t(klon), dflux_q(klon)
+cIM "slab" ocean
+      REAL flux_o(klon), flux_g(klon)
+      REAL y_flux_o(klon), y_flux_g(klon)
+      REAL tslab(klon), ytslab(klon)
+      REAL seaice(klon), y_seaice(klon)
 cIM cf JLD
       REAL y_fqcalving(klon), y_ffonte(klon)
@@ -189,4 +217,5 @@
       REAL ycoefm0(klon,klev), ycoefh0(klon,klev)
 
+cIM 081204 hcl_Anne ? BEG
       real yzlay(klon,klev),yzlev(klon,klev+1),yteta(klon,klev)
       real ykmm(klon,klev+1),ykmn(klon,klev+1)
@@ -194,10 +223,6 @@
       real yq2(klon,klev+1),q2(klon,klev+1,nbsrf)
       real q2diag(klon,klev+1)
-      real yustar(klon),y_cd_m(klon),y_cd_h(klon)
-
-
-
-
-
+cIM 081204   real yustar(klon),y_cd_m(klon),y_cd_h(klon)
+cIM 081204 hcl_Anne ? END
 c
 #include "YOMCST.h"
@@ -241,4 +266,5 @@
 c
       REAL yt2m(klon), yq2m(klon), yu10m(klon)
+      REAL yustar(klon)
 c -- LOOP
        REAL yu10mx(klon)
@@ -247,4 +273,30 @@
 c -- LOOP
 c
+      REAL yt10m(klon), yq10m(klon)
+cIM cf. AM : pbl, hbtm2 (Comme les autres diagnostics on cumule ds physic ce qui 
+c   permet de sortir les grdeurs par sous surface)
+      REAL pblh(klon,nbsrf)
+      REAL plcl(klon,nbsrf)
+      REAL capCL(klon,nbsrf)
+      REAL oliqCL(klon,nbsrf)
+      REAL cteiCL(klon,nbsrf)
+      REAL pblT(klon,nbsrf)
+      REAL therm(klon,nbsrf)
+      REAL trmb1(klon,nbsrf)
+      REAL trmb2(klon,nbsrf)
+      REAL trmb3(klon,nbsrf)
+      REAL ypblh(klon)
+      REAL ylcl(klon)
+      REAL ycapCL(klon)
+      REAL yoliqCL(klon)
+      REAL ycteiCL(klon)
+      REAL ypblT(klon)
+      REAL ytherm(klon)
+      REAL ytrmb1(klon)
+      REAL ytrmb2(klon)
+      REAL ytrmb3(klon)
+      REAL y_cd_h(klon), y_cd_m(klon)
+c     REAL ygamt(klon,2:klev) ! contre-gradient pour temperature
+c     REAL ygamq(klon,2:klev) ! contre-gradient pour humidite
       REAL uzon(klon), vmer(klon)
       REAL tair1(klon), qair1(klon), tairsol(klon)
@@ -269,6 +321,6 @@
           call flush(6)
       endif
-      IF (first_appel) THEN
-!          first_appel=.false.
+      IF (debugindex .and. first_appel) THEN
+          first_appel=.false.
 !
 ! initialisation sorties netcdf
@@ -447,4 +499,7 @@
         ypct(j) = pctsrf(i,nsrf)
         yts(j) = ts(i,nsrf)
+cIM "slab" ocean
+        ytslab(i) = tslab(i)
+c
         ysnow(j) = snow(i,nsrf)
         yqsurf(j) = qsurf(i,nsrf)
@@ -504,12 +559,5 @@
 c
 c
-cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
 c calculer Cdrag et les coefficients d'echange
-cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
-
-cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
-c  Calcul anciens du LMD. Effectues de toutes facons.
-cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
-
       CALL coefkz(nsrf, knon, ypaprs, ypplay,
 cIM 261103
@@ -519,32 +567,17 @@
      .            yqsurf, 
      .            ycoefm, ycoefh)
-
-      CALL coefkz2(nsrf, knon, ypaprs, ypplay,yt,
+cIM 081204 BEG
+cCR test
+      if (iflag_pbl.eq.1) then
+cIM 081204 END
+        CALL coefkz2(nsrf, knon, ypaprs, ypplay,yt,
      .                  ycoefm0, ycoefh0)
-      if (first_appel) then
-        if (prt_level > 9) THEN
-          WRITE(lunout,*)'Apres coefkz2 '
-          WRITE(lunout,*)'nsrf,knon,yts,yrugos,yqsurf',
-     .    nsrf,knon,yts,yrugos,yqsurf
-          WRITE(lunout,*)'ypaprs(1,k),ypplay(1,k),yu,yv,yt'
-          do k=1,klev
-            WRITE(lunout,*)ypaprs(1,k),ypplay(1,k),
-     .      yu(1,k),yv(1,k),yt(1,k)
-          enddo
-          do k=1,klev
-            WRITE(lunout,*)ycoefm(1,k),ycoefh(1,k),
-     .      ycoefm0(1,k),ycoefh0(1,k)
-          enddo
-        ENDIF
-        first_appel=.false.
+        DO k = 1, klev
+        DO i = 1, knon
+           ycoefm(i,k) = MAX(ycoefm(i,k),ycoefm0(i,k))
+           ycoefh(i,k) = MAX(ycoefh(i,k),ycoefh0(i,k))
+        ENDDO
+        ENDDO
       endif
-
-      DO k = 1, klev
-      DO i = 1, knon
-         ycoefm(i,k) = MAX(ycoefm(i,k),ycoefm0(i,k))
-         ycoefh(i,k) = MAX(ycoefh(i,k),ycoefh0(i,k))
-      ENDDO
-      ENDDO
-
 c
 cIM cf JLD : on seuille ycoefm et ycoefh
@@ -690,5 +723,7 @@
      s          y_d_t, y_d_q, y_d_ts, yz0_new,
      s          y_flux_t, y_flux_q, y_dflux_t, y_dflux_q,
-     s          y_fqcalving,y_ffonte,y_run_off_lic_0)
+     s          y_fqcalving,y_ffonte,y_run_off_lic_0,
+cIM "slab" ocean
+     s          y_flux_o, y_flux_g, ytslab, y_seaice)
 c
 c calculer la longueur de rugosite sur ocean
@@ -829,33 +864,11 @@
       ENDDO
 c
-      if (check) THEN
-       WRITE(*,*)' avant stdlevvar. nsrf=',nsrf
-       IF(nsrf.EQ.3) THEN
-        j=1465
-        WRITE(*,*)' INstO',klon,knon,nsrf,zxli,uzon(j),vmer(j), 
-     &      tair1(j),qair1(j),zgeo1(j),tairsol(j),qairsol(j),rugo1(j),
-     &      psfce(j),patm(j)
-       ENDIF
-       WRITE(*,*)' qairsol (min, max)'
-     $     , minval(qairsol(1:knon)), maxval(qairsol(1:knon))
-       call flush(6)
-      ENDIF
-c
       CALL stdlevvar(klon, knon, nsrf, zxli,
      &               uzon, vmer, tair1, qair1, zgeo1,
      &               tairsol, qairsol, rugo1, psfce, patm,
-     &               yt2m, yq2m, yu10m)
-
-c
-      if (check) THEN
-      IF(nsrf.EQ.3) THEN
-       j=1465
-       WRITE(*,*)' OUstd',klon,knon,nsrf,zxli,uzon(j),vmer(j), 
-     & tair1(j),qair1(j),zgeo1(j),tairsol(j),qairsol(j),rugo1(j),
-     & psfce(j),patm(j)
-       WRITE(*,*)' tqu',yt2m(j),yq2m(j),yu10m(j)
-          call flush(6)
-      ENDIF
-      ENDIF
+cIM  &               yt2m, yq2m, yu10m)
+     &               yt2m, yq2m, yt10m, yq10m, yu10m, yustar)
+cIM 081204 END
+c
 c
       DO j=1, knon
@@ -863,11 +876,4 @@
        t2m(i,nsrf)=yt2m(j)
 
-       if (check) THEN
-        IF(nsrf.EQ.3 .and. j.EQ.1465) THEN
-         WRITE(*,*) 't2m APRES stdlev',j,i,tair1(j),t2m(i,nsrf),
-     $   tairsol(j),rlon(i),rlat(i)
-         call flush(6)
-        ENDIF
-       ENDIF
 c
        q2m(i,nsrf)=yq2m(j)
@@ -878,12 +884,54 @@
 c
       ENDDO
+c
+cIM cf AM : pbl, HBTM
+      DO i = 1, knon
+         y_cd_h(i) = ycoefh(i,1)
+         y_cd_m(i) = ycoefm(i,1)
+      ENDDO
+c     print*,'appel hbtm2'
+      CALL HBTM(knon, ypaprs, ypplay,
+     .          yt2m,yt10m,yq2m,yq10m,yustar,
+     .          y_flux_t,y_flux_q,yu,yv,yt,yq,
+     .          ypblh,ycapCL,yoliqCL,ycteiCL,ypblT,
+     .          ytherm,ytrmb1,ytrmb2,ytrmb3,ylcl)
+c     print*,'fin hbtm2'
+c
+      DO j=1, knon
+       i = ni(j)
+       pblh(i,nsrf)   = ypblh(j)
+       plcl(i,nsrf)   = ylcl(j)
+       capCL(i,nsrf)  = ycapCL(j)
+       oliqCL(i,nsrf) = yoliqCL(j)
+       cteiCL(i,nsrf) = ycteiCL(j)
+       pblT(i,nsrf)   = ypblT(j)
+       therm(i,nsrf)  = ytherm(j)
+       trmb1(i,nsrf)  = ytrmb1(j)
+       trmb2(i,nsrf)  = ytrmb2(j)
+       trmb3(i,nsrf)  = ytrmb3(j)
+      ENDDO
+c
 #else
-       DO j=1, knon
-         i = ni(j) 
-         t2m(i,nsrf)=0.
-         q2m(i,nsrf)=0.
-         u10m(i,nsrf)=0.
-         v10m(i,nsrf)=0.
-       ENDDO 
+cIM cf AM : pbl, HBTM
+      DO j=1, knon
+       i = ni(j)
+       pblh(i,nsrf)   = 0.
+       plcl(i,nsrf)   = 0.
+       capCL(i,nsrf)  = 0.
+       oliqCL(i,nsrf) = 0.
+       cteiCL(i,nsrf) = 0.
+       pblT(i,nsrf)   = 0.
+       therm(i,nsrf)  = 0.
+       trmb1(i,nsrf)  = 0.
+       trmb2(i,nsrf)  = 0.
+       trmb3(i,nsrf)  = 0.
+      ENDDO 
+      DO j=1, knon
+       i = ni(j) 
+       t2m(i,nsrf)=0.
+       q2m(i,nsrf)=0.
+       u10m(i,nsrf)=0.
+       v10m(i,nsrf)=0.
+      ENDDO 
 #endif
 
@@ -894,8 +942,38 @@
          enddo
       enddo
-c
-
+cIM "slab" ocean 
+      IF(OCEAN.EQ.'slab  '.OR.OCEAN.EQ.'force ') THEN
+       IF (nsrf.EQ.is_oce) THEN
+        DO j = 1, knon
+c on projette sur la grille globale
+         i = ni(j)
+         IF(pctsrf_new(i,is_oce).GT.epsfra) THEN
+          flux_o(i) = y_flux_o(j)
+         ELSE
+          flux_o(i) = 0.
+         ENDIF
+        ENDDO
+       ENDIF
+c
+       IF (nsrf.EQ.is_sic) THEN
+        DO j = 1, knon
+         i = ni(j)
+cIM 230604 on pondere lorsque l'on fait le bilan au sol :  flux_g(i) = y_flux_g(j)*ypct(j)
+         IF(pctsrf_new(i,is_sic).GT.epsfra) THEN
+          flux_g(i) = y_flux_g(j)
+         ELSE
+          flux_g(i) = 0.
+         ENDIF
+        ENDDO
+       ENDIF !nsrf.EQ.is_sic
+      ENDIF !OCEAN
+c
+      IF(OCEAN.EQ.'slab  ') THEN
+       IF(nsrf.EQ.is_oce) then
+        tslab(1:klon) = ytslab(1:klon)
+        seaice(1:klon) = y_seaice(1:klon)
+       ENDIF !nsrf
+      ENDIF !OCEAN
 99999 CONTINUE
-c
 C
 C On utilise les nouvelles surfaces
@@ -924,5 +1002,7 @@
      s                d_t, d_q, d_ts, z0_new, 
      s                flux_t, flux_q,dflux_s,dflux_l,
-     s                fqcalving,ffonte,run_off_lic_0)
+     s                fqcalving,ffonte,run_off_lic_0,
+cIM "slab" ocean
+     s                flux_o,flux_g,tslab,seaice)
 
       USE interface_surf
@@ -1001,4 +1081,10 @@
 c hauteur de neige, en kg/m2/s
       REAL fqcalving(klon)
+cIM "slab" ocean
+      REAL tslab(klon)  !temperature du slab ocean (K) (OCEAN='slab  ')
+      REAL seaice(klon) ! glace de mer en kg/m2
+      REAL flux_o(klon) ! flux entre l'ocean et l'atmosphere W/m2
+      REAL flux_g(klon) ! flux entre l'ocean et la glace de mer W/m2
+c
 c======================================================================
       REAL t_grnd  ! temperature de rappel pour glace de mer
@@ -1199,5 +1285,13 @@
         zlev1(1:knon) = delp(1:knon,1)
 c        swnet = swdown * (1. - albedo)
-        swdown(1:knon) = swnet(1:knon)
+c
+cIM swdown=flux SW incident sur terres
+cIM swdown=flux SW net sur les autres surfaces 
+cIM     swdown(1:knon) = swnet(1:knon)
+        if(nisurf.eq.is_ter) THEN 
+         swdown(1:knon) = swnet(1:knon)/(1-albedo(1:knon)) 
+        else 
+         swdown(1:knon) = swnet(1:knon)
+        endif
 c      enddo
       ccanopy = co2_ppm
@@ -1220,5 +1314,7 @@
      s evap, fluxsens, fluxlat, dflux_l, dflux_s,              
      s tsol_rad, tsurf_new, alb_new, alblw, emis_new, z0_new, 
-     s pctsrf_new, agesno,fqcalving,ffonte, run_off_lic_0)
+     s pctsrf_new, agesno,fqcalving,ffonte, run_off_lic_0,
+cIM "slab" ocean 
+     s flux_o, flux_g, tslab, seaice)
 
 
@@ -1472,5 +1568,5 @@
 c Variables locales:
 c
-      INTEGER i, k
+      INTEGER i, k, kk !IM 120704
       REAL zgeop(klon,klev)
       REAL zmgeom(klon)
Index: /LMDZ4/trunk/libf/phylmd/cltracrn.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/cltracrn.F	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/cltracrn.F	(revision 644)
@@ -82,5 +82,5 @@
 cAA que le pondere par la fraction de nature de sol.
 c 
-      print*,'PASSAGE DANS CLTRACRN'
+c      print*,'PASSAGE DANS CLTRACRN'
 
       DO i = 1,klon
Index: /LMDZ4/trunk/libf/phylmd/condsurf.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/condsurf.F	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/condsurf.F	(revision 644)
@@ -0,0 +1,126 @@
+c $Header$
+c
+      SUBROUTINE condsurf( jour, jourvrai, lmt_bils )
+      IMPLICIT none
+c
+c I. Musat 05.2005
+c
+c Lire chaque jour le bilan de chaleur au sol issu 
+c d'un run atmospherique afin de l'utiliser dans
+c dans un run "slab" ocean 
+c -----------------------------------------
+c jour     : input  , numero du jour a lire
+c jourvrai : input  , vrai jour de la simulation  
+c
+c lmt_bils: bilan chaleur au sol (a utiliser pour "slab-ocean")
+c
+#include "netcdf.inc"
+      INTEGER nid, nvarid
+      INTEGER debut(2)
+      INTEGER epais(2)
+c
+#include "dimensions.h"
+#include "dimphy.h"
+#include "indicesol.h"
+#include "temps.h"
+#include "clesphys.h"
+c
+      INTEGER     nannemax
+      PARAMETER ( nannemax = 60 )
+c
+      INTEGER jour, jourvrai
+      INTEGER jourvrai
+      REAL lmt_bils(klon) !bilan chaleur au sol
+c
+c Variables locales:
+      INTEGER ig, i, kt, ierr
+      LOGICAL ok
+      INTEGER anneelim,anneemax
+      CHARACTER*20 fich
+cc
+cc   .....................................................................
+cc
+cc    Pour lire le fichier limit correspondant vraiment  a l'annee de la
+cc     simulation en cours , il suffit de mettre  ok_limitvrai = .TRUE.
+cc
+cc   ......................................................................
+c
+c
+      IF (jour.LT.0 .OR. jour.GT.(360-1)) THEN
+         PRINT*,'Le jour demande n est pas correct: ', jour
+         CALL ABORT
+      ENDIF
+c
+       anneelim  = annee_ref
+       anneemax  = annee_ref + nannemax
+c
+c
+       IF( ok_limitvrai )       THEN
+          DO  kt = 1, nannemax
+           IF(jourvrai.LE. (kt-1)*360 + 359  )  THEN
+              WRITE(fich,'("limit",i4,".nc")') anneelim
+c             PRINT *,' Fichier  Limite ',fich
+              GO TO 100
+             ENDIF
+           anneelim = anneelim + 1
+          ENDDO
+
+         PRINT *,' PBS ! Le jour a lire sur le fichier limit ne se '
+         PRINT *,' trouve pas sur les ',nannemax,' annees a partir de '
+         PRINT *,' l annee de debut', annee_ref
+         CALL EXIT(1)
+c
+100     CONTINUE
+c
+       ELSE
+     
+            WRITE(fich,'("limitNEW.nc")') 
+c           PRINT *,' Fichier  Limite ',fich
+       ENDIF
+c
+c Ouvrir le fichier en format NetCDF:
+c
+      ierr = NF_OPEN (fich, NF_NOWRITE,nid)
+      IF (ierr.NE.NF_NOERR) THEN
+        WRITE(6,*)' Pb d''ouverture du fichier ', fich
+        WRITE(6,*)' Le fichier limit ',fich,' (avec 4 chiffres , pour' 
+        WRITE(6,*)'       l an 2000 )  ,  n existe  pas !  ' 
+        WRITE(6,*)' ierr = ', ierr
+        CALL EXIT(1)
+      ENDIF
+c     DO k = 1, jour
+c La tranche de donnees a lire:
+c
+      debut(1) = 1
+      debut(2) = jour
+      epais(1) = klon
+      epais(2) = 1
+c
+c Bilan flux de chaleur au sol:
+c
+      ierr = NF_INQ_VARID (nid, "BILS", nvarid)
+      IF (ierr .NE. NF_NOERR) THEN
+         PRINT*, "condsurf: Le champ <BILS> est absent"
+         CALL abort
+      ENDIF
+c     PRINT*,'debut,epais',debut,epais
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VARA_DOUBLE(nid, nvarid,debut,epais,lmt_bils)
+#else
+      ierr = NF_GET_VARA_REAL(nid, nvarid,debut,epais,lmt_bils)
+#endif
+      IF (ierr .NE. NF_NOERR) THEN
+         PRINT*, "condsurf: Lecture echouee pour <BILS>"
+         CALL abort
+      ENDIF
+c     ENDDO !k = 1, jour
+c
+c Fermer le fichier:
+c
+      ierr = NF_CLOSE(nid)
+c
+c
+c     PRINT*, 'lmt_bils est lu pour jour: ', jour
+c
+      RETURN
+      END
Index: /LMDZ4/trunk/libf/phylmd/conf_phys.F90
===================================================================
--- /LMDZ4/trunk/libf/phylmd/conf_phys.F90	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/conf_phys.F90	(revision 644)
@@ -22,4 +22,5 @@
 include "clesphys.inc"
 include "compbl.h"
+#include "control.inc"
 !
 ! Configuration de la "physique" de LMDZ a l'aide de la fonction
@@ -577,16 +578,131 @@
 
 !
-!
-!Config Key  = 
-!Config Desc =  
-!Config Def  =
-!Config Help = 
-!
-!   =
-!  call getin('',)
-!
-!
-!
-!
+!Config Key  = type_run
+!Config Desc =
+!Config Def  = 'AMIP' ou 'ENSP'
+!Config Help =
+!
+  type_run = 'AMIP'
+  call getin('type_run',type_run)
+
+!
+!Config Key  = ok_isccp
+!Config Desc =
+!Config Def  = .true.
+!Config Help =
+!
+! ok_isccp = .true.
+  ok_isccp = .false.
+  call getin('ok_isccp',ok_isccp)
+
+!
+!
+!Config Key  = ok_regdyn
+!Config Desc =
+!Config Def  = 'AMIP'
+!Config Help =
+!
+! ok_regdyn = .true.
+  ok_regdyn = .false.
+  call getin('ok_regdyn',ok_regdyn)
+!
+! coordonnees (lonmin_ins, lonmax_ins, latmin_ins, latmax_ins) pour la zone 
+! avec sorties instantannees tous les pas de temps de la physique => "histbilKP_ins.nc"
+!
+!Config Key  = lonmin_ins
+!Config Desc = 100.  
+!Config Def  = longitude minimale sorties "bilKP_ins"
+!Config Help = 
+!
+   lonmin_ins = 100.
+   call getin('lonmin_ins',lonmin_ins)
+!
+!Config Key  = lonmax_ins
+!Config Desc = 130. 
+!Config Def  = longitude maximale sorties "bilKP_ins"
+!Config Help =
+!
+   lonmax_ins = 130.
+   call getin('lonmax_ins',lonmax_ins)
+!
+!Config Key  = latmin_ins
+!Config Desc = -20.  
+!Config Def  = latitude minimale sorties "bilKP_ins"
+!Config Help = 
+!
+   latmin_ins = -20.
+   call getin('latmin_ins',latmin_ins)
+!
+!Config Key  = latmax_ins
+!Config Desc = 20. 
+!Config Def  = latitude maximale sorties "bilKP_ins"
+!Config Help =
+!
+   latmax_ins = 20.
+   call getin('latmax_ins',latmax_ins)
+!
+!Config Key  = ecrit_ins
+!Config Desc =
+!Config Def  = NINT(86400./dtime/48.) !a chaque pas de temps physique
+!Config Help =
+!
+! ecrit_ins = NINT(86400./dtime/48.)
+  ecrit_ins = NINT(86400./48.)
+  call getin('ecrit_ins',ecrit_ins)
+!
+!Config Key  = ecrit_hf
+!Config Desc =
+!Config Def  = NINT(86400./dtime *0.25) !toutes les 6h
+!Config Help =
+!
+! ecrit_hf = NINT(86400./dtime *0.25)
+  ecrit_hf = NINT(86400. *0.25)
+  call getin('ecrit_hf',ecrit_hf)
+!
+!Config Key  = ecrit_hf2mth
+!Config Desc =
+!Config Def  = 4*30 !ecriture mens. a partir de val. inst. toutes les 6h
+!Config Help =
+!
+  ecrit_hf2mth = 4*30
+  call getin('ecrit_hf2mth',ecrit_hf2mth)
+!
+!Config Key  = ecrit_day
+!Config Desc =
+!Config Def  = NINT(86400./dtime *1.0) !tous les jours
+!Config Help =
+!
+! ecrit_day = NINT(86400./dtime *1.0)
+  ecrit_day = NINT(86400. *1.0)
+  call getin('ecrit_day',ecrit_day)
+!
+!Config Key  = ecrit_mth
+!Config Desc =
+!Config Def  = NINT(86400./dtime *ecritphy) !1fois par mois
+!Config Help =
+!
+! ecrit_mth = NINT(86400./dtime *ecritphy)
+  ecrit_mth = NINT(86400. *ecritphy)
+  call getin('ecrit_mth',ecrit_mth)
+!
+!Config Key  = ecrit_tra
+!Config Desc =
+!Config Def  = NINT(86400./dtime * ecritphy) !tous les pas de temps physiques
+!Config Help =
+!
+! ecrit_tra = NINT(86400./dtime * ecritphy)
+  ecrit_tra = NINT(86400.* ecritphy)
+  call getin('ecrit_tra',ecrit_tra)
+!
+!Config Key  = ecrit_reg
+!Config Desc =
+!Config Def  = NINT(86400./dtime *0.25)  !4 fois par jour
+!Config Help =
+!
+! ecrit_reg = NINT(86400./dtime *0.25)  !4 fois par jour
+  ecrit_reg = NINT(86400. *0.25)  !4 fois par jour
+  call getin('ecrit_reg',ecrit_reg)
+!
+
 
   write(numout,*)' ##############################################'
@@ -642,5 +758,11 @@
   write(numout,*)' iflag_pbl = ', iflag_pbl
   write(numout,*)' iflag_thermals = ', iflag_thermals
-
+  write(numout,*)' type_run = ',type_run 
+  write(numout,*)' ok_isccp = ',ok_isccp 
+  write(numout,*)' ok_regdyn = ',ok_regdyn
+  write(numout,*)' lonmin lonmax latmin latmax bilKP_ins =',&
+ & lonmin_ins, lonmax_ins, latmin_ins, latmax_ins
+  write(numout,*)' ecrit_ ins, hf, hf2mth, day, mth, reg, tra',&
+ & ecrit_ins, ecrit_hf, ecrit_hf2mth, ecrit_day, ecrit_mth, ecrit_reg, ecrit_tra
   return
 
Index: /LMDZ4/trunk/libf/phylmd/hbtm.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/hbtm.F	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/hbtm.F	(revision 644)
@@ -0,0 +1,762 @@
+      SUBROUTINE HBTM(knon, paprs, pplay,
+     .                t2m,t10m,q2m,q10m,ustar,
+     .                flux_t,flux_q,u,v,t,q,
+     .                pblh,cape,EauLiq,ctei,pblT,
+     .                therm,trmb1,trmb2,trmb3,plcl)
+        IMPLICIT none
+
+c***************************************************************
+c*                                                             *
+c* HBTM2   D'apres Holstag&Boville et Troen&Mahrt              *
+c*                 JAS 47              BLM                     *
+c* Algorithme These Anne Mathieu                               *
+c* Critere d'Entrainement Peter Duynkerke (JAS 50)             *
+c* written by  : Anne MATHIEU & Alain LAHELLEC, 22/11/99       *
+c* features : implem. exces Mathieu                            *
+c***************************************************************
+c* mods : decembre 99 passage th a niveau plus bas. voir fixer *
+c* la prise du th a z/Lambda = -.2 (max Ray)                   *
+c* Autre algo : entrainement ~ Theta+v =cste mais comment=>The?*
+c* on peut fixer q a .7qsat(cf non adiab)=>T2 et The2          *
+c* voir aussi //KE pblh = niveau The_e ou l = env.             *
+c***************************************************************
+c* fin therm a la HBTM passage a forme Mathieu 12/09/2001      *
+c***************************************************************
+c*
+c
+c
+cAM Fev 2003
+c Adaptation a LMDZ version couplee
+c
+c Pour le moment on fait passer en argument les grdeurs de surface : 
+c flux, t,q2m, t,q10m, on va utiliser systematiquement les grdeurs a 2m ms 
+c on garde la possibilite de changer si besoin est (jusqu'a present la 
+c forme de HB avec le 1er niveau modele etait conservee)
+c
+c
+c
+c
+c
+#include "dimensions.h"
+#include "dimphy.h"
+#include "YOMCST.h"
+      REAL RLvCp, REPS
+c Arguments:
+c
+      INTEGER knon ! nombre de points a calculer
+cAM
+      REAL t2m(klon), t10m(klon) ! temperature a 2 et 10m
+      REAL q2m(klon), q10m(klon) ! q a 2 et 10m
+      REAL ustar(klon)
+      REAL paprs(klon,klev+1) ! pression a inter-couche (Pa)
+      REAL pplay(klon,klev)   ! pression au milieu de couche (Pa)
+      REAL flux_t(klon,klev), flux_q(klon,klev)     ! Flux 
+      REAL u(klon,klev) ! vitesse U (m/s)
+      REAL v(klon,klev) ! vitesse V (m/s)
+      REAL t(klon,klev) ! temperature (K)
+      REAL q(klon,klev) ! vapeur d'eau (kg/kg)
+cAM      REAL cd_h(klon) ! coefficient de friction au sol pour chaleur
+cAM      REAL cd_m(klon) ! coefficient de friction au sol pour vitesse
+c
+      INTEGER isommet
+      PARAMETER (isommet=klev) ! limite max sommet pbl
+      REAL vk
+      PARAMETER (vk=0.35)     ! Von Karman => passer a .41 ! cf U.Olgstrom
+      REAL ricr
+      PARAMETER (ricr=0.4)
+      REAL fak
+      PARAMETER (fak=8.5)     ! b calcul du Prandtl et de dTetas
+      REAL fakn
+      PARAMETER (fakn=7.2)    ! a
+      REAL onet
+      PARAMETER (onet=1.0/3.0)
+      REAL t_coup
+      PARAMETER(t_coup=273.15)
+      REAL zkmin
+      PARAMETER (zkmin=0.01)
+      REAL betam
+      PARAMETER (betam=15.0)  ! pour Phim / h dans la S.L stable
+      REAL betah
+      PARAMETER (betah=15.0)
+      REAL betas
+      PARAMETER (betas=5.0)   ! Phit dans la S.L. stable (mais 2 formes / z/OBL<>1
+      REAL sffrac
+      PARAMETER (sffrac=0.1)  ! S.L. = z/h < .1
+      REAL binm
+      PARAMETER (binm=betam*sffrac)
+      REAL binh
+      PARAMETER (binh=betah*sffrac)
+      REAL ccon
+      PARAMETER (ccon=fak*sffrac*vk)
+c
+      REAL q_star,t_star
+      REAL b1,b2,b212,b2sr     ! Lambert correlations T' q' avec T* q*
+      PARAMETER (b1=70.,b2=20.)
+c
+      REAL z(klon,klev)
+cAM      REAL pcfm(klon,klev), pcfh(klon,klev)
+cAM
+      REAL zref
+      PARAMETER (zref=2.)    ! Niveau de ref a 2m peut eventuellement 
+c                              etre choisi a 10m
+cMA
+c
+      INTEGER i, k, j
+      REAL zxt
+cAM      REAL zxt, zxq, zxu, zxv, zxmod, taux, tauy
+cAM      REAL zx_alf1, zx_alf2 ! parametres pour extrapolation
+      REAL khfs(klon)       ! surface kinematic heat flux [mK/s]
+      REAL kqfs(klon)       ! sfc kinematic constituent flux [m/s]
+      REAL heatv(klon)      ! surface virtual heat flux
+      REAL rhino(klon,klev) ! bulk Richardon no. mais en Theta_v
+      LOGICAL unstbl(klon)  ! pts w/unstbl pbl (positive virtual ht flx)
+      LOGICAL stblev(klon)  ! stable pbl with levels within pbl
+      LOGICAL unslev(klon)  ! unstbl pbl with levels within pbl
+      LOGICAL unssrf(klon)  ! unstb pbl w/lvls within srf pbl lyr
+      LOGICAL unsout(klon)  ! unstb pbl w/lvls in outer pbl lyr
+      LOGICAL check(klon)   ! True=>chk if Richardson no.>critcal
+      LOGICAL omegafl(klon) ! flag de prolongerment cape pour pt Omega
+      REAL pblh(klon)
+      REAL pblT(klon)
+      REAL plcl(klon)
+cAM      REAL cgh(klon,2:klev) ! counter-gradient term for heat [K/m]
+cAM      REAL cgq(klon,2:klev) ! counter-gradient term for constituents
+cAM      REAL cgs(klon,2:klev) ! counter-gradient star (cg/flux)
+      REAL obklen(klon)     ! Monin-Obukhov lengh
+cAM      REAL ztvd, ztvu, 
+      REAL zdu2
+      REAL therm(klon)      ! thermal virtual temperature excess
+      REAL trmb1(klon),trmb2(klon),trmb3(klon)
+C  Algorithme thermique
+      REAL s(klon,klev)     ! [P/Po]^Kappa milieux couches
+      REAL Th_th(klon)      ! potential temperature of thermal
+      REAL The_th(klon)     ! equivalent potential temperature of thermal
+      REAL qT_th(klon)      ! total water  of thermal
+      REAL Tbef(klon)       ! T thermique niveau precedent
+      REAL qsatbef(klon)
+      LOGICAL Zsat(klon)    ! le thermique est sature
+      REAL Cape(klon)       ! Cape du thermique
+      REAL Kape(klon)       ! Cape locale
+      REAL EauLiq(klon)     ! Eau liqu integr du thermique
+      REAL ctei(klon)       ! Critere d'instab d'entrainmt des nuages de CL
+      REAL the1,the2,aa,bb,zthvd,zthvu,xintpos,qqsat
+cIM 091204 BEG
+      REAL a1,a2,a3
+cIM 091204 END
+      REAL xhis,rnum,denom,th1,th2,thv1,thv2,ql2
+      REAL dqsat_dt,qsat2,qT1,q2,t1,t2,xnull,delt_the
+      REAL delt_qt,delt_2,quadsat,spblh,reduc
+c
+      REAL phiminv(klon)    ! inverse phi function for momentum
+      REAL phihinv(klon)    ! inverse phi function for heat
+      REAL wm(klon)         ! turbulent velocity scale for momentum
+      REAL fak1(klon)       ! k*ustar*pblh
+      REAL fak2(klon)       ! k*wm*pblh
+      REAL fak3(klon)       ! fakn*wstr/wm
+      REAL pblk(klon)       ! level eddy diffusivity for momentum
+      REAL pr(klon)         ! Prandtl number for eddy diffusivities
+      REAL zl(klon)         ! zmzp / Obukhov length
+      REAL zh(klon)         ! zmzp / pblh
+      REAL zzh(klon)        ! (1-(zmzp/pblh))**2
+      REAL wstr(klon)       ! w*, convective velocity scale
+      REAL zm(klon)         ! current level height
+      REAL zp(klon)         ! current level height + one level up
+      REAL zcor, zdelta, zcvm5
+cAM      REAL zxqs
+      REAL fac, pblmin, zmzp, term
+c
+#include "YOETHF.h"
+#include "FCTTRE.h"
+       b212=sqrt(b1*b2)
+       b2sr=sqrt(b2)
+c
+C ============================================================
+C     Fonctions thermo implicites
+C ============================================================
+c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+c Tetens : pression partielle de vap d'eau e_sat(T)
+c =================================================
+C++ e_sat(T) = r2*exp( r3*(T-Tf)/(T-r4) ) id a r2*FOEWE
+C++ avec :
+C++ Tf = 273.16 K  (Temp de fusion de la glace)
+C++ r2 = 611.14 Pa
+C++ r3 = 17.269 (liquide) 21.875 (solide) adim
+C++ r4 = 35.86             7.66           Kelvin
+C++  q_sat = eps*e_sat/(p-(1-eps)*e_sat)
+C++ derivée :
+C++ =========
+C++                   r3*(Tf-r4)*q_sat(T,p)
+C++ d_qsat_dT = --------------------------------
+C++             (T-r4)^2*( 1-(1-eps)*e_sat(T)/p )
+c++ pour zcvm5=Lv, c'est FOEDE
+c++ Rq :(1.-REPS)*esarg/Parg id a RETV*Qsat
+C     ------------------------------------------------------------------
+c
+c Initialisation
+      RLvCp = RLVTT/RCPD
+      REPS  = RD/RV
+
+c
+c      DO i = 1, klon
+c         pcfh(i,1) = cd_h(i)
+c         pcfm(i,1) = cd_m(i)
+c      ENDDO
+c      DO k = 2, klev
+c      DO i = 1, klon
+c         pcfh(i,k) = zkmin
+c         pcfm(i,k) = zkmin
+c         cgs(i,k) = 0.0
+c         cgh(i,k) = 0.0
+c         cgq(i,k) = 0.0
+c      ENDDO
+c      ENDDO
+c
+c Calculer les hauteurs de chaque couche
+c (geopotentielle Int_dp/ro = Int_[Rd.T.dp/p] z = geop/g)
+c  pourquoi ne pas utiliser Phi/RG ?
+      DO i = 1, knon
+         z(i,1) = RD * t(i,1) / (0.5*(paprs(i,1)+pplay(i,1)))
+     .               * (paprs(i,1)-pplay(i,1)) / RG
+         s(i,1) = (pplay(i,1)/paprs(i,1))**RKappa
+      ENDDO
+c                                 s(k) = [pplay(k)/ps]^kappa
+c    + + + + + + + + + pplay  <-> s(k)   t  dp=pplay(k-1)-pplay(k)
+c
+c    -----------------  paprs <-> sig(k)
+c
+c    + + + + + + + + + pplay  <-> s(k-1)
+c
+c
+c    + + + + + + + + + pplay  <-> s(1)   t  dp=paprs-pplay   z(1)
+c
+c    -----------------  paprs <-> sig(1)
+c
+      DO k = 2, klev
+      DO i = 1, knon
+         z(i,k) = z(i,k-1)
+     .              + RD * 0.5*(t(i,k-1)+t(i,k)) / paprs(i,k)
+     .                   * (pplay(i,k-1)-pplay(i,k)) / RG
+         s(i,k) = (pplay(i,k)/paprs(i,1))**RKappa
+      ENDDO
+      ENDDO
+c  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+c +++  Determination des grandeurs de surface  +++++++++++++++++++++
+c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+c  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      DO i = 1, knon
+cAM         IF (thermcep) THEN
+cAM           zdelta=MAX(0.,SIGN(1.,RTT-tsol(i)))
+c           zcvm5 = R5LES*RLVTT*(1.-zdelta) + R5IES*RLSTT*zdelta
+c           zcvm5 = zcvm5 / RCPD / (1.0+RVTMP2*q(i,1))
+cAM           zxqs= r2es * FOEEW(tsol(i),zdelta)/paprs(i,1)
+cAM           zxqs=MIN(0.5,zxqs)
+cAM           zcor=1./(1.-retv*zxqs)
+cAM           zxqs=zxqs*zcor
+cAM         ELSE
+cAM           IF (tsol(i).LT.t_coup) THEN
+cAM              zxqs = qsats(tsol(i)) / paprs(i,1)
+cAM           ELSE
+cAM              zxqs = qsatl(tsol(i)) / paprs(i,1)
+cAM           ENDIF
+cAM         ENDIF
+c niveau de reference bulk; mais ici, c,a pourrait etre le niveau de ref du thermique
+cAM        zx_alf1 = 1.0
+cAM        zx_alf2 = 1.0 - zx_alf1
+cAM        zxt = (t(i,1)+z(i,1)*RG/RCPD/(1.+RVTMP2*q(i,1)))
+cAM     .        *(1.+RETV*q(i,1))*zx_alf1
+cAM     .      + (t(i,2)+z(i,2)*RG/RCPD/(1.+RVTMP2*q(i,2)))
+cAM     .        *(1.+RETV*q(i,2))*zx_alf2
+cAM        zxu = u(i,1)*zx_alf1+u(i,2)*zx_alf2
+cAM        zxv = v(i,1)*zx_alf1+v(i,2)*zx_alf2
+cAM        zxq = q(i,1)*zx_alf1+q(i,2)*zx_alf2
+cAM      
+cAMAM           zxu = u10m(i)
+cAMAM           zxv = v10m(i)
+cAMAM           zxmod = 1.0+SQRT(zxu**2+zxv**2)
+cAM Niveau de ref choisi a 2m
+        zxt = t2m(i)
+
+c ***************************************************
+c attention, il doit s'agir de <w'theta'>
+c   ;Calcul de tcls virtuel et de w'theta'virtuel
+c   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+c   tcls=tcls*(1+.608*qcls)
+c
+c   ;Pour avoir w'theta',
+c   ; il faut diviser par ro.Cp
+c   Cp=Cpd*(1+0.84*qcls)
+c   fcs=fcs/(ro_surf*Cp)
+c   ;On transforme w'theta' en w'thetav'
+c   Lv=(2.501-0.00237*(tcls-273.15))*1.E6
+c   xle=xle/(ro_surf*Lv)
+c   fcsv=fcs+.608*xle*tcls
+c ***************************************************
+cAM        khfs(i) = (tsol(i)*(1.+RETV*q(i,1))-zxt) *zxmod*cd_h(i)
+cAM        kqfs(i) = (zxqs-zxq) *zxmod*cd_h(i) * beta(i)
+cAM
+cdif khfs est deja w't'_v / heatv(i) = khfs(i) + RETV*zxt*kqfs(i)
+cAM calcule de Ro = paprs(i,1)/Rd zxt
+cAM convention >0 vers le bas ds lmdz 
+        khfs(i) = - flux_t(i,1)*zxt*Rd / (RCPD*paprs(i,1))
+        kqfs(i) = - flux_q(i,1)*zxt*Rd / (paprs(i,1))
+cAM   verifier que khfs et kqfs sont bien de la forme w'l'
+        heatv(i) = khfs(i) + 0.608*zxt*kqfs(i)
+c a comparer aussi aux sorties de clqh : flux_T/RoCp et flux_q/RoLv
+cAM        heatv(i) = khfs(i)
+cAM ustar est en entree
+cAM        taux = zxu *zxmod*cd_m(i)
+cAM        tauy = zxv *zxmod*cd_m(i)
+cAM        ustar(i) = SQRT(taux**2+tauy**2)
+cAM        ustar(i) = MAX(SQRT(ustar(i)),0.01)
+c Theta et qT du thermique sans exces (interpolin vers surf)
+c chgt de niveau du thermique (jeudi 30/12/1999)
+c (interpolation lineaire avant integration phi_h)
+cAM        qT_th(i) = zxqs*beta(i) + 4./z(i,1)*(q(i,1)-zxqs*beta(i))
+cAM        qT_th(i) = max(qT_th(i),q(i,1))
+        qT_th(i) = q2m(i)
+cn The_th restera la Theta du thermique sans exces jusqu'a 2eme calcul
+cn reste a regler convention P) pour Theta
+c        The_th(i) = tsol(i) + 4./z(i,1)*(t(i,1)-tsol(i))
+c     -                      + RLvCp*qT_th(i)
+cAM        Th_th(i) = tsol(i) + 4./z(i,1)*(t(i,1)-tsol(i))
+        Th_th(i) = t2m(i)
+      ENDDO
+c
+      DO i = 1, knon
+         rhino(i,1) = 0.0   ! Global Richardson
+         check(i) = .TRUE.
+         pblh(i) = z(i,1)   ! on initialise pblh a l'altitude du 1er niveau
+         plcl(i) = 6000.
+c Lambda = -u*^3 / (alpha.g.kvon.<w'Theta'v>
+         obklen(i) = -t(i,1)*ustar(i)**3/(RG*vk*heatv(i))
+         trmb1(i)   = 0.
+         trmb2(i)   = 0.
+         trmb3(i) = 0.
+      ENDDO
+
+C
+c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+C PBL height calculation:
+C Search for level of pbl. Scan upward until the Richardson number between
+C the first level and the current level exceeds the "critical" value.
+C (bonne idee Nu de separer le Ric et l'exces de temp du thermique)
+c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      fac = 100.0
+      DO k = 2, isommet
+      DO i = 1, knon
+      IF (check(i)) THEN
+! pourquoi / niveau 1 (au lieu du sol) et le terme en u*^2 ?
+ctest     zdu2 = (u(i,k)-u(i,1))**2+(v(i,k)-v(i,1))**2+fac*ustar(i)**2
+         zdu2 = u(i,k)**2+v(i,k)**2
+         zdu2 = max(zdu2,1.0e-20)
+c Theta_v environnement
+         zthvd=t(i,k)/s(i,k)*(1.+RETV*q(i,k))
+c
+c therm Theta_v sans exces (avec hypothese fausse de H&B, sinon,
+c passer par Theta_e et virpot)
+c         zthvu=t(i,1)/s(i,1)*(1.+RETV*q(i,1))
+cAM         zthvu = Th_th(i)*(1.+RETV*q(i,1))
+         zthvu = Th_th(i)*(1.+RETV*qT_th(i))
+c  Le Ri par Theta_v
+cAM         rhino(i,k) = (z(i,k)-z(i,1))*RG*(zthvd-zthvu)
+cAM     .               /(zdu2*0.5*(zthvd+zthvu))
+cAM On a nveau de ref a 2m ???
+         rhino(i,k) = (z(i,k)-zref)*RG*(zthvd-zthvu)
+     .               /(zdu2*0.5*(zthvd+zthvu))
+c
+         IF (rhino(i,k).GE.ricr) THEN
+           pblh(i) = z(i,k-1) + (z(i,k-1)-z(i,k)) *
+     .              (ricr-rhino(i,k-1))/(rhino(i,k-1)-rhino(i,k))
+c test04
+           pblh(i) = pblh(i) + 100.
+           pblT(i) = t(i,k-1) + (t(i,k)-t(i,k-1)) *
+     .              (pblh(i)-z(i,k-1))/(z(i,k)-z(i,k-1))
+           check(i) = .FALSE.
+         ENDIF
+      ENDIF
+      ENDDO
+      ENDDO
+
+C
+C Set pbl height to maximum value where computation exceeds number of
+C layers allowed
+C
+      DO i = 1, knon
+        if (check(i)) pblh(i) = z(i,isommet)
+      ENDDO
+C
+C Improve estimate of pbl height for the unstable points.
+C Find unstable points (sensible heat flux is upward):
+C
+      DO i = 1, knon
+      IF (heatv(i) .GT. 0.) THEN
+        unstbl(i) = .TRUE.
+        check(i) = .TRUE.
+      ELSE
+        unstbl(i) = .FALSE.
+        check(i) = .FALSE.
+      ENDIF
+      ENDDO
+C
+C For the unstable case, compute velocity scale and the
+C convective temperature excess:
+C
+      DO i = 1, knon
+      IF (check(i)) THEN
+        phiminv(i) = (1.-binm*pblh(i)/obklen(i))**onet
+c ***************************************************
+c Wm ? et W* ? c'est la formule pour z/h < .1
+c   ;Calcul de w* ;;
+c   ;;;;;;;;;;;;;;;;
+c   w_star=((g/tcls)*fcsv*z(ind))^(1/3.) [ou prendre la premiere approx de h)
+c   ;; CALCUL DE wm ;;
+c   ;;;;;;;;;;;;;;;;;;
+c   ; Ici on considerera que l'on est dans la couche de surf jusqu'a 100m
+c   ; On prend svt couche de surface=0.1*h mais on ne connait pas h
+c   ;;;;;;;;;;;Dans la couche de surface
+c   if (z(ind) le 20) then begin
+c   Phim=(1.-15.*(z(ind)/L))^(-1/3.)
+c   wm=u_star/Phim
+c   ;;;;;;;;;;;En dehors de la couche de surface
+c   endif else if (z(ind) gt 20) then begin
+c   wm=(u_star^3+c1*w_star^3)^(1/3.)
+c   endif
+c ***************************************************
+        wm(i)= ustar(i)*phiminv(i)
+c======================================================================
+cvaleurs de Dominique Lambert de la campagne SEMAPHORE :
+c <T'^2> = 100.T*^2; <q'^2> = 20.q*^2 a 10m
+c <Tv'^2> = (1+1.2q).100.T* + 1.2Tv.sqrt(20*100).T*.q* + (.608*Tv)^2*20.q*^2;
+c et dTetavS = sqrt(<Tv'^2>) ainsi calculee.
+c avec : T*=<w'T'>_s/w* et q*=<w'q'>/w*
+c !!! on peut donc utiliser w* pour les fluctuations <-> Lambert
+c(leur corellation pourrait dependre de beta par ex)
+c  if fcsv(i,j) gt 0 then begin
+c    dTetavs=b1*(1.+2.*.608*q_10(i,j))*(fcs(i,j)/wm(i,j))^2+$
+c    (.608*Thetav_10(i,j))^2*b2*(xle(i,j)/wm(i,j))^2+$
+c    2.*.608*thetav_10(i,j)*sqrt(b1*b2)*(xle(i,j)/wm(i,j))*(fcs(i,j)/wm(i,j))
+c    dqs=b2*(xle(i,j)/wm(i,j))^2
+c    theta_s(i,j)=thetav_10(i,j)+sqrt(dTetavs)
+c    q_s(i,j)=q_10(i,j)+sqrt(dqs)
+c  endif else begin
+c    Theta_s(i,j)=thetav_10(i,j)
+c    q_s(i,j)=q_10(i,j)
+c  endelse
+c======================================================================
+c
+cHBTM        therm(i) = heatv(i)*fak/wm(i)
+c forme Mathieu :
+        q_star = kqfs(i)/wm(i)
+        t_star = khfs(i)/wm(i)
+cIM 091204 BEG
+        IF(1.EQ.0) THEN
+        IF(t_star.LT.0..OR.q_star.LT.0.) THEN
+          print*,'i t_star q_star khfs kqfs wm',i,t_star,q_star,
+     $    khfs(i),kqfs(i),wm(i)
+        ENDIF
+        ENDIF
+cIM 091204 END
+cAM Nveau cde ref 2m =>
+cAM        therm(i) = sqrt( b1*(1.+2.*RETV*q(i,1))*t_star**2
+cAM     +             + (RETV*T(i,1))**2*b2*q_star**2
+cAM     +             + 2.*RETV*T(i,1)*b212*q_star*t_star
+cAM     +                 )
+cIM 091204 BEG
+        a1=b1*(1.+2.*RETV*qT_th(i))*t_star**2
+        a2=(RETV*Th_th(i))**2*b2*q_star**2
+        a3=2.*RETV*Th_th(i)*b212*q_star*t_star
+        aa=a1+a2+a3
+        IF(1.EQ.0) THEN
+        IF (aa.LT.0.) THEN 
+         print*,'i a1 a2 a3 aa',i,a1,a2,a3,aa
+         print*,'i qT_th Th_th t_star q_star RETV b1 b2 b212',
+     $   i,qT_th(i),Th_th(i),t_star,q_star,RETV,b1,b2,b212
+        ENDIF
+        ENDIF
+cIM 091204 END
+        therm(i) = sqrt( b1*(1.+2.*RETV*qT_th(i))*t_star**2
+     +             + (RETV*Th_th(i))**2*b2*q_star**2
+cIM 101204  +             + 2.*RETV*Th_th(i)*b212*q_star*t_star
+     +             + max(0.,2.*RETV*Th_th(i)*b212*q_star*t_star)
+     +                 )
+c
+c Theta et qT du thermique (forme H&B) avec exces
+c (attention, on ajoute therm(i) qui est virtuelle ...)
+c pourquoi pas sqrt(b1)*t_star ?
+c        dqs = b2sr*kqfs(i)/wm(i)
+        qT_th(i) = qT_th(i)  + b2sr*q_star
+cnew on differre le calcul de Theta_e
+c        The_th(i) = The_th(i) + therm(i) + RLvCp*qT_th(i)
+c ou:    The_th(i) = The_th(i) + sqrt(b1)*khfs(i)/wm(i) + RLvCp*qT_th(i)
+        rhino(i,1) = 0.0
+      ENDIF
+      ENDDO
+C
+c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+C ++ Improve pblh estimate for unstable conditions using the +++++++
+C ++          convective temperature excess :                +++++++
+c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+C
+      DO k = 2, isommet
+      DO i = 1, knon
+      IF (check(i)) THEN
+ctest     zdu2 = (u(i,k)-u(i,1))**2+(v(i,k)-v(i,1))**2+fac*ustar(i)**2
+         zdu2 = u(i,k)**2+v(i,k)**2
+         zdu2 = max(zdu2,1.0e-20)
+c Theta_v environnement
+         zthvd=t(i,k)/s(i,k)*(1.+RETV*q(i,k))
+c
+c et therm Theta_v (avec hypothese de constance de H&B,
+c         zthvu=(t(i,1)+therm(i))/s(i,1)*(1.+RETV*q(i,1))
+         zthvu = Th_th(i)*(1.+RETV*qT_th(i)) + therm(i)
+
+c
+c  Le Ri par Theta_v
+cAM Niveau de ref 2m
+cAM         rhino(i,k) = (z(i,k)-z(i,1))*RG*(zthvd-zthvu)
+cAM     .               /(zdu2*0.5*(zthvd+zthvu))
+         rhino(i,k) = (z(i,k)-zref)*RG*(zthvd-zthvu)
+     .               /(zdu2*0.5*(zthvd+zthvu))
+c
+c
+         IF (rhino(i,k).GE.ricr) THEN
+           pblh(i) = z(i,k-1) + (z(i,k-1)-z(i,k)) *
+     .              (ricr-rhino(i,k-1))/(rhino(i,k-1)-rhino(i,k))
+c test04
+           pblh(i) = pblh(i) + 100.
+           pblT(i) = t(i,k-1) + (t(i,k)-t(i,k-1)) *
+     .              (pblh(i)-z(i,k-1))/(z(i,k)-z(i,k-1))
+           check(i) = .FALSE.
+cIM 170305 BEG
+      IF(1.EQ.0) THEN
+c debug print -120;34       -34-        58 et    0;26 wamp
+      if (i.eq.950.or.i.eq.192.or.i.eq.624.or.i.eq.118) then
+            print*,' i,Th_th,Therm,qT :',i,Th_th(i),therm(i),qT_th(i)
+            q_star = kqfs(i)/wm(i)
+            t_star = khfs(i)/wm(i)
+            print*,'q* t*, b1,b2,b212 ',q_star,t_star
+     -            , b1*(1.+2.*RETV*qT_th(i))*t_star**2
+     -            , (RETV*Th_th(i))**2*b2*q_star**2
+     -            , 2.*RETV*Th_th(i)*b212*q_star*t_star
+            print*,'zdu2 ,100.*ustar(i)**2',zdu2 ,fac*ustar(i)**2
+      endif
+      ENDIF !(1.EQ.0) THEN
+cIM 170305 END
+c             q_star = kqfs(i)/wm(i)
+c             t_star = khfs(i)/wm(i)
+c             trmb1(i) = b1*(1.+2.*RETV*q(i,1))*t_star**2
+c             trmb2(i) = (RETV*T(i,1))**2*b2*q_star**2
+c Omega now   trmb3(i) = 2.*RETV*T(i,1)*b212*q_star*t_star
+         ENDIF
+      ENDIF
+      ENDDO
+      ENDDO
+C
+C Set pbl height to maximum value where computation exceeds number of
+C layers allowed
+C
+      DO i = 1, knon
+        if (check(i)) pblh(i) = z(i,isommet)
+      ENDDO
+C
+C PBL height must be greater than some minimum mechanical mixing depth
+C Several investigators have proposed minimum mechanical mixing depth
+C relationships as a function of the local friction velocity, u*.  We
+C make use of a linear relationship of the form h = c u* where c=700.
+C The scaling arguments that give rise to this relationship most often
+C represent the coefficient c as some constant over the local coriolis
+C parameter.  Here we make use of the experimental results of Koracin
+C and Berkowicz (1988) [BLM, Vol 43] for wich they recommend 0.07/f
+C where f was evaluated at 39.5 N and 52 N.  Thus we use a typical mid
+C latitude value for f so that c = 0.07/f = 700.
+C
+      DO i = 1, knon
+        pblmin  = 700.0*ustar(i)
+        pblh(i) = MAX(pblh(i),pblmin)
+c par exemple :
+        pblT(i) = t(i,2) + (t(i,3)-t(i,2)) *
+     .              (pblh(i)-z(i,2))/(z(i,3)-z(i,2))
+      ENDDO
+
+C ********************************************************************
+C  pblh is now available; do preparation for diffusivity calculation :
+C ********************************************************************
+      DO i = 1, knon
+        check(i) = .TRUE.
+        Zsat(i)   = .FALSE.
+c omegafl utilise pour prolongement CAPE
+        omegafl(i) = .FALSE.
+        Cape(i)   = 0.
+        Kape(i)   = 0.
+        EauLiq(i) = 0.
+        CTEI(i)   = 0.
+        pblk(i) = 0.0
+        fak1(i) = ustar(i)*pblh(i)*vk
+C
+C Do additional preparation for unstable cases only, set temperature
+C and moisture perturbations depending on stability.
+C *** Rq: les formule sont prises dans leur forme CS ***
+        IF (unstbl(i)) THEN
+cAM Niveau de ref du thermique
+cAM          zxt=(t(i,1)-z(i,1)*0.5*RG/RCPD/(1.+RVTMP2*q(i,1)))
+cAM     .         *(1.+RETV*q(i,1))
+          zxt=(Th_th(i)-zref*0.5*RG/RCPD/(1.+RVTMP2*qT_th(i)))
+     .         *(1.+RETV*qT_th(i))
+          phiminv(i) = (1. - binm*pblh(i)/obklen(i))**onet
+          phihinv(i) = sqrt(1. - binh*pblh(i)/obklen(i))
+          wm(i)      = ustar(i)*phiminv(i)
+          fak2(i)    = wm(i)*pblh(i)*vk
+          wstr(i)    = (heatv(i)*RG*pblh(i)/zxt)**onet
+          fak3(i)    = fakn*wstr(i)/wm(i)
+        ENDIF
+c Computes Theta_e for thermal (all cases : to be modified)
+c   attention ajout therm(i) = virtuelle
+        The_th(i) = Th_th(i) + therm(i) + RLvCp*qT_th(i)
+c ou:    The_th(i) = Th_th(i) + sqrt(b1)*khfs(i)/wm(i) + RLvCp*qT_th(i)
+      ENDDO
+
+C Main level loop to compute the diffusivities and
+C counter-gradient terms:
+C
+      DO 1000 k = 2, isommet
+C
+C Find levels within boundary layer:
+C
+        DO i = 1, knon
+          unslev(i) = .FALSE.
+          stblev(i) = .FALSE.
+          zm(i) = z(i,k-1)
+          zp(i) = z(i,k)
+          IF (zkmin.EQ.0.0 .AND. zp(i).GT.pblh(i)) zp(i) = pblh(i)
+          IF (zm(i) .LT. pblh(i)) THEN
+            zmzp = 0.5*(zm(i) + zp(i))
+C debug
+c          if (i.EQ.1864) then
+c             print*,'i,pblh(1864),obklen(1864)',i,pblh(i),obklen(i)
+c          endif
+
+            zh(i) = zmzp/pblh(i)
+            zl(i) = zmzp/obklen(i)
+            zzh(i) = 0.
+            IF (zh(i).LE.1.0) zzh(i) = (1. - zh(i))**2
+C
+C stblev for points zm < plbh and stable and neutral
+C unslev for points zm < plbh and unstable
+C
+            IF (unstbl(i)) THEN
+              unslev(i) = .TRUE.
+            ELSE
+              stblev(i) = .TRUE.
+            ENDIF
+          ENDIF
+        ENDDO
+c        print*,'fin calcul niveaux'
+C
+C Stable and neutral points; set diffusivities; counter-gradient
+C terms zero for stable case:
+C
+        DO i = 1, knon
+          IF (stblev(i)) THEN
+            IF (zl(i).LE.1.) THEN
+              pblk(i) = fak1(i)*zh(i)*zzh(i)/(1. + betas*zl(i))
+            ELSE
+              pblk(i) = fak1(i)*zh(i)*zzh(i)/(betas + zl(i))
+            ENDIF
+c            pcfm(i,k) = pblk(i)
+c            pcfh(i,k) = pcfm(i,k)
+          ENDIF
+        ENDDO
+C
+C unssrf, unstable within surface layer of pbl
+C unsout, unstable within outer   layer of pbl
+C
+        DO i = 1, knon
+          unssrf(i) = .FALSE.
+          unsout(i) = .FALSE.
+          IF (unslev(i)) THEN
+            IF (zh(i).lt.sffrac) THEN
+              unssrf(i) = .TRUE.
+            ELSE
+              unsout(i) = .TRUE.
+            ENDIF
+          ENDIF
+        ENDDO
+C
+C Unstable for surface layer; counter-gradient terms zero
+C
+        DO i = 1, knon
+          IF (unssrf(i)) THEN
+            term = (1. - betam*zl(i))**onet
+            pblk(i) = fak1(i)*zh(i)*zzh(i)*term
+            pr(i) = term/sqrt(1. - betah*zl(i))
+          ENDIF
+        ENDDO
+c        print*,'fin counter-gradient terms zero'
+C
+C Unstable for outer layer; counter-gradient terms non-zero:
+C
+        DO i = 1, knon
+          IF (unsout(i)) THEN
+            pblk(i) = fak2(i)*zh(i)*zzh(i)
+c            cgs(i,k) = fak3(i)/(pblh(i)*wm(i))
+c            cgh(i,k) = khfs(i)*cgs(i,k)
+            pr(i) = phiminv(i)/phihinv(i) + ccon*fak3(i)/fak
+c            cgq(i,k) = kqfs(i)*cgs(i,k)
+          ENDIF
+        ENDDO
+c        print*,'fin counter-gradient terms non zero'
+C
+C For all unstable layers, compute diffusivities and ctrgrad ter m
+C
+c        DO i = 1, knon
+c        IF (unslev(i)) THEN
+c            pcfm(i,k) = pblk(i)
+c            pcfh(i,k) = pblk(i)/pr(i)
+c etc cf original
+c        ENDIF
+c        ENDDO
+C
+C For all layers, compute integral info and CTEI
+C
+        DO i = 1, knon
+        if (check(i).or.omegafl(i)) then
+          if (.not.Zsat(i)) then
+c            Th2 = The_th(i) - RLvCp*qT_th(i)
+            Th2 = Th_th(i)
+            T2 = Th2*s(i,k)
+c thermodyn functions
+            zdelta=MAX(0.,SIGN(1.,RTT-T2))
+            qqsat= r2es * FOEEW(T2,zdelta)/pplay(i,k)
+            qqsat=MIN(0.5,qqsat)
+            zcor=1./(1.-retv*qqsat)
+            qqsat=qqsat*zcor
+c
+            if (qqsat.lt.qT_th(i)) then
+c on calcule lcl
+              if (k.eq.2) then
+                plcl(i) = z(i,k)
+              else
+                plcl(i) =  z(i,k-1) + (z(i,k-1)-z(i,k)) *
+     .                 (qT_th(i)-qsatbef(i))/(qsatbef(i)-qqsat)
+              endif
+              Zsat(i) = .true.
+              Tbef(i) = T2
+            endif
+c
+          endif
+          qsatbef(i) = qqsat
+camn ???? cette ligne a deja ete faite normalement ?
+        endif
+c            print*,'hbtm2 i,k=',i,k
+        ENDDO
+ 1000 continue           ! end of level loop
+cIM 170305 BEG
+        IF(1.EQ.0) THEN
+            print*,'hbtm2  ok'
+        ENDIF !(1.EQ.0) THEN
+cIM 170305 END
+      RETURN
+      END
Index: /LMDZ4/trunk/libf/phylmd/ini_bilKP_ave.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_bilKP_ave.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/ini_bilKP_ave.h	(revision 644)
@@ -0,0 +1,256 @@
+c
+c $Header$
+c
+      IF (ok_journe) THEN
+c
+         zsto = dtime
+         zout = dtime * FLOAT(ecrit_day)
+         typeval=tave
+c
+         idayref = day_ref
+         CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
+c
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon,zx_lon)
+         DO i = 1, iim
+            zx_lon(i,1) = rlon(i+1)
+            zx_lon(i,jjmp1) = rlon(i+1)
+         ENDDO
+         DO ll=1,klev
+            znivsig(ll)=float(ll)
+         ENDDO
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
+         write(*,*)'zx_lon = ',zx_lon(:,1)
+         write(*,*)'zx_lat = ',zx_lat(1,:)
+         CALL histbeg("histbilKP_ave", iim,zx_lon(:,1), jjmp1,
+     .                zx_lat(1,:),
+     .                1,iim,1,jjmp1, itau_phy, zjulian, dtime,
+     .                nhori, nid_bilKPave)
+         write(*,*)'Journee ', itau_phy, zjulian
+         CALL histvert(nid_bilKPave, "presnivs",
+     .                "Vertical levels","mb",
+     .                 klev, presnivs/100., nvert)
+c
+c
+c Champs 3D:
+c
+         CALL histdef(nid_bilKPave,"ue",
+     .   "Zonal energy transport","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32, 
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"ve",
+     .   "Merid energy transport","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32, 
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"uq",
+     .   "Zonal humidity transport","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32, 
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"vq",
+     .   "Merid humidity transport","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32, 
+     .                typeval, zsto,zout)
+c
+c Champs 3D:
+c
+         CALL histdef(nid_bilKPave,"temp",
+     .   "Air temperature","K",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"ovap",
+     .   "Specific humidity","Kg/Kg",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"geop",
+     .   "Geopotential height","m",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"vitu",
+     .   "Zonal wind","m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"vitv",
+     .   "Meridional wind","m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "vitw", 
+     .   "Vertical wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "pres", 
+     .   "Inter-Layer Air pressure",
+     .                "Pa",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "play", 
+     .   "Mean-Layer Air pressure",
+     .                "Pa",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "oliq", 
+     .   "Liquid water content", 
+     .                "kg/kg",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dtdyn", 
+     .   "Dynamics dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dqdyn", 
+     .   "Dynamics dQ", "Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dtcon", 
+     .   "Convection dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "ducon", 
+     .   "Convection du", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dvcon", 
+     .   "Convection dv", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"dqcon",
+     .   "Convection dQ","Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dtlsc", 
+     .   "Condensation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"dqlsc",
+     .   "Condensation dQ","Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"dtvdf",
+     .   "Boundary-layer dT","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dqvdf", 
+     .   "Boundary-layer dQ", 
+     .               "Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"dtajs",
+     .   "Ajustement sec dT","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dqajs",
+     .   "Ajustement sec dQ", 
+     .               "Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dteva", 
+     .   "Reevaporation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"dqeva",
+     .   "Reevaporation dQ",
+     .                "Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+
+c
+         CALL histdef(nid_bilKPave, "dtswr", 
+     .   "SW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dtsw0", 
+     .   "SW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dtlwr", 
+     .   "LW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dtlw0", 
+     .   "LW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"duvdf",
+     .   "Boundary-layer dU","m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave,"dvvdf",
+     .   "Boundary-layer dV","m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         IF (ok_orodr) THEN
+         IF (ok_orolf) THEN
+         CALL histdef(nid_bilKPave, "duoli",
+     .   "Orography dU", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPave, "dvoli", 
+     .   "Orography dV", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         ENDIF
+         ENDIF
+C
+         CALL histdef(nid_bilKPave, "duphy",
+     .   "Physiq dU","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+C
+         CALL histdef(nid_bilKPave, "dvphy",
+     .   "Physiq dV","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+C
+         CALL histdef(nid_bilKPave, "dtphy",
+     .   "Physiq dT","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+C
+         CALL histdef(nid_bilKPave, "dqphy",
+     .   "Physiq dQ","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+C
+         CALL histdef(nid_bilKPave, "dqlphy",
+     .   "Physiq dQl","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+C
+C
+         CALL histend(nid_bilKPave)
+c
+         ndex2d = 0
+         ndex3d = 0
+c
+      ENDIF ! fin de test sur ok_journe
Index: /LMDZ4/trunk/libf/phylmd/ini_bilKP_ins.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_bilKP_ins.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/ini_bilKP_ins.h	(revision 644)
@@ -0,0 +1,324 @@
+c
+c $Header$
+c
+      IF (ok_journe) THEN
+c
+         zsto = dtime
+         zout = dtime
+         typeval=tinst
+c
+         idayref = day_ref
+         CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
+c
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon,zx_lon)
+         DO i = 1, iim
+            zx_lon(i,1) = rlon(i+1)
+            zx_lon(i,jjmp1) = rlon(i+1)
+         ENDDO
+         DO ll=1,klev
+            znivsig(ll)=float(ll)
+         ENDDO
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
+         write(*,*)'zx_lon = ',zx_lon(:,1)
+         write(*,*)'zx_lat = ',zx_lat(1,:)
+c
+cIM 280405 BEG
+c
+cIM cf. AM 081204 BEG region
+          imin_ins=1
+          imax_ins=iim
+          jmin_ins=1
+          jmax_ins=jjmp1
+          do i=1,iim-1
+             if(zx_lon(i,1).lt.lonmin_ins) imin_ins=i
+             if(zx_lon(i,1).le.lonmax_ins) imax_ins=i+1
+          enddo
+          do j=1,jjmp1-1
+             if(zx_lat(1,j).ge.latmin_ins) jmax_ins=j
+             if(zx_lat(1,j).gt.latmax_ins) jmin_ins=j
+          enddo
+c
+          print*,'On stoke le fichier bilKP instantanne sur ',
+     s   imin_ins,imax_ins,jmin_ins,jmax_ins
+          print*,'On stoke le fichier bilKP instantanne sur ',
+     s   zx_lon(imin_ins,1),zx_lon(imax_ins,1),
+     s   zx_lat(1,jmin_ins),zx_lat(1,jmax_ins)
+cIM cf. AM 081204 END region
+c
+cIM 280405 END
+c
+         IF(1.EQ.0) THEN
+         CALL histbeg("histbilKP_ins", iim,zx_lon(:,1), jjmp1,
+     .                zx_lat(1,:),
+     .                1,iim,1,jjmp1, itau_phy, zjulian, dtime,
+     .                nhori, nid_bilKPins)
+         ENDIF
+c
+cIM 280405 BEG
+c
+cIM cf. AM 081204 BEG region
+         CALL histbeg("histbilKP_ins", iim,zx_lon(:,1), 
+     .                 jjmp1,zx_lat(1,:),
+     .                 imin_ins,imax_ins-imin_ins+1,
+     .                 jmin_ins,jmax_ins-jmin_ins+1,
+     .                 itau_phy, zjulian, dtime,
+     .                 nhori, nid_bilKPins)
+cIM 081204 END
+c
+cIM 280405 END
+c
+         write(*,*)'Journee ', itau_phy, zjulian
+         CALL histvert(nid_bilKPins, "presnivs",
+     .                "Vertical levels","mb",
+     .                 klev, presnivs/100., nvert)
+c
+c Champs 3D:
+c
+         CALL histdef(nid_bilKPins,"ue",
+     .   "Zonal energy transport","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32, 
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"ve",
+     .   "Merid energy transport","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32, 
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"uq",
+     .   "Zonal humidity transport","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32, 
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"vq",
+     .   "Merid humidity transport","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32, 
+     .                typeval, zsto,zout)
+c
+c Champs 3D:
+c
+         CALL histdef(nid_bilKPins, "temp",
+     .   "Air temperature", "K",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"ovap",
+     .   "Specific humidity","Kg/Kg",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"geop",
+     .   "Geopotential height", "m",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"vitu", 
+     .   "Zonal wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"vitv", 
+     .   "Meridional wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "vitw",
+     .   "Vertical wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "pres",
+     .   "Inter-Layer Air pressure",
+     .                "Pa",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "play",
+     .   "Mean-Layer Air pressure",
+     .                "Pa",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "oliq",
+     .   "Liquid water content", 
+     .                "kg/kg",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "dtdyn",
+     .   "Dynamics dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "dqdyn",
+     .   "Dynamics dQ", "Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "dtcon",
+     .   "Convection dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "ducon",
+     .   "Convection du", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "dvcon",
+     .   "Convection dv", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"dqcon",
+     .   "Convection dQ","Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "dtlsc",
+     .   "Condensation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"dqlsc",
+     .   "Condensation dQ","Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"dtvdf",
+     .   "Boundary-layer dT","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "dqvdf", 
+     .   "Boundary-layer dQ", 
+     .               "Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"dtajs",
+     .   "Ajustement sec dT","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"dqajs",
+     .   "Ajustement sec dQ", 
+     .               "Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"dteva",
+     .   "Reevaporation dT","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"dqeva",
+     .   "Reevaporation dQ",
+     .                "Kg/Kg/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+
+c
+         CALL histdef(nid_bilKPins, "dtswr", 
+     .   "SW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "dtsw0", 
+     .   "SW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "dtlwr", 
+     .   "LW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "dtlw0", 
+     .   "LW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"duvdf",
+     .   "Boundary-layer dU","m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins,"dvvdf",
+     .   "Boundary-layer dV","m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         IF (ok_orodr) THEN
+         IF (ok_orolf) THEN
+         CALL histdef(nid_bilKPins, "duoli", 
+     .   "Orography dU", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         CALL histdef(nid_bilKPins, "dvoli", 
+     .   "Orography dV", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+c
+         ENDIF
+         ENDIF
+C
+         CALL histdef(nid_bilKPins, "duphy",
+     .   "Physiq dU","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+C
+         CALL histdef(nid_bilKPins, "dvphy",
+     .   "Physiq dV","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+C
+         CALL histdef(nid_bilKPins, "dtphy",
+     .   "Physiq dT","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+C
+         CALL histdef(nid_bilKPins, "dqphy",
+     .   "Physiq dQ","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+C
+         CALL histdef(nid_bilKPins, "dqlphy",
+     .   "Physiq dQl","-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                typeval, zsto,zout)
+cIM 280405 BEG
+c
+c Champs 2D:
+c
+c u850, v850
+c        DO k=1, nlevSTD
+         DO k=1, 12
+c
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c
+         IF(bb2.EQ."850") THEN 
+c
+          CALL histdef(nid_bilKPins, "u"//bb2,
+     .                 "Zonal wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                typeval, zsto,zout)
+c
+          CALL histdef(nid_bilKPins, "v"//bb2,
+     .                 "Meridional wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                typeval, zsto,zout)
+c
+         ENDIF !(bb2.EQ."850") 
+c
+         ENDDO !k=1, 12
+c
+cIM 280405 END
+c
+         CALL histend(nid_bilKPins)
+c
+         ndex2d = 0
+         ndex3d = 0
+c
+      ENDIF ! fin de test sur ok_journe
Index: /LMDZ4/trunk/libf/phylmd/ini_coord_REGDYN.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_coord_REGDYN.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/ini_coord_REGDYN.h	(revision 644)
@@ -0,0 +1,81 @@
+c
+c $Header$
+c
+       nsrf=3
+       DO nreg=1, nbregdyn
+       DO i=1, klon
+
+c       IF (debut) THEN
+         IF(rlon(i).LT.0.) THEN
+           rlonPOS(i)=rlon(i)+360.
+         ELSE
+           rlonPOS(i)=rlon(i)  
+         ENDIF
+c       ENDIF
+
+        pct_ocean(i,nreg)=0
+
+c test si c'est 1 point d'ocean
+        IF(pctsrf(i,nsrf).EQ.1.) THEN
+
+         IF(nreg.EQ.1) THEN
+
+c TROP
+          IF(rlat(i).GE.-30.AND.rlat(i).LE.30.) THEN
+           pct_ocean(i,nreg)=1
+          ENDIF
+
+c PACIFIQUE NORD
+          ELSEIF(nreg.EQ.2) THEN
+           IF(rlat(i).GE.40.AND.rlat(i).LE.60.) THEN
+            IF(rlonPOS(i).GE.160..AND.rlonPOS(i).LE.235.) THEN 
+             pct_ocean(i,nreg)=1
+            ENDIF
+           ENDIF
+c CALIFORNIE ST-CU
+         ELSEIF(nreg.EQ.3) THEN
+          IF(rlonPOS(i).GE.220..AND.rlonPOS(i).LE.250.) THEN
+           IF(rlat(i).GE.15.AND.rlat(i).LE.35.) THEN
+            pct_ocean(i,nreg)=1
+           ENDIF
+          ENDIF
+c HAWAI
+        ELSEIF(nreg.EQ.4) THEN 
+         IF(rlonPOS(i).GE.180..AND.rlonPOS(i).LE.220.) THEN
+          IF(rlat(i).GE.15.AND.rlat(i).LE.35.) THEN
+           pct_ocean(i,nreg)=1
+          ENDIF
+         ENDIF
+c WARM POOL
+        ELSEIF(nreg.EQ.5) THEN 
+         IF(rlonPOS(i).GE.70..AND.rlonPOS(i).LE.150.) THEN
+          IF(rlat(i).GE.-5.AND.rlat(i).LE.20.) THEN
+           pct_ocean(i,nreg)=1
+          ENDIF
+         ENDIF
+        ENDIF !nbregdyn
+c TROP
+c        IF(rlat(i).GE.-30.AND.rlat(i).LE.30.) THEN
+c         pct_ocean(i)=.TRUE.
+c         WRITE(*,*) 'pct_ocean =',i, rlon(i), rlat(i)
+c          ENDIF !lon
+c         ENDIF !lat
+
+        ENDIF !pctsrf
+       ENDDO !klon
+       ENDDO !nbregdyn
+cIM 190504      ENDIF !ok_regdyn
+ 
+cIM somme de toutes les nhistoW BEG
+      IF (debut) THEN
+      DO nreg = 1, nbregdyn
+       DO k = 1, kmaxm1
+        DO l = 1, lmaxm1
+         DO iw = 1, iwmax
+          nhistoWt(k,l,iw,nreg)=0.
+         ENDDO !iw
+        ENDDO !l
+       ENDDO !k
+      ENDDO !nreg
+      ENDIF !(debut) THEN
+cIM 190504 BEG
Index: /LMDZ4/trunk/libf/phylmd/ini_histISCCP.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_histISCCP.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/ini_histISCCP.h	(revision 644)
@@ -7,7 +7,7 @@
 c zout et zsto.
 c dtime est passe par ailleurs a histbeg
-c zsto = frequence de stockage des champs
+c zstophy = frequence de stockage des champs tous les pdt physiques
 c zout = frequence d'ecriture des champs
-         zsto = dtime
+        zstophy = dtime
 c
 c ecriture 8 fois par jour
@@ -15,11 +15,10 @@
 c ecriture toutes les 2h (12 fois par jour)
 c       zout = dtime * 4.
-c ecriture toutes les 1/h (48 fois par jour)
+c ecriture toutes les 1/2 h (48 fois par jour)
 c       zout = dtime
 c
 c ecriture mensuelle
         zout = dtime * ecrit_mth
-c
-        print*,'ISCCP zout,zsto=',zout,zsto
+c       zout = dtime * ecrit_day
 c
 c       PRINT*, 'La frequence de sortie ISCCP est de ', ecrit_isccp
@@ -48,4 +47,6 @@
      .                 lmaxm1, cldtopres, nvert,'down')
 c
+        IF(type_run.EQ."ENSP".OR.type_run.EQ."CLIM") THEN
+c
 c variables a ecrire
 c
@@ -54,5 +55,5 @@
      .                "LMDZ ISCCP cld", "%",
      .                iim, jjmp1,nhori,lmaxm1,1,lmaxm1,nvert,32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
          ENDDO
 c
@@ -60,5 +61,25 @@
      .                "Nb of calls with sunlit ", "%",
      .                iim, jjmp1,nhori,1,1,1,-99,32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+        ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
+c
+         DO k=1, kmaxm1
+          DO l=1, lmaxm1
+c
+          CALL histdef(nid_isccp, pclev(l)//taulev(k),
+     .                "LMDZ ISCCP cld "//cnameisccp(l,k), "%",
+     .                iim, jjmp1,nhori,1,1,1,-99,32,
+     .                "ave(X)", zstophy,zout)
+c
+          ENDDO
+         ENDDO
+c
+         CALL histdef(nid_isccp, "nsunlit",
+     .                "Nb of calls with sunlit ", "%",
+     .                iim, jjmp1,nhori,1,1,1,-99,32,
+     .                "ave(X)", zstophy,zout)
+c
+        ENDIF 
 c
         CALL histend(nid_isccp)
Index: /LMDZ4/trunk/libf/phylmd/ini_histREGDYN.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_histREGDYN.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/ini_histREGDYN.h	(revision 644)
@@ -5,15 +5,9 @@
       IF (ok_regdyn) THEN
 c
-         PRINT*, 'La frequence de sortie REGDYN est de ', ecrit_mth
-c        PRINT*, 'La frequence de sortie REGDYN est de ', ecrit_regdyn
-cIM cf. LF
+cIM      PRINT*, 'La frequence de sortie REGDYN est de ', ecrit_mth
+c
          idayref = day_ref
          CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-
-cccIM    CALL ymds2ju(anne_ini, 1, 1, 0.0, zjulian)
-c        CALL ymds2ju(annee_ref, 1, 1, 0.0, zjulian)
-c        zjulian = zjulian + day_ini
 c
-
 c axe vertical pour les differents niveaux des histogrammes
       DO iw=1, iwmax
@@ -28,16 +22,23 @@
      .                 "mb/day",
      .                 iwmax, zx_o500, komega)
-
+c
 c   pour les champs instantannes, il faut mettre la meme valeur pour
-c   zout et tsto.
+c   zout et zsto.
 c   dtime est passe par ailleurs a histbeg
-
+c
 c        zout = dtime * REAL(NINT(86400./dtime*ecrit_regdyn))
 c        zsto = zout
 c        print*,'zout,zsto=',zout,zsto
+c
+c stockage a chaque pas de temps de la physique
+c
+         zstophy = dtime
+cIM 020904      zstophy = dtime * nbapp_isccp
+
 c ecriture mensuelle
 c
-         zsto = dtime
          zout = dtime * ecrit_mth
+cIM 020904      
+c        zout = dtime * ecrit_day
 c        zout = dtime * REAL(NINT(86400./dtime*ecrit_regdyn))
 
@@ -48,71 +49,73 @@
          CALL histdef(nid_regdyn, "hw1", "Tropics Histogram ", "%",
      &                kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega, 32, 
-     &                "ave(X)", zsto,zout)
+     &                "ave(X)", zstophy,zout)
 
          CALL histdef(nid_regdyn, "nh1", "Nb of pixels Tropics Histo",
      &                "%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
-     &                32,"ave(X)", zsto,zout)
+     &                32,"ave(X)", zstophy,zout)
 c
 
-         CALL histdef(nid_regdyn, "nht1","Total Nb pixels Tropics Histo"
-     &                ,"%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
-     &                32,"ave(X)", zsto,zout)
+         CALL histdef(nid_regdyn, "nht1",
+     &                "Total Nb pixels Tropics Histo",
+     &                "%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
+     &                32,"ave(X)", zstophy,zout)
 c
 c PAN
          CALL histdef(nid_regdyn, "hw2", "North Pacific Histogram", "%",
      &                kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega, 32, 
-     &                "ave(X)", zsto,zout)
+     &                "ave(X)", zstophy,zout)
 
          CALL histdef(nid_regdyn, "nh2", "Nb of pixels North Pacific",
      &                "%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
-     &                32,"ave(X)", zsto,zout)
+     &                32,"ave(X)", zstophy,zout)
 c
 
-         CALL histdef(nid_regdyn, "nht2","Total Nb pixels North Pacific 
-     &                Histo"
-     &                ,"%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
-     &                32,"ave(X)", zsto,zout)
+         CALL histdef(nid_regdyn, "nht2",
+     &                "Total Nb pixels North Pacific Histo",
+     &                "%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
+     &                32,"ave(X)", zstophy,zout)
 c CAL
          CALL histdef(nid_regdyn, "hw3", "California Histogram", "%",
      &                kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega, 32, 
-     &                "ave(X)", zsto,zout)
+     &                "ave(X)", zstophy,zout)
 
-         CALL histdef(nid_regdyn, "nh3", "Nb of pixels California 
-     &                Histo",
+         CALL histdef(nid_regdyn, "nh3", 
+     &                "Nb of pixels California Histo",
      &                "%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
-     &                32,"ave(X)", zsto,zout)
+     &                32,"ave(X)", zstophy,zout)
 c
 
-         CALL histdef(nid_regdyn, "nht3","Total Nb pixels California 
-     &                Histo"
-     &                ,"%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
-     &                32,"ave(X)", zsto,zout)
+         CALL histdef(nid_regdyn, "nht3",
+     &                "Total Nb pixels California Histo",
+     &                "%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
+     &                32,"ave(X)", zstophy,zout)
 c HAW
          CALL histdef(nid_regdyn, "hw4", "Hawai Histogram", "%",
      &                kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega, 32, 
-     &                "ave(X)", zsto,zout)
+     &                "ave(X)", zstophy,zout)
 
          CALL histdef(nid_regdyn, "nh4", "Nb of pixels Hawai Histo",
      &                "%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
-     &                32,"ave(X)", zsto,zout)
+     &                32,"ave(X)", zstophy,zout)
 c
 
-         CALL histdef(nid_regdyn, "nht4","Total Nb pixels Hawai Histo"
-     &                ,"%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
-     &                32,"ave(X)", zsto,zout)
+         CALL histdef(nid_regdyn, "nht4",
+     &                "Total Nb pixels Hawai Histo",
+     &                "%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
+     &                32,"ave(X)", zstophy,zout)
 c WAP
          CALL histdef(nid_regdyn, "hw5", "Warm Pool Histogram", "%",
      &                kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega, 32, 
-     &                "ave(X)", zsto,zout)
+     &                "ave(X)", zstophy,zout)
 
          CALL histdef(nid_regdyn, "nh5", "Nb of pixels Warm Pool Histo",
      &                "%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
-     &                32,"ave(X)", zsto,zout)
+     &                32,"ave(X)", zstophy,zout)
 c
 
-         CALL histdef(nid_regdyn, "nht5","Total Nb pixels Warm Pool 
-     &                Histo"
-     &                ,"%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
-     &                32,"ave(X)", zsto,zout)
+         CALL histdef(nid_regdyn, "nht5",
+     &                "Total Nb pixels Warm Pool Histo",
+     &                "%",kmaxm1,lmaxm1,nhoriRD, iwmax,1,iwmax, komega,
+     &                32,"ave(X)", zstophy,zout)
 c
          CALL histend(nid_regdyn)
Index: /LMDZ4/trunk/libf/phylmd/ini_histday.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_histday.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/ini_histday.h	(revision 644)
@@ -1,12 +1,10 @@
-!
-! $Header$
-!
+c
+c $Header$
+c
       IF (ok_journe) THEN
 c
-         zsto = dtime
-         zout = dtime * FLOAT(ecrit_day)
-         zsto1= dtime * FLOAT(ecrit_day)
-c         zout = dtime * REAL(ecrit_day)
-c         zsto1= dtime * REAL(ecrit_day)
+       zstophy = dtime
+       zstoday= dtime * FLOAT(ecrit_day)
+       zout = dtime * FLOAT(ecrit_day)
 c
          idayref = day_ref
@@ -25,25 +23,24 @@
      .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime, 
      .                 nhori, nid_day)
-         write(*,*)'Journee ', itau_phy, zjulian
          CALL histvert(nid_day, "presnivs", "Vertical levels", "mb",
-     .                 klev, presnivs, nvert)
+     .                 klev, presnivs/100., nvert)
 c
        IF(lev_histday.GE.1) THEN
 c
-         CALL histdef(nid_day, "phis", "Surface geop. height", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "once", zsto,zout)
+         CALL histdef(nid_day, "phis", "Surface geop. height", "m2/s2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "once", zstophy,zout)
 c
          CALL histdef(nid_day, "aire", "Grid area", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "once", zsto,zout)
+     .                "once", zstophy,zout)
 c
          CALL histdef(nid_day, "contfracATM","% sfce ter+lic ","-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "once", zsto,zout)
+     .                "once", zstophy,zout)
 c
          CALL histdef(nid_day, "contfracOR","% sfce terre OR", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "once", zsto,zout)
+     .                "once", zstophy,zout)
 c
 c Champs 2D:
@@ -51,9 +48,9 @@
          CALL histdef(nid_day, "tsol", "Surface Temperature", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "t2m", "Temperature 2m", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
 c Champs retires momentannéement en attendant un hypothetique
@@ -63,168 +60,230 @@
      .                "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                t2mincels, zsto,zout)
+     .                t2mincels, zstophy,zout)
 c
          CALL histdef(nid_day, "t2m_max", "Temp. 2m max.",
      .                "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                t2maxcels, zsto,zout)
+     .                t2maxcels, zstophy,zout)
 c
          CALL histdef(nid_day, "plul", "Large-scale Precip.",
      .   "kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "pluc", "Convective Precip.",
      .   "kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "snowl", "Solid Large-scale Precip.",
-     .   "kg/(s*m2)",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .   "kg/(m2*s)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
 c
          IF(1.EQ.0) THEN !snowc=0.
          CALL histdef(nid_day, "snowc", "Solid Convective Precip.",
-     .   "kg/(s*m2)",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .   "kg/(m2*s)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
          ENDIF !snowc=0.
 c
          CALL histdef(nid_day, "flat", "Latent heat flux", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "sicf", "Sea-ice fraction", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto1,zout)
+     .                "inst(X)", zstoday,zout)
 c
          CALL histdef(nid_day, "q2m", "Specific humidity", "kg/kg",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "u10m", "Vent zonal 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "v10m", "Vent meridien 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "wind10m","10-m wind speed","m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "wind10max", "10-m wind speed max.",
      .                "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                t2maxcels, zsto,zout)
+     .                t2maxcels, zstophy,zout)
 c
          CALL histdef(nid_day, "psol", "Surface Pressure", "Pa",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "precip","Precipitation Totale liq+sol"
      .                , "kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "snowf", "Snow fall", "kg/(s*m2)",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "snow_mass", "Snow Mass", "kg/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "evap", "Evaporation", "kg/(s*m2)",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "snowf", "Snow fall", "kg/(m2*s)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+c        CALL histdef(nid_day, "snow_mass", "Snow Mass", "kg/m2",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+c    .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "evap", "Evaporation", "kg/(m2*s)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "tops", "Solar rad. at TOA", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "topl", "IR rad. at TOA", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "sols", "Net Solar rad. at surf.", 
      .                "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "soll", "Net IR rad. at surface", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "cldl", "Low-level cloudiness", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "cldm", "Mid-level cloudiness", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "cldh", "High-level cloudiness", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "cldt", "Total cloudiness", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "cldq", "Cloud liquid water path", 
      .                "kg/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "prw", "Precipitable water", "kg/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
 c  Champs dynamiques sur niveaux de pression
-         DO k=1, nlevENS
-c
-          CALL histdef(nid_day, "u"//clev(k),
-     .                 "Zonal wind"//clev(k)//"mb","m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-          CALL histdef(nid_day, "v"//clev(k),
-     .                 "Meridional wind"//clev(k)//"mb","m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         ENDDO !nlevENS
-c
-         CALL histdef(nid_day, "w500", "Verical wind 500mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day,"phi500", "Geopotentiel a 500mb","m2/s2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+c
+c        DO k=1, nlevENS
+         DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb2=clevSTD(k)
+c        ENDIF
+c
+         IF(bb2.EQ."850".OR.bb2.EQ."700"
+     .   .OR.bb2.EQ."500".OR.bb2.EQ."200") THEN
+c
+          CALL histdef(nid_day, "u"//bb2,
+     .                 "Zonal wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+          CALL histdef(nid_day, "v"//bb2,
+     .                 "Meridional wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+         ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.bb2.EQ."500".OR.bb2.EQ."200") THEN
+c
+         IF(bb2.EQ."500") THEN
+c
+         CALL histdef(nid_day, "w"//bb2, "Vertical wind "//bb2//"mb",
+     .                "m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+         CALL histdef(nid_day,"phi"//bb2, "Geopotential "//bb2//"mb",
+     .                "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+         ENDIF !(bb2.EQ."500")
+c
+         ENDDO !nlevSTD
 c
          CALL histdef(nid_day, "slp", "Sea Level Pressure", "Pa",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "cape_max", "CAPE max.",
      .                "J/kg",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                capemaxcels, zsto,zout)
+     .                capemaxcels, zstophy,zout)
 c
          CALL histdef(nid_day, "solldown", "Down. IR rad. at surface", 
      .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "sens", "Sensible heat flux", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "SWdnSFC", "SWdn at surface","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
+     .                32, "ave(X)", zstophy,zout)
+c
+cIM diagnostiques flux ocean-atm ou ocean-glace de mer
+cIM pour utilisation dans un modele de "slab" ocean
+c
+         IF (OCEAN.EQ.'force ') THEN
+c
+          CALL histdef(nid_day, "lmt_bils", 
+     .         "Bilan au sol atmosphere forcee", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         ELSE IF (OCEAN.EQ.'slab  ') THEN
+c
+          CALL histdef(nid_day, "slab_bils",
+     .                "Bilan au sol slab", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_day, "tslab", "Slab SST ", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_day, "seaice", "Slab seaice", "kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_day, "siceh", "Slab seaice height", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         ENDIF !OCEAN.EQ.force/slab
+c
+         CALL histdef(nid_day, "fluxo",
+     .                "Flux turbulents ocean-atmosphere", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "fluxg",
+     .                "Flux ocean-glace de mer", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
 c
       ENDIF !lev_histday.GE.1
@@ -234,9 +293,9 @@
          CALL histdef(nid_day, "bils", "Surf. total heat flux", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "fder", "Heat flux derivation", "W/m2/K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
       ENDIF !lev_histday.GE.2
@@ -252,29 +311,29 @@
          CALL histdef(nid_day, "temp", "Air temperature", "K",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "ovap", "Specific humidity", "kg/kg",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "geop", "Geopotential height", "m",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "geop", "Geopotential height", "m2/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "vitu", "Zonal wind", "m/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "vitv", "Meridional wind", "m/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "vitw", "Vertical wind", "Pa/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "vitw", "Vertical wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "pres", "Air pressure", "Pa",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
 c=================================================================
@@ -292,33 +351,33 @@
          CALL histdef(nid_day, "SWupTOA", "SWup at TOA","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "SWupSFC", "SWup at surface","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "SWdnTOA", "SWdn at TOA","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "SWupTOAclr",
      .                "SWup clear sky at TOA","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
+     .                32, "ave(X)", zstophy,zout)
 
          CALL histdef(nid_day, "SWupSFCclr",
      .                "SWup clear sky at surface","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
+     .                32, "ave(X)", zstophy,zout)
 
          CALL histdef(nid_day, "SWdnTOAclr",
      .                "SWdn clear sky at TOA","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
+     .                32, "ave(X)", zstophy,zout)
 
          CALL histdef(nid_day, "SWdnSFCclr",
      .                "SWdn clear sky at surface","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
 c=================================================================
@@ -328,119 +387,124 @@
 c=================================================================
 c
-         CALL histdef(nid_day, "tter", "Surface Temperature", "K",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "tlic", "Surface Temperature", "K",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "toce", "Surface Temperature", "K",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "tsic", "Surface Temperature", "K",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "t2mter", "Temp.terre 2m", "K",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+         CALL histdef(nid_day, "tter", "Surface Temperature ter", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "tlic", "Surface Temperature lic", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "toce", "Surface Temperature oce", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "tsic", "Surface Temperature sic", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "t2mter", "Temp.tere 2m", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "t2mlic", "Temp.lic 2m", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "t2moce", "Temp.oce 2m", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "t2msic", "Temp.sic 2m", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "t2mter_min", "Temp.terre 2m min.",
      .                "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                t2mincels, zsto,zout)
+     .                t2mincels, zstophy,zout)
 c
          CALL histdef(nid_day, "t2mter_max", "Temp.terre 2m max.",
      .                "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                t2maxcels, zsto,zout)
+     .                t2maxcels, zstophy,zout)
 c
          CALL histdef(nid_day, "u10mter", "Vent zonal ter 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "u10mlic", "Vent zonal lic 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "u10moce", "Vent zonal oce 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "u10msic", "Vent zonal sic 10m",
      .                 "m/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "v10mter", "Vent meridien ter 10m", 
      .                "m/s", iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "v10mlic", "Vent meridien lic 10m",
      .                 "m/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "v10moce", "Vent meridien oce 10m",
      .                 "m/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_day, "v10msic", "Vent meridien sic 10m",
      .                 "m/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          DO nsrf = 1, nbsrf
 C
            call histdef(nid_day, "pourc_"//clnsurf(nsrf), 
-     $         "Fraction"//clnsurf(nsrf), "W/m2",  
-     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "% "//clnsurf(nsrf), "%",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+C
+           call histdef(nid_day, "fract_"//clnsurf(nsrf), 
+     $         "Fraction "//clnsurf(nsrf), "1",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
 C
            call histdef(nid_day, "tsol_"//clnsurf(nsrf), 
-     $         "Fraction"//clnsurf(nsrf), "W/m2",  
-     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "Temperature "//clnsurf(nsrf), "K",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
 C
            call histdef(nid_day, "sens_"//clnsurf(nsrf), 
      $         "Sensible heat flux "//clnsurf(nsrf), "W/m2",  
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "ave(X)", zstophy,zout)
 c
            call histdef(nid_day, "lat_"//clnsurf(nsrf), 
      $         "Latent heat flux "//clnsurf(nsrf), "W/m2",  
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "ave(X)", zstophy,zout)
 C
            call histdef(nid_day, "taux_"//clnsurf(nsrf), 
-     $         "Zonal wind stress"//clnsurf(nsrf),"Pa",
-     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "Zonal wind stress "//clnsurf(nsrf),"Pa",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
 
            call histdef(nid_day, "tauy_"//clnsurf(nsrf), 
-     $         "Meridional xind stress "//clnsurf(nsrf), "Pa",  
-     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "Meridional wind stress "//clnsurf(nsrf), "Pa",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
 C
            call histdef(nid_day, "albe_"//clnsurf(nsrf), 
-     $         "Albedo surf. "//clnsurf(nsrf), "W/m2",  
-     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "Albedo surf. "//clnsurf(nsrf), "-",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
 C
            call histdef(nid_day, "rugs_"//clnsurf(nsrf), 
-     $         "Latent heat flux "//clnsurf(nsrf), "W/m2",  
-     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "Rugosite "//clnsurf(nsrf), "m",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
 C
          END DO 
@@ -452,4 +516,68 @@
 c=================================================================
       ENDIF !lev_histday.GE.4
+c
+      IF(lev_histday.GE.5) THEN !lev_histday.GE.5
+c
+c rajout sorties F. Aires
+         CALL histdef(nid_day, "tops0", "CS Solar rad. at TOA", 
+     .                "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "topl0", "CS IR rad. at TOA", 
+     .                "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "sols0", "CS Net Solar rad. at surf.", 
+     .                "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "soll0", "CS Net IR rad. at surface", 
+     .                "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "rneb", "Cloud fraction", "-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day, "rnebcon", "Convective Cloud Fraction"
+     .                , "-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day,"lwcon","Cloud liquid water content",
+     .                "kg/kg",
+     .                iim,jjmp1,nhori, klev,1,klev, nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_day,"iwcon","Cloud ice water content","kg/kg",
+     .                iim,jjmp1,nhori, klev,1,klev, nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day,"lwp","Cloud water path","kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day,"iwp","Cloud ice water path","kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_day,"meantaucld",
+     .                "ISCCP mean cloud optical thickness","1",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_day,"cldtau","Cloud optical thickness","1",
+     .                iim,jjmp1,nhori, klev,1,klev, nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_day,"cldemi","Cloud optical emissivity","1",
+     .                iim,jjmp1,nhori, klev,1,klev, nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+      ENDIF !lev_histday.GE.5
 c=================================================================
 c
Index: /LMDZ4/trunk/libf/phylmd/ini_histday_seri.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_histday_seri.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/ini_histday_seri.h	(revision 644)
@@ -0,0 +1,126 @@
+c
+c $Header$
+c
+      IF (type_run.EQ."AMIP") THEN
+c
+       zstophy = dtime
+       zout = dtime * FLOAT(ecrit_day)
+c
+         idayref = day_ref
+         CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
+c
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon,zx_lon)
+         DO i = 1, iim
+            zx_lon(i,1) = rlon(i+1)
+            zx_lon(i,jjmp1) = rlon(i+1)
+         ENDDO
+         DO ll=1,klev
+            znivsig(ll)=float(ll)
+         ENDDO
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
+c
+         imin_debut=1 
+         nbpti=1
+         jmin_debut=1 
+         nbptj=1
+c
+         CALL histbeg("histday_seri.nc", 
+     .                 iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
+     .                 imin_debut,nbpti,jmin_debut,nbptj,
+     .                 itau_phy, zjulian, dtime,
+     .                 nhori, nid_day_seri)
+c
+         CALL histvert(nid_day_seri, "presnivs", 
+     .                "Vertical levels","mb",
+     .                 klev, presnivs/100., nvert)
+c
+         CALL histdef(nid_day_seri, "bilTOA", 
+     .                "Net radiation at model top", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day_seri, "bils", 
+     .                "Net downward energy flux at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day_seri, "ecin", 
+     .                "Total kinetic energy (per unit area)","J/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+cIM 151004 BEG
+         IF(1.EQ.0) THEN
+c
+         CALL histdef(nid_day_seri, "momang", 
+     .               "Total relative angular momentum (per unit area)",
+     .               "kg/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day_seri, "frictor", 
+     .               "Friction torque (per unit area)", "N/m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day_seri, "mountor", 
+     .               "Mountain torque (per unit area)", "N/m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         ENDIF !(1.EQ.0) THEN
+c
+         CALL histdef(nid_day_seri, "momang", 
+     .               "Axial angular momentum (per unit area)",
+     .               "kg/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day_seri, "torsfc", 
+     .        "Total surface torque (including mountain torque)", "N/m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+cIM 151004 END        
+c
+         CALL histdef(nid_day_seri, "tamv", 
+     .                "Temperature (mass-weighted vert. ave)", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day_seri, "psol", 
+     .                "Surface pressure", "Pa",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_day_seri, "evap", 
+     .                "Evaporation and sublimation (per unit area)", 
+     .                "kg/(m2*s)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+c          call histdef(nid_day_seri, 
+c    .         "SnowFrac", 
+c    .         "Snow-covered area ", "%",  
+c    .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+c    .         "ave(X)", zstophy,zout)
+c
+c        CALL histdef(nid_day_seri, "snow_depth", 
+cIM 080904  .                "Snow Depth (water equivalent)", "m",
+cIM 191104  .                "Snow Depth (water equivalent)", "kg/m2",
+c    .                "Snow Mass", "kg/m2",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+c    .               "ave(X)", zstophy,zout)
+c
+           call histdef(nid_day_seri, 
+     .         "tsol_"//clnsurf(is_oce), 
+     .         "SST over open (ice-free) ocean ", "K",  
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "ave(X)", zstophy,zout)
+c
+c=================================================================
+c
+         CALL histend(nid_day_seri)
+c
+c=================================================================
+      ENDIF ! fin de test sur type_run.EQ.AMIP
Index: /LMDZ4/trunk/libf/phylmd/ini_histhf.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_histhf.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/ini_histhf.h	(revision 644)
@@ -5,8 +5,8 @@
       IF (ok_hf) THEN
 c
-        zout = dtime * REAL(NINT(86400./dtime*ecrit_hf))
-        zsto = zout
-        zsto1 = dtime
-        PRINT*, 'La frequence de sortie instant. est de ', ecrit_hf
+       zstohf = dtime * FLOAT(ecrit_hf)
+       zstophy = dtime
+       zstoday = dtime * FLOAT(ecrit_day)
+       zout = dtime * FLOAT(ecrit_hf)
 c
          idayref = day_ref
@@ -21,6 +21,4 @@
 
          CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
-
-cccIM      CALL histbeg("histhf", iim,zx_lon, jjmp1,zx_lat,
          CALL histbeg("histhf", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
      .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime, 
@@ -28,28 +26,22 @@
 
          CALL histvert(nid_hf, "presnivs", "Vertical levels", "mb",
-     .                 klev, presnivs, nvert)
-c
-
+     .                 klev, presnivs/100., nvert)
+c
+
+      IF(type_run.EQ."CLIM".OR.type_run.EQ."ENSP") THEN
+c
       IF(lev_histhf.GE.1) THEN
 c
-c        CALL histdef(nid_hf, "phis", "Surface geop. height", "-",
-c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-c    .                "once", zsto,zout)
-c
-c        CALL histdef(nid_hf, "aire", "Grid area", "-",
-c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-c    .                "once", zsto,zout)
-c
          CALL histdef(nid_hf, "aireTER","Grid area CONT","-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "once", zsto,zout)
+     .                "once", zstohf,zout)
 c
          CALL histdef(nid_hf, "contfracATM","% sfce ter+lic ","-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "once", zsto,zout)
+     .                "once", zstohf,zout)
 c
          CALL histdef(nid_hf, "contfracOR","% sfce terre OR", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "once", zsto,zout)
+     .                "once", zstohf,zout)
 c
 c Champs 2D:
@@ -57,51 +49,58 @@
          CALL histdef(nid_hf, "t2m", "Temperature 2m", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "q2m", "Specific humidity", "kg/kg",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "psol", "Surface Pressure", "Pa",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
-c
-         print*,'ATTENTION METTRE AVE(X) POUR LES PRECIPS'
-
-         CALL histdef(nid_hf, "rain", "Precipitation", "kg/m^2s",
+     .                "inst(X)", zstohf,zout)
+c
+         CALL histdef(nid_hf, "precip", "Precipitation", "kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto1,zout)
+     .                "ave(X)", zstophy,zout)
 c
 cIM ENSEMBLES BEG
-c
          CALL histdef(nid_hf, "tsol", "Surface Temperature", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "slp", "Sea Level Pressure", "Pa",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "u10m", "Vent zonal 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "v10m", "Vent meridien 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
+     .                "inst(X)", zstohf,zout)
 c
          CALL histdef(nid_hf, "wind10m","10-m wind speed","m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-         DO k=1, nlevENS 
-          IF(clev(k).EQ."500") THEN
-          CALL histdef(nid_hf, "phi"//clev(k),
-     .                "Geopotential"//clev(k)//"mb", "m2/s2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-          ENDIF !clev(k).EQ."500"
-         ENDDO !k=1, nlevENS
+     .                "inst(X)", zstohf,zout)
+c
+         DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+          IF(bb2.EQ."500") THEN
+          CALL histdef(nid_hf, "phi"//bb2,
+     .                "Geopotential "//bb2//"mb", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
+          ENDIF !bb2.EQ."500"
+         ENDDO !k=1, nlevSTD
 c
       ENDIF !lev_histhf.GE.1
@@ -109,24 +108,22 @@
       IF(lev_histhf.GE.2) THEN
 c
-         CALL histdef(nid_hf, "cldt", "Total cloudiness", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto1,zout)
-c
-c -- LOOP
+         CALL histdef(nid_hf, "cldt", "Total cloudiness", "%",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_hf, "SWnetOR",
+     .                "Sfce net SW radiation OR", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
          CALL histdef(nid_hf, "SWdownOR",
-     .                "Sfce incident SW down radiation OR", "W/m^2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto1,zout)
-c
-         CALL histdef(nid_hf, "SWnetOR",
-     .                "Sfce incident SW net radiation OR", "W/m^2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto1,zout)
-c -- LOOP
+     .                "Sfce incident SW radiation OR", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_hf, "LWdownOR",
-     .                "Sfce incident LW radiation OR", "W/m^2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto1,zout)
+     .                "Sfce incident LW radiation OR", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
       ENDIF !lev_histhf.GE.2
 c
@@ -135,54 +132,56 @@
       IF(lev_histhf.GE.3) THEN
 c
-         DO k=1, nlevENS
-c
-          CALL histdef(nid_hf, "t"//clev(k),
-     .                 "Temperature"//clev(k)//"mb","K",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-          IF(clev(k).NE."500") THEN
-          CALL histdef(nid_hf, "phi"//clev(k), 
-     .                "Geopotential"//clev(k)//"mb", "m2/s2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
+         DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+         IF(bb2.EQ."850".or.bb2.EQ."700".OR.
+     $      bb2.EQ."500".or.bb2.EQ."200") THEN
+c
+          CALL histdef(nid_hf, "t"//bb2,
+     .                 "Temperature "//bb2//"mb","K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
+c
+          IF(bb2.NE."500") THEN
+          CALL histdef(nid_hf, "phi"//bb2, 
+     .                "Geopotential "//bb2//"mb", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
           ENDIF
 c
-          CALL histdef(nid_hf, "q"//clev(k),
-     .                 "Specific humidity"//clev(k)//"mb","kg/kg",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-         IF(1.EQ.0) THEN
-         CALL histdef(nid_hf, "rh"//clev(k),
-     .                 "Relative humidity"//clev(k)//"mb", "%",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-         ENDIF
-c
-          CALL histdef(nid_hf, "u"//clev(k),
-     .                 "Zonal wind"//clev(k)//"mb","m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-          CALL histdef(nid_hf, "v"//clev(k),
-     .                 "Meridional wind"//clev(k)//"mb","m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-         ENDDO !nlevENS
-         IF(1.EQ.0) THEN
-         CALL histdef(nid_hf, "cdrm", " Momentum drag coef.", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-c
-         CALL histdef(nid_hf, "cdrh", "Heat drag coef.", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-         ENDIF !(1.EQ.0) THEN
+          CALL histdef(nid_hf, "q"//bb2,
+     .                 "Specific humidity "//bb2//"mb","kg/kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
+c
+          CALL histdef(nid_hf, "u"//bb2,
+     .                 "Zonal wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
+c
+          CALL histdef(nid_hf, "v"//bb2,
+     .                 "Meridional wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zout)
+c
+         ENDIF !IF(bb2.EQ."850".or.bb2.EQ."700".OR.
+c
+         ENDDO !nlevSTD
 c
       ENDIF !lev_histhf.GE.3
 c
       IF(lev_histhf.GE.4) THEN
+c
+cIM sorties hf 3D
+c
+#undef histhf3d
 #define histhf3d
 #ifdef histhf3d
@@ -191,10 +190,206 @@
       ENDIF !lev_histhf.GE.4
 c
-c#define histhf3d
-c#ifdef histhf3d
-c#include "ini_histhf3d.h"
-c#endif
-c
-         CALL histend(nid_hf)
-c
-      endif ! ok_hf
+      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
+c
+      IF(lev_histhf.GE.1) THEN
+c
+        DO k=1, nlevSTD 
+c
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+         IF(bb2.EQ."850".or.bb2.EQ."200") THEN
+c
+          CALL histdef(nid_hf, "u"//bb2,
+     .                 "Zonal wind "//bb2//"mb","m/s",
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "inst(X)", zstohf,zstohf)
+c
+          CALL histdef(nid_hf, "v"//bb2,
+     .                 "Meridional wind "//bb2//"mb","m/s",
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "inst(X)", zstohf,zstohf)
+c
+         ENDIF !bb2.EQ."850".or.bb2.EQ."200"
+        ENDDO !k=1, nlevSTD
+c
+        CALL histdef(nid_hf, "topl", 
+     .       "Outgoing longwave radiation", "W/m2",
+     .       iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .       "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_hf, "precip","Total precipitation rate",
+     .       "kg/(s*m2)",iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .       "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_hf, "slp", 
+     .       "Mean sea-level pressure", "Pa",
+     .       iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .       "inst(X)", zstohf,zout)
+c
+cIM 280504 BEG
+      ENDIF !(lev_histhf.GE.1) THEN
+c
+      IF(lev_histhf.GE.2) THEN
+c
+        DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+         IF(bb2.EQ."850".OR.bb2.EQ."500") THEN
+c
+          CALL histdef(nid_hf, "t"//bb2,
+     .                 "Temperature "//bb2//"mb","K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zstohf)
+c
+          CALL histdef(nid_hf, "q"//bb2,
+     .                 "Specific humidity "//bb2//"mb","kg/kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zstohf)
+c
+         ENDIF !bb2
+c
+         IF(bb2.EQ."500") THEN
+c
+          CALL histdef(nid_hf, "phi"//bb2,
+     .                "Geopotential "//bb2//"mb", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zstohf)
+c
+          CALL histdef(nid_hf, "w"//bb2,
+     .                 "Vertical motion "//bb2//"mb","Pa/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zstohf)
+         ENDIF !bb2.EQ."500"
+c
+         IF(bb3.EQ."50") THEN
+c
+          CALL histdef(nid_hf, "t"//bb3,
+     .                 "Temperature "//bb3//"mb","K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zstohf,zstohf)
+c
+          CALL histdef(nid_hf, "u"//bb3,
+     .                 "Zonal wind "//bb3//"mb","m/s",
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "inst(X)", zstohf,zstohf)
+c
+          CALL histdef(nid_hf, "v"//bb3,
+     .                 "Meridional wind "//bb3//"mb","m/s",
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "inst(X)", zstohf,zstohf)
+c
+         ENDIF !bb3
+c
+        ENDDO !k=1, nlevSTD
+c
+        CALL histdef(nid_hf, "u10m", "Vent zonal 10m", "m/s",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .               "inst(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "v10m", "Vent meridien 10m", "m/s",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .               "inst(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "t2m", "Temperature 2m", "K",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .               "inst(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "q2m", "Specific humidity", "kg/kg",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .               "inst(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "psol", "Surface Pressure", "Pa",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .               "inst(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "cldt", "Total cloudiness", "%",
+     .               iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .               "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "taux",
+     $         "Zonal wind stress","Pa",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "tauy",
+     $         "Meridional wind stress ", "Pa",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "prw", "Precipitable water", "kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+cIM 090904  .                "ave(X)", zstohf,zout)
+     .                "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_hf, "sens", "Sensible heat flux", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+cIM 090904  .                "ave(X)", zstohf,zout)
+     .                "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_hf, "flat", "Latent heat flux", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstohf,zout)
+c
+c       CALL histdef(nid_hf, "snow_mass", "Snow Mass", "kg/m2",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+c    .                "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "SWdnSFC", "SWdn at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "SWupSFC", "SWup at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf,"LWdnSFC","Down. IR rad. at surface",
+     .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf,"LWupSFC","Upwd. IR rad. at surface",
+     .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "SWdnTOA", "SWdn at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstohf,zout)
+c
+        CALL histdef(nid_hf, "SWupTOA", "SWup at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstohf,zout)
+c
+        DO k=1, nbteta
+         CALL histdef(nid_hf, "PV"//ctetaSTD(k),
+     $               "Vorticite potentielle "//ctetaSTD(k)//"K",
+     $               "1/(Pa*s)",iim,jjmp1,nhori, 1,1,1, -99,
+     $                 32, "inst(X)", zstohf,zout) 
+        ENDDO !k=1, nbteta
+c
+c planetary boundary layer height
+c
+c       ENDIF !1.EQ.0
+c
+      ENDIF !(lev_histhf.GE.2) THEN
+cIM 280504 END
+c
+      ENDIF !type_run
+c
+      CALL histend(nid_hf)
+c
+      ENDIF ! ok_hf
Index: /LMDZ4/trunk/libf/phylmd/ini_histhf3d.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_histhf3d.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/ini_histhf3d.h	(revision 644)
@@ -1,63 +1,51 @@
-!
-! $Header$
-!
-
-c     IF (ok_hf) THEN
 c
-        zout = dtime * REAL(NINT(86400./dtime*ecrit_hf))
-        zsto = zout
-        zsto1 = dtime
-        PRINT*, 'La frequence de sortie instant. est de ', ecrit_hf
+c $Header$
 c
-cIM cf LF
-         idayref = day_ref
-         CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
-
-cccIM    CALL ymds2ju(anne_ini, 1, 1, 0.0, zjulian)
-c        CALL ymds2ju(annee_ref, 1, 1, 0.0, zjulian)
-c        zjulian = zjulian + day_ini
-cIM cf LF
-
+c sorties hf 3d
 c
-         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon,zx_lon)
-         DO i = 1, iim
-            zx_lon(i,1) = rlon(i+1)
-            zx_lon(i,jjmp1) = rlon(i+1)
-         ENDDO
-
-         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
-
-cccIM      CALL histbeg("histhf", iim,zx_lon, jjmp1,zx_lat,
-         CALL histbeg("histhf3d", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
+cIM 130904     zstohf = dtime * REAL(NINT(86400./dtime*ecrit_hf))
+cIM 130904     zout = dtime * REAL(NINT(86400./dtime*ecrit_hf))
+cIM     zstohf = dtime * FLOAT(ecrit_hf)
+cIM     zout = dtime * FLOAT(ecrit_hf)
+        zstohf = dtime * FLOAT(ecrit_hf)
+        zout = dtime * FLOAT(ecrit_hf)
+c
+c       PRINT*, 'La frequence de sortie hf3d est de ', ecrit_hf
+c
+        idayref = day_ref
+        CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
+c
+        CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon,zx_lon)
+        DO i = 1, iim
+         zx_lon(i,1) = rlon(i+1)
+         zx_lon(i,jjmp1) = rlon(i+1)
+        ENDDO
+c
+        CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
+        CALL histbeg("histhf3d", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
      .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime, 
      .                 nhori, nid_hf3d)
-
-         CALL histvert(nid_hf3d, "presnivs", "Vertical levels", "mb",
-     .                 klev, presnivs, nvert)
 c
-
-c     IF(lev_histhf.GE.4) THEN
+        CALL histvert(nid_hf3d, "presnivs", "Vertical levels", "mb",
+     .                 klev, presnivs/100., nvert)
 c
 c Champs 3D:
 c
-         CALL histdef(nid_hf3d, "temp", "Air temperature", "K",
+        CALL histdef(nid_hf3d, "temp", "Air temperature", "K",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstohf,zout)
 c
-         CALL histdef(nid_hf3d, "ovap", "Specific humidity", "kg/kg",
+        CALL histdef(nid_hf3d, "ovap", "Specific humidity", "kg/kg",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstohf,zout)
 c
-         CALL histdef(nid_hf3d, "vitu", "Zonal wind", "m/s",
+        CALL histdef(nid_hf3d, "vitu", "Zonal wind", "m/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstohf,zout)
 c
-         CALL histdef(nid_hf3d, "vitv", "Meridional wind", "m/s",
+        CALL histdef(nid_hf3d, "vitv", "Meridional wind", "m/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstohf,zout)
 c
-c     ENDIF
+        CALL histend(nid_hf3d)
 c
-         CALL histend(nid_hf3d)
-c
-c     endif ! ok_hf
Index: /LMDZ4/trunk/libf/phylmd/ini_histins.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_histins.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/ini_histins.h	(revision 644)
@@ -24,5 +24,6 @@
          write(*,*)'Inst ', itau_phy, zjulian
          CALL histvert(nid_ins, "presnivs", "Vertical levels", "mb",
-     .                 klev, presnivs, nvert)
+cIM    .                 klev, presnivs, nvert)
+     .                 klev, presnivs/100., nvert)
 c        call histvert(nid_ins, 'sig_s', 'Niveaux sigma','-',
 c    .              klev, znivsig, nvert)
@@ -88,7 +89,7 @@
      .                "inst(X)", zsto,zout)
 c
-         CALL histdef(nid_ins, "snow_mass", "Snow Mass", "kg/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
+c        CALL histdef(nid_ins, "snow_mass", "Snow Mass", "kg/m2",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+c    .                "inst(X)", zsto,zout)
 c
          CALL histdef(nid_ins, "topl", "OLR", "W/m2",
@@ -143,5 +144,10 @@
 C
            call histdef(nid_ins, "pourc_"//clnsurf(nsrf), 
-     $         "Fraction"//clnsurf(nsrf), "W/m2",  
+     $         "% "//clnsurf(nsrf), "%",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "inst(X)", zsto,zout)
+
+           call histdef(nid_ins, "fract_"//clnsurf(nsrf), 
+     $         "Fraction "//clnsurf(nsrf), "1",  
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
      $         "inst(X)", zsto,zout)
@@ -196,4 +202,51 @@
 c
 c
+cIM cf. AM 081204 BEG
+c HBTM2
+         CALL histdef(nid_ins, "s_pblh", "Boundary Layer Height", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_ins, "s_pblt", "T at Boundary Layer Height", 
+     .                "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_ins, "s_lcl", "Condensation level", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_ins, "s_capCL", "Conv avlbl pot ener for 
+     .                ABL", "J/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_ins, "s_oliqCL", "Liq Water in BL", "kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_ins, "s_cteiCL", "Instability criteria 
+     .                (ABL)", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_ins, "s_therm", "Exces du thermique", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_ins, "s_trmb1", "deep_cape(HBTM2)", "J/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_ins, "s_trmb2", "inhibition (HBTM2)", "J/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_ins, "s_trmb3", "Point Omega (HBTM2)", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+cIM cf. AM 081204 END
+c
 c Champs 3D:
 c
Index: /LMDZ4/trunk/libf/phylmd/ini_histmth.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_histmth.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/ini_histmth.h	(revision 644)
@@ -1,15 +1,15 @@
-!
-! $Header$
-!
+c
+c $Header$
+c
       IF (ok_mensuel) THEN
 c
-         zsto = dtime
-         zout = dtime * ecrit_mth
-c
-c zsto1: pour des valeurs "instantannees" mensuelles
-         zsto1 = dtime * ecrit_mth
-c zsto2: pour des flux radiatifs calcules tous les 2 heures
-         zsto2 = dtime * radpas
-         PRINT*,' zsto,zsto1,zsto2,zout=',zsto, zsto1, zsto2,zout
+       zstophy = dtime
+       zstomth = dtime * FLOAT(ecrit_mth) !valeurs mensuelles "instantannees"
+       zstorad = dtime * FLOAT(radpas)    !variables stockees toutes les 2h
+       zstohf = dtime *FLOAT(ecrit_hf)   !variables stockees toutes les 6h
+       zout = dtime * FLOAT(ecrit_mth)    !frequence des sorties : 1 val. par mois
+c
+cIM    PRINT*,' La zstophy,zstorad,zstohf,zstomth,zout=',
+cIM  . zstophy,zstorad,zstohf,zstomth,zout
 c
          idayref = day_ref
@@ -21,4 +21,26 @@
             zx_lon(i,jjmp1) = rlon(i+1)
          ENDDO
+c
+cIM cf. AM 081204 BEG region
+c         imin_histmth=1
+c         imax_histmth=iim
+c         jmin_histmth=1
+c         jmax_histmth=jjmp1
+c         do i=1,iim-1
+c            if(zx_lon(i,1).lt.lonmin_histmth) imin_histmth=i
+c            if(zx_lon(i,1).le.lonmax_histmth) imax_histmth=i+1
+c         enddo
+c         do j=1,jjmp1-1
+c            if(zx_lat(1,j).ge.latmin_histmth) jmax_histmth=j
+c            if(zx_lat(1,j).gt.latmax_histmth) jmin_histmth=j
+c         enddo
+c
+c         print*,'On stoke le fichier instantanne sur, ',
+c     s   imin_histmth,imax_histmth,jmin_histmth,jmax_histmth
+c         print*,'On stoke le fichier instantanne sur, ',
+c     s   zx_lon(imin_histmth,1),zx_lon(imax_histmth,1),
+c     s   zx_lat(1,jmin_histmth),zx_lat(1,jmax_histmth)
+cIM cf. AM 081204 END region
+c
          DO ll=1,klev
             znivsig(ll)=float(ll)
@@ -28,24 +50,38 @@
      .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime, 
      .                 nhori, nid_mth)
-         write(*,*)'Mensuel ', itau_phy, zjulian
+c
+cIM cf. AM 081204 BEG region
+c         CALL histbeg("histmth.nc", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
+c     .                 imin_histmth,imax_histmth-imin_histmth+1
+c     .                 ,jmin_histmth,jmax_histmth-jmin_histmth+1
+c     .                 , itau_phy, zjulian, dtime,
+c     .                 nhori, nid_mth)
+cIM 081204 END
+c
          CALL histvert(nid_mth, "presnivs", "Vertical levels", "mb",
-     .                 klev, presnivs, nvert)
-c        call histvert(nid_mth, 'sig_s', 'Niveaux sigma','-',
-c    .              klev, znivsig, nvert)
-c
+     .                 klev, presnivs/100., nvert)
+c
+      IF(type_run.EQ."CLIM".OR.type_run.EQ."ENSP") THEN
 c
       IF(lev_histmth.GE.1) THEN
-         CALL histdef(nid_mth, "phis", "Surface geop. height", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "once",  zsto,zout)
+c
+         CALL histdef(nid_mth, "phis", 
+     .                "Surface geop. height", "m2/s2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "once",  zstophy,zout)
 c
          CALL histdef(nid_mth, "aire", "Grid area", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "once",  zsto,zout)
-c
-           call histdef(nid_mth, "pourc_"//clnsurf(is_ter), 
-     $         "Fraction "//clnsurf(is_ter), "W/m2",  
-     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "once", zsto,zout)
+     .                "once",  zstophy,zout)
+c
+         CALL histdef(nid_mth, "pourc_"//clnsurf(is_ter), 
+     .         "% "//clnsurf(is_ter), "%",  
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "once", zstophy,zout)
+c
+         CALL histdef(nid_mth, "fract_"//clnsurf(is_ter), 
+     .         "Fraction "//clnsurf(is_ter), "1",  
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "once", zstophy,zout)
 c
 c Champs 2D:
@@ -53,63 +89,63 @@
          CALL histdef(nid_mth, "slp", "Sea Level Pressure", "Pa",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "tsol", "Surface Temperature", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "t2m", "Temperature 2m", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
 c ENSEMBLES BEG
          CALL histdef(nid_mth, "t2m_min", "Temp. 2m min.",
      .                "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                t2mincels, zsto,zout)
+     .                t2mincels, zstophy,zout)
 c
          CALL histdef(nid_mth, "t2m_max", "Temp. 2m max.",
      .                "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                t2maxcels, zsto,zout)
+     .                t2maxcels, zstophy,zout)
 c
 c        CALL histdef(nid_mth, "tsoil", "Sfce soil Temperature",
 c    .                "K",
 c    .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-c    .                "ave(X)", zsto,zout)
+c    .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "wind10m","10-m wind speed","m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "sicf", "Sea-ice fraction", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-
+     .                "ave(X)", zstophy,zout)
 c
 c ENSEMBLES END
          CALL histdef(nid_mth, "q2m", "Specific humidity 2m", "kg/kg",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "u10m", "Vent zonal 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "v10m", "Vent meridien 10m", "m/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "psol", "Surface Pressure", "Pa",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "qsurf", "Surface Air humidity", "kg/kg",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
       if (.not. ok_veget) then
          CALL histdef(nid_mth, "qsol", "Soil watter content", "mm",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
       endif
 c
@@ -117,256 +153,254 @@
      .                "Number of day with rain (liq+sol)", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto1,zout)
+     .                "inst(X)", zstomth,zout)
 c
          CALL histdef(nid_mth, "precip", "Precipitation Totale liq+sol", 
      .                "kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "plul", "Large-scale Precip.", 
      .   "kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "pluc", "Convective Precip.", 
      .   "kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "snow", "Snow fall", "kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "snow_mass", "Snow Mass", "kg/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+c        CALL histdef(nid_mth, "snow_mass", "Snow Mass", "kg/m2",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+c    .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "evap", "Evaporation", "kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "tops", "Solar rad. at TOA", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "tops0", "Solar rad. at TOA", "W/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "tops0", "CS Solar rad. at TOA", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "topl", "IR rad. at TOA", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "topl0", "IR rad. at TOA", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "SWupTOA", "SWup at TOA","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "SWupTOAclr", 
      .                "SWup clear sky at TOA","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "SWdnTOA", "SWdn at TOA","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "SWdnTOAclr", 
      .                "SWdn clear sky at TOA","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
-c
-         CALL histdef(nid_mth, "SWup200", "SWup at 200hPa","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWup200", "SWup at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "SWup200clr", 
-     .                "SWup clear sky at 200hPa","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
-c
-         CALL histdef(nid_mth, "SWdn200", "SWdn at 200hPa","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                "SWup clear sky at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWdn200", "SWdn at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "SWdn200clr", 
-     .                "SWdn clear sky at 200hPa","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
-c
-         CALL histdef(nid_mth, "LWup200", "LWup at 200hPa","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                "SWdn clear sky at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "LWup200", "LWup at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "LWup200clr", 
-     .                "LWup clear sky at 200hPa","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
-c
-         CALL histdef(nid_mth, "LWdn200", "LWdn at 200hPa","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                "LWup clear sky at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "LWdn200", "LWdn at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "LWdn200clr", 
-     .                "LWdn clear sky at 200hPa","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                "LWdn clear sky at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "sols", "Solar rad. at surf.", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "sols0", "Solar rad. at surf.", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "soll", "IR rad. at surface", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "soll0", "IR rad. at surface", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "SWupSFC", "SWup at surface","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "SWupSFCclr", 
      .                "SWup clear sky at surface","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "SWdnSFC", "SWdn at surface","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "SWdnSFCclr", 
      .                "SWdn clear sky at surface","W/m2",
      .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto2,zout)
+     .                32, "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth,"LWupSFC","Upwd. IR rad. at surface", 
      .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto2,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth,"LWdnSFC","Down. IR rad. at surface", 
      .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto2,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth,"LWupSFCclr",
      .                "CS Upwd. IR rad. at surface", 
      .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto2,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth,"LWdnSFCclr",
      .                "Down. CS IR rad. at surface", 
      .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto2,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "bils", "Surf. total heat flux", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "sens", "Sensible heat flux", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "fder", "Heat flux derivation", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-c Effets des aerosols
-c
-c     IF (ok_ade.OR.ok_aie) THEN
-         CALL histdef(nid_mth, "topsad", "ADE at TOA", "W/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "solsad", "ADE at sfc", "W/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "topsai", "AIE at TOA", "W/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "solsai", "AIE at sfc", "W/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c     endif
-c
-
+     .                "ave(X)", zstophy,zout)
 c
 c          CALL histdef(nid_mth, "frtu", "Zonal wind stress", "Pa",
 c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-c    .                "ave(X)", zsto,zout)
+c    .                "ave(X)", zstophy,zout)
 c
 c        CALL histdef(nid_mth, "frtv", "Meridional wind stress", "Pa",
 c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-c    .                "ave(X)", zsto,zout)
+c    .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "ffonte","Thermal flux for snow melting",
      .                "W/m2",iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "fqcalving","Ice Calving",
      .                "kg/m2/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-cIM: 171003
+     .                "ave(X)", zstophy,zout)
+c
          DO nsrf = 1, nbsrf
            call histdef(nid_mth, "taux_"//clnsurf(nsrf), 
      $         "Zonal wind stress"//clnsurf(nsrf), "Pa",  
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "ave(X)", zstophy,zout)
 
            call histdef(nid_mth, "tauy_"//clnsurf(nsrf), 
-     $         "Meridional xind stress "//clnsurf(nsrf), "Pa",  
-     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "Meridional wind stress "//clnsurf(nsrf), "Pa",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
          ENDDO
-cIM: 171003
 c
          DO nsrf = 1, nbsrf
 C
-          IF(nsrf.GT.1) THEN
+          IF(nsrf.GT.2) THEN
            call histdef(nid_mth, "pourc_"//clnsurf(nsrf), 
-     $         "Fraction "//clnsurf(nsrf), "W/m2",  
-     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
-          ENDIF !nsrf.GT.1
+     $         "% "//clnsurf(nsrf), "%",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+c
+           call histdef(nid_mth, "fract_"//clnsurf(nsrf), 
+     $         "Fraction "//clnsurf(nsrf), "1",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+          ENDIF !nsrf.GT.2
 C
            call histdef(nid_mth, "tsol_"//clnsurf(nsrf), 
-     $         "Fraction "//clnsurf(nsrf), "W/m2",  
-     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "Temperature "//clnsurf(nsrf), "K",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
 C
            call histdef(nid_mth, "sens_"//clnsurf(nsrf), 
      $         "Sensible heat flux "//clnsurf(nsrf), "W/m2",  
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "ave(X)", zstophy,zout)
 c
            call histdef(nid_mth, "lat_"//clnsurf(nsrf), 
      $         "Latent heat flux "//clnsurf(nsrf), "W/m2",  
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "ave(X)", zstophy,zout)
 C
            call histdef(nid_mth, "flw_"//clnsurf(nsrf),
      $         "LW "//clnsurf(nsrf), "W/m2",
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto2,zout)
+     $         "ave(X)", zstophy,zout)
 c
            call histdef(nid_mth, "fsw_"//clnsurf(nsrf),
      $         "SW "//clnsurf(nsrf), "W/m2",
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto2,zout)
+     $         "ave(X)", zstophy,zout)
 C
            call histdef(nid_mth, "wbils_"//clnsurf(nsrf),
      $         "Bilan sol "//clnsurf(nsrf), "W/m2",
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "ave(X)", zstophy,zout)
+C
+cIM 250105 BEG
+          IF(1.EQ.0) THEN
+C
+           call histdef(nid_mth, "evapour_"//clnsurf(nsrf),
+     $         "Evap*pourc "//clnsurf(nsrf), "kg/(s*m2)",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+C
+           call histdef(nid_mth, "prepour_"//clnsurf(nsrf),
+     $         "Precip*pourc "//clnsurf(nsrf), "kg/(s*m2)",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+C
+          ENDIF !(1.EQ.0) THEN
+cIM 250105 END
 C
          END DO
@@ -374,54 +408,53 @@
          CALL histdef(nid_mth, "cdrm", "Momentum drag coef.", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "cdrh", "Heat drag coef.", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "cldl", "Low-level cloudiness", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "cldm", "Mid-level cloudiness", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "cldh", "High-level cloudiness", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "cldt", "Total cloudiness", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth,"cldq","Cloud liquid water path","kg/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-cIM: 071003
+     .                "ave(X)", zstophy,zout)
+c
          CALL histdef(nid_mth,"lwp","Cloud water path","kg/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth,"iwp","Cloud ice water path","kg/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-cIM: 071003
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "ue", "Zonal energy transport", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "ve", "Merid energy transport", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "uq", "Zonal humidity transport", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "vq", "Merid humidity transport", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 cKE43
       IF(iflag_con.GE.3) THEN ! sb
@@ -429,49 +462,142 @@
          CALL histdef(nid_mth, "cape", "Conv avlbl pot ener", "J/kg",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "pbase", "Cld base pressure", "hPa",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "ptop", "Cld top pressure", "hPa",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "pbase", "Cld base pressure", "mb",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "ptop", "Cld top pressure", "mb",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "fbase", "Cld base mass flux", "kg/m2/s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "prw", "Precipitable water", "kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
 c
       ENDIF !iflag_con .GE. 3
-c
-         CALL histdef(nid_mth, "prw", "Precipitable water", "kg/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
 c34EK
+cIM cf. AM 081204 BEG
+c34EK
+c HBTM2
+         CALL histdef(nid_mth, "s_pblh", "Boundary Layer Height", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_pblt", "t at Boundary Layer Height",
+     .                "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_lcl", "Condensation level", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_capCL", "Conv avlbl pot ener 
+     .                for ABL", "J/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_oliqCL", "Liq Water in BL", "kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_cteiCL", "Instability criteria 
+     .                (ABL)", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_therm", "Exces du thermique", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_trmb1", "deep_cape(HBTM2)", "J/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_trmb2", "inhibition (HBTM2)", "J/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_trmb3", "Point Omega (HBTM2)", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+cIM cf. AM 081204 END
 c
 c Champs interpolles sur des niveaux de pression
-         DO k=1, nlevENS
-          CALL histdef(nid_mth, "u"//clev(k),
-     .                 "Zonal wind"//clev(k)//"mb","m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-          CALL histdef(nid_mth, "v"//clev(k),
-     .                 "Meridional wind"//clev(k)//"mb","m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-          CALL histdef(nid_mth, "w"//clev(k),
-     .                 "Vertical wind"//clev(k)//"mb","Pa/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-          CALL histdef(nid_mth, "phi"//clev(k),
-     .                 "Geopotential"//clev(k)//"mb","m2/s2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         ENDDO
+         DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+      IF(bb2.EQ."850".OR.bb2.EQ."700".OR.
+     $   bb2.EQ."500".OR.bb2.EQ."200") THEN
+c
+          CALL histdef(nid_mth, "u"//bb2,
+     .                 "Zonal wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+          CALL histdef(nid_mth, "v"//bb2,
+     .                 "Meridional wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+          CALL histdef(nid_mth, "w"//bb2,
+     .                 "Vertical wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+          CALL histdef(nid_mth, "phi"//bb2,
+     .                 "Geopotential "//bb2//"mb","m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+        ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
+       ENDDO
+c
+cIM diagnostiques flux ocean-atm ou ocean-glace de mer
+cIM pour utilisation dans un modele de "slab" ocean
+c
+       CALL histdef(nid_mth, "fluxo",
+     .              "Flux turbulents ocean-atmosphere", "W/m2",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+       CALL histdef(nid_mth, "fluxg",
+     .              "Flux turbulents ocean-glace de mer","W/m2",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+       IF (OCEAN.EQ.'force ') THEN
+c
+        CALL histdef(nid_mth, "lmt_bils",
+     .       "Bilan au sol atmosphere forcee", "W/m2",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+       ELSE IF (OCEAN.EQ.'slab  ') THEN
+c
+        CALL histdef(nid_mth, "slab_bils",
+     .       "Bilan au sol Slab", "W/m2",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_mth, "tslab", "Slab SST ", "K",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_mth, "seaice", "Slab seaice", "kg/m2",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_mth, "siceh", "Slab seaice height", "m",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+       ENDIF
+c
       ENDIF !lev_histmth.GE.1
 c
@@ -481,73 +607,73 @@
 c
 c
-         CALL histdef(nid_mth,"lwcon","Cloud water content","kg/kg",
+         CALL histdef(nid_mth,"lwcon","Cloud liquid water content",
+     .                "kg/kg",
      .                iim,jjmp1,nhori, klev,1,klev, nvert, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth,"iwcon","Cloud ice water content","kg/kg",
      .                iim,jjmp1,nhori, klev,1,klev, nvert, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "temp", "Air temperature", "K",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "ovap", "Specific humidity", "kg/kg",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
 c        CALL histdef(nid_mth,"wvap","Water vapor mixing ratio","kg/kg",
 c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-c    .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "geop", "Geopotential height", "m",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+c    .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "geop", "Geopotential height", "m2/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "vitu", "Zonal wind", "m/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "vitv", "Meridional wind", "m/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "vitw", "Vertical wind", "Pa/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "vitw", "Vertical wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "pres", "Air pressure", "Pa",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
         CALL histdef(nid_mth, "rneb", "Cloud fraction", "-",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "rnebcon", "Convective Cloud Fraction"
      .                , "-",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "rhum", "Relative humidity", "-",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "ozone", "Ozone concentration", "-",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "ozone", "Ozone concentration", "ppmv",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "upwd", "saturated updraft", "kg/m2/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dtphy", "Physics dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "dqphy", "Physics dQ", "kg/kg/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-c#define histmthNMC
-c#ifdef histmthNMC
-c#include "ini_histmthNMC.h"
-c#endif
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqphy", "Physics dQ", "(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
       ENDIF !lev_histmth.GE.2
@@ -560,14 +686,14 @@
      $         "Albedo surf. "//clnsurf(nsrf), "-",  
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "ave(X)", zstophy,zout)
 c
            call histdef(nid_mth, "rugs_"//clnsurf(nsrf), 
      $         "Latent heat flux "//clnsurf(nsrf), "W/m2",  
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "ages_"//clnsurf(nsrf), "Snow age","day",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
 	 ENDDO !nsrf=1, nbsrf
@@ -575,8 +701,8 @@
          CALL histdef(nid_mth, "albs", "Surface albedo", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
          CALL histdef(nid_mth, "albslw", "Surface albedo LW", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
       ENDIF !lev_histmth.GE.3
@@ -588,127 +714,119 @@
      .                , "kg/kg",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-      IF (iflag_con.GE.3) THEN 
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth,"Ma","undilute adiab updraft","kg/m2/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "upwd", "saturated updraft", "kg/m2/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dnwd", "saturated downdraft","kg/m2/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dnwd0", "unsat. downdraft", "kg/m2/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-      ENDIF !iflag_con.GE.3
-c
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dtdyn", "Dynamics dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "dqdyn", "Dynamics dQ", "kg/kg/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqdyn", "Dynamics dQ", "(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dtcon", "Convection dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
 c        CALL histdef(nid_mth, "ducon", "Convection du", "m/s2",
 c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-c    .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "dqcon", "Convection dQ", "kg/kg/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+c    .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqcon", "Convection dQ", "(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dtlsc", "Condensation dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-cIM: 071003
+     .                "ave(X)", zstophy,zout)
+c
          CALL histdef(nid_mth, "dtlschr",
      $       "Large-scale condensational heating rate", "K/s",iim,jjmp1
-     $       ,nhori, klev,1,klev,nvert, 32,"ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "dqlsc", "Condensation dQ", "kg/kg/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     $       ,nhori, klev,1,klev,nvert, 32,"ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqlsc", "Condensation dQ", "(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dtvdf", "Boundary-layer dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "dqvdf", "Boundary-layer dQ", "kg/kg/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqvdf","Boundary-layer dQ","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dteva", "Reevaporation dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "dqeva", "Reevaporation dQ", "kg/kg/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqeva","Reevaporation dQ","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 
          CALL histdef(nid_mth, "ptconv", "POINTS CONVECTIFS"," ",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 
          CALL histdef(nid_mth, "ratqs", "RATQS"," ",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 
 c
          CALL histdef(nid_mth, "dtajs", "Dry adjust. dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 
-         CALL histdef(nid_mth, "dqajs", "Dry adjust. dQ", "kg/kg/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+         CALL histdef(nid_mth,"dqajs","Dry adjust. dQ","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dtswr", "SW radiation dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dtsw0", "CS SW radiation dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dtlwr", "LW radiation dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth,"dtlw0","CS LW radiation dT","K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dtec", "Cinetic dissip dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "duvdf", "Boundary-layer dU", "m/s2",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dvvdf", "Boundary-layer dV", "m/s2",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          IF (ok_orodr) THEN
          CALL histdef(nid_mth, "duoro", "Orography dU", "m/s2",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dvoro", "Orography dV", "m/s2",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          ENDIF
@@ -717,37 +835,22 @@
          CALL histdef(nid_mth, "dulif", "Orography dU", "m/s2",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
 c
          CALL histdef(nid_mth, "dvlif", "Orography dV", "m/s2",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+     .                "ave(X)", zstophy,zout)
          ENDIF
-c
-c Effets des aerosols
-c
-c     IF (ok_ade.OR.ok_aie) THEN
-         CALL histdef(nid_mth, "re", "CDR", "um",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "redenom", "CDR denominator", "-",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "tau", "cloud opt thickness", "-",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "taupi", "cloud opt thickn. (pi)", "-",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c     endif
-c
+C
          if (nqmax.GE.3) THEN
-         DO iq=3,nqmax
-         iiq=niadv(iq)
-         CALL histdef(nid_mth, tnom(iq), ttext(iiq), "-",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
+         DO iq=1,nqmax-2
+         IF (iq.LE.99) THEN
+         WRITE(str2,'(i2.2)') iq
+         CALL histdef(nid_mth, "trac"//str2, "Tracer No."//str2, "-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+         ELSE
+         PRINT*, "Trop de traceurs"
+         CALL abort
+         ENDIF
          ENDDO
          ENDIF
@@ -755,4 +858,903 @@
       ENDIF !lev_histmth.GE.4
 c
+      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
+c
+      IF(lev_histmth.GE.1) THEN
+c
+         CALL histdef(nid_mth, "phis", "Surface geop. height", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "once",  zstophy,zout)
+c
+         CALL histdef(nid_mth, "aire", "Grid area", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "once",  zstophy,zout)
+c
+         CALL histdef(nid_mth, "pourc_"//clnsurf(is_ter), 
+     .         "% "//clnsurf(is_ter), "%",  
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "once", zstophy,zout)
+c
+         CALL histdef(nid_mth, "fract_"//clnsurf(is_ter), 
+     .         "Fraction "//clnsurf(is_ter), "1",  
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "once", zstophy,zout)
+c
+         CALL histdef(nid_mth, "pourc_"//clnsurf(is_lic), 
+     .         "% "//clnsurf(is_lic), "%",  
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "once", zstophy,zout)
+c
+         CALL histdef(nid_mth, "fract_"//clnsurf(is_lic), 
+     .         "Fraction "//clnsurf(is_lic), "1",  
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "once", zstophy,zout)
+c
+         CALL histdef(nid_mth, "pourc_"//clnsurf(is_sic),
+     .         "% "//clnsurf(is_sic), "%",
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "fract_"//clnsurf(is_sic),
+     .         "Fraction "//clnsurf(is_sic), "1",
+     .         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "flat", "Latent heat flux", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "bilTOA",
+     .                "Net radiation at TOA", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+c
+c        CALL histdef(nid_mth, "tops01",
+c    .                "TOA reflected clear-sky shortwave 
+c    .                radiation (method 1)", "W/m2",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+c    .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dtdia","dtdia","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dtsw","dtsw","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dtlw","dtlw","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dtcon","dtcon","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dtajs","dtajs","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dtlsc","dtlsc","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dqdia","dqdia","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "duoli",
+     .         "duoli","m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dvoli",
+     .         "dvoli","m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "ducon",
+     .         "ducon","m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dvcon",
+     .         "dvcon","m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dutot",
+     .         "dutot","m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "dvtot",
+     .         "dvtot","m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+c         CALL histdef(nid_mth, "cldtrue",
+c    .         "TRUE Cloud fraction ","%",
+c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+c    .         "inst(X)", zout,zout)
+c
+c         CALL histdef(nid_mth, "cldTOA",
+c    .         "Cloud amount (satellite view)","%",
+c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+c    .         "ave(X)", zstophy,zout)
+c
+c         CALL histdef(nid_mth, "cldSFC",
+c    .         "Cloud amount (surface view)","%",
+c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+c    .         "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "GWDtaux",
+     .         "GWD induced Ewd wind stress","Pa",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "ave(X)", zstophy,zout)
+c
+          CALL histdef(nid_mth, "GWDtauy",
+     .         "GWD induced Nwd wind stress","Pa",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .         "ave(X)", zstophy,zout)
+c
+c Champs 2D:
+c
+         CALL histdef(nid_mth, "slp", "Sea Level Pressure", "Pa",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstorad,zout)
+c
+         CALL histdef(nid_mth, "tsol", "Surface Temperature", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "t2m", "Temperature 2m", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstorad,zout)
+c
+         CALL histdef(nid_mth, "t2m_min", "Temp. 2m min.",
+     .                "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                t2mincels, zstophy,zout)
+c
+         CALL histdef(nid_mth, "t2m_max", "Temp. 2m max.",
+     .                "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                t2maxcels, zstophy,zout)
+c
+c        CALL histdef(nid_mth, "tsoil", "Sfce soil Temperature",
+c    .                "K",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+c    .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "wind10m","10-m wind speed","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstorad,zout)
+c
+         CALL histdef(nid_mth, "sicf", "Sea-ice fraction", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+
+c
+         CALL histdef(nid_mth, "q2m","Specific humidity 2m","kg/kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstorad,zout)
+c
+         CALL histdef(nid_mth, "u10m", "Vent zonal 10m", "m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstorad,zout)
+c
+         CALL histdef(nid_mth, "v10m", "Vent meridien 10m", "m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstorad,zout)
+c
+         CALL histdef(nid_mth, "psol", "Surface Pressure", "Pa",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstorad,zout)
+c
+         CALL histdef(nid_mth, "qsurf","Surface Air humidity","kg/kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+      if (.not. ok_veget) then
+         CALL histdef(nid_mth, "qsol", "Soil watter content", "mm",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+      endif
+c
+         CALL histdef(nid_mth, "ndayrain", 
+     .                "Number of day with rain (liq+sol)", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "inst(X)", zstomth,zout)
+c
+         CALL histdef(nid_mth, "precip", "Precipitation Totale liq+sol", 
+     .                "kg/(s*m2)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "plul", "Large-scale Precip.", 
+     .   "kg/(s*m2)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "pluc", "Convective Precip.", 
+     .   "kg/(s*m2)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "snowf", "Snow fall", "kg/(s*m2)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+c        CALL histdef(nid_mth, "snow_mass", "Snow Mass", "kg/m2",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+c    .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "evap", 
+     .                "Evaporation plus sublimation rate", "kg/(s*m2)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "tops", "Solar rad. at TOA", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "tops0", "CS Solar rad. at TOA", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "topl", "IR rad. at TOA", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "topl0", "IR rad. at TOA", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWupTOA", "SWup at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWupTOAclr", 
+     .                "SWup clear sky at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWdnTOA", "SWdn at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWdnTOAclr", 
+     .                "SWdn clear sky at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWup200", "SWup at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWup200clr", 
+     .                "SWup clear sky at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWdn200", "SWdn at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWdn200clr", 
+     .                "SWdn clear sky at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "LWup200", "LWup at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "LWup200clr", 
+     .                "LWup clear sky at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "LWdn200", "LWdn at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "LWdn200clr", 
+     .                "LWdn clear sky at 200mb","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "sols", "Solar rad. at surf.", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "sols0", "Solar rad. at surf.", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "soll", "IR rad. at surface", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "soll0", "IR rad. at surface", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWupSFC", "SWup at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWupSFCclr", 
+     .                "SWup clear sky at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWdnSFC", "SWdn at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "SWdnSFCclr", 
+     .                "SWdn clear sky at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"LWupSFC","Upwd. IR rad. at surface", 
+     .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"LWdnSFC","Down. IR rad. at surface", 
+     .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"LWupSFCclr",
+     .                "CS Upwd. IR rad. at surface", 
+     .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"LWdnSFCclr",
+     .                "Down. CS IR rad. at surface", 
+     .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "bils", "Surf. total heat flux", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "sens", "Sensible heat flux", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "fder", "Heat flux derivation", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+c          CALL histdef(nid_mth, "frtu", "Zonal wind stress", "Pa",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+c    .                "ave(X)", zstophy,zout)
+c
+c        CALL histdef(nid_mth, "frtv", "Meridional wind stress", "Pa",
+c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+c    .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "ffonte","Thermal flux for snow melting",
+     .                "W/m2",iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "fqcalving","Ice Calving",
+     .                "kg/m2/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         DO nsrf = 1, nbsrf
+           call histdef(nid_mth, "taux_"//clnsurf(nsrf), 
+     $         "Zonal wind stress"//clnsurf(nsrf), "Pa",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+
+           call histdef(nid_mth, "tauy_"//clnsurf(nsrf), 
+     $         "Meridional wind stress "//clnsurf(nsrf), "Pa",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+         ENDDO
+c
+           call histdef(nid_mth, "pourc_"//clnsurf(is_oce), 
+     $         "% "//clnsurf(is_oce), "%",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+c
+           call histdef(nid_mth, "fract_"//clnsurf(is_oce), 
+     $         "Fraction "//clnsurf(is_oce), "1",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+C
+         DO nsrf = 1, nbsrf
+C
+           call histdef(nid_mth, "tsol_"//clnsurf(nsrf), 
+     $         "Temperature "//clnsurf(nsrf), "K",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+C
+           call histdef(nid_mth, "sens_"//clnsurf(nsrf), 
+     $         "Sensible heat flux "//clnsurf(nsrf), "W/m2",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+c
+           call histdef(nid_mth, "lat_"//clnsurf(nsrf), 
+     $         "Latent heat flux "//clnsurf(nsrf), "W/m2",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+C
+           call histdef(nid_mth, "flw_"//clnsurf(nsrf),
+     $         "LW "//clnsurf(nsrf), "W/m2",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+c
+           call histdef(nid_mth, "fsw_"//clnsurf(nsrf),
+     $         "SW "//clnsurf(nsrf), "W/m2",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+C
+           call histdef(nid_mth, "wbils_"//clnsurf(nsrf),
+     $         "Bilan sol "//clnsurf(nsrf), "W/m2",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+C
+cIM 250105 BEG
+          IF(1.EQ.0) THEN
+C
+           call histdef(nid_mth, "evapour_"//clnsurf(nsrf),
+     $         "Evap*pourc "//clnsurf(nsrf), "kg/(s*m2)",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+C
+           call histdef(nid_mth, "prepour_"//clnsurf(nsrf),
+     $         "Precip*pourc "//clnsurf(nsrf), "kg/(s*m2)",
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+C
+          ENDIF !(1.EQ.0) THEN
+cIM 250105 END
+C
+         END DO
+c
+         CALL histdef(nid_mth, "cdrm", "Momentum drag coef.", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "cdrh", "Heat drag coef.", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "cldl", "Low-level cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "cldm", "Mid-level cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "cldh", "High-level cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "cldt", "Total cloudiness", "%",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"cldq","Cloud liquid water path","kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"lwp","Cloud water path","kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"iwp","Cloud ice water path","kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "ue", "Zonal energy transport", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "ve", "Merid energy transport", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "uq", "Zonal humidity transport", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "vq", "Merid humidity transport", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+cKE43
+      IF(iflag_con.GE.3) THEN ! sb
+c
+         CALL histdef(nid_mth, "cape", "Conv avlbl pot ener", "J/kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "pbase", "Cld base pressure", "mb",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "ptop", "Cld top pressure", "mb",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "fbase", "Cld base mass flux", "kg/m2/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "prw", "Precipitable water", "kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+      ENDIF !iflag_con .GE. 3
+c34EK
+cIM cf. AM 081204 BEG
+c34EK
+c HBTM2
+         CALL histdef(nid_mth, "s_pblh", "Boundary Layer Height", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_pblt", "T at Boundary Layer Height",
+     .                "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_lcl", "Condensation level", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth,"s_capCL","Conv avlbl pot ener for ABL",
+     .                "J/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_oliqCL", "Liq Water in BL", "kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth,"s_cteiCL","Instability criteria (ABL)",
+     .                "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_therm", "Exces du thermique", "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_trmb1", "deep_cape(HBTM2)", "J/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_trmb2", "inhibition (HBTM2)", "J/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "s_trmb3", "Point Omega (HBTM2)", "m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zstophy,zout)
+c
+cIM cf. AM 081204 END
+c
+c Champs interpolles sur des niveaux de pression
+         DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+       IF(bb2.EQ."850".OR.bb2.EQ."700"
+     $   .OR.bb2.EQ."500".OR.bb2.EQ."200") THEN
+c
+          CALL histdef(nid_mth, "u"//bb2,
+     .                 "Zonal wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+          CALL histdef(nid_mth, "v"//bb2,
+     .                 "Meridional wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+          CALL histdef(nid_mth, "w"//bb2,
+     .                 "Vertical wind "//bb2//"mb","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+          CALL histdef(nid_mth, "phi"//bb2,
+     .                 "Geopotential "//bb2//"mb","m",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zout,zout)
+c
+         ENDIF !(bb2.EQ."850".OR.bb2.EQ."700"
+c
+       ENDDO !nlevSTD
+c
+cIM diagnostiques flux ocean-atm ou ocean-glace de mer
+cIM pour utilisation dans un modele de "slab" ocean
+c
+       CALL histdef(nid_mth, "fluxo",
+     .              "Flux turbulents ocean-atmosphere", "W/m2",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+       CALL histdef(nid_mth, "fluxg",
+     .              "Flux turbulents ocean-glace de mer","W/m2",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+       IF (OCEAN.EQ.'force ') THEN
+c
+        CALL histdef(nid_mth, "lmt_bils",
+     .       "Bilan au sol atmosphere forcee", "W/m2",
+     .       iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .       "ave(X)", zstophy,zout)
+c
+       ELSE IF (OCEAN.EQ.'slab  ') THEN
+c
+        CALL histdef(nid_mth, "slab_bils",
+     .              "Bilan au sol Slab", "W/m2",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_mth, "tslab", "Slab SST ", "K",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_mth, "seaice", "Slab seaice", "kg/m2",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_mth, "siceh", "Slab seaice height", "m",
+     .              iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .              "ave(X)", zstophy,zout)
+c
+       ENDIF !OCEAN.EQ.slab/force
+c
+      ENDIF !lev_histmth.GE.1
+c
+      IF(lev_histmth.GE.2) THEN
+c
+c Champs 3D:
+c
+c
+         CALL histdef(nid_mth,"lwcon","Cloud liquid water content",
+     .                "kg/kg",
+     .                iim,jjmp1,nhori, klev,1,klev, nvert, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"iwcon","Cloud ice water content","kg/kg",
+     .                iim,jjmp1,nhori, klev,1,klev, nvert, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "temp", "Air temperature", "K",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "ovap", "Specific humidity", "kg/kg",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+c        CALL histdef(nid_mth,"wvap","Water vapor mixing ratio","kg/kg",
+c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+c    .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "geop", "Geopotential height", "m2/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "vitu", "Zonal wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "vitv", "Meridional wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "vitw", "Vertical wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "pres", "Air pressure", "Pa",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+        CALL histdef(nid_mth, "rneb", "Cloud fraction", "%",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "rnebcon", "Convective Cloud Fraction"
+     .                , "-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "rhum", "Relative humidity", "-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "ozone", "Ozone concentration", "ppmv",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "upwd", "saturated updraft", "kg/m2/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dtphy", "Physics dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqphy","Physics dQ","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+      ENDIF !lev_histmth.GE.2
+c
+      IF(lev_histmth.GE.3) THEN
+c
+        DO nsrf=1, nbsrf
+c
+           call histdef(nid_mth, "albe_"//clnsurf(nsrf), 
+     $         "Albedo surf. "//clnsurf(nsrf), "-",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+c
+           call histdef(nid_mth, "rugs_"//clnsurf(nsrf), 
+     $         "Rugosite "//clnsurf(nsrf), "m",  
+     $         iim,jjmp1,nhori, 1,1,1, -99, 32,
+     $         "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "ages_"//clnsurf(nsrf), "Snow age","day",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+	 ENDDO !nsrf=1, nbsrf
+c
+         CALL histdef(nid_mth, "albs", "Surface albedo", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+         CALL histdef(nid_mth, "albslw", "Surface albedo LW", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zstophy,zout)
+c
+      ENDIF !lev_histmth.GE.3
+c
+      IF(lev_histmth.GE.4) THEN
+c
+         CALL histdef(nid_mth, "clwcon", 
+     .                "Convective Cloud Liquid water content"
+     .                , "kg/kg",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"Ma","undilute adiab updraft","kg/m2/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dnwd", "saturated downdraft","kg/m2/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dnwd0", "unsat. downdraft", "kg/m2/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dtdyn", "Dynamics dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqdyn","Dynamics dQ","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqcon","Convection dQ","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dtlschr",
+     $       "Large-scale condensational heating rate", "K/s",iim,jjmp1
+     $       ,nhori, klev,1,klev,nvert, 32,"ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqlsc","Condensation dQ","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dtvdf", "Boundary-layer dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dqvdf","Boundary-layer dQ","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dteva", "Reevaporation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"dqeva","Reevaporation dQ","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+
+         CALL histdef(nid_mth, "ptconv", "POINTS CONVECTIFS"," ",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+
+         CALL histdef(nid_mth, "ratqs", "RATQS"," ",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+
+c
+         CALL histdef(nid_mth, "dqajs","Dry adjust. dQ","(kg/kg)/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dtswr", "SW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dtsw0", "CS SW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dtlwr", "LW radiation dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth,"dtlw0","CS LW radiation dT","K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dtec", "Cinetic dissip dT", "K/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "duvdf", "Boundary-layer dU", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dvvdf", "Boundary-layer dV", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         IF (ok_orodr) THEN
+         CALL histdef(nid_mth, "duoro", "Orography dU", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dvoro", "Orography dV", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         ENDIF
+C
+         IF (ok_orolf) THEN
+         CALL histdef(nid_mth, "dulif", "Orography dU", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+c
+         CALL histdef(nid_mth, "dvlif", "Orography dV", "m/s2",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+         ENDIF
+C
+         if (nqmax.GE.3) THEN
+         DO iq=1,nqmax-2
+         IF (iq.LE.99) THEN
+         WRITE(str2,'(i2.2)') iq
+         CALL histdef(nid_mth, "trac"//str2, "Tracer No."//str2, "-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zstophy,zout)
+         ELSE
+         PRINT*, "Trop de traceurs"
+         CALL abort
+         ENDIF
+         ENDDO
+         ENDIF
+c
+      ENDIF !lev_histmth.GE.4
+c
+      ENDIF !type_run.EQ."CLIM".OR.type_run.EQ."ENSP")
+c
          CALL histend(nid_mth)
 c
Index: /LMDZ4/trunk/libf/phylmd/ini_histmthNMC.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_histmthNMC.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/ini_histmthNMC.h	(revision 644)
@@ -4,6 +4,8 @@
       IF (ok_mensuel) THEN
 c
-         zsto = dtime
-         zout = dtime * ecrit_mth
+       zstophy = dtime
+       zstohf = dtime * FLOAT(ecrit_hf)
+       zstomth = dtime * FLOAT(ecrit_mth)
+       zout = dtime * FLOAT(ecrit_mth)
 c
          idayref = day_ref
@@ -22,61 +24,155 @@
      .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime, 
      .                 nhori, nid_nmc)
-         write(*,*)'Mensuel NMC ', itau_phy, zjulian
+c
          CALL histvert(nid_nmc, "presnivs", "Vertical levels", "mb",
-     .                 klev, presnivs, nvert)
-c        call histvert(nid_nmc, 'sig_s', 'Niveaux sigma','-',
-c    .              klev, znivsig, nvert)
+     .                 nlevSTD, rlevSTD/100., nvert)
+ccc
+ccc Champs 3D interpolles sur des niveaux de pression du NMC
+ccc
+      IF(type_run.EQ."ENSP".OR.type_run.EQ."CLIM") THEN
 c
-c Champs 2D:
-
-c Champs interpolles sur des niveaux de pression du NMC
-c IMIMIM 110304 BEG
+          CALL histdef(nid_nmc, "temp",
+     .                 "Temperature","K",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
 c
-         DO k=1, nlevSTD
+         CALL histdef(nid_nmc, "phi",
+     .                "Geopotential", "m",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
 c
-         bb=clevSTD(k)
+          CALL histdef(nid_nmc, "q",
+     .                 "Specific humidity","kg/kg",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
 c
-         IF(k.GE.2) THEN
-          aa=clevSTD(k)
-          bb=aa(1:lnblnk1(aa))
-         ENDIF 
+         CALL histdef(nid_nmc, "rh",
+     .                 "Relative humidity", "%",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
 c
-          CALL histdef(nid_nmc, "t"//bb,
-     .                 "Temperature"//bb//"mb","K",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+          CALL histdef(nid_nmc, "u",
+     .                 "Zonal wind","m/s",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
 c
-         CALL histdef(nid_nmc, "phi"//bb,
-     .                "Geopotential"//bb//"mb", "m2/s2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+          CALL histdef(nid_nmc, "v",
+     .                 "Meridional wind","m/s",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
 c
-          CALL histdef(nid_nmc, "q"//bb,
-     .                 "Specific humidity"//bb//"mb","kg/kg",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
 c
-         CALL histdef(nid_nmc, "rh"//bb,
-     .                 "Relative humidity"//bb//"mb", "%",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+c ATTENTION : pour AMIP2 on interpole t,u,v,wphi,q,rh
+c             sur les niveaux du NMC et on somme & moyenne
+c             toutes les 6 heures par des routines undefSTD et
+c             moy_undefSTD pour eliminer les valeurs "undef"
+c             de la moyenne mensuelle
+c ======> le "inst(X)" ci-dessous est par consequence factice !
 c
-          CALL histdef(nid_nmc, "u"//bb,
-     .                 "Zonal wind"//bb//"mb","K",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+          CALL histdef(nid_nmc, "temp",
+     .                 "Temperature","K",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
 c
-          CALL histdef(nid_nmc, "v"//bb,
-     .                 "Meridional wind"//bb//"mb","K",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+         CALL histdef(nid_nmc, "phi",
+     .                "Geopotential ", "m",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
 c
-         ENDDO !nlevSTD
-c IMIMIM 110304 END
+          CALL histdef(nid_nmc, "q",
+     .                 "Specific humidity","kg/kg",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
+c
+         CALL histdef(nid_nmc, "rh",
+     .                 "Relative humidity", "%",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "u",
+     .                 "Zonal wind","m/s",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "v",
+     .                 "Meridional wind","m/s",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "w",
+     .                 "Vertical motion","Pa/s",
+     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .                "inst(X)", zout,zout)
+c
+c ATTENTION : pour AMIP2 on interpole t,u,v,wphi,q,rh
+c             sur les niveaux du NMC et on somme & moyenne
+c             toutes les 6 heures par des routines undefSTD et
+c             moy_undefSTD pour eliminer les valeurs "undef"
+c             de la moyenne mensuelle
+c ======> le "inst(X)" ci-dessus est par consequence factice !
+c
+c
+          CALL histdef(nid_nmc, "psbg",
+     .         "Pressure sfce below ground","%",
+     .         iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .         "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "uv",
+     .         "uv ",
+     .         "m2/s2",iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
+     .         "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "vq",
+     .         "vq ",
+     .         "m/s * (kg/kg)",iim,jjmp1,nhori, 
+     .          nlevSTD,1,nlevSTD, nvert, 32,
+     .         "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "vT",
+     .         "vT ", 
+     .         "mK/s",iim,jjmp1,nhori, 
+     .          nlevSTD,1,nlevSTD, nvert, 32,
+     .         "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "wq",
+     .         "wq ", 
+     .         "(Pa/s)*(kg/kg)",iim,jjmp1,nhori,
+     .          nlevSTD,1,nlevSTD, nvert, 32,
+     .         "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "vphi",
+     .         "vphi ", 
+     .         "m2/s",iim,jjmp1,nhori, 
+     .          nlevSTD,1,nlevSTD, nvert, 32,
+     .         "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "wT",
+     .         "wT ", 
+     .         "K*Pa/s",iim,jjmp1,nhori,
+     .          nlevSTD,1,nlevSTD, nvert, 32,
+     .         "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "uxu",
+     .         "u2 ", 
+     .         "m2/s2",iim,jjmp1,nhori,
+     .          nlevSTD,1,nlevSTD, nvert, 32,
+     .         "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "vxv",
+     .         "v2 ", 
+     .         "m2/s2",iim,jjmp1,nhori,
+     .          nlevSTD,1,nlevSTD, nvert, 32,
+     .         "inst(X)", zout,zout)
+c
+          CALL histdef(nid_nmc, "TxT",
+     .         "T2 ", 
+     .         "K2",iim,jjmp1,nhori,
+     .          nlevSTD,1,nlevSTD, nvert, 32,
+     .         "inst(X)", zout,zout)
+c
+      ENDIF !(type_run.EQ."AMIP")
 
          CALL histend(nid_nmc)
 c
-c        ndex2d = 0
-c
       ENDIF ! fin de test sur ok_mensuel
-
Index: /LMDZ4/trunk/libf/phylmd/ini_undefSTD.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/ini_undefSTD.F	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/ini_undefSTD.F	(revision 644)
@@ -0,0 +1,81 @@
+      SUBROUTINE ini_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,
+     $           tnondef,tsumSTD)
+      IMPLICIT none
+c
+c====================================================================
+c
+c I. Musat : 09.2004
+c
+c Initialisation - a des frequences differentes : 
+c
+c 1) des variables moyennees sur la journee "day" ou sur le mois "mth"
+c    calculees a partir des valeurs "instantannees" de la physique
+c
+c 2) des variables moyennes mensuelles "NMC" calculees a partir des val.
+c    toutes les 6 heures
+c
+c nout=1 !var. journaliere "day" moyenne sur tous les pas de temps
+c              ! de la physique
+c nout=2 !var. mensuelle "mth" moyennee sur tous les pas de temps
+c              ! de la physique
+c nout=3 !var. mensuelle "NMC" moyennee toutes les 6heures
+c
+c
+c NB: mettre "inst(X)" dans le write_histXXX.h !
+c====================================================================
+c
+#include "dimensions.h"
+      integer jjmp1
+      parameter (jjmp1=jjm+1-1/jjm)
+#include "dimphy.h"
+c variables Input/Output
+      INTEGER nlevSTD, klevSTD, itap
+      PARAMETER(klevSTD=17)
+      INTEGER ecrit_day,ecrit_mth
+c
+c variables locales
+      INTEGER i, k, nout
+      PARAMETER(nout=3) !nout=1 day/nout=2 mth/nout=3 NMC
+c
+c variables Output
+      REAL tnondef(klon,klevSTD,nout)
+      REAL tsumSTD(klon,klevSTD,nout)
+c
+c initialisation variables journalieres en debut de journee
+c
+      IF(MOD(itap,ecrit_day).EQ.1.) THEN
+       DO k=1, nlevSTD
+        DO i=1, klon
+         tnondef(i,k,1)=0.
+         tsumSTD(i,k,1)=0.
+        ENDDO !i
+       ENDDO !k
+      ENDIF
+c
+c initialisation variables mensuelles (calculees a chaque pas de temps) 
+c en debut de mois : nout=2
+c
+      IF(MOD(itap,ecrit_mth).EQ.1.) THEN
+c
+       DO k=1, nlevSTD
+        DO i=1, klon
+         tnondef(i,k,2)=0.
+         tsumSTD(i,k,2)=0.
+        ENDDO !i
+       ENDDO !k
+c
+c initialisation variables mensuelles - runs type Amip - (calculees toutes les 6h)
+c en debut de mois : nout = 3
+c
+       DO k=1, nlevSTD
+        DO i=1, klon
+         tnondef(i,k,3)=0.
+         tsumSTD(i,k,3)=0.
+        ENDDO !i
+       ENDDO !k
+c
+      ENDIF
+c
+      RETURN
+      END  
Index: /LMDZ4/trunk/libf/phylmd/interface_surf.F90
===================================================================
--- /LMDZ4/trunk/libf/phylmd/interface_surf.F90	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/interface_surf.F90	(revision 644)
@@ -74,5 +74,7 @@
       & evap, fluxsens, fluxlat, dflux_l, dflux_s, &              
       & tsol_rad, tsurf_new, alb_new, alblw, emis_new, &
-      & z0_new, pctsrf_new, agesno,fqcalving,ffonte, run_off_lic_0)
+      & z0_new, pctsrf_new, agesno,fqcalving,ffonte, run_off_lic_0,&
+!IM "slab" ocean
+      & flux_o, flux_g, tslab, seaice)
 
 
@@ -125,4 +127,7 @@
 !   albedo       albedo de la surface
 !   tsurf        temperature de surface
+!   tslab        temperature slab ocean
+!   pctsrf_slab  pourcentages (0-1) des sous-surfaces dans le slab
+!   tmp_pctsrf_slab = pctsrf_slab
 !   p1lay        pression 1er niveau (milieu de couche)
 !   ps           pression au sol
@@ -179,4 +184,9 @@
   real, dimension(klon), intent(IN) :: ps, albedo
   real, dimension(klon), intent(IN) :: tsurf, p1lay
+!IM: "slab" ocean
+  real, dimension(klon), intent(INOUT) :: tslab
+  real, allocatable, dimension(:), save :: tmp_tslab
+  real, dimension(klon), intent(OUT) :: flux_o, flux_g
+  real, dimension(klon), intent(INOUT)        :: seaice ! glace de mer (kg/m2)
   REAL, DIMENSION(klon), INTENT(INOUT) :: radsol,fder
   real, dimension(klon), intent(IN) :: zmasq
@@ -212,4 +222,14 @@
 !jld a rajouter   real, dimension(klon), intent(INOUT):: fqcalving
   real, dimension(klon), intent(INOUT):: fqcalving
+!IM: "slab" ocean
+  real, dimension(klon) :: new_dif_grnd 
+!IM: "slab" ocean - Local
+  real, parameter :: t_grnd=271.35
+  real, dimension(klon) :: zx_sl
+  integer i
+  real, allocatable, dimension(:), save :: tmp_flux_o, tmp_flux_g
+  real, allocatable, dimension(:), save :: tmp_radsol
+  real, allocatable, dimension(:,:), save :: tmp_pctsrf_slab
+  real, allocatable, dimension(:), save :: tmp_seaice
 
 ! Local
@@ -287,4 +307,72 @@
   tsurf_new = 999999.
   alblw = 999999.
+
+!IM: "slab" ocean; initialisations
+  flux_o = 0.
+  flux_g = 0.
+!
+    if (.not. allocated(tmp_flux_o)) then
+      allocate(tmp_flux_o(klon), stat = error)
+      DO i=1, knon
+       tmp_flux_o(knindex(i))=flux_o(i)
+      ENDDO
+      if (error /= 0) then
+        abort_message='Pb allocation tmp_flux_o'
+        call abort_gcm(modname,abort_message,1)
+      endif
+    endif
+    if (.not. allocated(tmp_flux_g)) then  
+      allocate(tmp_flux_g(klon), stat = error)
+      DO i=1, knon
+       tmp_flux_g(knindex(i))=flux_g(i)
+      ENDDO
+      if (error /= 0) then
+        abort_message='Pb allocation tmp_flux_g'
+        call abort_gcm(modname,abort_message,1)
+      endif
+    endif
+    if (.not. allocated(tmp_radsol)) then  
+      allocate(tmp_radsol(klon), stat = error)
+      if (error /= 0) then
+        abort_message='Pb allocation tmp_radsol'
+        call abort_gcm(modname,abort_message,1)
+      endif
+    endif
+    DO i=1, knon
+     tmp_radsol(knindex(i))=radsol(i)
+    ENDDO
+    if (.not. allocated(tmp_pctsrf_slab)) then
+      allocate(tmp_pctsrf_slab(klon,nbsrf), stat = error)
+      if (error /= 0) then
+        abort_message='Pb allocation tmp_pctsrf_slab'
+        call abort_gcm(modname,abort_message,1)
+      endif
+    DO i=1, klon
+     tmp_pctsrf_slab(i,1:nbsrf)=pctsrf(i,1:nbsrf)
+    ENDDO
+    endif
+!
+    if (.not. allocated(tmp_seaice)) then
+      allocate(tmp_seaice(klon), stat = error)
+      if (error /= 0) then
+        abort_message='Pb allocation tmp_seaice'
+        call abort_gcm(modname,abort_message,1)
+      endif
+    DO i=1, klon
+     tmp_seaice(i)=seaice(i)
+    ENDDO
+    endif
+!
+    if (.not. allocated(tmp_tslab)) then
+      allocate(tmp_tslab(klon), stat = error)
+      if (error /= 0) then
+        abort_message='Pb allocation tmp_tslab'
+        call abort_gcm(modname,abort_message,1)
+      endif
+    endif
+    DO i=1, klon
+     tmp_tslab(i)=tslab(i)
+    ENDDO
+!
 ! Aiguillage vers les differents schemas de surface
 
@@ -465,6 +553,9 @@
       & pctsrf_new)
 
-!    else if (ocean == 'slab  ') then
-!      call interfoce(nisurf)
+!IM: "slab" ocean
+     else if (ocean == 'slab  ') then
+      tsurf_new = tsurf
+      pctsrf_new = tmp_pctsrf_slab
+!
     else                              ! lecture conditions limites
       call interfoce(itime, dtime, jour, & 
@@ -504,4 +595,12 @@
 !!$      endwhere
 
+!IM: flux ocean-atmosphere utile pour le "slab" ocean
+    DO i=1, knon
+     zx_sl(i) = RLVTT
+     if (tsurf_new(i) .LT. RTT) zx_sl(i) = RLSTT
+     flux_o(i) = fluxsens(i)-evap(i)*zx_sl(i)
+     tmp_flux_o(knindex(i)) = flux_o(i)
+     tmp_radsol(knindex(i))=radsol(i)
+    ENDDO
 !
 ! 2eme appel a interfoce pour le cumul des champs (en particulier
@@ -524,7 +623,18 @@
       & pctsrf_new)
 
-!    else if (ocean == 'slab  ') then
-!      call interfoce(nisurf)
-
+!IM: "slab" ocean 
+    else if (ocean == 'slab  ') then
+!
+       seaice=tmp_seaice
+       cumul = .true.
+       call interfoce(klon, debut, itime, dtime, jour, &
+     & tmp_radsol, tmp_flux_o, tmp_flux_g, pctsrf, &
+     & tslab, seaice, pctsrf_new)
+!
+       tmp_pctsrf_slab=pctsrf_new
+       DO i=1, knon
+        tsurf_new(i)=tslab(knindex(i))
+       ENDDO !i
+!
     endif
 
@@ -585,6 +695,31 @@
       beta = 1.0
 
-!    else if (ocean == 'slab  ') then
-!      call interfoce(nisurf)
+!IM: "slab" ocean
+    else if (ocean == 'slab  ') then
+     pctsrf_new=tmp_pctsrf_slab
+!
+     DO ii = 1, knon
+      tsurf_new(ii) = tsurf(ii)
+      IF (pctsrf_new(knindex(ii),nisurf) < EPSFRA) then
+       snow(ii) = 0.0
+       tsurf_new(ii) = RTT - 1.8
+       IF (soil_model) tsoil(ii,:) = RTT -1.8
+      ENDIF
+     ENDDO
+
+     CALL calbeta(dtime, nisurf, knon, snow, qsol, beta, capsol, dif_grnd)
+      
+     IF (soil_model) THEN 
+      CALL soil(dtime, nisurf, knon,snow, tsurf_new, tsoil,soilcap, soilflux)
+      cal(1:knon) = RCPD / soilcap(1:knon)
+      radsol(1:knon) = radsol(1:knon)  + soilflux(1:knon)
+     ELSE 
+      dif_grnd = 1.0 / tau_gl
+      cal = RCPD * calice
+      WHERE (snow > 0.0) cal = RCPD * calsno 
+     ENDIF
+     tsurf_temp = tsurf_new
+     beta = 1.0
+!
     ELSE
 !                              ! lecture conditions limites
@@ -596,5 +731,7 @@
 !IM cf LF
       DO ii = 1, knon
-       IF (pctsrf_new(ii,nisurf) < EPSFRA) then
+       tsurf_new(ii) = tsurf(ii)
+!IMbad IF (pctsrf_new(ii,nisurf) < EPSFRA) then
+       IF (pctsrf_new(knindex(ii),nisurf) < EPSFRA) then
           snow(ii) = 0.0
 !IM cf LF/JLD         tsurf(ii) = RTT - 1.8
@@ -617,5 +754,6 @@
          WHERE (snow > 0.0) cal = RCPD * calsno 
       ENDIF
-      tsurf_temp = tsurf
+!IMbadtsurf_temp = tsurf
+      tsurf_temp = tsurf_new
       beta = 1.0
     ENDIF
@@ -627,4 +765,27 @@
          &   petAcoef, peqAcoef, petBcoef, peqBcoef, &
          &   tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
+!
+!IM: flux entre l'ocean et la glace de mer pour le "slab" ocean
+    DO i = 1, knon
+     flux_g(i) = 0.0
+!
+!IM: faire dependre le coefficient de conduction de la glace de mer
+!    de l'epaisseur de la glace de mer, dans l'hypothese ou le coeff.
+!    actuel correspond a 3m de glace de mer, cf. L.Li
+!
+!      IF(1.EQ.0) THEN
+!       IF(siceh(i).GT.0.) THEN
+!        new_dif_grnd(i) = dif_grnd(i)*3./siceh(i)
+!       ELSE
+!        new_dif_grnd(i) = 0.
+!       ENDIF
+!      ENDIF !(1.EQ.0) THEN
+!
+     IF (cal(i).GT.1.0e-15) flux_g(i)=(tsurf_new(i)-t_grnd) &
+    &                          * dif_grnd(i) *RCPD/cal(i)
+!   &                          * new_dif_grnd(i) *RCPD/cal(i)
+      tmp_flux_g(knindex(i))=flux_g(i)
+      tmp_radsol(knindex(i))=radsol(i)
+    ENDDO
 
     IF (ocean /= 'couple') THEN
@@ -744,9 +905,10 @@
      alb_new(1 : knon)  = alb_neig(1 : knon)*zfra(1:knon) + &
     &                     0.6 * (1.0-zfra(1:knon))
-!IM cf FH/GK     alb_new(1 : knon)  = 0.6
+!
+!IM: plusieurs choix/tests sur l'albedo des "glaciers continentaux"
+!       alb_new(1 : knon)  = 0.6 !IM cf FH/GK 
 !       alb_new(1 : knon)  = 0.82
-!IM cf JLD/ GK
-!IM: 211003 Ksta0.77      alb_new(1 : knon)  = 0.77
-!IM: KstaTER0.8 & LMD_ARMIP5    alb_new(1 : knon)  = 0.8
+!       alb_new(1 : knon)  = 0.77 !211003 Ksta0.77
+!       alb_new(1 : knon)  = 0.8 !KstaTER0.8 & LMD_ARMIP5
 !IM: KstaTER0.77 & LMD_ARMIP6    
         alb_new(1 : knon)  = 0.77
@@ -1137,4 +1299,10 @@
       resolution(igrid,2) = cvfi(ij)
     enddo  
+!IM tester la resolution que recoit Orchidee
+    IF((maxval(resolution(:,2)) == 0.).OR. &
+   &   (maxval(resolution(:,1)) == 0.)) THEN
+     abort_message='STOP interfsol : resolution recue par Orchidee = 0.'
+     call abort_gcm(modname,abort_message,1)
+    ENDIF
 
   endif                          ! (fin debut) 
@@ -1187,5 +1355,7 @@
 
 !IM cf. JP +++
-  swdown_vrai(1:knon) = swnet(1:knon)/(1. - albedo_keep(1:knon))
+!IM swdown_vrai(1:knon) = swnet(1:knon)/(1. - albedo_keep(1:knon))
+!IM modification faite dans clmain
+    swdown_vrai(1:knon) = swdown(1:knon)
 !IM cf. JP ---
 
@@ -1887,21 +2057,181 @@
 !#########################################################################
 !
-
-  SUBROUTINE interfoce_slab(nisurf)
-
-! Cette routine sert d'interface entre le modele atmospherique et un 
-! modele de 'slab' ocean
-!
-! L. Fairhead 02/2000
+   SUBROUTINE interfoce_slab(klon, debut, itap, dtime, ijour, &
+ & radsol, fluxo, fluxg, pctsrf, &
+ & tslab, seaice, pctsrf_slab)
+!
+! Cette routine calcule la temperature d'un slab ocean, la glace de mer 
+! et les pourcentages de la maille couverte par l'ocean libre et/ou 
+! la glace de mer pour un "slab" ocean de 50m
+!
+! I. Musat 04.02.2005
 !
 ! input:
-!   nisurf       index de la surface a traiter (1 = sol continental)
-!
-! output:
-!
-
+!   klon         nombre total de points de grille
+!   debut        logical: 1er appel a la physique
+!   itap         numero du pas de temps
+!   dtime        pas de temps de la physique (en s)
+!   ijour        jour dans l'annee en cours
+!   radsol       rayonnement net au sol (LW + SW)
+!   fluxo        flux turbulent (sensible + latent) sur les mailles oceaniques 
+!   fluxg        flux de conduction entre la surface de la glace de mer et l'ocean
+!   pctsrf       tableau des pourcentages de surface de chaque maille
+! output: 
+!   tslab        temperature de l'ocean libre
+!   seaice       glace de mer (kg/m2)
+!   pctsrf_slab  "pourcentages" (valeurs entre 0. et 1.) surfaces issus du slab
+!
+#include "indicesol.inc"
+#include "clesphys.inc"
 ! Parametres d'entree
-  integer, intent(IN) :: nisurf
-
+  integer, intent(IN) :: klon
+  logical, intent(IN) :: debut
+  INTEGER, intent(IN) :: itap
+  REAL, intent(IN) :: dtime
+  INTEGER, intent(IN) :: ijour
+  REAL, dimension(klon), intent(IN) :: radsol
+  REAL, dimension(klon), intent(IN) :: fluxo
+  REAL, dimension(klon), intent(IN) :: fluxg
+  real, dimension(klon, nbsrf), intent(IN) :: pctsrf
+! Parametres de sortie
+  real, dimension(klon), intent(INOUT) :: tslab
+  real, dimension(klon), intent(INOUT)        :: seaice ! glace de mer (kg/m2)
+  real, dimension(klon, nbsrf), intent(OUT) :: pctsrf_slab
+!
+! Variables locales :
+  INTEGER, save :: lmt_pas, julien, idayvrai
+  REAL, parameter :: unjour=86400.
+  real, allocatable, dimension(:), save :: tmp_tslab, tmp_seaice
+  REAL, allocatable, dimension(:), save :: slab_bils
+  REAL, allocatable, dimension(:), save :: lmt_bils
+  logical,save              :: check = .false.
+!
+  REAL, parameter :: cyang=50.0 * 4.228e+06 ! capacite calorifique volumetrique de l'eau J/(m2 K)
+  REAL, parameter :: cbing=0.334e+05        ! J/kg
+  real, dimension(klon)                 :: siceh !hauteur de la glace de mer (m)
+  INTEGER :: i
+  integer :: sum_error, error
+  REAL :: zz, za, zb
+!
+  character (len = 80) :: abort_message
+  character (len = 20) :: modname = 'interfoce_slab'
+!
+  julien = MOD(ijour,360)
+  sum_error = 0
+  IF (debut) THEN
+   allocate(slab_bils(klon), stat = error); sum_error = sum_error + error
+   allocate(lmt_bils(klon), stat = error); sum_error = sum_error + error
+   allocate(tmp_tslab(klon), stat = error); sum_error = sum_error + error
+   allocate(tmp_seaice(klon), stat = error); sum_error = sum_error + error
+   if (sum_error /= 0) then
+    abort_message='Pb allocation var. slab_bils,lmt_bils,tmp_tslab,tmp_seaice'
+    call abort_gcm(modname,abort_message,1)
+   endif
+   tmp_tslab=tslab
+   tmp_seaice=seaice
+   lmt_pas = nint(86400./dtime * 1.0) ! pour une lecture une fois par jour
+!
+   IF (check) THEN
+    PRINT*,'interfoce_slab klon, debut, itap, dtime, ijour, &
+ &          lmt_pas ', klon, debut, itap, dtime, ijour, &
+ &          lmt_pas
+   ENDIF !check
+!
+   PRINT*, '************************'
+   PRINT*, 'SLAB OCEAN est actif, prenez precautions !'
+   PRINT*, '************************'
+!
+! a mettre un slab_bils aussi en force !!!
+!
+    DO i = 1, klon
+     slab_bils(i) = 0.0
+    ENDDO
+!
+   ENDIF !debut
+   pctsrf_slab(1:klon,1:nbsrf) = pctsrf(1:klon,1:nbsrf)
+!
+! lecture du bilan au sol lmt_bils issu d'une simulation forcee en debut de journee
+! 
+   IF (MOD(itap,lmt_pas) .EQ. 1) THEN !1er pas de temps de la journee
+    idayvrai = ijour
+    CALL condsurf(julien,idayvrai, lmt_bils)
+   ENDIF !(MOD(itap-1,lmt_pas) .EQ. 0) THEN
+
+   DO i = 1, klon
+     IF((pctsrf_slab(i,is_oce).GT.epsfra).OR. &
+     &  (pctsrf_slab(i,is_sic).GT.epsfra)) THEN
+!
+! fabriquer de la glace si congelation atteinte:
+!
+      IF (tmp_tslab(i).LT.(RTT-1.8)) THEN
+       zz =  (RTT-1.8)-tmp_tslab(i)
+       tmp_seaice(i) = tmp_seaice(i) + cyang/cbing * zz
+       seaice(i) = tmp_seaice(i)
+       tmp_tslab(i) = RTT-1.8
+      ENDIF
+!
+! faire fondre de la glace si temperature est superieure a 0:
+!
+      IF ((tmp_tslab(i).GT.RTT) .AND. (tmp_seaice(i).GT.0.0)) THEN
+       zz = cyang/cbing * (tmp_tslab(i)-RTT)
+       zz = MIN(zz,tmp_seaice(i))
+       tmp_seaice(i) = tmp_seaice(i) - zz
+       seaice(i) = tmp_seaice(i)
+       tmp_tslab(i) = tmp_tslab(i) - zz*cbing/cyang
+      ENDIF
+!
+! limiter la glace de mer a 10 metres (10000 kg/m2)
+!
+      IF(tmp_seaice(i).GT.45.) THEN
+       tmp_seaice(i) = MIN(tmp_seaice(i),10000.0)
+      ELSE
+       tmp_seaice(i) = 0. 
+      ENDIF
+      seaice(i) = tmp_seaice(i)
+      siceh(i)=tmp_seaice(i)/1000. !en metres
+!
+! determiner la nature du sol (glace de mer ou ocean libre):
+!
+! on fait dependre la fraction de seaice "pctsrf(i,is_sic)" 
+! de l'epaisseur de seaice :
+! pctsrf(i,is_sic)=1. si l'epaisseur de la glace de mer est >= a 20cm
+! et pctsrf(i,is_sic) croit lineairement avec seaice de 0. a 20cm d'epaisseur
+!
+      pctsrf_slab(i,is_sic)=MIN(siceh(i)/0.20, &
+     &                      1.-(pctsrf_slab(i,is_ter)+pctsrf_slab(i,is_lic)))
+      pctsrf_slab(i,is_oce)=1.0 - &
+     &      (pctsrf_slab(i,is_ter)+pctsrf_slab(i,is_lic)+pctsrf_slab(i,is_sic))
+     ENDIF !pctsrf
+   ENDDO
+!
+! Calculer le bilan du flux de chaleur au sol :
+!
+   DO i = 1, klon
+    za = radsol(i) + fluxo(i)
+    zb = fluxg(i)
+    IF((pctsrf_slab(i,is_oce).GT.epsfra).OR. &
+   &   (pctsrf_slab(i,is_sic).GT.epsfra)) THEN
+     slab_bils(i)=slab_bils(i)+(za*pctsrf_slab(i,is_oce) &
+   &             +zb*pctsrf_slab(i,is_sic))/ FLOAT(lmt_pas)
+    ENDIF
+   ENDDO !klon
+!
+! calcul tslab 
+!
+   IF (MOD(itap,lmt_pas).EQ.0) THEN !fin de journee
+    DO i = 1, klon
+      IF ((pctsrf_slab(i,is_oce).GT.epsfra).OR. &
+     &    (pctsrf_slab(i,is_sic).GT.epsfra)) THEN
+       tmp_tslab(i) = tmp_tslab(i) + &
+     & (slab_bils(i)-lmt_bils(i)) &
+     &                         /cyang*unjour
+! on remet l'accumulation a 0
+       slab_bils(i) = 0.
+      ENDIF !pctsrf
+    ENDDO !klon
+   ENDIF !(MOD(itap,lmt_pas).EQ.0) THEN
+!
+   tslab = tmp_tslab
+   seaice = tmp_seaice
   END SUBROUTINE interfoce_slab
 !
Index: /LMDZ4/trunk/libf/phylmd/moy_undefSTD.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/moy_undefSTD.F	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/moy_undefSTD.F	(revision 644)
@@ -0,0 +1,79 @@
+      SUBROUTINE moy_undefSTD(nlevSTD,itap,
+     $           ecrit_day,ecrit_mth,ecrit_hf2mth,
+     $           tnondef,tsumSTD)
+      IMPLICIT none
+c
+c====================================================================
+c
+c I. Musat : 09.2004
+c
+c Moyenne - a des frequences differentes - des valeurs bien definies
+c         (.NE.1.E+20) des variables interpolees a un niveau de
+c         pression.
+c 1) les variables de type "day" (nout=1) ou "mth" (nout=2) sont sommees
+c    tous les pas de temps de la physique
+c
+c 2) les variables de type "NMC" (nout=3) sont calculees a partir
+c    des valeurs instantannees toutes les 6 heures
+c
+c
+c NB: mettre "inst(X)" dans le write_histXXX.h !
+c====================================================================
+#include "dimensions.h"
+      integer jjmp1
+      parameter (jjmp1=jjm+1-1/jjm)
+#include "dimphy.h"
+c
+c variables Input
+      INTEGER nlevSTD, klevSTD, itap
+      PARAMETER(klevSTD=17)
+      INTEGER ecrit_day, ecrit_mth, ecrit_hf2mth
+c
+c variables locales
+      INTEGER i, k, nout
+      PARAMETER(nout=3) !nout=1 day/nout=2 mth/nout=3 NMC
+c
+c variables Output
+      REAL tnondef(klon,klevSTD,nout)
+      REAL tsumSTD(klon,klevSTD,nout)
+c
+c calcul 1 fois par jour
+c
+      IF(MOD(itap,ecrit_day).EQ.0) THEN
+       DO k=1, nlevSTD
+        DO i=1, klon
+         IF(tnondef(i,k,1).NE.FLOAT(ecrit_day)) THEN
+          tsumSTD(i,k,1)=tsumSTD(i,k,1)/
+     $    (FLOAT(ecrit_day)-tnondef(i,k,1))
+         ELSE
+          tsumSTD(i,k,1)=1.E+20
+         ENDIF !tnondef
+        ENDDO !i
+       ENDDO !k
+      ENDIF !MOD(itap,ecrit_day).EQ.0
+c
+c calcul 1 fois par mois
+c
+      IF(MOD(itap,ecrit_mth).EQ.0) THEN
+       DO k=1, nlevSTD
+        DO i=1, klon
+         IF(tnondef(i,k,2).NE.FLOAT(ecrit_mth)) THEN
+          tsumSTD(i,k,2)=tsumSTD(i,k,2)/
+     $    (FLOAT(ecrit_mth)-tnondef(i,k,2))
+         ELSE
+          tsumSTD(i,k,2)=1.E+20
+         ENDIF !tnondef
+c
+         IF(tnondef(i,k,3).NE.FLOAT(ecrit_hf2mth)) THEN
+          tsumSTD(i,k,3)=tsumSTD(i,k,3)/
+     $    (FLOAT(ecrit_hf2mth)-tnondef(i,k,3))
+         ELSE
+          tsumSTD(i,k,3)=1.E+20
+         ENDIF !tnondef
+c
+        ENDDO !i
+       ENDDO !k
+      ENDIF !MOD
+c
+      RETURN
+      END  
Index: /LMDZ4/trunk/libf/phylmd/moyglo_aire.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/moyglo_aire.F	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/moyglo_aire.F	(revision 644)
@@ -0,0 +1,155 @@
+      SUBROUTINE moyglo_pondaire(nhori, champ, aire, 
+     .            ok_msk, msk, moyglo)
+c
+       IMPLICIT none
+c
+c ==================================================================
+c I. Musat, 07.2004
+c
+c Calcul moyenne globale ponderee par l'aire totale, avec ou sans masque
+c
+c moyenne = Somme_(champ* aire)/Somme_aire
+c
+c ==================================================================
+c
+#include "dimensions.h"
+#include "dimphy.h"
+       INTEGER i, nhori
+       REAL champ(klon), aire(klon), msk(klon)
+       LOGICAL ok_msk 
+       REAL moyglo
+c
+c var locale
+       REAL airetot
+c
+c      PRINT*,'moyglo_pondaire nhori',nhori
+c
+       airetot=0.
+       moyglo=0.
+c
+       IF(ok_msk) THEN
+        DO i=1, nhori
+c        IF(msk(i).EQ.1.) THEN 
+         IF(msk(i).GT.0.) THEN 
+c
+c aire totale
+          airetot=airetot+aire(i)*msk(i)
+c
+c ponderation par la masse
+          moyglo=moyglo+champ(i)* aire(i)*msk(i) 
+         ENDIF
+        ENDDO
+c
+       ELSE !ok_msk
+        DO i=1, nhori
+c
+c aire totale
+          airetot=airetot+aire(i)
+c
+c ponderation par la masse
+          moyglo=moyglo+champ(i)* aire(i) 
+        ENDDO 
+c
+       ENDIF
+c 
+c moyenne ponderee par l'aire
+       moyglo=moyglo/airetot
+c
+       RETURN 
+       END
+c
+       SUBROUTINE moyglo_pondaima(nhori, nvert, champ,
+     . aire, pbord, moyglo)
+       IMPLICIT none
+c ==================================================================
+c I. Musat, 07.2004
+c
+c Calcul moyenne globale ponderee par la masse d'air, divisee par l'aire
+c totale avec ou sans masque
+c
+c moyenne = Somme_(champ* masse_dair)/Somme_aire
+c
+c ==================================================================
+#include "dimensions.h"
+#include "dimphy.h"
+#include "YOMCST.h"
+       INTEGER i, k, nhori, nvert
+       REAL champ(klon,klev), aire(klon)
+       REAL pbord(klon,klev+1)
+       REAL moyglo
+c
+c var locale
+       REAL airetot
+c
+c      PRINT*,'moyglo_pondaima RG, nhori, nvert',RG,nhori,nvert
+c
+c ponderation par la masse
+       moyglo=0.
+       DO k=1, nvert
+       DO i=1, nhori
+        moyglo=moyglo+
+     .  champ(i,k)*(pbord(i,k)-pbord(i,k+1))/RG*aire(i)
+       ENDDO
+       ENDDO
+c
+c aire totale
+       airetot=0.
+       DO i=1, nhori
+        airetot=airetot+aire(i)
+       ENDDO
+c
+c moyenne par mettre carre avec ponderation par la masse
+       moyglo=moyglo/airetot
+c
+      RETURN
+      END
+c
+       SUBROUTINE moyglo_pondmass(nhori, nvert, champ,
+     . aire, pbord, moyglo)
+       IMPLICIT none
+c ==================================================================
+c I. Musat, 07.2004
+c
+c Calcul moyenne globale ponderee par la masse d'air, divisee par la
+c masse totale d'air, avec ou sans masque
+c
+c moyenne = Somme_(champ* masse_dair)/Somme_(masse_dair)
+c
+c ==================================================================
+#include "dimensions.h"
+#include "dimphy.h"
+#include "YOMCST.h"
+       INTEGER i, k, nhori, nvert
+       REAL champ(klon,klev), aire(klon)
+       REAL pbord(klon,klev+1)
+       REAL moyglo
+c
+c var locale
+       REAL massetot
+c
+c      PRINT*,'moyglo_pondmass RG, nhori, nvert',RG,nhori,nvert
+c
+c ponderation par la masse
+       moyglo=0.
+       DO k=1, nvert
+       DO i=1, nhori
+        moyglo=moyglo+
+     .  champ(i,k)*(pbord(i,k)-pbord(i,k+1))/RG*aire(i)
+       ENDDO
+       ENDDO
+c
+c masse totale
+       massetot=0.
+       DO k=1, nvert
+       DO i=1, nhori
+        massetot=massetot+
+     .  (pbord(i,k)-pbord(i,k+1))/RG*aire(i)
+       ENDDO
+       ENDDO
+c
+c moyenne par mettre carre avec ponderation par la masse
+       moyglo=moyglo/massetot
+c
+      RETURN
+      END
+c
Index: /LMDZ4/trunk/libf/phylmd/orografi.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/orografi.F	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/orografi.F	(revision 644)
@@ -113,7 +113,9 @@
          d_t(i,klev+1-k) = dtime*pdtdt(i,k)
          pustr(i)        = pustr(i)
-     .                    +rg*pdudt(i,k)*(papmh(i,k+1)-papmh(i,k))
+cIM BUG  .                +rg*pdudt(i,k)*(papmh(i,k+1)-papmh(i,k))
+     .                    +pdudt(i,k)*(papmh(i,k+1)-papmh(i,k))/RG
          pvstr(i)        = pvstr(i)
-     .                    +rg*pdvdt(i,k)*(papmh(i,k+1)-papmh(i,k))
+cIM BUG  .                +rg*pdvdt(i,k)*(papmh(i,k+1)-papmh(i,k))
+     .                    +pdvdt(i,k)*(papmh(i,k+1)-papmh(i,k))/RG
       ENDDO
       ENDDO
@@ -1402,7 +1404,9 @@
          d_t(i,klev+1-k) = dtime*pdtdt(i,k)
          pustr(i)        = pustr(i)
-     .                    +RG*pdudt(i,k)*(papmh(i,k+1)-papmh(i,k))
+cIM BUG .                 +RG*pdudt(i,k)*(papmh(i,k+1)-papmh(i,k))
+     .                    +pdudt(i,k)*(papmh(i,k+1)-papmh(i,k))/RG
          pvstr(i)        = pvstr(i)
-     .                    +RG*pdvdt(i,k)*(papmh(i,k+1)-papmh(i,k))
+cIM BUG .                 +RG*pdvdt(i,k)*(papmh(i,k+1)-papmh(i,k))
+     .                    +pdvdt(i,k)*(papmh(i,k+1)-papmh(i,k))/RG
       ENDDO
       ENDDO
Index: /LMDZ4/trunk/libf/phylmd/phyetat0.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/phyetat0.F	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/phyetat0.F	(revision 644)
@@ -5,5 +5,8 @@
 c
       SUBROUTINE phyetat0 (fichnom,dtime,co2_ppm_etat0,solaire_etat0,
-     .            rlat,rlon, pctsrf, tsol,tsoil,deltat,qsurf,qsol,snow,
+     .            rlat,rlon, pctsrf, tsol,tsoil,
+cIM "slab" ocean
+     .           tslab,seaice,
+     .           qsurf,qsol,snow,
      .           albe, alblw, evap, rain_fall, snow_fall, solsw, sollw,
      .           fder,radsol,frugs,agesno,clesphy0,
@@ -32,12 +35,11 @@
       REAL tsol(klon,nbsrf)
       REAL tsoil(klon,nsoilmx,nbsrf)
-      REAL deltat(klon)
+cIM "slab" ocean
+      REAL tslab(klon), seaice(klon)
       REAL qsurf(klon,nbsrf)
       REAL qsol(klon)
       REAL snow(klon,nbsrf)
       REAL albe(klon,nbsrf)
-cIM BEG alblw
       REAL alblw(klon,nbsrf)
-cIM END alblw
       REAL evap(klon,nbsrf)
       REAL radsol(klon)
@@ -420,27 +422,53 @@
       ENDDO
 c
-c Lecture de deltat (pour slab ocean seulement):
-c
-      ierr = NF_INQ_VARID (nid, "DELTAT", nvarid)
-      IF (ierr.NE.NF_NOERR) THEN
-         PRINT*, "phyetat0: Le champ <DELTAT> est absent"
-         CALL abort
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, deltat)
-#else
-      ierr = NF_GET_VAR_REAL(nid, nvarid, deltat)
-#endif
-      IF (ierr.NE.NF_NOERR) THEN
-         PRINT*, "phyetat0: Lecture echouee pour <DELTAT>"
-         CALL abort
-      ENDIF
-      xmin = 1.0E+20
-      xmax = -1.0E+20
-      DO i = 1, klon
-         xmin = MIN(deltat(i),xmin)
-         xmax = MAX(deltat(i),xmax)
-      ENDDO
-      PRINT*,'Ecart de la SST deltat:', xmin, xmax
+cIM "slab" ocean 
+c
+c Lecture de tslab (pour slab ocean seulement):      
+c
+      ierr = NF_INQ_VARID (nid, "TSLAB", nvarid)
+      IF (ierr.NE.NF_NOERR) THEN
+         PRINT*, "phyetat0: Le champ <TSLAB> est absent"
+         CALL abort
+      ENDIF
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, tslab)
+#else
+      ierr = NF_GET_VAR_REAL(nid, nvarid, tslab)
+#endif
+      IF (ierr.NE.NF_NOERR) THEN
+         PRINT*, "phyetat0: Lecture echouee pour <TSLAB>"
+         CALL abort
+      ENDIF
+      xmin = 1.0E+20
+      xmax = -1.0E+20
+      DO i = 1, klon
+         xmin = MIN(tslab(i),xmin)
+         xmax = MAX(tslab(i),xmax)
+      ENDDO
+      PRINT*,'Ecart de la SST tslab:', xmin, xmax
+c
+c Lecture de seaice (pour slab ocean seulement):
+c
+      ierr = NF_INQ_VARID (nid, "SEAICE", nvarid)
+      IF (ierr.NE.NF_NOERR) THEN
+         PRINT*, "phyetat0: Le champ <SEAICE> est absent"
+         CALL abort
+      ENDIF
+#ifdef NC_DOUBLE
+      ierr = NF_GET_VAR_DOUBLE(nid, nvarid, seaice)
+#else
+      ierr = NF_GET_VAR_REAL(nid, nvarid, seaice)
+#endif
+      IF (ierr.NE.NF_NOERR) THEN
+         PRINT*, "phyetat0: Lecture echouee pour <SEAICE>"
+         CALL abort
+      ENDIF
+      xmin = 1.0E+20
+      xmax = -1.0E+20
+      DO i = 1, klon
+         xmin = MIN(seaice(i),xmin)
+         xmax = MAX(seaice(i),xmax)
+      ENDDO
+      PRINT*,'Masse de la glace de mer seaice:', xmin, xmax
 c
 c Lecture de l'humidite de l'air juste au dessus du sol:
@@ -652,5 +680,4 @@
 
 c
-cIM BEG alblw
 c Lecture de albedo au sol LW:
 c
@@ -690,7 +717,4 @@
          ENDDO
       ENDIF
-
-cIM END alblw
-
 c
 c Lecture de evaporation:  
Index: /LMDZ4/trunk/libf/phylmd/phyredem.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/phyredem.F	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/phyredem.F	(revision 644)
@@ -4,5 +4,8 @@
 c
       SUBROUTINE phyredem (fichnom,dtime,radpas,
-     .           rlat,rlon, pctsrf,tsol,tsoil,deltat,qsurf,qsol,snow,
+     .           rlat,rlon, pctsrf,tsol,tsoil,
+cIM "slab" ocean
+     .           tslab,seaice,
+     .           qsurf,qsol,snow,
      .           albedo, alblw, evap, rain_fall, snow_fall,
      .           solsw, sollw,fder,
@@ -31,5 +34,6 @@
       REAL tsol(klon,nbsrf)
       REAL tsoil(klon,nsoilmx,nbsrf)
-      REAL deltat(klon)
+cIM "slab" ocean
+      REAL tslab(klon), seaice(klon)
       REAL qsurf(klon,nbsrf)
       REAL qsol(klon)
@@ -288,10 +292,10 @@
       ENDDO
 c
-c
-      ierr = NF_REDEF (nid)
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "DELTAT", NF_DOUBLE, 1, idim2,nvarid)
-#else
-      ierr = NF_DEF_VAR (nid, "DELTAT", NF_FLOAT, 1, idim2,nvarid)
+cIM "slab" ocean
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "TSLAB", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "TSLAB", NF_FLOAT, 1, idim2,nvarid)
 #endif
       ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 33,
@@ -299,7 +303,22 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,deltat)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,deltat)
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,tslab)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,tslab)
+#endif
+c
+      ierr = NF_REDEF (nid)
+#ifdef NC_DOUBLE
+      ierr = NF_DEF_VAR (nid, "SEAICE", NF_DOUBLE, 1, idim2,nvarid)
+#else
+      ierr = NF_DEF_VAR (nid, "SEAICE", NF_FLOAT, 1, idim2,nvarid)
+#endif
+      ierr = NF_PUT_ATT_TEXT (nid,nvarid,"title", 33,
+     .                        "Glace de mer kg/m2 (pour slab-ocean)")
+      ierr = NF_ENDDEF(nid)
+#ifdef NC_DOUBLE
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,seaice)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,seaice)
 #endif
 c
Index: /LMDZ4/trunk/libf/phylmd/physiq.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/physiq.F	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/physiq.F	(revision 644)
@@ -11,5 +11,8 @@
      .            flxmass_w,
 #endif
-     .            d_u, d_v, d_t, d_qx, d_ps)
+     .            d_u, d_v, d_t, d_qx, d_ps
+cIM Amip2
+     .            , dudyn
+     .            , PVteta)
 
       USE ioipsl
@@ -40,6 +43,6 @@
 #define histins
 c#define histISCCP
-#define histREGDYN
-#define histmthNMC
+c#define histREGDYN
+c#define histmthNMC
 c======================================================================
 c    modif   ( P. Le Van ,  12/10/98 )
@@ -73,4 +76,6 @@
 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======================================================================
 #include "dimensions.h"
@@ -116,4 +121,12 @@
 c     parameter (ocean = 'couple')
       logical ok_ocean
+      SAVE ok_ocean
+c
+cIM "slab" ocean
+      REAL tslab(klon)    !Temperature du slab-ocean
+      REAL seaice(klon)   !glace de mer (kg/m2) 
+      REAL fluxo(klon)    !flux turbulents ocean-glace de mer 
+      REAL fluxg(klon)    !flux turbulents ocean-atmosphere
+c
 c======================================================================
 c Clef controlant l'activation du cycle diurne:
@@ -188,5 +201,8 @@
       REAL znivsig(klev)
       REAL zsurf(nbsrf)
-
+cIM 
+      INTEGER kinv
+      real pir
+cMI
       REAL u(klon,klev)
       REAL v(klon,klev)
@@ -213,4 +229,18 @@
       REAL d_ps(klon)
       real da(klon,klev),phi(klon,klev,klev),mp(klon,klev)
+c
+cIM Amip2 PV a theta constante 
+c
+      INTEGER nbteta
+      PARAMETER(nbteta=3)
+      CHARACTER*3 ctetaSTD(nbteta)
+      DATA ctetaSTD/'350','380','405'/
+      REAL rtetaSTD(nbteta)
+      DATA rtetaSTD/350., 380., 405./
+c
+      REAL PVteta(klon,nbteta)
+      REAL zx_tmp_3dte(iim,jjmp1,nbteta)
+c
+cMI Amip2 PV a theta constante
 
       INTEGER klevp1, klevm1
@@ -238,5 +268,6 @@
       SAVE LWdnTOA, LWdnTOAclr
 c
-c vents meridien et zonal a un niveau de pression
+cIM Amip2
+c variables a une pression donnee
 c
       integer nlevSTD
@@ -246,28 +277,66 @@
      .60000., 50000., 40000., 30000., 25000., 20000.,
      .15000., 10000., 7000., 5000., 3000., 2000., 1000./
-      CHARACTER*5 clevSTD(nlevSTD), aa, bb
+      CHARACTER*4 clevSTD(nlevSTD)
       DATA clevSTD/'1000','925 ','850 ','700 ','600 ',
      .'500 ','400 ','300 ','250 ','200 ','150 ','100 ',
      .'70  ','50  ','30  ','20  ','10  '/
 c
+      CHARACTER*3 bb2
+      CHARACTER*2 bb3
+c
       real tlevSTD(klon,nlevSTD), qlevSTD(klon,nlevSTD)
       real rhlevSTD(klon,nlevSTD), philevSTD(klon,nlevSTD)
       real ulevSTD(klon,nlevSTD), vlevSTD(klon,nlevSTD)
-c
-cIM ENSEMBLES BEG
-c
-      integer nlevENS
-      PARAMETER(nlevENS=4)
-      integer indENS(nlevENS)
-      save indENS
-      real rlevENS(nlevENS)
-      DATA rlevENS/85000., 70000., 50000., 20000./
-      CHARACTER*3 clev(nlevENS)
-      DATA clev/'850','700','500','200'/
- 
-      real tlev(klon,nlevENS), qlev(klon,nlevENS), rhlev(klon,nlevENS)
-      real ulev(klon,nlevENS), vlev(klon,nlevENS), philev(klon,nlevENS)
-      real wlev(klon,nlevENS)
-cIM ENSEMBLES END
+      real wlevSTD(klon,nlevSTD) 
+c
+c nout : niveau de output des variables a une pression donnee
+      INTEGER nout
+      PARAMETER(nout=3) !nout=1 : day; =2 : mth; =3 : NMC
+c
+      REAL tsumSTD(klon,nlevSTD,nout)
+      REAL usumSTD(klon,nlevSTD,nout), vsumSTD(klon,nlevSTD,nout)
+      REAL wsumSTD(klon,nlevSTD,nout), phisumSTD(klon,nlevSTD,nout)
+      REAL qsumSTD(klon,nlevSTD,nout), rhsumSTD(klon,nlevSTD,nout)
+c
+      SAVE tsumSTD, usumSTD, vsumSTD, wsumSTD, phisumSTD, 
+     .     qsumSTD, rhsumSTD
+c
+      logical oknondef(klon,nlevSTD,nout)
+      real tnondef(klon,nlevSTD,nout) 
+      save tnondef
+c
+c les produits uvSTD, vqSTD, .., T2STD sont calcules
+c a partir des valeurs instantannees toutes les 6 h
+c qui sont moyennees sur le mois
+c
+      real uvSTD(klon,nlevSTD)
+      real vqSTD(klon,nlevSTD)
+      real vTSTD(klon,nlevSTD)
+      real wqSTD(klon,nlevSTD)
+c
+      real uvsumSTD(klon,nlevSTD,nout)
+      real vqsumSTD(klon,nlevSTD,nout)
+      real vTsumSTD(klon,nlevSTD,nout)
+      real wqsumSTD(klon,nlevSTD,nout)
+c
+      real vphiSTD(klon,nlevSTD)
+      real wTSTD(klon,nlevSTD)
+      real u2STD(klon,nlevSTD)
+      real v2STD(klon,nlevSTD)
+      real T2STD(klon,nlevSTD)
+c
+      real vphisumSTD(klon,nlevSTD,nout)
+      real wTsumSTD(klon,nlevSTD,nout)
+      real u2sumSTD(klon,nlevSTD,nout)
+      real v2sumSTD(klon,nlevSTD,nout)
+      real T2sumSTD(klon,nlevSTD,nout)
+c
+      SAVE uvsumSTD, vqsumSTD, vTsumSTD, wqsumSTD
+      SAVE vphisumSTD, wTsumSTD, u2sumSTD, v2sumSTD, T2sumSTD
+cMI Amip2
+c
+#include "radepsi.h"
+#include "radopt.h"
+c
 c
 c prw: precipitable water
@@ -282,5 +351,5 @@
       REAL cldt_s(klon),cldq_s(klon) !nuage total, eau liquide integree
 
-      INTEGER linv, kp1
+      INTEGER kp1
 c flwp, fiwp = Liquid Water Path & Ice Water Path (kg/m2)
 c flwc, fiwc = Liquid Water Content & Ice Water Content (kg/kg)
@@ -292,5 +361,5 @@
       REAL flwc_s(klon,klev), fiwc_s(klon,klev)
 
-c ISCCP simulator v3.4
+cIM ISCCP simulator v3.4
 c dans clesphys.h top_height, overlap
 cv3.4
@@ -322,5 +391,5 @@
       REAL emsfc_lw
       PARAMETER(emsfc_lw=0.99)
-      REAL    ran0                      ! type for random number fuction
+c     REAL    ran0                      ! type for random number fuction
 c
       REAL cldtot(klon,klev)
@@ -351,5 +420,5 @@
       REAL boxptop(klon,ncol) 
 c
-      INTEGER l, ni, nj, kmax, lmax
+      INTEGER l, kmax, lmax
       PARAMETER(kmax=8, lmax=8)
       INTEGER kmaxm1, lmaxm1
@@ -358,6 +427,4 @@
       PARAMETER(iimx7=iim*kmaxm1, jjmx7=jjm*lmaxm1, 
      .jjmp1x7=jjmp1*lmaxm1)
-      REAL fq4d(iim,jjmp1,kmaxm1,lmaxm1)
-      REAL fq3d(iimx7, jjmp1x7)
 c
       INTEGER iw, iwmax
@@ -376,33 +443,42 @@
       SAVE nhistoWt
 
+      INTEGER linv
       INTEGER pct_ocean(klon,nbregdyn)
-      REAL rlonPOS(klon) 
  
 c sorties ISCCP
 
-      logical ok_isccp
-      real ecrit_isccp
+c     logical ok_isccp
+c     real ecrit_isccp
       integer nid_isccp
-      save ok_isccp, ecrit_isccp, nid_isccp        
-
-#ifdef histISCCP
-      data ok_isccp/.true./      
-#else
-      data ok_isccp/.false./
-#endif
+c     save ok_isccp, ecrit_isccp, nid_isccp        
+      save nid_isccp        
+cIM 090704 BEG
+      INTEGER nbapp_isccp,isccppas
+
+#undef histISCCP
+#define histISCCP
+c     data ok_isccp,ecrit_isccp/.true.,0.125/      
+c     data ok_isccp,ecrit_isccp/.true.,1./      
+cIM 190504     data ok_isccp/.true./      
+cIM 190504 #else
+cIM 190504     data ok_isccp/.false./
+cIM 190504 #endif
 
 c sorties statistiques regime dynamique
-      logical ok_regdyn
-      real ecrit_regdyn
+c     logical ok_regdyn
+c     real ecrit_regdyn
       integer nid_regdyn
-      save ok_regdyn, ecrit_regdyn, nid_regdyn
-
-#ifdef histREGDYN
+c     save ok_regdyn, ecrit_regdyn, nid_regdyn
+      save nid_regdyn
+
+#undef histREGDYN
+#define histREGDYN
+cIM 190504 #ifdef histREGDYN
 c     data ok_regdyn,ecrit_regdyn/.true.,0.125/
 c     data ok_regdyn,ecrit_regdyn/.true.,1./
-       data ok_regdyn/.true./
-#else
-      data ok_regdyn/.false./
-#endif 
+cIM 190504    data ok_regdyn/.true./
+cIM 190504 #else
+cIM 190504   data ok_regdyn/.false./
+cIM 190504 #endif 
 
       REAL zx_tau(kmaxm1), zx_pc(lmaxm1), zx_o500(iwmax)
@@ -418,21 +494,83 @@
 c taulev: numero du niveau de tau dans les sorties ISCCP
       CHARACTER *4 taulev(kmaxm1)
-      DATA taulev/'tau1','tau2','tau3','tau4','tau5','tau6','tau7'/
-
-      REAL zx_lonx7(iimx7), zx_latx7(jjmp1x7)
-      INTEGER nhorix7
+c     DATA taulev/'tau1','tau2','tau3','tau4','tau5','tau6','tau7'/
+      DATA taulev/'tau0','tau1','tau2','tau3','tau4','tau5','tau6'/
+      CHARACTER *3 pclev(lmaxm1)
+      DATA pclev/'pc1','pc2','pc3','pc4','pc5','pc6','pc7'/
+c
+c cnameisccp
+      CHARACTER *27 cnameisccp(lmaxm1,kmaxm1)
+      DATA cnameisccp/'pc< 50hPa, tau< 0.3', 
+     .                'pc= 50-180hPa, tau< 0.3',
+     .                'pc= 180-310hPa, tau< 0.3',
+     .                'pc= 310-440hPa, tau< 0.3',
+     .                'pc= 440-560hPa, tau< 0.3',
+     .                'pc= 560-680hPa, tau< 0.3',
+     .                'pc= 680-800hPa, tau< 0.3',
+     .                'pc< 50hPa, tau= 0.3-1.3',
+     .                'pc= 50-180hPa, tau= 0.3-1.3',
+     .                'pc= 180-310hPa, tau= 0.3-1.3',
+     .                'pc= 310-440hPa, tau= 0.3-1.3',
+     .                'pc= 440-560hPa, tau= 0.3-1.3',
+     .                'pc= 560-680hPa, tau= 0.3-1.3',
+     .                'pc= 680-800hPa, tau= 0.3-1.3',
+     .                'pc< 50hPa, tau= 1.3-3.6',
+     .                'pc= 50-180hPa, tau= 1.3-3.6',
+     .                'pc= 180-310hPa, tau= 1.3-3.6',
+     .                'pc= 310-440hPa, tau= 1.3-3.6',
+     .                'pc= 440-560hPa, tau= 1.3-3.6',
+     .                'pc= 560-680hPa, tau= 1.3-3.6',
+     .                'pc= 680-800hPa, tau= 1.3-3.6',
+     .                'pc< 50hPa, tau= 3.6-9.4',
+     .                'pc= 50-180hPa, tau= 3.6-9.4',
+     .                'pc= 180-310hPa, tau= 3.6-9.4',
+     .                'pc= 310-440hPa, tau= 3.6-9.4',
+     .                'pc= 440-560hPa, tau= 3.6-9.4',
+     .                'pc= 560-680hPa, tau= 3.6-9.4',
+     .                'pc= 680-800hPa, tau= 3.6-9.4',
+     .                'pc< 50hPa, tau= 9.4-23',
+     .                'pc= 50-180hPa, tau= 9.4-23',
+     .                'pc= 180-310hPa, tau= 9.4-23',
+     .                'pc= 310-440hPa, tau= 9.4-23',
+     .                'pc= 440-560hPa, tau= 9.4-23',
+     .                'pc= 560-680hPa, tau= 9.4-23',
+     .                'pc= 680-800hPa, tau= 9.4-23',
+     .                'pc< 50hPa, tau= 23-60',
+     .                'pc= 50-180hPa, tau= 23-60',
+     .                'pc= 180-310hPa, tau= 23-60',
+     .                'pc= 310-440hPa, tau= 23-60',
+     .                'pc= 440-560hPa, tau= 23-60',
+     .                'pc= 560-680hPa, tau= 23-60',
+     .                'pc= 680-800hPa, tau= 23-60',
+     .                'pc< 50hPa, tau> 60.',
+     .                'pc= 50-180hPa, tau> 60.',
+     .                'pc= 180-310hPa, tau> 60.',
+     .                'pc= 310-440hPa, tau> 60.',
+     .                'pc= 440-560hPa, tau> 60.',
+     .                'pc= 560-680hPa, tau> 60.',
+     .                'pc= 680-800hPa, tau> 60.'/
+c
+c     REAL zx_lonx7(iimx7), zx_latx7(jjmp1x7)
+c     INTEGER nhorix7
 cIM: region='3d' <==> sorties en global
       CHARACTER*3 region
       PARAMETER(region='3d')
 c
+cIM ISCCP simulator v3.4
+c
       logical ok_hf
-      real ecrit_hf
+cIM200505     integer ecrit_hf
+cIM200505    integer ecrit_hf2mth
+cIM200505    save ecrit_hf2mth
+c
       integer nid_hf, nid_hf3d
-      save ok_hf, ecrit_hf, nid_hf, nid_hf3d
+cIM200505     save ok_hf, ecrit_hf, nid_hf, nid_hf3d
+      save ok_hf, nid_hf, nid_hf3d
 
 c  QUESTION : noms de variables ?
 
 #ifdef histhf
-      data ok_hf,ecrit_hf/.true.,0.25/
+cIM 130904   data ok_hf,ecrit_hf/.true.,0.25/
+      data ok_hf/.true./
 #else
       data ok_hf/.false./
@@ -465,4 +603,7 @@
       REAL rlon(klon)
       SAVE rlon                   ! longitude pour chaque point
+c
+      REAL rlonPOS(klon)
+      SAVE rlonPOS                ! longitudes > 0. pour chaque point
 c
 cc      INTEGER iflag_con
@@ -534,5 +675,6 @@
       SAVE rugoro                 ! longueur de rugosite de l'OESM
 c
-      REAL zulow(klon),zvlow(klon),zustr(klon), zvstr(klon)
+cIM 141004     REAL zulow(klon),zvlow(klon),zustr(klon), zvstr(klon)
+      REAL zulow(klon),zvlow(klon)
 c
       REAL zuthe(klon),zvthe(klon)
@@ -621,8 +763,10 @@
       REAL snow_fall(klon) ! neige
       save snow_fall, rain_fall
-cIM 050204 BEG
+cIM cf FH pour Tiedtke 080604
+      REAL rain_tiedtke(klon),snow_tiedtke(klon)
+c
       REAL total_rain(klon), nday_rain(klon)
-      save total_rain, nday_rain
-cIM 050204 END
+      save nday_rain
+c
       REAL evap(klon), devap(klon) ! evaporation et sa derivee
       REAL sens(klon), dsens(klon) ! chaleur sensible et sa derivee
@@ -655,5 +799,5 @@
       REAL pctsrf_new(klon,nbsrf) !pourcentage surfaces issus d'ORCHIDEE
       REAL paire_ter(klon)        !surfaces terre 
-cIM
+c
       SAVE pctsrf                 ! sous-fraction du sol
       REAL albsol(klon)
@@ -699,4 +843,9 @@
       EXTERNAL lnblnk1   !enleve les blancs a la fin d'une variable de type
                          !caracter
+      EXTERNAL ini_undefSTD  !initialise a 0 une variable a 1 niveau de pression
+      EXTERNAL undefSTD      !somme les valeurs definies d'1 var a 1 niveau de pression
+c     EXTERNAL moy_undefSTD  !moyenne d'1 var a 1 niveau de pression
+c     EXTERNAL moyglo_aire   !moyenne globale d'1 var ponderee par l'aire de la maille (moyglo_pondaire)
+c                            !par la masse/airetot (moyglo_pondaima) et la vraie masse (moyglo_pondmass)
 c
 c Variables locales
@@ -704,4 +853,7 @@
       real clwcon(klon,klev),rnebcon(klon,klev)
       real clwcon0(klon,klev),rnebcon0(klon,klev)
+cIM cf. AM 081204 BEG
+      real clwcon0th(klon,klev),rnebcon0th(klon,klev)
+cIM cf. AM 081204 END
       save rnebcon, clwcon
 
@@ -770,12 +922,29 @@
       REAL zx_t, zx_qs, zdelta, zcor, zfra, zlvdcp, zlsdcp
       real zqsat(klon,klev)
-      INTEGER i, k, iq, ig, j, iiq, nsrf, ll
+      INTEGER i, k, iq, ig, j, nsrf, ll
       REAL t_coup
       PARAMETER (t_coup=234.0)
 c
       REAL zphi(klon,klev)
-      REAL zx_tmp_x(iim), zx_tmp_yjjmp1
       REAL zx_relief(iim,jjmp1)
       REAL zx_aire(iim,jjmp1)
+c
+cIM cf. AM Variables locales pour la CLA (hbtm2)
+c
+      REAL pblh(klon, nbsrf)           ! Hauteur de couche limite
+      REAL plcl(klon, nbsrf)           ! Niveau de condensation de la CLA
+      REAL capCL(klon, nbsrf)          ! CAPE de couche limite
+      REAL oliqCL(klon, nbsrf)          ! eau_liqu integree de couche limite
+      REAL cteiCL(klon, nbsrf)          ! cloud top instab. crit. couche limite
+      REAL pblt(klon, nbsrf)          ! T a la Hauteur de couche limite
+      REAL therm(klon, nbsrf)
+      REAL trmb1(klon, nbsrf)          ! deep_cape
+      REAL trmb2(klon, nbsrf)          ! inhibition 
+      REAL trmb3(klon, nbsrf)          ! Point Omega
+c Grdeurs de sorties
+      REAL s_pblh(klon), s_lcl(klon), s_capCL(klon)
+      REAL s_oliqCL(klon), s_cteiCL(klon), s_pblt(klon)
+      REAL s_therm(klon), s_trmb1(klon), s_trmb2(klon)
+      REAL s_trmb3(klon)
 cKE43
 c Variables locales pour la convection de K. Emanuel (sb):
@@ -796,5 +965,5 @@
       INTEGER iflagctrl(klon)          ! flag fonctionnement de convect
 c -- convect43:
-      INTEGER ntra              ! nb traceurs 
+      INTEGER ntra              ! nb traceurs pour convect4.3
       REAL pori_con(klon)    ! pressure at the origin level of lifted parcel
       REAL plcl_con(klon),dtma_con(klon),dtlcl_con(klon)
@@ -820,5 +989,14 @@
       REAL d_u_ajs(klon,klev), d_v_ajs(klon,klev)
       REAL d_t_eva(klon,klev),d_q_eva(klon,klev)
+      REAL d_t_oli(klon,klev) !tendances dues a oro et lif 
       REAL rneb(klon,klev)
+c
+*********************************************************
+*     declarations
+      real zqasc(klon,klev)
+      save zqasc
+      
+*********************************************************
+cIM 081204 END
 c
       REAL pmfu(klon,klev), pmfd(klon,klev)
@@ -863,19 +1041,37 @@
 
       logical ptconv(klon,klev)
-
+cIM cf. AM 081204 BEG
+      logical ptconvth(klon,klev)
+cIM cf. AM 081204 END
 c
 c Variables liees a l'ecriture de la bande histoire physique
 c
-      INTEGER ecrit_mth
-      SAVE ecrit_mth   ! frequence d'ecriture (fichier mensuel)
-c
-      INTEGER ecrit_day
-      SAVE ecrit_day   ! frequence d'ecriture (fichier journalier)
-c
-      INTEGER ecrit_ins
-      SAVE ecrit_ins   ! frequence d'ecriture (fichier instantane)
-c
-      INTEGER ecrit_reg
-      SAVE ecrit_reg   ! frequence d'ecriture
+c======================================================================
+cIM200505     INTEGER ecrit_mth
+cIM200505     SAVE ecrit_mth   ! frequence d'ecriture (fichier mensuel)
+c
+cIM cf. AM 081204 BEG
+c   declarations pour sortir sur une sous-region
+      integer imin_ins,imax_ins,jmin_ins,jmax_ins
+      save imin_ins,imax_ins,jmin_ins,jmax_ins
+c      real lonmin_ins,lonmax_ins,latmin_ins
+c     s  ,latmax_ins
+c     data lonmin_ins,lonmax_ins,latmin_ins
+c    s  ,latmax_ins/
+c valeurs initiales     s   -5.,20.,41.,55./   
+c    s   100.,130.,-20.,20./
+c    s   -180.,180.,-90.,90./
+c======================================================================
+cIM cf. AM 081204 END
+
+c
+cIM200505     INTEGER ecrit_day
+cIM200505     SAVE ecrit_day   ! frequence d'ecriture (fichier journalier)
+c
+cIM200505     INTEGER ecrit_ins
+cIM200505     SAVE ecrit_ins   ! frequence d'ecriture (fichier instantane)
+c
+cIM200505     INTEGER ecrit_reg
+cIM200505     SAVE ecrit_reg   ! frequence d'ecriture
 c
       integer itau_w   ! pas de temps ecriture = itap + itau_phy
@@ -898,14 +1094,53 @@
 c
       INTEGER ndex2d(iim*jjmp1),ndex3d(iim*jjmp1*klev)
+c
+cIM AMIP2 BEG
+      REAL moyglo, mountor
+cIM 141004 BEG
+      REAL zustrdr(klon), zvstrdr(klon)
+      REAL zustrli(klon), zvstrli(klon)
+      REAL zustrph(klon), zvstrph(klon)
+      REAL aam, torsfc
+cIM 141004 END
+cIM 190504 BEG
+      INTEGER ij, imp1jmp1
+      PARAMETER(imp1jmp1=(iim+1)*jjmp1)
+      REAL zx_tmp(imp1jmp1), airedyn(iim+1,jjmp1)
+      REAL padyn(iim+1,jjmp1,klev+1)
+      REAL dudyn(iim+1,jjmp1,klev)
+      REAL rlatdyn(iim+1,jjmp1)
+cIM 190504 END
+      LOGICAL ok_msk
+      REAL msk(klon)
+cIM 
+      REAL airetot, pi
+      REAL zm_wo(jjmp1, klev)
+cIM AMIP2 END
+c
       REAL zx_tmp_fi2d(klon)      ! variable temporaire grille physique
       REAL zx_tmp_fi3d(klon,klev) ! variable temporaire pour champs 3D 
+      REAL*8 zx_tmp2_fi3d(klon,klev) ! variable temporaire pour champs 3D 
       REAL zx_tmp_2d(iim,jjmp1), zx_tmp_3d(iim,jjmp1,klev)
       REAL zx_lon(iim,jjmp1), zx_lat(iim,jjmp1)
 c
-      INTEGER nid_day, nid_mth, nid_ins, nid_nmc
-      SAVE nid_day, nid_mth, nid_ins, nid_nmc
-c
-      INTEGER nhori, nvert
+      INTEGER nid_day, nid_mth, nid_ins, nid_nmc, nid_day_seri
+      SAVE nid_day, nid_mth, nid_ins, nid_nmc, nid_day_seri
+c
+cIM 280405 BEG
+      INTEGER nid_bilKPins, nid_bilKPave
+      SAVE nid_bilKPins, nid_bilKPave
+c
+      REAL ve_lay(klon,klev) ! transport meri. de l'energie a chaque niveau vert.
+      REAL vq_lay(klon,klev) ! transport meri. de l'eau a chaque niveau vert.
+      REAL ue_lay(klon,klev) ! transport zonal de l'energie a chaque niveau vert.
+      REAL uq_lay(klon,klev) ! transport zonal de l'eau a chaque niveau vert.
+c
+cIM 280405 END
+c
+      INTEGER nhori, nvert, nvert1
+c     REAL zstok
       REAL zsto, zout, zsto1, zsto2
+c     REAL zstoave, zstoin 
+      REAL zstophy, zstorad, zstohf, zstoday, zstomth
       real zjulian
       save zjulian
@@ -954,4 +1189,5 @@
       REAL zu10m(klon), zv10m(klon)           !vents a 10m moyennes s/1 maille
       CHARACTER*40 t2mincels, t2maxcels       !t2m min., t2m max
+      CHARACTER*40 tinst, tave, typeval
 cjq   Aerosol effects (Johannes Quaas, 27/11/2003)
       REAL sulfate(klon, klev) ! SO4 aerosol concentration [ug/m3]
@@ -1041,34 +1277,8 @@
       IF (debut) THEN
          CALL suphec ! initialiser constantes et parametres phys.
-c
-cIM 050204 BEG
-         DO i=1, klon
-          nday_rain(i)=0.
-         ENDDO
-cIM 050204 END
-c
+      ENDIF
+
+
 c======================================================================
-cIM BEG
-        DO k=1, nlevENS
-          DO l=1, nlevSTD
-c
-            bb=clevSTD(l)
-c
-            IF(l.GE.2) THEN
-             aa=clevSTD(l)
-             bb=aa(1:lnblnk1(aa))
-            ENDIF
-c
-            IF(bb.EQ.clev(k)) THEN
-c             print*,'k=',k,'l=',l,'clev=',clev(k)
-              indENS(k)=l
-c             print*,'k=',k,'l=',l,'clev=',clev(k),'indENS=',indENS(k)
-            ENDIF 
-c
-          ENDDO 
-        ENDDO 
-c
-      ENDIF !debut
-cIM END
       xjour = rjourvrai
 c
@@ -1098,5 +1308,8 @@
          itaprad = 0
          CALL phyetat0 ("startphy.nc",dtime,co2_ppm_etat0,solaire_etat0,
-     .       rlat,rlon,pctsrf, ftsol,ftsoil,deltat,fqsurf,qsol,fsnow,
+     .       rlat,rlon,pctsrf, ftsol,ftsoil,
+cIM "slab" ocean
+     .       tslab,seaice,
+     .       fqsurf,qsol,fsnow,
      .       falbe, falblw, fevap, rain_fall,snow_fall,solsw, sollwdown,
      .       dlw,radsol,frugs,agesno,clesphy0,
@@ -1116,4 +1329,11 @@
          ENDIF
 
+cIM cf. AM 081204 BEG
+         PRINT*,'cycle_diurne3 =',cycle_diurne
+cIM cf. AM 081204 END
+c
+         IF(ocean.NE.'force ') THEN
+          ok_ocean=.TRUE.
+         ENDIF
 c
          CALL printflag( tabcntr0,radpas,ok_ocean,ok_oasis ,ok_journe,
@@ -1191,28 +1411,52 @@
      .                   lmt_pas
 c
-         ecrit_mth = NINT(86400./dtime *ecritphy)  ! tous les ecritphy jours
-         IF (ok_mensuel) THEN
-         WRITE(lunout,*)'La frequence de sortie mensuelle est de ', 
-     .                   ecrit_mth
-         ENDIF
-         ecrit_day = NINT(86400./dtime *1.0)  ! tous les jours
-         IF (ok_journe) THEN
-         WRITE(lunout,*)'La frequence de sortie journaliere est de ',
-     .                   ecrit_day
-         ENDIF
+cIM200505        ecrit_mth = NINT(86400./dtime *ecritphy)  ! tous les ecritphy jours
+c        IF (ok_mensuel) THEN
+c        WRITE(lunout,*)'La frequence de sortie mensuelle est de ', 
+c    .                   ecrit_mth
+c        ENDIF
+c        ecrit_day = NINT(86400./dtime *1.0)  ! tous les jours
+c        IF (ok_journe) THEN
+c        WRITE(lunout,*)'La frequence de sortie journaliere est de ',
+c    .                   ecrit_day
+c        ENDIF
+cIM 130904 BEG
+cIM 080205      ecrit_hf = 86400./dtime *0.25  ! toutes les 6h
+cIM 170305      
+c        ecrit_hf = 86400./dtime/12.  ! toutes les 2h
+cIM 230305      
+cIM200505        ecrit_hf = 86400./dtime *0.25  ! toutes les 6h
+c
+cIM200505        ecrit_hf2mth = ecrit_day/ecrit_hf*30
+c
+cIM200505        IF (ok_journe) THEN
+cIM200505        WRITE(lunout,*)'La frequence de sortie hf est de ',
+cIM200505    .                   ecrit_hf
+cIM200505        ENDIF
+cIM 130904 END
 ccc         ecrit_ins = NINT(86400./dtime *0.5)  ! 2 fois par jour
 ccc         ecrit_ins = NINT(86400./dtime *0.25)  ! 4 fois par jour
-         ecrit_ins = NINT(86400./dtime/48.)  ! a chaque pas de temps ==> PB. dans time_counter pour 1mois
-         ecrit_ins = NINT(86400./dtime/12.)  ! toutes les deux heures
-         IF (ok_instan) THEN
-         WRITE(lunout,*)'La frequence de sortie instant. est de ', 
-     .                   ecrit_ins
-         ENDIF
-         ecrit_reg = NINT(86400./dtime *0.25)  ! 4 fois par jour
-         IF (ok_region) THEN
-         WRITE(lunout,*)'La frequence de sortie region est de ', 
-     .                   ecrit_reg
-         ENDIF
-
+c        ecrit_ins = NINT(86400./dtime/48.)  ! a chaque pas de temps ==> PB. dans time_counter pour 1mois
+c        ecrit_ins = NINT(86400./dtime/12.)  ! toutes les deux heures
+cIM200505        ecrit_ins = NINT(86400./dtime/8.)  ! toutes les trois heures
+cIM200505        IF (ok_instan) THEN
+cIM200505        WRITE(lunout,*)'La frequence de sortie instant. est de ', 
+cIM200505    .                   ecrit_ins
+cIM200505        ENDIF
+cIM200505        ecrit_reg = NINT(86400./dtime *0.25)  ! 4 fois par jour
+cIM200505        IF (ok_region) THEN
+cIM200505        WRITE(lunout,*)'La frequence de sortie region est de ', 
+cIM200505    .                   ecrit_reg
+cIM200505        ENDIF
+c
+cIM 230505 BEG
+         ecrit_ins = NINT(ecrit_ins/dtime)
+         ecrit_hf = NINT(ecrit_hf/dtime)
+c        ecrit_hf2mth = 4*30
+         ecrit_day = NINT(ecrit_day/dtime)
+         ecrit_mth = NINT(ecrit_mth/dtime)
+         ecrit_tra = NINT(ecrit_tra/dtime)
+         ecrit_reg = NINT(ecrit_reg/dtime)
+cIM 230505 END
 c
 c Initialiser le couplage si necessaire
@@ -1229,10 +1473,12 @@
       endif        
 c
-c
-cIM
       capemaxcels = 't_max(X)'
       t2mincels = 't_min(X)'
       t2maxcels = 't_max(X)'
-
+      tinst = 'inst(X)'
+      tave = 'ave(X)'
+cIM cf. AM 081204 BEG
+      write(lunout,*)'AVANT HIST IFLAG_CON=',iflag_con
+cIM cf. AM 081204 END
 c
 c=============================================================
@@ -1248,4 +1494,8 @@
 #ifdef histday
 #include "ini_histday.h"
+cIM rajout diagnostiques bilan KP pour analyse MJO par Jun-Ichi Yano
+c#include "ini_bilKP_ins.h"
+c#include "ini_bilKP_ave.h"
+#include "ini_histday_seri.h"
 #endif
 
@@ -1273,4 +1523,11 @@
 #include "ini_histISCCP.h"
 #endif
+
+c#undef histmthNMC
+c#define histmthNMC
+#ifdef histmthNMC
+#include "ini_histmthNMC.h"
+#endif
+
 #endif
 
@@ -1504,11 +1761,5 @@
         rmu0 = -999.999
       ENDIF
-cIM BEG
-      DO i=1, klon
-       sunlit(i)=1 
-       IF(rmu0(i).EQ.0.) sunlit(i)=0
-       nbsunlit(1,i)=FLOAT(sunlit(i))
-      ENDDO
-cIM END
+c
 C     Calcul de l'abedo moyen par maille
       albsol(:)=0.
@@ -1545,8 +1796,9 @@
      $            soil_model,cdmmax, cdhmax,
      $            ksta, ksta_ter, ok_kzmin, ftsoil, qsol, 
-     $            paprs,pplay,radsol, fsnow,fqsurf,fevap,falbe,falblw,
+cIM BAD    $            paprs,pplay,radsol, fsnow,fqsurf,fevap,falbe,falblw,
+     $            paprs,pplay, fsnow,fqsurf,fevap,falbe,falblw,
      $            fluxlat,
-cIM cf. JLD  e            rain_fall, snow_fall, solsw, sollw, sollwdown, fder,
-     e            rain_fall, snow_fall, fsolsw, fsollw, sollwdown, fder,
+     e            rain_fall, snow_fall,
+     e            fsolsw, fsollw, sollwdown, fder,
      e            rlon, rlat, cuphy, cvphy, frugs,
      e            debut, lafin, agesno,rugoro ,
@@ -1556,5 +1808,11 @@
      s            dsens, devap,
      s            ycoefh,yu1,yv1, t2m, q2m, u10m, v10m,
-     s            fqcalving, ffonte, run_off_lic_0) 
+cIM cf. AM 081204 BEG
+     s            pblh,capCL,oliqCL,cteiCL,pblT,
+     s            therm,trmb1,trmb2,trmb3,plcl,
+cIM cf. AM 081204 END
+     s            fqcalving, ffonte, run_off_lic_0,
+cIM "slab" ocean
+     s            fluxo, fluxg, tslab, seaice) 
 c
 CXXX PB
@@ -1623,4 +1881,16 @@
          zxffonte(i) = 0.0
          zxfqcalving(i) = 0.0
+cIM cf. AM 081204 BEG
+c
+         s_pblh(i) = 0.0 
+         s_lcl(i) = 0.0 
+         s_capCL(i) = 0.0
+         s_oliqCL(i) = 0.0
+         s_cteiCL(i) = 0.0
+         s_pblT(i) = 0.0
+         s_therm(i) = 0.0
+         s_trmb1(i) = 0.0
+         s_trmb2(i) = 0.0
+         s_trmb3(i) = 0.0
 c
          IF ( abs( pctsrf(i, is_ter) + pctsrf(i, is_lic) + 
@@ -1649,4 +1919,15 @@
             zxfqcalving(i) = zxfqcalving(i) + 
      .                      fqcalving(i,nsrf)*pctsrf(i,nsrf)
+cIM cf. AM 081204 BEG
+            s_pblh(i) = s_pblh(i) + pblh(i,nsrf)*pctsrf(i,nsrf)
+            s_lcl(i) = s_lcl(i) + plcl(i,nsrf)*pctsrf(i,nsrf)
+            s_capCL(i) = s_capCL(i) + capCL(i,nsrf) *pctsrf(i,nsrf)
+            s_oliqCL(i) = s_oliqCL(i) + oliqCL(i,nsrf) *pctsrf(i,nsrf)
+            s_cteiCL(i) = s_cteiCL(i) + cteiCL(i,nsrf) *pctsrf(i,nsrf)
+            s_pblT(i) = s_pblT(i) + pblT(i,nsrf) *pctsrf(i,nsrf)
+            s_therm(i) = s_therm(i) + therm(i,nsrf) *pctsrf(i,nsrf)
+            s_trmb1(i) = s_trmb1(i) + trmb1(i,nsrf) *pctsrf(i,nsrf)
+            s_trmb2(i) = s_trmb2(i) + trmb2(i,nsrf) *pctsrf(i,nsrf)
+            s_trmb3(i) = s_trmb3(i) + trmb3(i,nsrf) *pctsrf(i,nsrf)
 c        ENDIF 
         ENDDO
@@ -1668,4 +1949,15 @@
           IF (pctsrf(i,nsrf) .LT. epsfra) 
      .    fqcalving(i,nsrf) = zxfqcalving(i)
+cIM cf. AM 081204 BEG
+          IF (pctsrf(i,nsrf) .LT. epsfra) pblh(i,nsrf)=s_pblh(i)
+          IF (pctsrf(i,nsrf) .LT. epsfra) plcl(i,nsrf)=s_lcl(i)
+          IF (pctsrf(i,nsrf) .LT. epsfra) capCL(i,nsrf)=s_capCL(i)
+          IF (pctsrf(i,nsrf) .LT. epsfra) oliqCL(i,nsrf)=s_oliqCL(i)
+          IF (pctsrf(i,nsrf) .LT. epsfra) cteiCL(i,nsrf)=s_cteiCL(i)
+          IF (pctsrf(i,nsrf) .LT. epsfra) pblT(i,nsrf)=s_pblT(i)
+          IF (pctsrf(i,nsrf) .LT. epsfra) therm(i,nsrf)=s_therm(i)
+          IF (pctsrf(i,nsrf) .LT. epsfra) trmb1(i,nsrf)=s_trmb1(i)
+          IF (pctsrf(i,nsrf) .LT. epsfra) trmb2(i,nsrf)=s_trmb2(i)
+          IF (pctsrf(i,nsrf) .LT. epsfra) trmb3(i,nsrf)=s_trmb3(i)
         ENDDO
       ENDDO
@@ -2040,9 +2332,33 @@
 c 1. NUAGES CONVECTIFS
 c
-      IF (iflag_cldcon.eq.-1) THEN ! seulement pour Tiedtke
+cIM cf FH
+c     IF (iflag_cldcon.eq.-1) THEN ! seulement pour Tiedtke
+       IF (iflag_cldcon.le.-1) THEN ! seulement pour Tiedtke
+       snow_tiedtke=0.
+c     print*,'avant calcul de la pseudo precip '
+c     print*,'iflag_cldcon',iflag_cldcon
+       if (iflag_cldcon.eq.-1) then
+          rain_tiedtke=rain_con
+       else
+c       print*,'calcul de la pseudo precip '
+          rain_tiedtke=0.
+c         print*,'calcul de la pseudo precip 0'
+          do k=1,klev
+          do i=1,klon
+             if (d_q_con(i,k).lt.0.) then
+                rain_tiedtke(i)=rain_tiedtke(i)-d_q_con(i,k)/pdtphys
+     s         *(paprs(i,k)-paprs(i,k+1))/rg
+             endif
+          enddo
+          enddo
+       endif
+c
+c     call dump2d(iim,jjm,rain_tiedtke(2:klon-1),'PSEUDO PRECIP ')
+c
 
 c Nuages diagnostiques pour Tiedtke
       CALL diagcld1(paprs,pplay,
-     .             rain_con,snow_con,ibas_con,itop_con,
+cIM cf FH  .             rain_con,snow_con,ibas_con,itop_con,
+     .             rain_tiedtke,snow_tiedtke,ibas_con,itop_con,
      .             diafra,dialiq)
       DO k = 1, klev
@@ -2072,234 +2388,9 @@
       enddo
 
+c
 cIM calcul nuages par le simulateur ISCCP
+c
       IF (ok_isccp) THEN
-cIM calcul tau. emi nuages convectifs
-      convfra(:,:)=rnebcon(:,:)
-      convliq(:,:)=rnebcon(:,:)*clwcon(:,:)
-      CALL newmicro (paprs, pplay,ok_newmicro,
-     .            t_seri, convliq, convfra, dtau_c, dem_c,
-     .            cldh_c, cldl_c, cldm_c, cldt_c, cldq_c,
-     .            flwp_c, fiwp_c, flwc_c, fiwc_c,
-     e            ok_aie,
-     e            sulfate, sulfate_pi,
-     e            bl95_b0, bl95_b1,
-     s            cldtaupi, re, fl)
-c
-cIM calcul tau. emi nuages startiformes
-      CALL newmicro (paprs, pplay,ok_newmicro,
-     .            t_seri, cldliq, cldfra, dtau_s, dem_s,
-     .            cldh_s, cldl_s, cldm_s, cldt_s, cldq_s,
-     .            flwp_s, fiwp_s, flwc_s, fiwc_s,
-     e            ok_aie,
-     e            sulfate, sulfate_pi,
-     e            bl95_b0, bl95_b1,
-     s            cldtaupi, re, fl)
-c
-      cldtot(:,:)=min(max(cldfra(:,:),rnebcon(:,:)),1.)
-
-cIM inversion des niveaux de pression ==> de haut en bas
-      CALL haut2bas(klon, klev, pplay, pfull)
-      CALL haut2bas(klon, klev, q_seri, qv)
-      CALL haut2bas(klon, klev, cldtot, cc)
-      CALL haut2bas(klon, klev, rnebcon, conv)
-      CALL haut2bas(klon, klev, dtau_s, dtau_sH2B)
-      CALL haut2bas(klon, klev, dtau_c, dtau_cH2B)
-      CALL haut2bas(klon, klev, t_seri, at)
-      CALL haut2bas(klon, klev, dem_s, dem_sH2B)
-      CALL haut2bas(klon, klev, dem_c, dem_cH2B)
-      CALL haut2bas(klon, klevp1, paprs, phalf)
-
-c     open(99,file='tautab.bin',access='sequential',
-c    $     form='unformatted',status='old')
-c     read(99) tautab
-
-cIM210503
-      IF (debut) THEN
-      open(99,file='tautab.formatted', FORM='FORMATTED')
-      read(99,'(f30.20)') tautab
-      close(99)
-c
-      open(99,file='invtau.formatted',form='FORMATTED')
-      read(99,'(i10)') invtau
-      close(99)
-c
-cIM: calcul coordonnees regions pour statistiques distribution 
-cIM: nuages en ftion du regime dynamique pour regions oceaniques
-       IF (ok_regdyn) THEN !histREGDYN
-       nsrf=3
-       DO nreg=1, nbregdyn
-       DO i=1, klon
-
-c       IF (debut) THEN
-         IF(rlon(i).LT.0.) THEN
-           rlonPOS(i)=rlon(i)+360.
-         ELSE
-           rlonPOS(i)=rlon(i)  
-         ENDIF
-c       ENDIF
-
-        pct_ocean(i,nreg)=0
-
-c test si c'est 1 point d'ocean
-        IF(pctsrf(i,nsrf).EQ.1.) THEN
-
-         IF(nreg.EQ.1) THEN
-
-c TROP
-          IF(rlat(i).GE.-30.AND.rlat(i).LE.30.) THEN
-           pct_ocean(i,nreg)=1
-          ENDIF
-
-c PACIFIQUE NORD
-          ELSEIF(nreg.EQ.2) THEN
-           IF(rlat(i).GE.40.AND.rlat(i).LE.60.) THEN
-            IF(rlonPOS(i).GE.160..AND.rlonPOS(i).LE.235.) THEN 
-             pct_ocean(i,nreg)=1
-            ENDIF
-           ENDIF
-c CALIFORNIE ST-CU
-         ELSEIF(nreg.EQ.3) THEN
-          IF(rlonPOS(i).GE.220..AND.rlonPOS(i).LE.250.) THEN
-           IF(rlat(i).GE.15.AND.rlat(i).LE.35.) THEN
-            pct_ocean(i,nreg)=1
-           ENDIF
-          ENDIF
-c HAWAI
-        ELSEIF(nreg.EQ.4) THEN 
-         IF(rlonPOS(i).GE.180..AND.rlonPOS(i).LE.220.) THEN
-          IF(rlat(i).GE.15.AND.rlat(i).LE.35.) THEN
-           pct_ocean(i,nreg)=1
-          ENDIF
-         ENDIF
-c WARM POOL
-        ELSEIF(nreg.EQ.5) THEN 
-         IF(rlonPOS(i).GE.70..AND.rlonPOS(i).LE.150.) THEN
-          IF(rlat(i).GE.-5.AND.rlat(i).LE.20.) THEN
-           pct_ocean(i,nreg)=1
-          ENDIF
-         ENDIF
-        ENDIF !nbregdyn
-c TROP
-c        IF(rlat(i).GE.-30.AND.rlat(i).LE.30.) THEN
-c         pct_ocean(i)=.TRUE.
-c         WRITE(*,*) 'pct_ocean =',i, rlon(i), rlat(i)
-c          ENDIF !lon
-c         ENDIF !lat
-
-        ENDIF !pctsrf
-       ENDDO !klon
-       ENDDO !nbregdyn
-       ENDIF !ok_regdyn
- 
-cIM somme de toutes les nhistoW BEG
-      DO nreg = 1, nbregdyn
-       DO k = 1, kmaxm1
-        DO l = 1, lmaxm1
-         DO iw = 1, iwmax
-          nhistoWt(k,l,iw,nreg)=0.
-         ENDDO !iw
-        ENDDO !l
-       ENDDO !k
-      ENDDO !nreg
-cIM somme de toutes les nhistoW END
-      ENDIF
-cIM: initialisation de seed
-        DO i=1, klon
-          seed(i)=i+100
-        ENDDO
-     
-cIM: pas de debug, debugcol
-      debug=0
-      debugcol=0
-cIM260503
-c o500 ==> distribution nuage ftion du regime dynamique a 500 hPa
-        DO k=1, klevm1
-        kp1=k+1
-c       PRINT*,'k, presnivs',k,presnivs(k), presnivs(kp1)
-        if(presnivs(k).GT.50000.AND.presnivs(kp1).LT.50000.) THEN
-         DO i=1, klon
-          o500(i)=omega(i,k)*RDAY/100.
-c         if(i.EQ.1) print*,' 500hPa lev',k,presnivs(k),presnivs(kp1)
-         ENDDO
-         GOTO 1000
-        endif 
-1000  continue
-      ENDDO
-
-      CALL ISCCP_CLOUD_TYPES(
-     &     debug,
-     &     debugcol,
-     &     klon,
-     &     sunlit,
-     &     klev,
-     &     ncol,
-     &     seed,
-     &     pfull,
-     &     phalf,
-     &     qv, cc, conv, dtau_sH2B, dtau_cH2B,
-     &     top_height,
-     &     overlap,
-     &     tautab,
-     &     invtau,
-     &     ztsol,
-     &     emsfc_lw,
-     &     at, dem_sH2B, dem_cH2B,
-     &     fq_isccp,
-     &     totalcldarea,
-     &     meanptop,
-     &     meantaucld,
-     &     boxtau,
-     &     boxptop)
-
-
-c passage de la grille (klon,7,7) a (iim,jjmp1,7,7)
-      DO l=1, lmaxm1
-       DO k=1, kmaxm1
-        DO i=1, iim
-         fq4d(i,1,k,l)=fq_isccp(1,k,l) 
-        ENDDO
-        DO j=2, jjm
-         DO i=1, iim
-          ig=i+1+(j-2)*iim
-          fq4d(i,j,k,l)=fq_isccp(ig,k,l)              
-         ENDDO
-        ENDDO
-        DO i=1, iim
-         fq4d(i,jjmp1,k,l)=fq_isccp(klon,k,l) 
-        ENDDO
-       ENDDO 
-      ENDDO 
-c
-      DO l=1, lmaxm1
-       DO k=1, kmaxm1  
-        DO j=1, jjmp1
-         DO i=1, iim
-           ni=(i-1)*lmaxm1+l
-           nj=(j-1)*kmaxm1+k
-           fq3d(ni,nj)=fq4d(i,j,k,l)
-         ENDDO
-        ENDDO
-       ENDDO
-      ENDDO
-
-c
-c calculs statistiques distribution nuage ftion du regime dynamique 
-c
-c Ce calcul doit etre fait a partir de valeurs mensuelles ??
-      CALL histo_o500_pctau(nbregdyn,pct_ocean,o500,fq_isccp,
-     &histoW,nhistoW)
-c
-c nhistoWt = somme de toutes les nhistoW
-      DO nreg=1, nbregdyn
-       DO k = 1, kmaxm1
-        DO l = 1, lmaxm1
-         DO iw = 1, iwmax
-          nhistoWt(k,l,iw,nreg)=nhistoWt(k,l,iw,nreg)+
-     &    nhistoW(k,l,iw,nreg)
-         ENDDO
-        ENDDO
-       ENDDO
-      ENDDO
-c
+#include "calcul_simulISCCP.h"
       ENDIF !ok_isccp
 
@@ -2571,5 +2662,6 @@
      e                   igwd,idx,itest,
      e                   t_seri, u_seri, v_seri,
-     s                   zulow, zvlow, zustr, zvstr,
+cIM 141004    s                   zulow, zvlow, zustr, zvstr,
+     s                   zulow, zvlow, zustrdr, zvstrdr,
      s                   d_t_oro, d_u_oro, d_v_oro)
 c
@@ -2603,5 +2695,5 @@
      e                   itest,
      e                   t_seri, u_seri, v_seri,
-     s                   zulow, zvlow, zustr, zvstr,
+     s                   zulow, zvlow, zustrli, zvstrli,
      s                   d_t_lif, d_u_lif, d_v_lif)
 c
@@ -2616,4 +2708,31 @@
 c
       ENDIF ! fin de test sur ok_orolf
+c
+cIM cf. FLott BEG
+C STRESS NECESSAIRES: TOUTE LA PHYSIQUE
+
+      DO i = 1, klon
+        zustrph(i)=0.
+        zvstrph(i)=0.
+      ENDDO
+      DO k = 1, klev
+      DO i = 1, klon
+       zustrph(i)=zustrph(i)+(u_seri(i,k)-u(i,k))/dtime*
+     c            (paprs(i,k)-paprs(i,k+1))/rg
+       zvstrph(i)=zvstrph(i)+(v_seri(i,k)-v(i,k))/dtime*
+     c            (paprs(i,k)-paprs(i,k+1))/rg
+      ENDDO
+      ENDDO
+c
+cIM calcul composantes axiales du moment angulaire et couple des montagnes
+c
+      CALL aaam_bud (27,klon,klev,rjourvrai,gmtime,
+     C               ra,rg,romega,
+     C               rlat,rlon,pphis,
+     C               zustrdr,zustrli,zustrph,
+     C               zvstrdr,zvstrli,zvstrph,
+     C               paprs,u,v,
+     C               aam, torsfc)
+cIM cf. FLott END
 c
       IF (if_ebil.ge.2) THEN 
@@ -2712,7 +2831,11 @@
      s                   ve, vq, ue, uq)
 c
+cIM diag. bilKP
+c
+      CALL transp_lay (paprs,zxtsol,
+     e                   t_seri, q_seri, u_seri, v_seri, zphi,
+     s                   ve_lay, vq_lay, ue_lay, uq_lay)
+c
 c Accumuler les variables a stocker dans les fichiers histoire:
-c
-c
 c
 c+jld ec_conser
@@ -2750,62 +2873,8 @@
 c=======================================================================
 
-c   Interpollation sur quelques niveaux de pression
-c   -----------------------------------------------
-c
-c on moyenne mensuellement les champs 3D et on les interpole sur les niveaux STD
-c     if(itap.EQ.1.OR.itap.EQ.13.OR.itap.EQ.25.OR.itap.EQ.37) THEN
-c     if(MOD(itap,12).EQ.1) THEN
-cIM 120304 END
-      DO k=1, nlevSTD
-       call plevel(klon,klev,.true.,pplay,rlevSTD(k),
-     .             t_seri,tlevSTD(:,k))
-       call plevel(klon,klev,.false.,pplay,rlevSTD(k),
-     .             u_seri,ulevSTD(:,k))
-       call plevel(klon,klev,.false.,pplay,rlevSTD(k),
-     .             v_seri,vlevSTD(:,k))
-       call plevel(klon,klev,.false.,pplay,rlevSTD(k),
-     .             zphi,philevSTD(:,k))
-       call plevel(klon,klev,.false.,pplay,rlevSTD(k),
-     .             qx(:,:,ivap),qlevSTD(:,k))
-       call plevel(klon,klev,.false.,pplay,rlevSTD(k),
-     .             zx_rh,rhlevSTD(:,k))
-      ENDDO !nlevSTD
-c ENSEMBLES BEG
-      DO k=1, nlevENS
-cIM 170304
-       tlev(:,k)=tlevSTD(:,indENS(k))
-       ulev(:,k)=ulevSTD(:,indENS(k))
-       vlev(:,k)=vlevSTD(:,indENS(k))
-       philev(:,k)=philevSTD(:,indENS(k))
-       qlev(:,k)=qlevSTD(:,indENS(k))
-       rhlev(:,k)=rhlevSTD(:,indENS(k))
-c
-       call plevel(klon,klevp1,.true.,paprs,rlevENS(k),
-     .             omega,wlev(:,k))
-c
-       ENDDO !k=1, nlevENS 
-cIM 100304 BEG
-cIM interpolation a chaque pas de temps du SWup(clr) et SWdn(clr) a 200 hPa
-      call plevel(klon,klevp1,.true.,paprs,20000.,
-     $     swdn0,SWdn200clr)
-      call plevel(klon,klevp1,.false.,paprs,20000.,
-     $     swdn,SWdn200)
-      call plevel(klon,klevp1,.false.,paprs,20000.,
-     $     swup0,SWup200clr)
-      call plevel(klon,klevp1,.false.,paprs,20000.,
-     $     swup,SWup200)
-c
-      call plevel(klon,klevp1,.false.,paprs,20000.,
-     $     lwdn0,LWdn200clr)
-      call plevel(klon,klevp1,.false.,paprs,20000.,
-     $     lwdn,LWdn200)
-      call plevel(klon,klevp1,.false.,paprs,20000.,
-     $     lwup0,LWup200clr)
-      call plevel(klon,klevp1,.false.,paprs,20000.,
-     $     lwup,LWup200)
-c
-cIM 100304 END
-c     
-c ENSEMBLES END
+cIM Interpolation sur les niveaux de pression du NMC
+c   -------------------------------------------------
+c
+#include "calcul_STDlev.h"
 c
 c slp sea level pressure
@@ -2821,31 +2890,8 @@
       ENDDO
 c
-cIM sorties bilans energie cinetique et potentielle MJO
-      DO k = 1, klev
-      DO i = 1, klon
-        d_u_oli(i,k) = d_u_oro(i,k) + d_u_lif(i,k)
-        d_v_oli(i,k) = d_v_oro(i,k) + d_v_lif(i,k)
-      ENDDO
-      ENDDO
-c
-      IF (MOD(itap-1,lmt_pas) .EQ. 0) THEN
-cIM      PRINT *,' PHYS cond  julien ',julien
-c        CALL ozonecm( FLOAT(julien), rlat, paprs, wo)
-        DO i = 1, klon
-         total_rain(i)=rain_fall(i)+snow_fall(i)  
-         IF(total_rain(i).GT.0.) nday_rain(i)=nday_rain(i)+1.
-        ENDDO
-c 
-      ENDIF
-c surface terre
-      IF (debut) THEN
-       DO i=1, klon
-         IF(pctsrf_new(i,is_ter).GT.0.) THEN
-            paire_ter(i)=airephy(i)*pctsrf_new(i,is_ter)
-         ENDIF 
-       ENDDO
-      ENDIF
-cIM 050204 END
-
+cIM initialisation + calculs divers diag AMIP2
+c
+#include "calcul_divers.h"
+c
 c=============================================================
 c
@@ -2872,4 +2918,8 @@
       ENDIF
 c
+cIM rajout diagnostiques bilan KP pour analyse MJO par Jun-Ichi Yano
+c#include "write_bilKP_ins.h"
+c#include "write_bilKP_ave.h"
+c
 c Sauvegarder les valeurs de t et q a la fin de la physique:
 c
@@ -2893,4 +2943,5 @@
 #ifdef histday
 #include "write_histday.h"
+#include "write_histday_seri.h"
 #endif
 
@@ -2910,4 +2961,5 @@
 #include "write_histISCCP.h"
 #endif
+
 
 #ifdef histmthNMC
@@ -2957,5 +3009,8 @@
 ccc         IF (ok_oasis) CALL quitcpl
          CALL phyredem ("restartphy.nc",dtime,radpas,
-     .      rlat, rlon, pctsrf, ftsol, ftsoil, deltat, fqsurf, qsol,
+     .      rlat, rlon, pctsrf, ftsol, ftsoil,
+cIM "slab" ocean
+     .      tslab, seaice, 
+     .      fqsurf, qsol,
      .      fsnow, falbe,falblw, fevap, rain_fall, snow_fall,
      .      solsw, sollwdown,dlw,
Index: /LMDZ4/trunk/libf/phylmd/phytrac.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/phytrac.F	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/phytrac.F	(revision 644)
@@ -628,5 +628,5 @@
 
       if (thermiques) then
-        print*,'calcul de leffet des thermiques'
+c        print*,'calcul de leffet des thermiques'
         nsplit=10
         DO it=1, nqmax
@@ -652,5 +652,5 @@
             enddo
           enddo ! nsplit
-          print*,'apres thermiques'
+c          print*,'apres thermiques'
 c             call dump2d(iim,jjm-1,d_tr_th(1,1,1),'d_tr_th      ')
 c            do k=1,klev
@@ -868,5 +868,5 @@
          close(99)
       else
-         print*, 'physique pas fini'
+c         print*, 'physique pas fini'
       endif
 
Index: /LMDZ4/trunk/libf/phylmd/raddim.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/raddim.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/raddim.h	(revision 644)
@@ -1,5 +1,5 @@
 !
-! $Header $
+! $Header$
 !
       INTEGER kdlon, kflev
-      PARAMETER (kdlon=klon,kflev=klev)
+      PARAMETER (kdlon=149,kflev=klev)
Index: /LMDZ4/trunk/libf/phylmd/radiornpb.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/radiornpb.F	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/radiornpb.F	(revision 644)
@@ -21,5 +21,5 @@
       REAL tautr(nbtr)
 C
-      WRITE(*,'(''PASSAGE radiornpb ... '',$)')
+c      WRITE(*,'(''PASSAGE radiornpb ... '',$)')
 C Attention, pour un pas de temps beaucoup plus petit que la decroissance!!!
 
@@ -48,5 +48,5 @@
       ENDDO
 c
-      WRITE(*,*) ' radiornpb OK'
+c      WRITE(*,*) ' radiornpb OK'
 c
       RETURN
Index: /LMDZ4/trunk/libf/phylmd/radlwsw.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/radlwsw.F	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/radlwsw.F	(revision 644)
@@ -89,14 +89,10 @@
       real topsw0(klon), toplw0(klon), solsw0(klon), sollw0(klon)
       real sollwdown(klon)
-cccIM 
+cIM output 3D 
       REAL*8 ZFSUP(KDLON,KFLEV+1)
       REAL*8 ZFSDN(KDLON,KFLEV+1)
       REAL*8 ZFSUP0(KDLON,KFLEV+1)
       REAL*8 ZFSDN0(KDLON,KFLEV+1)
-cIM
-cIM
-cIM   real sollwdownclr(klon) !LWdnSFCclr
-cIM   real toplwdown(klon) !LWdnTOA
-cIM   real toplwdownclr(klon) !LWdnTOAclr
+c
       REAL*8 ZFLUP(KDLON,KFLEV+1)
       REAL*8 ZFLDN(KDLON,KFLEV+1)
@@ -134,19 +130,15 @@
       REAL*8 ztopsw(kdlon), ztoplw(kdlon)
       REAL*8 zsolsw(kdlon), zsollw(kdlon), zalbpla(kdlon)
-cIM BEG
+cIM
       REAL*8 zsollwdown(kdlon)
-cIM   REAL*8 zsollwdown(kdlon), zsollwdownclr(kdlon)
-cIM   REAL*8 ztoplwdown(kdlon), ztoplwdownclr(kdlon)
-cIM END
+c
       REAL*8 ztopsw0(kdlon), ztoplw0(kdlon)
       REAL*8 zsolsw0(kdlon), zsollw0(kdlon)
       REAL*8 zznormcp
-cIM 080304   REAL swdn(klon,2),swdn0(klon,2),swup(klon,2),swup0(klon,2)
+cIM output 3D : SWup, SWdn, LWup, LWdn
       REAL swdn(klon,kflev+1),swdn0(klon,kflev+1)
       REAL swup(klon,kflev+1),swup0(klon,kflev+1)
-cIM BEG
       REAL lwdn(klon,kflev+1),lwdn0(klon,kflev+1)
       REAL lwup(klon,kflev+1),lwup0(klon,kflev+1)
-cIM END
 c-OB
 cjq the following quantities are needed for the aerosol radiative forcings
@@ -308,6 +300,4 @@
      .        ztoplw,zsollw,ztoplw0,zsollw0,
      .        zsollwdown,
-cIM  .        zsollwdown,zsollwdownclr,
-cIM  .        ztoplwdown,ztoplwdownclr)
      .        ZFLUP, ZFLDN, ZFLUP0,ZFLDN0)
 cIM ctes ds clesphys.h   CALL SW(PSCT, RCO2, zrmu0, zfract,
@@ -334,10 +324,4 @@
          sollwdown(iof+i) = zsollwdown(i)
 cIM
-cIM      sollwdownclr(iof+i) = zsollwdownclr(i)
-cIM BEG
-cIM      toplwdown(iof+i) = ztoplwdown(i)
-cIM      toplwdownclr(iof+i) = ztoplwdownclr(i)
-cIM END
-cIM 110304 BEG
          DO k = 1, kflev+1
          lwdn0 ( iof+i,k)   = ZFLDN0 ( i,k)
@@ -346,5 +330,5 @@
          lwup  ( iof+i,k)   = ZFLUP  ( i,k)
          ENDDO
-cIM 110304 END
+c
          topsw0(iof+i) = ztopsw0(i)
          toplw0(iof+i) = ztoplw0(i)
@@ -352,5 +336,5 @@
          sollw0(iof+i) = zsollw0(i)
          albpla(iof+i) = zalbpla(i)
-cIM 080304 BEG
+cIM
          DO k = 1, kflev+1
          swdn0 ( iof+i,k)   = ZFSDN0 ( i,k)
@@ -359,13 +343,4 @@
          swup  ( iof+i,k)   = ZFSUP  ( i,k)
          ENDDO !k=1, kflev+1
-cIM 080304 END
-c        swdn0 ( iof+i,1)   = ZFSDN0 ( i,1 )
-c        swdn0 ( iof+i,2)   = ZFSDN0 ( i,kflev + 1 )
-c        swdn  ( iof+i,1)   = ZFSDN  ( i,1 )
-c        swdn  ( iof+i,2)   = ZFSDN  ( i,kflev + 1 )
-c        swup0 ( iof+i,1)   = ZFSUP0 ( i,1 )
-c        swup0 ( iof+i,2)   = ZFSUP0 ( i,kflev + 1 )
-c        swup  ( iof+i,1)   = ZFSUP  ( i,1 )
-c        swup  ( iof+i,2)   = ZFSUP  ( i,kflev + 1 )
       ENDDO
 cjq-transform the aerosol forcings, if they have
@@ -2803,6 +2778,4 @@
      .              PTOPLW,PSOLLW,PTOPLW0,PSOLLW0,
      .              psollwdown,
-cIM  .              psollwdown,psollwdownclr,
-cIM  .              ptoplwdown,ptoplwdownclr)
      .              plwup, plwdn, plwup0, plwdn0)
       IMPLICIT none
@@ -2871,8 +2844,4 @@
 c Rajout LF
       real*8 psollwdown(kdlon)    ! LONGWAVE downwards flux at surface
-c Rajout IM
-cIM   real*8 psollwdownclr(kdlon) ! LONGWAVE CS downwards flux at surface
-cIM   real*8 ptoplwdown(kdlon)    ! LONGWAVE downwards flux at T.O.A.
-cIM   real*8 ptoplwdownclr(kdlon) ! LONGWAVE CS downwards flux at T.O.A.
 cIM
       REAL*8 plwup(KDLON,KFLEV+1)  ! LW up total sky
@@ -2953,9 +2922,5 @@
          PTOPLW0(i) = ZFLUC(i,1,KFLEV+1) + ZFLUC(i,2,KFLEV+1)
          psollwdown(i) = -ZFLUX(i,2,1)
-cIM
-cIM      psollwdownclr(i) = -ZFLUC(i,2,1)
-cIM      ptoplwdown(i) = ZFLUX(i,2,KFLEV+1)
-cIM      ptoplwdownclr(i) = ZFLUC(i,2,KFLEV+1)
-cIM
+c
 cIM attention aux signes !; LWtop >0, LWdn < 0
          DO k = 1, KFLEV+1
Index: /LMDZ4/trunk/libf/phylmd/stdlevvar.F90
===================================================================
--- /LMDZ4/trunk/libf/phylmd/stdlevvar.F90	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/stdlevvar.F90	(revision 644)
@@ -3,7 +3,7 @@
 !
       SUBROUTINE stdlevvar(klon, knon, nsrf, zxli, &
- &                         u1, v1, t1, q1, z1, &
- &                         ts1, qsurf, rugos, psol, pat1, &
- &                         t_2m, q_2m, u_10m) 
+                           u1, v1, t1, q1, z1, &
+                           ts1, qsurf, rugos, psol, pat1, &
+                           t_2m, q_2m, t_10m, q_10m, u_10m, ustar)
       IMPLICIT NONE
 !-------------------------------------------------------------------------
@@ -16,4 +16,7 @@
 !
 ! I. Musat, 01.07.2002
+!
+!AM On rajoute en sortie t et q a 10m pr le calcule d'hbtm2 dans clmain
+!
 !-------------------------------------------------------------------------
 !
@@ -36,4 +39,8 @@
 ! q_2m---output-R- humidite relative a 2m
 ! u_10m--output-R- vitesse du vent a 10m
+!AM
+! t_10m--output-R- temperature de l'air a 10m
+! q_10m--output-R- humidite specifique a 10m
+! ustar--output-R- u*
 !
       INTEGER, intent(in) :: klon, knon, nsrf
@@ -43,5 +50,6 @@
       REAL, dimension(klon), intent(in) :: psol, pat1
 !
-      REAL, dimension(klon), intent(out) :: t_2m, q_2m, u_10m
+      REAL, dimension(klon), intent(out) :: t_2m, q_2m, ustar
+      REAL, dimension(klon), intent(out) :: u_10m, t_10m, q_10m
 !-------------------------------------------------------------------------
 #include "YOMCST.inc"
@@ -67,5 +75,5 @@
 ! ri1 : nb. de Richardson entre la surface --> la 1ere couche
       REAL, dimension(klon) :: ri1 
-      REAL, dimension(klon) :: ustar, testar, qstar
+      REAL, dimension(klon) :: testar, qstar
       REAL, dimension(klon) :: zdte, zdq   
 ! lmon : longueur de Monin-Obukhov selon Hess, Colman and McAvaney 
@@ -101,11 +109,9 @@
         ustar(i) = sqrt(cdram(i) * speed(i) * speed(i))
         zdte(i) = tpot(i) - ts1(i)
-!       PRINT*,'AVANT i,zdte',i,zdte(i)
-!IM cf FH : on prend le max : pour eviter le plantage sur SUN
+        zdq(i) = max(q1(i),0.0) - max(qsurf(i),0.0)
+!
+!
 !IM BUG BUG BUG       zdte(i) = max(zdte(i),1.e-10)
         zdte(i) = sign(max(abs(zdte(i)),1.e-10),zdte(i))
-!       PRINT*,'APRES i,zdte',i,zdte(i)
-!
-        zdq(i) = max(q1(i),0.0) - max(qsurf(i),0.0)
 !
         testar(i) = (cdrah(i) * zdte(i) * speed(i))/ustar(i)
@@ -260,4 +266,11 @@
 !
         u_10m(i) = u_zref_p(i) * ok_pred(i) + u_zref_c(i) * ok_corr(i)
+!
+!AM
+        q_zref_c(i) = q_zref(i)
+        temp_c(i) = temp(i)
+        t_10m(i) = temp_p(i) * ok_pred(i) + temp_c(i) * ok_corr(i)
+        q_10m(i) = q_zref_p(i) * ok_pred(i) + q_zref_c(i) * ok_corr(i)
+!MA
       ENDDO
 ! 
Index: /LMDZ4/trunk/libf/phylmd/tetalevel.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/tetalevel.F	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/tetalevel.F	(revision 644)
@@ -0,0 +1,130 @@
+c================================================================
+c================================================================
+      SUBROUTINE tetalevel(ilon,ilev,lnew,pgcm,pres,Qgcm,Qpres)
+c================================================================
+c================================================================
+
+      IMPLICIT none
+
+#include "dimensions.h"
+#include "dimphy.h"
+
+c================================================================
+c
+c Interpoler des champs 3-D u, v et g du modele a un niveau de
+c pression donnee (pres)
+c
+c INPUT:  ilon ----- nombre de points
+c         ilev ----- nombre de couches
+c         lnew ----- true si on doit reinitialiser les poids
+c         pgcm ----- pressions modeles
+c         pres ----- pression vers laquelle on interpolle
+c         Qgcm ----- champ GCM
+c         Qpres ---- champ interpolle au niveau pres
+c
+c================================================================
+c
+c   arguments :
+c   -----------
+
+      INTEGER ilon, ilev
+      logical lnew
+
+      REAL pgcm(ilon,ilev)
+      REAL Qgcm(ilon,ilev)
+      real pres
+      REAL Qpres(ilon)
+
+c   local :
+c   -------
+c
+#include "paramet.h"
+c
+      INTEGER lt(ip1jmp1), lb(ip1jmp1)
+      REAL ptop, pbot, aist(ip1jmp1), aisb(ip1jmp1)
+      save lt,lb,ptop,pbot,aist,aisb
+
+      INTEGER i, k
+c
+c     PRINT*,'tetalevel pres=',pres
+c=====================================================================
+      if (lnew) then
+c   on réinitialise les réindicages et les poids
+c=====================================================================
+
+
+c Chercher les 2 couches les plus proches du niveau a obtenir
+c
+c Eventuellement, faire l'extrapolation a partir des deux couches
+c les plus basses ou les deux couches les plus hautes:
+      DO 130 i = 1, ilon
+cIM      IF ( ABS(pres-pgcm(i,ilev) ) .LT.
+         IF ( ABS(pres-pgcm(i,ilev) ) .GT.
+     .        ABS(pres-pgcm(i,1)) ) THEN
+            lt(i) = ilev     ! 2
+            lb(i) = ilev-1   ! 1
+         ELSE
+            lt(i) = 2
+            lb(i) = 1
+         ENDIF
+cIM   PRINT*,'i, ABS(pres-pgcm),ABS(pres-pgcm)',
+cIM  .i, ABS(pres-pgcm(i,ilev)),ABS(pres-pgcm(i,1))
+  130 CONTINUE
+      DO 150 k = 1, ilev-1
+         DO 140 i = 1, ilon
+            pbot = pgcm(i,k)
+            ptop = pgcm(i,k+1)
+cIM         IF (ptop.LE.pres .AND. pbot.GE.pres) THEN
+            IF (ptop.GE.pres .AND. pbot.LE.pres) THEN
+               lt(i) = k+1
+               lb(i) = k
+            ENDIF
+  140    CONTINUE
+  150 CONTINUE
+c
+c Interpolation lineaire:
+c
+      DO i = 1, ilon
+c interpolation en logarithme de pression:
+c
+c ...   Modif . P. Le Van    ( 20/01/98) ....
+c       Modif Frédéric Hourdin (3/01/02)
+
+c       IF(pgcm(i,lb(i)).NE.0.OR.
+c    $     pgcm(i,lt(i)).NE.0.) THEN
+c
+c       PRINT*,'i,lb,lt,2pgcm,pres',i,lb(i),
+c    .  lt(i),pgcm(i,lb(i)),pgcm(i,lt(i)),pres
+c
+        aist(i) = LOG( pgcm(i,lb(i))/ pres )
+     .       / LOG( pgcm(i,lb(i))/ pgcm(i,lt(i)) )
+        aisb(i) = LOG( pres / pgcm(i,lt(i)) )
+     .       / LOG( pgcm(i,lb(i))/ pgcm(i,lt(i)))
+      enddo
+
+
+      endif ! lnew
+
+c======================================================================
+c    inteprollation
+c======================================================================
+
+      do i=1,ilon
+         Qpres(i)= Qgcm(i,lb(i))*aisb(i)+Qgcm(i,lt(i))*aist(i)
+cIM      PRINT*,'i,Qgcm,Qpres',i,Qgcm(i,lb(i)),aisb(i),
+cIM  $   Qgcm(i,lt(i)),aist(i),Qpres(i)
+      enddo
+c
+c Je mets les vents a zero quand je rencontre une montagne
+      do i = 1, ilon
+cIM      if (pgcm(i,1).LT.pres) THEN
+         if (pgcm(i,1).GT.pres) THEN
+c           Qpres(i)=1e33
+            Qpres(i)=1e+20
+cIM         PRINT*,'i,pgcm(i,1),pres =',i,pgcm(i,1),pres
+         endif
+      enddo
+
+c
+      RETURN
+      END
Index: /LMDZ4/trunk/libf/phylmd/transp_lay.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/transp_lay.F	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/transp_lay.F	(revision 644)
@@ -0,0 +1,49 @@
+      SUBROUTINE transp_lay (paprs,tsol,
+     e                   t, q, u, v, geom,
+     s                   vtran_e, vtran_q, utran_e, utran_q)
+c
+      IMPLICIT none
+c======================================================================
+c Auteur(s): Z.X.Li (LMD/CNRS)
+c Date: le 25 avril 1994
+c Objet: Calculer le transport de l'energie et de la vapeur d'eau
+c======================================================================
+c
+#include "dimensions.h"
+#include "dimphy.h"
+#include "YOMCST.h"
+c
+      REAL paprs(klon,klev+1), tsol(klon)
+      REAL t(klon,klev), q(klon,klev), u(klon,klev), v(klon,klev)
+      REAL utran_e(klon,klev), utran_q(klon,klev)
+      REAL vtran_e(klon,klev), vtran_q(klon,klev)
+c
+      INTEGER i, l
+c     ------------------------------------------------------------------
+      REAL geom(klon,klev), esh
+c     ------------------------------------------------------------------
+      DO l = 1, klev
+      DO i = 1, klon
+         utran_e(i,l) = 0.0
+         utran_q(i,l) = 0.0
+         vtran_e(i,l) = 0.0
+         vtran_q(i,l) = 0.0
+      ENDDO
+      ENDDO
+c
+      DO l = 1, klev
+      DO i = 1, klon
+         esh = RCPD*t(i,l) + RLVTT*q(i,l) + geom(i,l)
+         utran_e(i,l)=utran_e(i,l)+ u(i,l)*esh*
+     .                (paprs(i,l)-paprs(i,l+1))/RG
+         utran_q(i,l)=utran_q(i,l)+ u(i,l)*q(i,l)
+     .                *(paprs(i,l)-paprs(i,l+1))/RG
+         vtran_e(i,l)=vtran_e(i,l)+ v(i,l)*esh*
+     .                (paprs(i,l)-paprs(i,l+1))/RG
+         vtran_q(i,l)=vtran_q(i,l)+ v(i,l)*q(i,l)
+     .                *(paprs(i,l)-paprs(i,l+1))/RG
+      ENDDO
+      ENDDO
+c
+      RETURN
+      END
Index: /LMDZ4/trunk/libf/phylmd/undefSTD.F
===================================================================
--- /LMDZ4/trunk/libf/phylmd/undefSTD.F	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/undefSTD.F	(revision 644)
@@ -0,0 +1,83 @@
+      SUBROUTINE undefSTD(nlevSTD,itap,tlevSTD,
+     $           ecrit_hf,
+     $           oknondef,tnondef,tsumSTD)
+      IMPLICIT none
+c
+c====================================================================
+c
+c I. Musat : 09.2004
+c
+c Calcul * du nombre de pas de temps (FLOAT(ecrit_XXX)-tnondef)) 
+c          ou la variable tlevSTD est bien definie (.NE.1.E+20), 
+c et 
+c        * de la somme de tlevSTD => tsumSTD
+c
+c nout=1 !var. journaliere "day" moyenne sur tous les pas de temps
+c        ! de la physique
+c nout=2 !var. mensuelle "mth" moyennee sur tous les pas de temps
+c        ! de la physique
+c nout=3 !var. mensuelle "NMC" moyennee toutes les 6heures
+c
+c
+c NB: mettre "inst(X)" dans le write_histXXX.h !
+c====================================================================
+c
+#include "dimensions.h"
+      integer jjmp1
+      parameter (jjmp1=jjm+1-1/jjm)
+#include "dimphy.h"
+c variables Input
+      INTEGER nlevSTD, klevSTD, itap
+      PARAMETER(klevSTD=17)
+      INTEGER ecrit_hf
+c
+c variables locales
+      INTEGER i, k, nout
+      PARAMETER(nout=3) !nout=1 : day; =2 : mth; =3 : NMC
+c
+c variables Output
+      REAL tlevSTD(klon,klevSTD), tsumSTD(klon,klevSTD,nout)
+      LOGICAL oknondef(klon,klevSTD,nout)
+      REAL tnondef(klon,klevSTD,nout)
+c
+c calcul variables tous les pas de temps de la physique 
+c
+      DO k=1, nlevSTD
+       DO i=1, klon
+        IF(tlevSTD(i,k).EQ.1E+20) THEN
+         IF(oknondef(i,k,1)) THEN          
+          tnondef(i,k,1)=tnondef(i,k,1)+1.
+         ENDIF !oknondef(i,k)
+c
+         IF(oknondef(i,k,2)) THEN          
+          tnondef(i,k,2)=tnondef(i,k,2)+1.
+         ENDIF !oknondef(i,k)
+c
+        ELSE IF(tlevSTD(i,k).NE.1E+20) THEN
+         tsumSTD(i,k,1)=tsumSTD(i,k,1)+tlevSTD(i,k)
+         tsumSTD(i,k,2)=tsumSTD(i,k,2)+tlevSTD(i,k)
+        ENDIF 
+       ENDDO !i
+      ENDDO !k
+c
+c calcul variables toutes les 6h
+c
+      IF(MOD(itap,ecrit_hf).EQ.0) THEN
+c
+       DO k=1, nlevSTD
+        DO i=1, klon
+         IF(tlevSTD(i,k).EQ.1E+20) THEN
+          IF(oknondef(i,k,3)) THEN          
+           tnondef(i,k,3)=tnondef(i,k,3)+1.
+          ENDIF !oknondef(i,k)
+c
+         ELSE IF(tlevSTD(i,k).NE.1E+20) THEN
+         tsumSTD(i,k,3)=tsumSTD(i,k,3)+tlevSTD(i,k)
+         ENDIF 
+        ENDDO !i
+       ENDDO !k
+
+      ENDIF !MOD(itap,ecrit_hf).EQ.0
+c
+      RETURN
+      END  
Index: /LMDZ4/trunk/libf/phylmd/write_bilKP_ave.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_bilKP_ave.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/write_bilKP_ave.h	(revision 644)
@@ -0,0 +1,195 @@
+c
+c $Header$
+c
+      IF (ok_journe) THEN
+c
+      ndex2d = 0
+      ndex3d = 0
+c
+c Champs 2D:
+c
+      itau_w = itau_phy + itap
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, ue_lay,zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"ue",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, ve_lay,zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"ve",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, uq_lay,zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"uq",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, vq_lay,zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"vq",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+c Champs 3D:
+C
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"temp",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"ovap",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"geop",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"vitu",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"vitv",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"vitw",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"pres",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, paprs, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"play",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldliq, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"oliq",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_dyn, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dtdyn",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_dyn, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dqdyn",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_con, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dtcon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_con, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"ducon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_con, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dvcon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_con, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dqcon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_lsc, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dtlsc",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_lsc, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dqlsc",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_vdf, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dtvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_vdf, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dqvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_ajs, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dtajs",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_ajs, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dqajs",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_eva, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dteva",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_eva, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dqeva",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, heat, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dtswr",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, heat0, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dtsw0",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cool, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dtlwr",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cool0, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dtlw0",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_vdf, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"duvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_vdf, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dvvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      IF (ok_orodr) THEN
+      IF (ok_orolf) THEN
+c
+      DO k = 1, klev
+      DO i = 1, klon
+        d_u_oli(i,k) = d_u_oro(i,k) + d_u_lif(i,k)
+        d_v_oli(i,k) = d_v_oro(i,k) + d_v_lif(i,k)
+      ENDDO
+      ENDDO
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_oli, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"duoli",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_oli, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dvoli",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      ENDIF
+      ENDIF
+C
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"duphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dvphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t, zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dtphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_qx(:,:,1), 
+     .zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dqphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_qx(:,:,2), 
+     .zx_tmp_3d)
+      CALL histwrite(nid_bilKPave,"dqlphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+C
+      if (ok_sync) then
+        call histsync(nid_bilKPave)
+      endif
+       ENDIF
+
Index: /LMDZ4/trunk/libf/phylmd/write_bilKP_ins.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_bilKP_ins.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/write_bilKP_ins.h	(revision 644)
@@ -0,0 +1,221 @@
+c
+c $Header$
+c
+      IF (ok_journe) THEN
+c
+      ndex2d = 0
+      ndex3d = 0
+c
+      itau_w = itau_phy + itap
+c
+c Champs 3D:
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, ue_lay,zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"ue",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, ve_lay,zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"ve",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, uq_lay,zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"uq",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, vq_lay,zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"vq",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+c Champs 3D:
+C
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"temp",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"ovap",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"geop",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"vitu",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"vitv",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"vitw",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"pres",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, paprs, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"play",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldliq, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"oliq",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_dyn, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dtdyn",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_dyn, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dqdyn",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_con, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dtcon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_con, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"ducon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_con, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dvcon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_con, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dqcon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_lsc, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dtlsc",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_lsc, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dqlsc",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_vdf, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dtvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_vdf, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dqvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_ajs, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dtajs",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_ajs, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dqajs",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_eva, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dteva",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_eva, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dqeva",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, heat, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dtswr",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, heat0, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dtsw0",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cool, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dtlwr",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cool0, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dtlw0",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_vdf, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"duvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_vdf, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dvvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      IF (ok_orodr) THEN
+      IF (ok_orolf) THEN
+c
+      DO k = 1, klev
+      DO i = 1, klon
+        d_u_oli(i,k) = d_u_oro(i,k) + d_u_lif(i,k)
+        d_v_oli(i,k) = d_v_oro(i,k) + d_v_lif(i,k)
+      ENDDO
+      ENDDO
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_oli, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"duoli",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_oli, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dvoli",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      ENDIF
+      ENDIF
+C
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"duphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dvphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t, zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dtphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_qx(:,:,1), 
+     .zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dqphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_qx(:,:,2), 
+     .zx_tmp_3d)
+      CALL histwrite(nid_bilKPins,"dqlphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+cIM 280405 BEG
+c
+c Champs 2D:
+c
+c   Ecriture de champs dynamiques sur des niveaux de pression
+c     DO k=1, nlevSTD
+      DO k=1, 12
+c
+       IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+       IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c
+       IF(bb2.EQ."850") THEN
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1,usumSTD(:,k,1),zx_tmp_2d)
+        CALL histwrite(nid_bilKPins,"u"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1,vsumSTD(:,k,1),zx_tmp_2d)
+        CALL histwrite(nid_bilKPins,"v"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+       ENDIF !(bb2.EQ."850")
+c
+       ENDDO !k=1, 12
+c
+cIM 280405 END
+C
+      if (ok_sync) then
+        call histsync(nid_bilKPins)
+      endif
+       ENDIF
+
Index: /LMDZ4/trunk/libf/phylmd/write_histISCCP.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_histISCCP.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/write_histISCCP.h	(revision 644)
@@ -8,4 +8,6 @@
 c
        itau_w = itau_phy + itap
+c
+       IF(type_run.EQ."ENSP".OR.type_run.EQ."CLIM") THEN
 c
         DO k=1,kmaxm1
@@ -24,4 +26,26 @@
      .                 zx_tmp_2d,iim*jjmp1,ndex2d)
 c
+        ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
+c
+         DO k=1, kmaxm1
+          DO l=1, lmaxm1
+c
+         zx_tmp_fi2d(1:klon)=fq_isccp(1:klon,k,l)*100.
+         CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,
+     .                    zx_tmp_2d)
+c
+cIM: champ 2d : (lon,lat) pour un tau et une pc fixes
+c
+         CALL histwrite(nid_isccp,pclev(l)//taulev(k),itau_w,
+     .                  zx_tmp_2d,iim*jjmp1,ndex2d)
+         ENDDO !l
+        ENDDO !k
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1,nbsunlit(1,:),zx_tmp_2d)
+        CALL histwrite(nid_isccp,"nsunlit",itau_w,
+     .                 zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+       ENDIF
+c
        if (ok_sync) then
         call histsync(nid_isccp)
Index: /LMDZ4/trunk/libf/phylmd/write_histREGDYN.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_histREGDYN.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/write_histREGDYN.h	(revision 644)
@@ -3,19 +3,8 @@
 !
       if (ok_regdyn) then
-
-c   Comprendre comment marche el i=nint(zout/zsto)
 c
-      ndex2d = 0
       ndex3d = 0
+      itau_w = itau_phy + itap
 c
-c        itap = 0
-c        zsto = dtime * REAL(NINT(86400./dtime*ecrit_regdyn))
-c        zout = dtime * ecrit_mth
-
-c        zsto = dtime
-c        zout = dtime * ecrit_mth
-c        zsto = dtime * REAL(NINT(86400./dtime*ecrit_regdyn))
-         itau_w = itau_phy + itap
-
        CALL histwrite(nid_regdyn,"hw1",itau_w,histoW(:,:,:,1),
      &               kmaxm1*lmaxm1*iwmax,ndex3d)
Index: /LMDZ4/trunk/libf/phylmd/write_histday.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_histday.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/write_histday.h	(revision 644)
@@ -1,6 +1,6 @@
-!
-! $Header$
-!
-      IF (ok_journe) THEN
+c
+c $Header$
+c
+      if (ok_journe) THEN
 c
       ndex2d = 0
@@ -9,24 +9,15 @@
 c Champs 2D:
 c
-         zsto = dtime
-         zout = dtime * FLOAT(ecrit_day)
          itau_w = itau_phy + itap
 
-         i = NINT(zout/zsto)
-         CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
 c
       IF(lev_histday.GE.1) THEN
 c
+       CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
        CALL histwrite(nid_day,"phis",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-         varname = 'phis'
-         vartitle= 'Surface geop. height'
-         varunits= '-'
-c
-         i = NINT(zout/zsto)
+c
+cIM 310804      CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
          CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
        CALL histwrite(nid_day,"aire",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-         varname = 'aire'
-         vartitle= 'Grid area'
-         varunits= '-'
 c
       DO i=1, klon
@@ -125,7 +116,8 @@
       CALL histwrite(nid_day,"snowf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxsnow,zx_tmp_2d)
-      CALL histwrite(nid_day,"snow_mass",itau_w,zx_tmp_2d,iim*jjmp1,
-     .               ndex2d)
+cIM: 140404   CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxsnow,zx_tmp_2d)
+c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zsnow_mass,zx_tmp_2d)
+c     CALL histwrite(nid_day,"snow_mass",itau_w,zx_tmp_2d,iim*jjmp1,
+c    .               ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
@@ -164,33 +156,42 @@
 
 c   Ecriture de champs dynamiques sur des niveaux de pression
-      DO k=1, nlevENS
-c
-        CALL gr_fi_ecrit(1, klon,iim,jjmp1, ulev(:,k),zx_tmp_2d)
-        CALL histwrite(nid_day,"u"//clev(k),itau_w,zx_tmp_2d,
+c     DO k=1, nlevENS
+      DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+      IF(bb2.EQ."850".OR.bb2.EQ."700"
+     $   .OR.bb2.EQ."500".OR.bb2.EQ."200") THEN
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1,usumSTD(:,k,1),zx_tmp_2d)
+        CALL histwrite(nid_day,"u"//bb2,itau_w,zx_tmp_2d,
      $       iim*jjmp1,ndex2d)
 c
-        CALL gr_fi_ecrit(1, klon,iim,jjmp1, vlev(:,k),zx_tmp_2d)
-        CALL histwrite(nid_day,"v"//clev(k),itau_w,zx_tmp_2d,
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1,vsumSTD(:,k,1),zx_tmp_2d)
+        CALL histwrite(nid_day,"v"//bb2,itau_w,zx_tmp_2d,
      $       iim*jjmp1,ndex2d)
 c
-      ENDDO !nlevENS
-c
-      DO k=1, nlevENS
-      IF(clev(k).EQ."500") THEN
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, wlev(:,indENS(k)),zx_tmp_2d)
-      CALL histwrite(nid_day,"w500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-c     DO i=1, klon
-c     print*,' ind, phi 500hPa',i,indENS(k),philev(:,indENS(k))
-c     print*,' ind, phi 500hPa',i,indENS(k)
-c     ENDDO
-c
-cBAD  CALL gr_fi_ecrit(1, klon,iim,jjmp1, philev(:,indENS(k)),zx_tmp_2d)
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, philev(:,k),zx_tmp_2d)
-      CALL histwrite(nid_day,"phi500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-      ENDIF !clev(k).EQ.500
-      ENDDO !k=1, nlevENS 
+      ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.bb2.EQ."500".OR.bb2.EQ."200") THEN
+c
+c w500
+c
+      IF(bb2.EQ."500") THEN
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,wsumSTD(:,k,1),zx_tmp_2d)
+      CALL histwrite(nid_day,"w"//bb2,itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,phisumSTD(:,k,1),zx_tmp_2d)
+      CALL histwrite(nid_day,"phi"//bb2,itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+
+      ENDIF !(bb2.EQ."500") THEN
+c
+      ENDDO !nlevSTD
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
@@ -216,4 +217,80 @@
       CALL histwrite(nid_day, "SWdnSFC",itau_w,zx_tmp_2d,
      .                               iim*jjmp1,ndex2d)
+c
+      IF (OCEAN.EQ.'force ') THEN
+c
+      DO i=1, klon
+      IF((pctsrf(i,is_oce).GT.epsfra).OR.
+     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
+       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
+     .                  fluxg(i)*pctsrf(i,is_sic)
+      ELSE
+       zx_tmp_fi2d(i) = 1.E+20
+      ENDIF
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"lmt_bils",itau_w,
+     .     zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      ELSE IF (OCEAN.EQ.'slab  ') THEN
+c
+      DO i=1, klon
+      IF((pctsrf(i,is_oce).GT.epsfra).OR.
+     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
+       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
+     .                  fluxg(i)*pctsrf(i,is_sic)
+      ELSE
+       zx_tmp_fi2d(i) = 1.E+20
+      ENDIF
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"slab_bils",itau_w,
+     .     zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      DO i=1, klon
+       IF(pctsrf(i,is_oce).GT.epsfra.OR.
+     $    pctsrf(i,is_sic).GT.epsfra) THEN
+        zx_tmp_fi2d(i)=tslab(i)
+       ELSE
+        zx_tmp_fi2d(i) = 1.E+20
+       ENDIF
+      ENDDO !i=1, klon
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"tslab",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice,zx_tmp_2d)
+      CALL histwrite(nid_day,"seaice",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice/1000.,zx_tmp_2d)
+      CALL histwrite(nid_day,"siceh",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      ENDIF !(OCEAN.EQ.'slab  ') THEN
+c
+      DO i=1, klon
+       IF (pctsrf(i,is_oce).GT.epsfra) THEN
+        zx_tmp_fi2d(i) = fluxo(i)
+       ELSE
+        zx_tmp_fi2d(i) = 1.E+20
+       ENDIF
+      ENDDO
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"fluxo",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      DO i=1, klon
+       IF (pctsrf(i,is_sic).GT.epsfra) THEN
+        zx_tmp_fi2d(i) = fluxg(i)
+       ELSE
+        zx_tmp_fi2d(i) = 1.E+20
+       ENDIF
+      ENDDO
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"fluxg",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
 c
       ENDIF !lev_histday.GE.1
@@ -398,7 +475,12 @@
       DO nsrf = 1, nbsrf
 C
+        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_day,"pourc_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
+C
         zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
         CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
-        CALL histwrite(nid_day,"pourc_"//clnsurf(nsrf),itau_w,
+        CALL histwrite(nid_day,"fract_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d) 
 C
@@ -444,4 +526,57 @@
       ENDIF !lev_histday.GE.4
 c
+      IF(lev_histday.GE.5) THEN !lev_histday.GE.5
+c
+c rajout sorties F. Aires
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw0,zx_tmp_2d)
+      CALL histwrite(nid_day,"tops0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw0,zx_tmp_2d)
+      CALL histwrite(nid_day,"topl0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw0,zx_tmp_2d)
+      CALL histwrite(nid_day,"sols0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw0,zx_tmp_2d)
+      CALL histwrite(nid_day,"soll0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldfra, zx_tmp_3d)
+      CALL histwrite(nid_day,"rneb",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, rnebcon, zx_tmp_3d)
+      CALL histwrite(nid_day,"rnebcon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, flwc,zx_tmp_3d)
+      CALL histwrite(nid_day,"lwcon",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, fiwc,zx_tmp_3d)
+      CALL histwrite(nid_day,"iwcon",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      zx_tmp_fi2d(1:klon) = flwp(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"lwp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1:klon) = fiwp(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"iwp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1, meantaucld,zx_tmp_2d)
+      CALL histwrite(nid_day,"meantaucld",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldtau,zx_tmp_3d)
+      CALL histwrite(nid_day,"cldtau",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldemi,zx_tmp_3d)
+      CALL histwrite(nid_day,"cldemi",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      ENDIF !lev_histday.GE.5
 c=================================================================
 c=================================================================
Index: /LMDZ4/trunk/libf/phylmd/write_histday_seri.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_histday_seri.h	(revision 644)
+++ /LMDZ4/trunk/libf/phylmd/write_histday_seri.h	(revision 644)
@@ -0,0 +1,238 @@
+c
+c $Header$
+c
+      IF (type_run.EQ."AMIP") THEN
+c
+      ndex2d = 0
+      itau_w = itau_phy + itap
+c
+c Champs 2D:
+c
+      pi = ACOS(-1.)
+      pir = 4.0*ATAN(1.0) / 180.0
+c
+      DO i=1, klon
+       zx_tmp_fi2d(i)=(topsw(i)-toplw(i))
+      ENDDO
+c
+      ok_msk=.FALSE.
+      msk(1:klon)=pctsrf(1:klon,is_ter)
+      CALL moyglo_pondaire(klon, zx_tmp_fi2d, airephy, 
+     .     ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"bilTOA",itau_w,
+     .               zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      ok_msk=.FALSE.
+      CALL moyglo_pondaire(klon, bils, airephy, 
+     .     ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"bils",itau_w,
+     .               zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      DO k=1, klev
+      DO i=1, klon
+cIM 080904    zx_tmp_fi3d(i,k)=u(i,k)**2+v(i,k)**2
+       zx_tmp_fi3d(i,k)=(u(i,k)**2+v(i,k)**2)/2.
+      ENDDO
+      ENDDO
+c
+      CALL moyglo_pondaima(klon, klev, zx_tmp_fi3d, 
+     .     airephy, paprs, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"ecin",itau_w,
+     .               zx_tmp_2d,iim*jjmp1,ndex2d) 
+c
+cIM 151004 BEG
+      IF(1.EQ.0) THEN
+c
+      DO k=1, klev
+      DO i=1, klon
+       zx_tmp_fi3d(i,k)=u_seri(i,k)*RA*cos(pir* rlat(i))
+      ENDDO
+      ENDDO
+c
+      CALL moyglo_pondaima(klon, klev, zx_tmp_fi3d, 
+     .     airephy, paprs, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"momang",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
+c
+c friction torque
+c
+      DO i=1, klon
+       zx_tmp_fi2d(i)=zxfluxu(i,1)*RA* cos(pir* rlat(i))
+      ENDDO
+c
+      ok_msk=.FALSE.
+      CALL moyglo_pondaire(klon, zx_tmp_fi2d, airephy, 
+     .     ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"frictor",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
+c
+c mountain torque
+c
+cIM 190504 BEG
+      CALL gr_fi_dyn(1,klon,iim+1,jjm+1,airephy,airedyn)
+      CALL gr_fi_dyn(klev+1,klon,iim+1,jjm+1,paprs,padyn)
+      CALL gr_fi_dyn(1,klon,iim+1,jjm+1,rlat,rlatdyn)
+      mountor=0.
+      airetot=0.
+      DO j = 1, jjmp1
+       DO i = 1, iim+1
+        ij=i+(iim+1)*(j-1)
+        zx_tmp(ij)=0.
+        DO k = 1, klev
+         zx_tmp(ij)=zx_tmp(ij)+dudyn(i,j,k)*airedyn(i,j)*
+     $              (padyn(i,j,k+1)-padyn(i,j,k))/RG
+         airetot=airetot+airedyn(i,j)
+        ENDDO
+cIM 190504 mountor=mountor+zx_tmp(ij)*airedyn(i,j)*RA*
+        mountor=mountor+zx_tmp(ij)*RA*
+     $           cos(pir* rlatdyn(i,j))
+       ENDDO
+      ENDDO
+cIM 151004 BEG
+      IF(itap.EQ.1) PRINT*,'airetot=',airetot,airetot/klev
+cIM 151004 END
+cIM 190504      mountor=mountor/(airetot*airetot)
+      mountor=mountor/airetot
+c
+cIM 190504 END
+      zx_tmp_2d(1:iim,1:jjmp1)=mountor
+      CALL histwrite(nid_day_seri,"mountor",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
+c
+      ENDIF !(1.EQ.0) THEN
+c
+c
+      CALL gr_fi_dyn(1,klon,iim+1,jjm+1,airephy,airedyn)
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
+      airetot=0.
+c     DO j = 1, jjmp1
+c      DO i = 1, iim+1
+c       ij=i+(iim+1)*(j-1)
+c       DO k = 1, klev
+c        airetot=airetot+airedyn(i,j)
+c        airetot=airetot+airedyn(i,j)
+c       ENDDO !k
+c      ENDDO !i
+c     ENDDO !j
+c
+      DO i=1, klon
+       airetot=airetot+airephy(i)
+      ENDDO
+c     IF(itap.EQ.1) PRINT*,'airetotphy=',airetot
+c
+      airetot=0.
+      DO j=1, jjmp1
+       DO i=1, iim
+        airetot=airetot+zx_tmp_2d(i,j)
+       ENDDO
+      ENDDO
+c
+c     IF(itap.EQ.1) PRINT*,'airetotij=',airetot,
+c    $ '4piR2',4.*pi*RA*RA
+c
+      zx_tmp_fi2d(1:klon)=aam/airetot
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"momang",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1:klon)=torsfc/airetot
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"torsfc",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
+c
+cIM 151004 END
+c
+      CALL moyglo_pondmass(klon, klev, t_seri,
+     .     airephy, paprs, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+c
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"tamv",itau_w,
+     .               zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      ok_msk=.FALSE.
+      CALL moyglo_pondaire(klon, paprs(:,1), airephy, 
+     .     ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"psol",itau_w,
+     .               zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      ok_msk=.FALSE.
+      CALL moyglo_pondaire(klon, evap, airephy, 
+     .     ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"evap",itau_w,
+     .               zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c     DO i=1, klon
+c      zx_tmp_fi2d(i)=SnowFrac(i,is_ter)
+c     ENDDO
+c
+c     ok_msk=.TRUE.
+c     msk(1:klon)=pctsrf_new(1:klon,is_ter)
+c     CALL moyglo_pondaire(klon, zx_tmp_fi2d, airephy, 
+c    .                     ok_msk, msk, moyglo)
+c     zx_tmp_fi2d(1:klon)=moyglo
+c
+c     CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+c     CALL histwrite(nid_day_seri,"SnowFrac",
+c    .               itau_w,zx_tmp_2d,iim*jjmp1,ndex2d) 
+c
+c     DO i=1, klon
+cIM 080904    zx_tmp_fi2d(i)=zsnow_mass(i)/330.*rowl
+c      zx_tmp_fi2d(i)=zsnow_mass(i)
+c     ENDDO
+c
+cIM 140904   ok_msk=.FALSE.
+c     ok_msk=.TRUE.
+c     msk(1:klon)=pctsrf(1:klon,is_ter)
+c     CALL moyglo_pondaire(klon, zx_tmp_fi2d, airephy, 
+c    .     ok_msk, msk, moyglo)
+c     zx_tmp_fi2d(1:klon)=moyglo
+c
+c     CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+c     CALL histwrite(nid_day_seri,"snow_depth",itau_w,
+c    .               zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      DO i=1, klon
+       zx_tmp_fi2d(i)=ftsol(i,is_oce)
+      ENDDO
+c
+      ok_msk=.TRUE.
+      msk(1:klon)=pctsrf(1:klon,is_oce)
+      CALL moyglo_pondaire(klon, zx_tmp_fi2d, airephy, 
+     .     ok_msk, msk, moyglo)
+      zx_tmp_fi2d(1:klon)=moyglo
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
+      CALL histwrite(nid_day_seri,"tsol_"//clnsurf(is_oce),
+     $               itau_w,zx_tmp_2d,iim*jjmp1,ndex2d) 
+c
+c=================================================================
+c=================================================================
+c=================================================================
+c
+      if (ok_sync) then
+        call histsync(nid_day_seri)
+      endif
+c
+      ENDIF !fin test sur type_run.EQ."AMIP"
Index: /LMDZ4/trunk/libf/phylmd/write_histhf.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_histhf.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/write_histhf.h	(revision 644)
@@ -4,24 +4,14 @@
       if (ok_hf) then
 
-c   Comprendre comment marche el i=nint(zout/zsto)
-c
-c     print*,'ACRITURE HF !!! ACRITURE HF !!! ACRITURE HF !!! '
+c
       ndex2d = 0
       ndex3d = 0
 c
-      zsto = dtime
-      zout = dtime * ecrit_hf
       itau_w = itau_phy + itap
 c
+      IF(type_run.EQ."CLIM".OR.type_run.EQ."ENSP") THEN
+c
       IF(lev_histhf.GE.1) THEN
 c
-c     i = NINT(zout/zsto)
-c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
-c     CALL histwrite(nid_hf,"phis",i,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-c     i = NINT(zout/zsto)
-c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
-c     CALL histwrite(nid_hf,"aire",i,zx_tmp_2d,iim*jjmp1,ndex2d)
-C
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, paire_ter, zx_tmp_2d)
       CALL histwrite(nid_hf,"aireTER",itau_w,
@@ -59,5 +49,5 @@
       ENDDO
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
-      CALL histwrite(nid_hf,"rain",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+      CALL histwrite(nid_hf,"precip",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
 c ENSEMBLES BEG
@@ -68,4 +58,5 @@
       CALL histwrite(nid_hf,"slp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
+c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zu10m,zx_tmp_2d)
       CALL histwrite(nid_hf,"u10m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
@@ -81,10 +72,21 @@
      $     iim*jjmp1,ndex2d)
 c
-      DO k=1, nlevENS
-      IF(clev(k).EQ."500") THEN
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, philev(:,k),zx_tmp_2d)
-      CALL histwrite(nid_hf,"phi"//clev(k),itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
-      ENDIF !clev(k).EQ."500"
+      DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+      IF(bb2.EQ."500") THEN
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, philevSTD(:,k),zx_tmp_2d)
+      CALL histwrite(nid_hf,"phi"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+      ENDIF !bb2.EQ."500"
       ENDDO
 c
@@ -93,5 +95,11 @@
       IF(lev_histhf.GE.2) THEN
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
+cIM 140904 BEG
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = cldt(i)*100.
+      ENDDO
+cIM 140904 END
+cIM 140904   CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_hf,"cldt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
@@ -115,34 +123,42 @@
       IF(lev_histhf.GE.3) THEN
 c
-      DO k=1, nlevENS
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, tlev(:,k),zx_tmp_2d)
-      CALL histwrite(nid_hf,"t"//clev(k),itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
-c
-      IF(clev(k).NE."500") THEN !clev(k).NE."500"
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, philev(:,k),zx_tmp_2d)
-      CALL histwrite(nid_hf,"phi"//clev(k),itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
-      ENDIF !clev(k).NE."500"
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, qlev(:,k),zx_tmp_2d)
-      CALL histwrite(nid_hf,"q"//clev(k),itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
-c
-      IF(1.EQ.0) THEN
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, rhlev(:,k),zx_tmp_2d)
-      CALL histwrite(nid_hf,"rh"//clev(k),itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
-      ENDIF !1.EQ.0
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ulev(:,k),zx_tmp_2d)
-      CALL histwrite(nid_hf,"u"//clev(k),itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, vlev(:,k),zx_tmp_2d)
-      CALL histwrite(nid_hf,"v"//clev(k),itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
-c
+      DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+      IF(bb2.EQ."850".OR.bb2.EQ."700".OR.
+     $   bb2.EQ."500".OR.bb2.EQ."200") THEN
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, tlevSTD(:,k),zx_tmp_2d)
+      CALL histwrite(nid_hf,"t"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+      IF(bb2.NE."500") THEN !bb2.NE."500"
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,philevSTD(:,k),zx_tmp_2d)
+      CALL histwrite(nid_hf,"phi"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+      ENDIF !bb2.NE."500"
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, qlevSTD(:,k),zx_tmp_2d)
+      CALL histwrite(nid_hf,"q"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ulevSTD(:,k),zx_tmp_2d)
+      CALL histwrite(nid_hf,"u"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, vlevSTD(:,k),zx_tmp_2d)
+      CALL histwrite(nid_hf,"v"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+      ENDIF !bb2.EQ."850".OR.bb2.EQ."700"
       ENDDO !nlevENS
 c
@@ -159,4 +175,5 @@
       IF(lev_histhf.GE.4) THEN 
 c
+#undef histhf3d
 #define histhf3d
 #ifdef histhf3d
@@ -166,7 +183,207 @@
       ENDIF !lev_histhf.GE.4
 c
-      if (ok_sync) then
+      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
+c
+      IF(lev_histhf.GE.1) THEN
+c
+      DO k=1, nlevSTD
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+        IF(bb2.EQ."850".or.bb2.EQ."200") THEN
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, ulevSTD(:,k),zx_tmp_2d)
+        CALL histwrite(nid_hf,"u"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, vlevSTD(:,k),zx_tmp_2d)
+        CALL histwrite(nid_hf,"v"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+        ENDIF !bb2.EQ."850".or.bb2.EQ."200"
+c
+      ENDDO !nlevSTD
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
+      CALL histwrite(nid_hf,"topl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_hf,"precip",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
+      CALL histwrite(nid_hf,"slp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+cIM 280504 BEG
+      ENDIF !(lev_histhf.GE.1) THEN
+c
+      IF(lev_histhf.GE.2) THEN
+c
+       DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+        IF(bb2.EQ."850".or.bb2.EQ."500") THEN
+c
+         CALL gr_fi_ecrit(1, klon,iim,jjmp1, tlevSTD(:,k),zx_tmp_2d)
+         CALL histwrite(nid_hf,"t"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+         CALL gr_fi_ecrit(1, klon,iim,jjmp1, qlevSTD(:,k),zx_tmp_2d)
+         CALL histwrite(nid_hf,"q"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+        ENDIF !bb2.EQ."850".or.bb2.EQ."500"
+c
+        IF(bb2.EQ."500") THEN
+c
+         CALL gr_fi_ecrit(1, klon,iim,jjmp1, philevSTD(:,k),zx_tmp_2d)
+         CALL histwrite(nid_hf,"phi"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, wlevSTD(:,k),zx_tmp_2d)
+        CALL histwrite(nid_hf,"w"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+        ENDIF !bb2.EQ."500"
+c
+        IF(bb3.EQ."50") THEN
+c
+         CALL gr_fi_ecrit(1, klon,iim,jjmp1, tlevSTD(:,k),zx_tmp_2d)
+         CALL histwrite(nid_hf,"t"//bb3,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, ulevSTD(:,k),zx_tmp_2d)
+        CALL histwrite(nid_hf,"u"//bb3,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, vlevSTD(:,k),zx_tmp_2d)
+        CALL histwrite(nid_hf,"v"//bb3,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+        ENDIF !bb3.EQ."50"
+c
+       ENDDO !k=1, nlevSTD
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zu10m,zx_tmp_2d)
+      CALL histwrite(nid_hf,"u10m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zv10m,zx_tmp_2d)
+      CALL histwrite(nid_hf,"v10m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zt2m,zx_tmp_2d)
+      CALL histwrite(nid_hf,"t2m",itau_w,zx_tmp_2d,iim*jjmp1,
+     $               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zq2m,zx_tmp_2d)
+      CALL histwrite(nid_hf,"q2m",itau_w,zx_tmp_2d,iim*jjmp1,
+     $               ndex2d)
+c
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = paprs(i,1)
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_hf,"psol",itau_w,zx_tmp_2d,iim*jjmp1,
+     $               ndex2d)
+c
+cIM 140904 BEG
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = cldt(i)*100.
+      ENDDO
+cIM 140904 END
+cIM 140904   CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_hf,"cldt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = zxfluxu(1 : klon, 1)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+      CALL histwrite(nid_hf,"taux",itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+      zx_tmp_fi2d(1 : klon) = zxfluxv(1 : klon, 1)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+      CALL histwrite(nid_hf,"tauy",itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, prw,zx_tmp_2d)
+      CALL histwrite(nid_hf,"prw",itau_w,zx_tmp_2d,
+     $               iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_hf,"sens",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfluxlat,zx_tmp_2d)
+      CALL histwrite(nid_hf,"flat",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zsnow_mass,zx_tmp_2d)
+c     CALL histwrite(nid_hf,"snow_mass",itau_w,zx_tmp_2d,iim*jjmp1,
+c    $               ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_hf, "SWdnSFC",itau_w,zx_tmp_2d,
+     $                               iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_hf, "SWupSFC",itau_w,zx_tmp_2d,
+     $                               iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdown,zx_tmp_2d)
+      CALL histwrite(nid_hf,"LWdnSFC",itau_w,zx_tmp_2d,iim*jjmp1,
+     $               ndex2d)
+c
+cIM 090904   zx_tmp_fi2d(1:klon)=sollw(1:klon)+sollwdown(1:klon)
+cIM 130904   zx_tmp_fi2d(1:klon)=sollw(1:klon)-sollwdown(1:klon)
+      zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
+      CALL histwrite(nid_hf,"LWupSFC",itau_w,zx_tmp_2d,iim*jjmp1,
+     $               ndex2d)                    
+c
+      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_hf, "SWdnTOA",itau_w,zx_tmp_2d,
+     $                               iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_hf, "SWupTOA",itau_w,zx_tmp_2d,
+     $                               iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(nbteta,klon,iim,jjmp1,PVteta,zx_tmp_3dte)
+      DO k=1, nbteta
+       CALL histwrite(nid_hf,"PV"//ctetaSTD(k),
+     .      itau_w,zx_tmp_3dte(:,:,k),iim*jjmp1,ndex2d)
+      ENDDO !k=1, nbteta
+c
+c
+c planetary boundary layer height
+c
+c     ENDIF !1.EQ.0
+c
+      ENDIF !(lev_histhf.GE.2) THEN
+cIM 280504 END
+c
+      ENDIF !type_run
+c
+      IF (ok_sync) THEN
         call histsync(nid_hf)
-      endif
+      ENDIF
 
-      endif
+      ENDIF
Index: /LMDZ4/trunk/libf/phylmd/write_histhf3d.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_histhf3d.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/write_histhf3d.h	(revision 644)
@@ -1,18 +1,10 @@
-!
-! $Header$
-!
-c     if (ok_hf) then
-
-c   Comprendre comment marche el i=nint(zout/zsto)
 c
-c     print*,'ACRITURE HF !!! ACRITURE HF !!! ACRITURE HF !!! '
+c $Header$
+c
+c
       ndex2d = 0
       ndex3d = 0
 c
-      zsto = dtime
-      zout = dtime * ecrit_hf
       itau_w = itau_phy + itap
-c
-c     IF(lev_histhf.GE.1) THEN
 c
 c Champs 3D:
@@ -34,9 +26,5 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-c     ENDIF !lev_histhf.GE.1
-c
       if (ok_sync) then
         call histsync(nid_hf3d)
       endif
-
-c     endif
Index: /LMDZ4/trunk/libf/phylmd/write_histins.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_histins.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/write_histins.h	(revision 644)
@@ -114,7 +114,12 @@
       DO nsrf = 1, nbsrf
 CXXX
+        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_ins,"pourc_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
+C 
         zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
         CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
-        CALL histwrite(nid_ins,"pourc_"//clnsurf(nsrf),itau_w,
+        CALL histwrite(nid_ins,"fract_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d) 
 C 
@@ -160,10 +165,55 @@
       CALL histwrite(nid_ins,"albslw",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxsnow,zx_tmp_2d)
-      CALL histwrite(nid_ins,"snow_mass",itau_w,zx_tmp_2d,iim*jjmp1,
-     .               ndex2d)
+cIM: 140404   CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxsnow,zx_tmp_2d)
+c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zsnow_mass,zx_tmp_2d)
+c     CALL histwrite(nid_ins,"snow_mass",itau_w,zx_tmp_2d,iim*jjmp1,
+c    .               ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxrugs,zx_tmp_2d)
       CALL histwrite(nid_ins,"rugs",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+cIM cf. AM 081204 BEG
+c
+cHBTM2
+c
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblh,zx_tmp_2d)
+      CALL histwrite(nid_ins,"s_pblh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblt,zx_tmp_2d)
+      CALL histwrite(nid_ins,"s_pblt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_lcl,zx_tmp_2d)
+      CALL histwrite(nid_ins,"s_lcl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_capCL,zx_tmp_2d)
+      CALL histwrite(nid_ins,"s_capCL",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_oliqCL,zx_tmp_2d)
+      CALL histwrite(nid_ins,"s_oliqCL",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_cteiCL,zx_tmp_2d)
+      CALL histwrite(nid_ins,"s_cteiCL",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_therm,zx_tmp_2d)
+      CALL histwrite(nid_ins,"s_therm",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb1,zx_tmp_2d)
+      CALL histwrite(nid_ins,"s_trmb1",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb2,zx_tmp_2d)
+      CALL histwrite(nid_ins,"s_trmb2",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb3,zx_tmp_2d)
+      CALL histwrite(nid_ins,"s_trmb3",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+cIM cf. AM 081204 END
 c
 c Champs 3D:
Index: /LMDZ4/trunk/libf/phylmd/write_histmth.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_histmth.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/write_histmth.h	(revision 644)
@@ -1,5 +1,5 @@
-!
-! $Header$
-!
+c
+c $Header$
+c
       IF (ok_mensuel) THEN
 c
@@ -7,9 +7,8 @@
       ndex3d = 0
 
-         zsto = dtime
-         zout = dtime * ecrit_mth
          itau_w = itau_phy + itap
 
-      i = NINT(zout/zsto)
+c
+      IF(type_run.EQ."CLIM".OR.type_run.EQ."ENSP") THEN
 c
       IF(lev_histmth.GE.1) THEN
@@ -20,11 +19,16 @@
       CALL histwrite(nid_mth,"phis",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 C
-      i = NINT(zout/zsto)
+cIM 310804   CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
       CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
       CALL histwrite(nid_mth,"aire",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
-      zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, is_ter)
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)* 100.
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_mth,"pourc_"//clnsurf(is_ter),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"fract_"//clnsurf(is_ter),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d)
 c
@@ -121,11 +125,8 @@
       CALL histwrite(nid_mth,"snow",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxsnow,zx_tmp_2d)
-      CALL histwrite(nid_mth,"snow_mass",itau_w,zx_tmp_2d,iim*jjmp1,
-     .               ndex2d)
-c
-cIM: 071003
-c     zx_tmp_fi2d(1:klon)=evap(1:klon)*86400.
-c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zsnow_mass,zx_tmp_2d)
+c     CALL histwrite(nid_mth,"snow_mass",itau_w,zx_tmp_2d,iim*jjmp1,
+c    .               ndex2d)
+c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
       CALL histwrite(nid_mth,"evap",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
@@ -143,6 +144,4 @@
       CALL histwrite(nid_mth,"topl0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
-c     zx_tmp_fi2d(1 : klon) = ZFSUP( 1 : klon, klevp1)
-cIM 080304   zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 2 )
       zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
       CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
@@ -150,7 +149,4 @@
      .                               iim*jjmp1,ndex2d)
 c
-c
-c      zx_tmp_fi2d(1 : klon) = ZFSUP0( 1 : klon, klevp1)
-cIM 080304   zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 2 )
       zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
       CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
@@ -158,6 +154,4 @@
      .                               iim*jjmp1,ndex2d)
 c
-c      zx_tmp_fi2d(1 : klon) = ZFSDN( 1 : klon, klevp1)
-cIM 080304   zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 2 )
       zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
       CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
@@ -165,6 +159,4 @@
      .                               iim*jjmp1,ndex2d)
 c
-c      zx_tmp_fi2d(1 : klon) = ZFSDN0( 1 : klon, klevp1)
-cIM 080304   zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 2 )
       zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
       CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
@@ -243,10 +235,18 @@
      .                               iim*jjmp1,ndex2d)
 c
-      zx_tmp_fi2d(1:klon)=sollw(1:klon)+sollwdown(1:klon)
+cIM 080904   zx_tmp_fi2d(1:klon)=sollw(1:klon)+sollwdown(1:klon)
+cIM 130904   zx_tmp_fi2d(1:klon)=sollw(1:klon)-sollwdown(1:klon)
+      zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
       CALL histwrite(nid_mth,"LWupSFC",itau_w,zx_tmp_2d,iim*jjmp1,
      .               ndex2d)
 c
-      zx_tmp_fi2d(1:klon)=sollw0(1:klon)+sollwdownclr(1:klon)
+      DO i=1, klon
+       sollwdownclr(i)=-1.*lwdn0(i,1)
+      ENDDO !i=1, klon
+
+cIM 080904   zx_tmp_fi2d(1:klon)=sollw0(1:klon)+sollwdownclr(1:klon)
+cIM 130904   zx_tmp_fi2d(1:klon)=sollw0(1:klon)-sollwdownclr(1:klon)
+      zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
       CALL histwrite(nid_mth,"LWupSFCclr",itau_w,zx_tmp_2d,iim*jjmp1,
@@ -257,36 +257,12 @@
      .               ndex2d)
 c
-      DO i=1, klon
-       sollwdownclr(i)=lwdn0(i,1)
-      ENDDO !i=1, klon
+c     DO i=1, klon
+cIM 080904     sollwdownclr(i)=lwdn0(i,1)
+c      sollwdownclr(i)=-1.*lwdn0(i,1)
+c     ENDDO !i=1, klon
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdownclr,zx_tmp_2d)
       CALL histwrite(nid_mth,"LWdnSFCclr",itau_w,zx_tmp_2d,
      $               iim*jjmp1,ndex2d)
-c
-c
-c effets des aerosols
-c
-c     IF (ok_ade.OR.ok_aie) THEN
-      zx_tmp_fi2d(1:klon) = topswai(1:klon) - topswad(1:klon)
-c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topswad,zx_tmp_2d)
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d ,zx_tmp_2d)
-      CALL histwrite(nid_mth,"topsad",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-      zx_tmp_fi2d(1:klon) = solswai(1:klon) - solswad(1:klon)
-c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solswad,zx_tmp_2d)
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d ,zx_tmp_2d)
-      CALL histwrite(nid_mth,"solsad",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-      zx_tmp_fi2d(1:klon) = topsw(1:klon) - topswai(1:klon)
-c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topswai,zx_tmp_2d)
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d ,zx_tmp_2d)
-      CALL histwrite(nid_mth,"topsai",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-      zx_tmp_fi2d(1:klon) = solsw(1:klon) - solswai(1:klon)
-c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solswai,zx_tmp_2d)
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d ,zx_tmp_2d)
-      CALL histwrite(nid_mth,"solsai",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     endif
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, bils,zx_tmp_2d)
@@ -322,5 +298,5 @@
        CALL histwrite(nid_mth,"fqcalving",itau_w,zx_tmp_2d,iim*jjmp1,
      $                ndex2d)
-cIM: 171003
+c
        DO nsrf = 1, nbsrf
         zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
@@ -334,15 +310,18 @@
      $      zx_tmp_2d,iim*jjmp1,ndex2d)
        ENDDO
-cIM: 171003
-c
-cIM      if ( lev_histday.gt.1 ) then
+c
       DO nsrf = 1, nbsrf
 CYYY
-       IF(nsrf.GT.1) THEN
-        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
+       IF(nsrf.GT.2) THEN
+        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
         CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
         CALL histwrite(nid_mth,"pourc_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d) 
-       ENDIF !nsrf.GT.1
+c
+        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"fract_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
+       ENDIF !nsrf.GT.2
 C 
         zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
@@ -376,8 +355,20 @@
      $      zx_tmp_2d,iim*jjmp1,ndex2d)
 C
-
+       IF(1.EQ.0) THEN
+C
+        zx_tmp_fi2d(1:klon) = fevap(1:klon,nsrf)*pctsrf(1:klon,nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"evapour_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+        zx_tmp_fi2d(1:klon) = (rain_fall(1:klon) + snow_fall(1:klon))
+     $                        *pctsrf(1:klon,nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"prepour_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+       ENDIF !(1.EQ.0) THEN
+C
       END DO  
-cIM      endif !lev_histday
-
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragm,zx_tmp_2d)
@@ -438,33 +429,164 @@
 c34EK
 c
-      ENDIF !iflag_con.GE.3
-c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, prw,zx_tmp_2d)
       CALL histwrite(nid_mth,"prw",itau_w,zx_tmp_2d,
      .               iim*jjmp1,ndex2d)
 c
-c
-c
+      ENDIF !iflag_con.GE.3
+c
+c
+cIM cf. AM 081204 BEG
+cHBTM2
+c
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblh,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_pblh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblt,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_pblt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_lcl,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_lcl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_capCL,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_capCL",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_oliqCL,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_oliqCL",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_cteiCL,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_cteiCL",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_therm,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_therm",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb1,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_trmb1",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb2,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_trmb2",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb3,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_trmb3",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+cIM cf. AM 081204 END
 c
 c  Champs interpolles sur des niveaux de pression
-      DO k=1, nlevENS
-c
-        CALL gr_fi_ecrit(1, klon,iim,jjmp1, ulev(:,k),zx_tmp_2d)
-        CALL histwrite(nid_mth,"u"//clev(k),itau_w,zx_tmp_2d,
+      DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+      IF(bb2.EQ."850".OR.bb2.EQ."700".OR.
+     $   bb2.EQ."500".OR.bb2.EQ."200") THEN
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1,usumSTD(:,k,2),zx_tmp_2d)
+        CALL histwrite(nid_mth,"u"//bb2,itau_w,zx_tmp_2d,
      $       iim*jjmp1,ndex2d)
 c
-        CALL gr_fi_ecrit(1, klon,iim,jjmp1, vlev(:,k),zx_tmp_2d)
-        CALL histwrite(nid_mth,"v"//clev(k),itau_w,zx_tmp_2d,
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1,vsumSTD(:,k,2),zx_tmp_2d)
+        CALL histwrite(nid_mth,"v"//bb2,itau_w,zx_tmp_2d,
      $       iim*jjmp1,ndex2d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, wlev(:,k),zx_tmp_2d)
-      CALL histwrite(nid_mth,"w"//clev(k),itau_w,zx_tmp_2d,
-     $     iim*jjmp1,ndex2d)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, philev(:,k),zx_tmp_2d)
-      CALL histwrite(nid_mth,"phi"//clev(k),itau_w,zx_tmp_2d,
-     $     iim*jjmp1,ndex2d)
-c
-      ENDDO !nlevENS
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,wsumSTD(:,k,2),zx_tmp_2d)
+      CALL histwrite(nid_mth,"w"//bb2,itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,phisumSTD(:,k,2),zx_tmp_2d)
+      CALL histwrite(nid_mth,"phi"//bb2,itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
+      ENDDO !nlevSTD
+c
+      DO i=1, klon
+       IF (pctsrf(i,is_oce).GT.epsfra) THEN
+        zx_tmp_fi2d(i) = fluxo(i)
+       ELSE
+        zx_tmp_fi2d(i) = 1.E+20
+       ENDIF
+      ENDDO
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"fluxo",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      DO i=1, klon
+       IF (pctsrf(i,is_sic).GT.epsfra) THEN
+        zx_tmp_fi2d(i) = fluxg(i)
+       ELSE
+        zx_tmp_fi2d(i) = 1.E+20
+       ENDIF
+      ENDDO
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"fluxg",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      IF (OCEAN.EQ.'force ') THEN
+c
+      DO i=1, klon
+      IF((pctsrf(i,is_oce).GT.epsfra).OR.
+     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
+       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
+     .                  fluxg(i)*pctsrf(i,is_sic)
+      ELSE
+       zx_tmp_fi2d(i) = 1.E+20
+      ENDIF
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"lmt_bils",itau_w,
+     .     zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      ELSE IF (OCEAN.EQ.'slab  ') THEN
+c
+      DO i=1, klon
+      IF((pctsrf(i,is_oce).GT.epsfra).OR.
+     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
+       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
+     .                  fluxg(i)*pctsrf(i,is_sic)
+      ELSE
+       zx_tmp_fi2d(i) = 1.E+20
+      ENDIF
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"slab_bils",itau_w,
+     .     zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      DO i=1, klon
+       IF(pctsrf(i,is_oce).GT.epsfra.OR.
+     $    pctsrf(i,is_sic).GT.epsfra) THEN
+        zx_tmp_fi2d(i)=tslab(i)
+       ELSE
+        zx_tmp_fi2d(i) = 1.E+20
+       ENDIF
+      ENDDO !i=1, klon
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"tslab",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice,zx_tmp_2d)
+      CALL histwrite(nid_mth,"seaice",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice/1000.,zx_tmp_2d)
+      CALL histwrite(nid_mth,"siceh",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      ENDIF !OCEAN.EQ.force/slab
+c
       ENDIF !lev_histmth.GE.1
 c
@@ -494,5 +616,4 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-cIM: 071003
 c     zx_tmp_fi3d(1:klon,1:klev)=qx(1:klon,1:klev,ivap)/
 c    .                         (1-qx(1:klon,1:klev,ivap))
@@ -533,9 +654,22 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, wo, zx_tmp_3d)
+      DO k=1, klev
+       DO i=1, klon
+cIM 151004      zx_tmp_fi3d(i,k)=MAX(wo(i,k),1.0e-12)*RG/46.6968
+c    $                    /(paprs(i,k)-paprs(i,k+1))
+c    $                    *(paprs(i,1)/101325.0)
+c        zx_tmp2_fi3d(i,k)=MAX(wo(i,k)*1.0e+6,1.0e-6)*RG/46.6968
+         zx_tmp_fi3d(i,k)=wo(i,k)*RG/46.6968
+     $                    /(paprs(i,k)-paprs(i,k+1))
+     $                    *(paprs(i,1)/101325.0)
+       ENDDO !i
+      ENDDO !k
+c
+c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, wo, zx_tmp_3d)
+c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp2_fi3d,zx_tmp_3d)
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"ozone",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
 c
-cIM 22.03.04 BEG
       CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t, zx_tmp_3d)
       CALL histwrite(nid_mth,"dtphy",itau_w,zx_tmp_3d,
@@ -546,5 +680,4 @@
       CALL histwrite(nid_mth,"dqphy",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
-cIM 22.03.04 END
 c
       ENDIF !lev_histmth.GE.2
@@ -586,6 +719,4 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      IF (iflag_con.GE.3) THEN
-c
       CALL gr_fi_ecrit(klev,klon,iim,jjmp1, Ma, zx_tmp_3d)
       CALL histwrite(nid_mth,"Ma",itau_w,zx_tmp_3d,
@@ -604,5 +735,4 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      ENDIF !iflag_con.GE.3
 c
       CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_dyn, zx_tmp_3d)
@@ -620,5 +750,6 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_con, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"dqcon",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
@@ -629,5 +760,4 @@
       CALL histwrite(nid_mth,"dtlsc",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
-cIM: 071003
 cIM: 101003 : K/30min ==> K/s
       zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+
@@ -637,5 +767,6 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_lsc, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"dqlsc",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
@@ -647,5 +778,6 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_vdf, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"dqvdf",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
@@ -657,5 +789,6 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_eva, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"dqeva",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
@@ -677,10 +810,10 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_ajs, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"dqajs",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
 c
 cIM: 101003 : K/day ==> K/s
-cIM: LMD_ARMIP3   zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)*pdtphys/RDAY 
       zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY 
       CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
@@ -689,5 +822,4 @@
 c
 cIM: 101003 : K/day ==> K/s      
-cIM: LMD_ARMIP3   zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)*pdtphys/RDAY
       zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
       CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
@@ -696,5 +828,4 @@
 c
 cIM: 101003 : K/day ==> K/s      
-cIM: LMD_ARMIP3     zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)*pdtphys/RDAY
       zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
       CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
@@ -703,5 +834,4 @@
 c
 cIM: 101003 : K/day ==> K/s      
-cIM: LMD_ARMIP3     zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)*pdtphys/RDAY
       zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
       CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
@@ -715,18 +845,22 @@
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_vdf, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"duvdf",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_vdf, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"dvvdf",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
 c
       IF (ok_orodr) THEN
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_oro, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"duoro",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_oro, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"dvoro",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
@@ -735,46 +869,1100 @@
 C
       IF (ok_orolf) THEN
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_u_lif, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"dulif",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
 c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_v_lif, zx_tmp_3d)
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_mth,"dvlif",itau_w,zx_tmp_3d,
      .                                   iim*jjmp1*klev,ndex3d)
       ENDIF
 C
-c
-c effets des aerosols
-c
-c     IF (ok_ade.OR.ok_aie) THEN
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, re, zx_tmp_3d)
-      CALL histwrite(nid_mth,"re",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, fl, zx_tmp_3d)
-      CALL histwrite(nid_mth,"redenom",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldtau, zx_tmp_3d)
-      CALL histwrite(nid_mth,"tau",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldtaupi, zx_tmp_3d)
-      CALL histwrite(nid_mth,"taupi",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c     endif
-c
       IF (nqmax.GE.3) THEN
-      DO iq=3,nqmax
-         CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,iq), zx_tmp_3d)
-         CALL histwrite(nid_mth,tnom(iq),itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-      ENDDO
+      DO iq=1,nqmax-2
+      IF (iq.LE.99) THEN
+         CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,iq+2), zx_tmp_3d)
+         WRITE(str2,'(i2.2)') iq
+         CALL histwrite(nid_mth,"trac"//str2,itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+      ELSE
+         PRINT*, "Trop de traceurs"
+         CALL abort
       ENDIF
+      ENDDO
+      ENDIF
 c
       ENDIF !lev_histmth.GE.4
+c
+      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
+c
+      IF(lev_histmth.GE.1) THEN
+c
+c Champs 2D:
+c
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis/RG,zx_tmp_2d)
+      CALL histwrite(nid_mth,"phis",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+cIM 310804   CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
+      CALL histwrite(nid_mth,"aire",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)* 100.
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
+      CALL histwrite(nid_mth,"pourc_"//clnsurf(is_ter),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
+      CALL histwrite(nid_mth,"fract_"//clnsurf(is_ter),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_lic)* 100.
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
+      CALL histwrite(nid_mth,"pourc_"//clnsurf(is_lic),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_lic)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
+      CALL histwrite(nid_mth,"fract_"//clnsurf(is_lic),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_sic)* 100.
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"pourc_"//clnsurf(is_sic),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_sic)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"fract_"//clnsurf(is_sic),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfluxlat,zx_tmp_2d)
+      CALL histwrite(nid_mth,"flat",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = topsw(1:klon)-toplw(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+      CALL histwrite(nid_mth,"bilTOA",itau_w,
+     .               zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c     IF(itap.EQ.ecrit_mth) THEN
+c       DO i=1, klon
+c         IF(nday_clr(i).GT.0.) THEN
+c          tops01(i)=tops01(i)/nday_clr(i)
+c         ELSE
+c          tops01(i)=1.e+20
+c         ENDIF
+c       ENDDO
+c       CALL gr_fi_ecrit(1, klon,iim,jjmp1, tops01,zx_tmp_2d)
+c       CALL histwrite(nid_mth,"tops01",itau_w,zx_tmp_2d,
+c    .       iim*jjmp1,ndex2d)
+c     ENDIF !itap.EQ.ecrit_mth 
+c
+c220404 BEG
+c
+c temperature tendency due to total diabatic heating
+       DO l=1, klev
+       DO i=1, klon
+       d_t(i,l) = (t_seri(i,l)-t(i,l))/dtime
+       ENDDO !i
+       ENDDO !l
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtdia",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+c temperature tendency due to SW radiation
+       DO l=1, klev
+       DO i=1, klon
+       zx_tmp_fi3d(i,l)=heat(i,l)/RDAY
+       ENDDO !i
+       ENDDO !l
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtsw",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+c temperature tendency due to LW radiation
+       DO l=1, klev
+       DO i=1, klon
+        zx_tmp_fi3d(i,l)=-1*cool(i,l)/RDAY
+       ENDDO !i
+       ENDDO !l
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtlw",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+c  temperature tendency due to moist convective processes
+       DO l=1, klev
+       DO i=1, klon
+        zx_tmp_fi3d(i,l)=d_t_con(i,l)/pdtphys
+       ENDDO !i
+       ENDDO !l
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtcon",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+c temperature tendency due to dry convective processes
+       DO l=1, klev
+       DO i=1, klon
+        zx_tmp_fi3d(i,l)=d_t_ajs(i,l)/pdtphys
+       ENDDO !i
+       ENDDO !l
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtajs",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+c  temperature tendency due to large scale precipitation
+       DO l=1, klev
+       DO i=1, klon
+       zx_tmp_fi3d(i,l)=d_t_lsc(i,l)/pdtphys
+       ENDDO !i
+       ENDDO !l
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtlsc",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+c  total moisture tendency due to diabatic processes
+       DO l=1, klev
+       DO i=1, klon
+        d_qx(i,l,ivap) = ( q_seri(i,l) - qx(i,l,ivap) ) / dtime
+        zx_tmp_fi3d(i,l)=d_qx(i,l,ivap)
+       ENDDO !i
+       ENDDO !l
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dqdia",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+cBEG 210404 BEG
+c
+      IF(ok_orodr.AND.ok_orolf) THEN
+      DO k = 1, klev
+      DO i = 1, klon
+        d_u_oli(i,k) = (d_u_oro(i,k) + d_u_lif(i,k))/pdtphys
+        d_v_oli(i,k) = (d_v_oro(i,k) + d_v_lif(i,k))/pdtphys
+      ENDDO
+      ENDDO
+      ENDIF !(ok_orodr.AND.ok_orolf) THEN
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_u_oli,zx_tmp_3d)
+      CALL histwrite(nid_mth,"duoli",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_v_oli,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dvoli",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_con(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"ducon",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_con(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dvcon",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_u,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dutot",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_v,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dvtot",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*klev,ndex3d)
+
+cEND 210404 END
+c
+c cldtrue
+c     CALL gr_fi_ecrit(klev, klon,iim,jjmp1,cldtrue,zx_tmp_3d)
+c     CALL histwrite(nid_mth,"cldtrue",itau_w,zx_tmp_3d,
+c    $       iim*jjmp1*klev,ndex3d)
+c
+c     CALL gr_fi_ecrit(klev, klon,iim,jjmp1,cldTOA,zx_tmp_3d)
+c     CALL histwrite(nid_mth,"cldTOA",itau_w,zx_tmp_3d,
+c    $       iim*jjmp1*klev,ndex3d)
+c
+c     CALL gr_fi_ecrit(klev, klon,iim,jjmp1,cldSFC,zx_tmp_3d)
+c     CALL histwrite(nid_mth,"cldSFC",itau_w,zx_tmp_3d,
+c    $       iim*jjmp1*klev,ndex3d)
+c
+      DO i=1, klon
+cIM 151004    zx_tmp_fi2d(i)=GWDtaux1(i,1)-GWDtaux0(i,1)
+       zx_tmp_fi2d(i)=zustrdr(i)+zustrli(i)
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"GWDtaux",
+     $               itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      DO i=1, klon
+cIM 151004    zx_tmp_fi2d(i)=GWDtauy1(i,1)-GWDtauy0(i,1)
+       zx_tmp_fi2d(i)=zvstrdr(i)+zvstrli(i)
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"GWDtauy",
+     $               itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c220404 END
+cAMIP2 END
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
+      CALL histwrite(nid_mth,"slp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
+      CALL histwrite(nid_mth,"tsol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zt2m,zx_tmp_2d)
+      CALL histwrite(nid_mth,"t2m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c ENSEMBLES BEG
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
+      CALL histwrite(nid_mth,"t2m_min",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
+      CALL histwrite(nid_mth,"t2m_max",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
+c
+c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,ftsoil(:,1,is_ter),zx_tmp_2d)
+c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,ftsol(:,is_ter),zx_tmp_2d)
+c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,ztsol,zx_tmp_2d)
+c     CALL histwrite(nid_mth,"tsoil",itau_w,zx_tmp_2d,
+c    .               iim*jjmp1,ndex2d)
+c
+      DO i=1, klon
+       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
+      ENDDO 
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"wind10m",itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"sicf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
+c     CALL histwrite(nid_mth,"temp",itau_w,zx_tmp_3d,
+c    .                                   iim*jjmp1*klev,ndex3d)
+c
+c ENSEMBLES END
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zq2m,zx_tmp_2d)
+      CALL histwrite(nid_mth,"q2m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zu10m,zx_tmp_2d)
+      CALL histwrite(nid_mth,"u10m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zv10m,zx_tmp_2d)
+      CALL histwrite(nid_mth,"v10m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = paprs(i,1)
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"psol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxqsurf,zx_tmp_2d)
+      CALL histwrite(nid_mth,"qsurf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      if (.not. ok_veget) then
+          CALL gr_fi_ecrit(1, klon,iim,jjmp1, qsol,zx_tmp_2d)
+          CALL histwrite(nid_mth,"qsol",itau_w,zx_tmp_2d,iim*jjmp1
+     $        ,ndex2d)
+      endif
+c
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"precip",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, nday_rain,zx_tmp_2d)
+      CALL histwrite(nid_mth,"ndayrain",itau_w,zx_tmp_2d,
+     $               iim*jjmp1,ndex2d)
+c
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"plul",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"pluc",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_fall,zx_tmp_2d)
+      CALL histwrite(nid_mth,"snowf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zsnow_mass,zx_tmp_2d)
+c     CALL histwrite(nid_mth,"snow_mass",itau_w,zx_tmp_2d,iim*jjmp1,
+c    .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
+      CALL histwrite(nid_mth,"evap",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
+      CALL histwrite(nid_mth,"tops",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw0,zx_tmp_2d)
+      CALL histwrite(nid_mth,"tops0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
+      CALL histwrite(nid_mth,"topl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw0,zx_tmp_2d)
+      CALL histwrite(nid_mth,"topl0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth, "SWupTOA",itau_w,zx_tmp_2d,
+     .                               iim*jjmp1,ndex2d)
+c
+c
+      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth, "SWupTOAclr",itau_w,zx_tmp_2d,
+     .                               iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth, "SWdnTOA",itau_w,zx_tmp_2d,
+     .                               iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth, "SWdnTOAclr",itau_w,zx_tmp_2d,
+     .                               iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWup200,zx_tmp_2d)
+      CALL histwrite(nid_mth,"SWup200",itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWup200clr,zx_tmp_2d)
+      CALL histwrite(nid_mth,"SWup200clr",itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWdn200,zx_tmp_2d)
+      CALL histwrite(nid_mth,"SWdn200",itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWdn200clr,zx_tmp_2d)
+      CALL histwrite(nid_mth,"SWdn200clr",itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, LWup200,zx_tmp_2d)
+      CALL histwrite(nid_mth,"LWup200",itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, LWup200clr,zx_tmp_2d)
+      CALL histwrite(nid_mth,"LWup200clr",itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1:klon)=-1*LWdn200(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"LWdn200",itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1:klon)=-1*LWdn200clr(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"LWdn200clr",itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+c200 END 
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw,zx_tmp_2d)
+      CALL histwrite(nid_mth,"sols",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw0,zx_tmp_2d)
+      CALL histwrite(nid_mth,"sols0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw,zx_tmp_2d)
+      CALL histwrite(nid_mth,"soll",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw0,zx_tmp_2d)
+      CALL histwrite(nid_mth,"soll0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c      zx_tmp_fi2d(1 : klon) = ZFSUP( 1 : klon, 1)
+      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth, "SWupSFC",itau_w,zx_tmp_2d,
+     .                               iim*jjmp1,ndex2d)
+c
+c      zx_tmp_fi2d(1 : klon) = ZFSUP0( 1 : klon, 1)
+      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth, "SWupSFCclr",itau_w,zx_tmp_2d,
+     .                               iim*jjmp1,ndex2d)
+c
+c      zx_tmp_fi2d(1 : klon) = ZFSDN( 1 : klon, 1)
+      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth, "SWdnSFC",itau_w,zx_tmp_2d,
+     .                               iim*jjmp1,ndex2d)
+c
+c      zx_tmp_fi2d(1 : klon) = ZFSDN0( 1 : klon, 1)
+      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 1 )
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth, "SWdnSFCclr",itau_w,zx_tmp_2d,
+     .                               iim*jjmp1,ndex2d)
+c
+cIM 080904   zx_tmp_fi2d(1:klon)=sollw(1:klon)+sollwdown(1:klon)
+cIM 130904   zx_tmp_fi2d(1:klon)=sollw(1:klon)-sollwdown(1:klon)
+      zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
+      CALL histwrite(nid_mth,"LWupSFC",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      DO i=1, klon
+       sollwdownclr(i)=-1.*lwdn0(i,1)
+      ENDDO !i=1, klon
+c
+cIM 080904   zx_tmp_fi2d(1:klon)=sollw0(1:klon)+sollwdownclr(1:klon)
+cIM 130904   zx_tmp_fi2d(1:klon)=sollw0(1:klon)-sollwdownclr(1:klon)
+      zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
+      CALL histwrite(nid_mth,"LWupSFCclr",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdown,zx_tmp_2d)
+      CALL histwrite(nid_mth,"LWdnSFC",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+c     DO i=1, klon
+cIM 08004    sollwdownclr(i)=lwdn0(i,1)
+c      sollwdownclr(i)=-1.*lwdn0(i,1)
+c     ENDDO !i=1, klon
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdownclr,zx_tmp_2d)
+      CALL histwrite(nid_mth,"LWdnSFCclr",itau_w,zx_tmp_2d,
+     $               iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, bils,zx_tmp_2d)
+      CALL histwrite(nid_mth,"bils",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
+c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, sens,zx_tmp_2d)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"sens",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, fder,zx_tmp_2d)
+      CALL histwrite(nid_mth,"fder",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c
+c      DO i = 1, klon
+c         zx_tmp_fi2d(i) = fluxu(i,1)
+c      ENDDO
+c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+c      CALL histwrite(nid_mth,"frtu",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c      DO i = 1, klon
+c         zx_tmp_fi2d(i) = fluxv(i,1)
+c      ENDDO
+c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+c      CALL histwrite(nid_mth,"frtv",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c
+       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxffonte,zx_tmp_2d)
+       CALL histwrite(nid_mth,"ffonte",itau_w,zx_tmp_2d,iim*jjmp1,
+     $                ndex2d)
+c
+       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfqcalving,zx_tmp_2d)
+       CALL histwrite(nid_mth,"fqcalving",itau_w,zx_tmp_2d,iim*jjmp1,
+     $                ndex2d)
+c
+       DO nsrf = 1, nbsrf
+        zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"taux_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
+C      
+        zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"tauy_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+       ENDDO
+c
+        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, is_oce)*100.
+        CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+        CALL histwrite(nid_mth,"pourc_"//clnsurf(is_oce),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
+c
+        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, is_oce)
+        CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+        CALL histwrite(nid_mth,"fract_"//clnsurf(is_oce),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
+c
+      DO nsrf = 1, nbsrf
+CYYY
+C 
+        zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"tsol_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+        zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"sens_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+        zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"lat_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
+C
+        zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"flw_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+        zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"fsw_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+        zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"wbils_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+       IF(1.EQ.0) THEN
+C
+        zx_tmp_fi2d(1:klon) = fevap(1:klon,nsrf)*pctsrf(1:klon,nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"evapour_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+        zx_tmp_fi2d(1:klon) = (rain_fall(1:klon) + snow_fall(1:klon))
+     $                        *pctsrf(1:klon,nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"prepour_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+       ENDIF !(1.EQ.0) THEN
+C
+      END DO  
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragm,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cdrm",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragh,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cdrh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldl,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cldl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldm,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cldm",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldh,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cldh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt*100.,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cldt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldq,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cldq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1:klon) = flwp(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"lwp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1:klon) = fiwp(1:klon)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"iwp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ue,zx_tmp_2d)
+      CALL histwrite(nid_mth,"ue",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ve,zx_tmp_2d)
+      CALL histwrite(nid_mth,"ve",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, uq,zx_tmp_2d)
+      CALL histwrite(nid_mth,"uq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, vq,zx_tmp_2d)
+      CALL histwrite(nid_mth,"vq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+cKE43
+      IF (iflag_con.GE.3) THEN ! sb
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cape,zx_tmp_2d)
+      CALL histwrite(nid_mth,"cape",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,pbase,zx_tmp_2d)
+      CALL histwrite(nid_mth,"pbase",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_pct,zx_tmp_2d)
+      CALL histwrite(nid_mth,"ptop",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_cbmf,zx_tmp_2d)
+      CALL histwrite(nid_mth,"fbase",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+c34EK
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, prw,zx_tmp_2d)
+      CALL histwrite(nid_mth,"prw",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
+c
+      ENDIF !iflag_con.GE.3
+c
+cIM cf. AM 081204 BEG
+cHBTM2
+c
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblh,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_pblh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblt,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_pblt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_lcl,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_lcl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_capCL,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_capCL",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_oliqCL,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_oliqCL",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_cteiCL,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_cteiCL",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_therm,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_therm",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb1,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_trmb1",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb2,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_trmb2",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb3,zx_tmp_2d)
+      CALL histwrite(nid_mth,"s_trmb3",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
+c
+cIM cf. AM 081204 END
+c
+c  Champs interpolles sur des niveaux de pression
+c     DO k=1, nlevENS
+      DO k=1, nlevSTD
+c
+c        bb=clevSTD(k)
+c
+c        IF(k.GE.2) THEN
+         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
+         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
+c         aa=clevSTD(k)
+c         bb=aa(1:lnblnk1(aa))
+c        ENDIF
+c
+       IF(bb2.EQ."850".OR.bb2.EQ."700"
+     $   .OR.bb2.EQ."500".OR.bb2.EQ."200") THEN
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1,usumSTD(:,k,2),zx_tmp_2d)
+        CALL histwrite(nid_mth,"u"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1,vsumSTD(:,k,2),zx_tmp_2d)
+        CALL histwrite(nid_mth,"v"//bb2,itau_w,zx_tmp_2d,
+     $       iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,wsumSTD(:,k,2),zx_tmp_2d)
+      CALL histwrite(nid_mth,"w"//bb2,itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1,phisumSTD(:,k,2),zx_tmp_2d)
+      CALL histwrite(nid_mth,"phi"//bb2,itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      ENDIF !(bb2.EQ."850".OR.bb2.EQ."700"
+      ENDDO !nlevSTD
+c
+      DO i=1, klon
+       IF (pctsrf(i,is_oce).GT.epsfra) THEN
+        zx_tmp_fi2d(i) = fluxo(i)
+       ELSE
+        zx_tmp_fi2d(i) = 1.E+20
+       ENDIF
+      ENDDO
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"fluxo",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      DO i=1, klon
+       IF (pctsrf(i,is_sic).GT.epsfra) THEN
+        zx_tmp_fi2d(i) = fluxg(i)
+       ELSE
+        zx_tmp_fi2d(i) = 1.E+20
+       ENDIF
+      ENDDO
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"fluxg",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      IF (OCEAN.EQ.'force ') THEN
+c
+      DO i=1, klon
+      IF((pctsrf(i,is_oce).GT.epsfra).OR.
+     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
+       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
+     .                  fluxg(i)*pctsrf(i,is_sic)
+      ELSE
+       zx_tmp_fi2d(i) = 1.E+20
+      ENDIF
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"lmt_bils",itau_w,
+     .     zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      ELSE IF (OCEAN.EQ.'slab  ') THEN
+c
+c
+      DO i=1, klon
+      IF((pctsrf(i,is_oce).GT.epsfra).OR.
+     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
+       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
+     .                  fluxg(i)*pctsrf(i,is_sic)
+      ELSE
+       zx_tmp_fi2d(i) = 1.E+20
+      ENDIF
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"slab_bils",itau_w,
+     .     zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      DO i=1, klon
+       IF(pctsrf(i,is_oce).GT.epsfra.OR.
+     $    pctsrf(i,is_sic).GT.epsfra) THEN
+        zx_tmp_fi2d(i)=tslab(i)
+       ELSE
+        zx_tmp_fi2d(i) = 1.E+20
+       ENDIF
+      ENDDO !i=1, klon
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_mth,"tslab",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice,zx_tmp_2d)
+      CALL histwrite(nid_mth,"seaice",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice/1000.,zx_tmp_2d)
+      CALL histwrite(nid_mth,"siceh",itau_w,zx_tmp_2d,
+     .     iim*jjmp1,ndex2d)
+c
+      ENDIF !OCEAN.EQ.force/slab
+c
+      ENDIF !lev_histmth.GE.1
+c
+      IF(lev_histmth.GE.2) THEN
+c
+c Champs 3D:
+C
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, flwc,zx_tmp_3d)
+      CALL histwrite(nid_mth,"lwcon",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, fiwc,zx_tmp_3d)
+      CALL histwrite(nid_mth,"iwcon",itau_w,zx_tmp_3d,
+     .               iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
+      CALL histwrite(nid_mth,"temp",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+c#ifdef histmthNMC
+c#include "write_histmthNMC.h"
+c#endif
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
+      CALL histwrite(nid_mth,"ovap",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+c     zx_tmp_fi3d(1:klon,1:klev)=qx(1:klon,1:klev,ivap)/
+c    .                         (1-qx(1:klon,1:klev,ivap))
+c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
+c     CALL histwrite(nid_mth,"wvap",itau_w,zx_tmp_3d,
+c    .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
+      CALL histwrite(nid_mth,"geop",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
+      CALL histwrite(nid_mth,"vitu",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
+      CALL histwrite(nid_mth,"vitv",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
+      CALL histwrite(nid_mth,"vitw",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
+      CALL histwrite(nid_mth,"pres",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldfra*100., zx_tmp_3d)
+      CALL histwrite(nid_mth,"rneb",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, rnebcon, zx_tmp_3d)
+      CALL histwrite(nid_mth,"rnebcon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_rh, zx_tmp_3d)
+      CALL histwrite(nid_mth,"rhum",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      DO k=1, klev
+       DO i=1, klon
+cIM 151004        zx_tmp_fi3d(i,k)=MAX(wo(i,k),1.0e-12)*RG/46.6968
+c    $                    /(paprs(i,k)-paprs(i,k+1))
+c    $                    *(paprs(i,1)/101325.0)
+c        zx_tmp2_fi3d(i,k)=MAX(wo(i,k)*1.0e+6,1.0e-6)*RG/46.6968
+         zx_tmp_fi3d(i,k)=wo(i,k)*RG/46.6968
+     $                    /(paprs(i,k)-paprs(i,k+1))
+     $                    *(paprs(i,1)/101325.0)
+       ENDDO !i
+      ENDDO !k
+c
+c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, wo, zx_tmp_3d)
+c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp2_fi3d,zx_tmp_3d)
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"ozone",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_qx(:,:,ivap), 
+     .                 zx_tmp_3d)
+      CALL histwrite(nid_mth,"dqphy",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      ENDIF !lev_histmth.GE.2
+c
+      IF(lev_histmth.GE.3) THEN
+c
+       DO nsrf=1, nbsrf
+c
+        zx_tmp_fi2d(1 : klon) = falbe( 1 : klon, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"albe_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+C
+        zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
+        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+        CALL histwrite(nid_mth,"rugs_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, agesno,zx_tmp_2d)
+      CALL histwrite(nid_mth,"ages_"//clnsurf(nsrf),itau_w
+     $    ,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      ENDDO !nsrf=1, nbsrf
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsol,zx_tmp_2d)
+      CALL histwrite(nid_mth,"albs",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsollw,zx_tmp_2d)
+      CALL histwrite(nid_mth,"albslw",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      ENDIF !lev_histmth.GE.3
+c
+c
+      IF(lev_histmth.GE.4) THEN
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, clwcon0, zx_tmp_3d)
+      CALL histwrite(nid_mth,"clwcon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, Ma, zx_tmp_3d)
+      CALL histwrite(nid_mth,"Ma",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, upwd, zx_tmp_3d)
+      CALL histwrite(nid_mth,"upwd",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dnwd",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd0, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dnwd0",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_dyn, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtdyn",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_dyn, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dqdyn",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+cIM: 101003 : K/30min ==> K/s
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dqcon",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+cIM: 101003 : K/30min ==> K/s
+      zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+
+     .                             d_t_eva(1:klon,1:klev))/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtlschr",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dqlsc",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+cIM: 101003 : K/30min ==> K/s
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dqvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+cIM: 101003 : K/30min ==> K/s
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dteva",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dqeva",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      zpt_conv = 0.
+      where (ptconv) zpt_conv = 1.
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zpt_conv, zx_tmp_3d)
+      CALL histwrite(nid_mth,"ptconv",itau_w,zx_tmp_3d,
+     .                                   iim*(jjmp1)*klev,ndex3d)
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, ratqs, zx_tmp_3d)
+      CALL histwrite(nid_mth,"ratqs",itau_w,zx_tmp_3d,
+     .                                   iim*(jjmp1)*klev,ndex3d)
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dqajs",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+cIM: 101003 : K/day ==> K/s
+      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY 
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtswr",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+cIM: 101003 : K/day ==> K/s      
+      zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtsw0",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+cIM: 101003 : K/day ==> K/s      
+      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtlwr",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+cIM: 101003 : K/day ==> K/s      
+      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtlw0",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+cIM: 101003 : deja en K/s      
+      zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dtec",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"duvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dvvdf",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      IF (ok_orodr) THEN
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"duoro",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dvoro",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      ENDIF
+C
+      IF (ok_orolf) THEN
+      zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dulif",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+      CALL histwrite(nid_mth,"dvlif",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+      ENDIF
+C
+      IF (nqmax.GE.3) THEN
+      DO iq=1,nqmax-2
+      IF (iq.LE.99) THEN
+         CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,iq+2), zx_tmp_3d)
+         WRITE(str2,'(i2.2)') iq
+         CALL histwrite(nid_mth,"trac"//str2,itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+      ELSE
+         PRINT*, "Trop de traceurs"
+         CALL abort
+      ENDIF
+      ENDDO
+      ENDIF
+c
+      ENDIF !lev_histmth.GE.4
+c
+      ENDIF !(type_run.EQ."AMIP")
 c
       if (ok_sync) then
         call histsync(nid_mth)
       endif
-      ENDIF
+c
+      ENDIF !ok_mensuel
Index: /LMDZ4/trunk/libf/phylmd/write_histmthNMC.h
===================================================================
--- /LMDZ4/trunk/libf/phylmd/write_histmthNMC.h	(revision 643)
+++ /LMDZ4/trunk/libf/phylmd/write_histmthNMC.h	(revision 644)
@@ -5,54 +5,140 @@
       IF (ok_mensuel) THEN
 c
-      ndex2d = 0
-      ndex3d = 0
+       ndex3d = 0
+       itau_w = itau_phy + itap
+ccc
+c  Champs interpolles sur des niveaux de pression du NMC
 c
-c Champs 2D:
+c     PARAMETER(nout=3) !nout=1 : day; =2 : mth; =3 : NMC
+ccc
+      IF(type_run.EQ."CLIM".OR.type_run.EQ."ENSP") THEN
+ccc
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,tsumSTD(:,:,2),
+     $      zx_tmp_3d)
+       CALL histwrite(nid_nmc,"temp",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
 c
-
-        zsto = dtime
-        zout = dtime * ecrit_mth
-        itau_w = itau_phy + itap
-
-      i = NINT(zout/zsto)
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,phisumSTD(:,:,2),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"phi",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
 c
-c  Champs interpolles sur des niveaux de pression du NMC
-c110304 BEG
-      DO k=1, nlevSTD
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,qsumSTD(:,:,2),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"q",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
 c
-         bb=clevSTD(k)
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,rhsumSTD(:,:,2),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"rh",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
 c
-         IF(k.GE.2) THEN
-          aa=clevSTD(k)
-          bb=aa(1:lnblnk1(aa))
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,usumSTD(:,:,2),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"u",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vsumSTD(:,:,2),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"v",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+ccc
+      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
+ccc
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,tsumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"temp",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,phisumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"phi",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,qsumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"q",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,rhsumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"rh",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,usumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"u",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vsumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"v",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,wsumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"w",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       DO k=1, nlevSTD
+        DO i=1, klon
+         IF(tnondef(i,k,3).NE.1.E+20) THEN
+          zx_tmp_fi3d(i,k) = (100.*tnondef(i,k,3))/FLOAT(ecrit_hf2mth)
+         ELSE
+          zx_tmp_fi3d(i,k) = 1.E+20
          ENDIF
+        ENDDO
+       ENDDO !k=1, nlevSTD
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, tlevSTD(:,k),zx_tmp_2d)
-      CALL histwrite(nid_nmc,"t"//bb,itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
+       CALL histwrite(nid_nmc,"psbg",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, philevSTD(:,k),zx_tmp_2d)
-      CALL histwrite(nid_nmc,"phi"//bb,itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,uvsumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"uv",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, qlevSTD(:,k),zx_tmp_2d)
-      CALL histwrite(nid_nmc,"q"//bb,itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vqsumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"vq",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, rhlevSTD(:,k),zx_tmp_2d)
-      CALL histwrite(nid_nmc,"rh"//bb,itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vTsumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"vT",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ulevSTD(:,k),zx_tmp_2d)
-      CALL histwrite(nid_nmc,"u"//bb,itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1, wqsumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"wq",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, vlevSTD(:,k),zx_tmp_2d)
-      CALL histwrite(nid_nmc,"v"//bb,itau_w,zx_tmp_2d,
-     $       iim*jjmp1,ndex2d)
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vphisumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"vphi",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
 c
-      ENDDO !k=1, nlevSTD
-ccc
-c110304 END
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,wTsumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"wT",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,u2sumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"uxu",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,v2sumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"vxv",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,T2sumSTD(:,:,3),
+     $     zx_tmp_3d)
+       CALL histwrite(nid_nmc,"TxT",itau_w,zx_tmp_3d,
+     $       iim*jjmp1*nlevSTD,ndex3d)
+c
+      ENDIF !type_run
 c
       if (ok_sync) then
Index: /LMDZ4/trunk/makegcm
===================================================================
--- /LMDZ4/trunk/makegcm	(revision 643)
+++ /LMDZ4/trunk/makegcm	(revision 644)
@@ -729,7 +729,11 @@
       \mv $libf/grid/dimensions90.tmp $libf/grid/dimensions90.h
 endif
-sed -e 's/^c/\!/' -e 's/^     s/  \&/' $libf/dyn3d/paramet.h >! $libf/dyn3d/paramet90.tmp
+sed -n -e 's/^c/\!/' -e '1 h' -e '2,$ H' -e '$ { x ; s/\n     s/ \&\n     \& /g ; p }' $libf/dyn3d/paramet.h >! $libf/dyn3d/paramet90.tmp
 if ( ! -f $libf/dyn3d/paramet90.h || `diff $libf/dyn3d/paramet90.tmp $libf/dyn3d/paramet90.h | wc -w` ) then
       \mv $libf/dyn3d/paramet90.tmp $libf/dyn3d/paramet90.h
+endif
+sed -n -e 's/^c/\!/' -e '1 h' -e '2,$ H' -e '$ { x ; s/\n     \./ \&\n     \& /g ; p }' $libf/dyn3d/control.h >! $libf/dyn3d/control.tmp
+if ( ! -f $libf/dyn3d/control.inc  || `diff $libf/dyn3d/control.tmp $libf/dyn3d/control.inc | wc -w` ) then
+      \mv $libf/dyn3d/control.tmp $libf/dyn3d/control.inc
 endif
 sed -e 's/^c/\!/' $libf/dyn3dpar/paramet.h >! $libf/dyn3dpar/paramet90.h
