Index: /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histday.h
===================================================================
--- /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histday.h	(revision 505)
+++ /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histday.h	(revision 506)
@@ -1,3 +1,15 @@
       IF (ok_journe) THEN
+c
+       IF(region.EQ.'3d') THEN
+         zsto = dtime
+c        zout = dtime * FLOAT(ecrit_day)
+c        zsto1= dtime * FLOAT(ecrit_day)
+         zout = dtime * REAL(ecrit_day)
+         zsto1= dtime * REAL(ecrit_day)
+       ELSEIF(region.EQ.'1d') THEN
+         zsto = dtime
+c        zout = dtime
+         zout = dtime *4.
+       ENDIF
 c
          idayref = day_ref
@@ -13,27 +25,19 @@
          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("histday", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
-     .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime, 
+c071103
+c    .                 1,iim,1,jjmp1, 
+     .                 imin_debut,nbpti,
+     .                 jmin_debut,nbptj,
+c071103
+     .                 itau_phy, zjulian, dtime, 
      .                 nhori, nid_day)
          write(*,*)'Journee ', itau_phy, zjulian
          CALL histvert(nid_day, "presnivs", "Vertical levels", "mb",
      .                 klev, presnivs, nvert)
-c        call histvert(nid_day, 'sig_s', 'Niveaux sigma','-',
-c    .              klev, znivsig, nvert)
-c
-         zsto = dtime
-         zout = dtime * FLOAT(ecrit_day)
-C Essai writephys
-c        nom_fichier = 'histday1'
-c        call writephy_ini(fid_day,nom_fichier,klon,iim,jjmp1,klev,
-c    .                     rlon,rlat, presnivs,
-c    .                     zjulian, dtime)
-c        call writephy_def(prof2d_on, fid_day, "once", zsto, zout, 0)
-c        call writephy_def(prof3d_on, fid_day, "once", zsto, zout,
-c    .                                                         klev)
-c        call writephy_def(prof2d_av, fid_day, "ave(X)", zsto, zout, 0) 
-c        call writephy_def(prof3d_av, fid_day, "ave(X)", zsto, zout, 
-c    .                                                         klev)
- 
+c
+       IF(lev_histday.GE.1) THEN
 c
          CALL histdef(nid_day, "phis", "Surface geop. height", "-",
@@ -45,4 +49,12 @@
      .                "once", zsto,zout)
 c
+         CALL histdef(nid_day, "contfracATM","% sfce ter+lic ","-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "once", zsto,zout)
+c
+         CALL histdef(nid_day, "contfracOR","% sfce terre OR", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "once", zsto,zout)
+c
 c Champs 2D:
 c
@@ -51,192 +63,8 @@
      .                "ave(X)", zsto,zout)
 c
-c
          CALL histdef(nid_day, "t2m", "Temperature 2m", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "ave(X)", zsto,zout)
 c
-         CALL histdef(nid_day, "q2m", "Specific humidity", "Kg/Kg",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "u10m", "Vent zonal 10m", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "v10m", "Vent meridien 10m", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "psol", "Surface Pressure", "Pa",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,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, "snow", "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)
-c
-         CALL histdef(nid_day, "tops", "Solar rad. at TOA", "W/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,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)
-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)
-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)
-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)
-c
-         CALL histdef(nid_day, "bils", "Surf. total heat flux", "W/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "sens", "Sensible heat flux", "W/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "fder", "Heat flux derivation", "W/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-c        CALL histdef(nid_day, "frtu", "Zonal wind stress", "Pa",
-c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-c    .                "ave(X)", zsto,zout)
-c
-c        CALL histdef(nid_day, "frtv", "Meridional wind stress", "Pa",
-c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-c    .                "ave(X)", zsto,zout)
-c
-c        CALL histdef(nid_day, "sicf", "Sea-ice fraction", "-",
-c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-c    .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "cldl", "Low-level cloudiness", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "cldm", "Mid-level cloudiness", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "cldh", "High-level cloudiness", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "cldt", "Total cloudiness", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "cldq", "Cloud liquid water path", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "SWupTOA", "SWup at TOA","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "SWupSFC", "SWup at surface","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "SWdnTOA", "SWdn at TOA","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "SWdnSFC", "SWdn at surface","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,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)
-
-         CALL histdef(nid_day, "SWupSFCclr",
-     .                "SWup clear sky at surface","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,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)
-
-         CALL histdef(nid_day, "SWdnSFCclr",
-     .                "SWdn clear sky at surface","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-cccIM   
-         CALL histdef(nid_day, "prw", "Precipitable water", "kg/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-c  Champs dynamiques sur niveaux de pression
-
-         CALL histdef(nid_day, "u850", "Zonal wind 850mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_day, "v850", "Meridional wind 850mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "u500", "Zonal wind 500mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_day, "v500", "Meridional wind 500mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_day, "u200", "Zonal wind 200mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_day, "v200", "Meridional wind 200mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_day,"phi500", "Geopotentiel à 500mb", "m2/s2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_day, "slp", "Sea Level Pressure", "Pa",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_day, "cape_max", "CAPE max.",
-     .                "J/Kg",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                capemaxcels, zsto,zout)
-
-
-c=================================================================
-c   CI DESSOUS, SORTIES A UTILISER EN DEBUG
-c=================================================================
-      if ( lev_histday.gt.1 ) then
-
 c Champs retires momentannéement en attendant un hypothetique
 c debugage
@@ -252,10 +80,262 @@
      .                t2maxcels, zsto,zout)
 c
-c=================================================================
-c=================================================================
-c=================================================================
+         CALL histdef(nid_day, "plul", "Large-scale Precip.",
+     .   "kg/(s*m2)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "pluc", "Convective Precip.",
+     .   "kg/(s*m2)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,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)
+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)
+         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)
+c
+         CALL histdef(nid_day, "sicf", "Sea-ice fraction", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "inst(X)", zsto1,zout)
+c
+         CALL histdef(nid_day, "q2m", "Specific humidity", "kg/kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "u10m", "Vent zonal 10m", "m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "v10m", "Vent meridien 10m", "m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,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)
+c
+         CALL histdef(nid_day, "wind10max", "10-m wind speed max.",
+     .                "m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                t2maxcels, zsto,zout)
+c
+         CALL histdef(nid_day, "psol", "Surface Pressure", "Pa",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,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)
+c
+         CALL histdef(nid_day, "tops", "Solar rad. at TOA", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,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)
+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)
+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)
+c
+         CALL histdef(nid_day, "cldl", "Low-level cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "cldm", "Mid-level cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "cldh", "High-level cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "cldt", "Total cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,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)
+c
+         CALL histdef(nid_day, "prw", "Precipitable water", "kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,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
+         CALL histdef(nid_day, "slp", "Sea Level Pressure", "Pa",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "cape_max", "CAPE max.",
+     .                "J/kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                capemaxcels, zsto,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)
+c
+         CALL histdef(nid_day, "sens", "Sensible heat flux", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "SWdnSFC", "SWdn at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zsto,zout)
+c
+      ENDIF !lev_histday.GE.1
+c
+      IF (lev_histday.GE.2) THEN
+c
+         CALL histdef(nid_day, "bils", "Surf. total heat flux", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,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)
+c
+      ENDIF !lev_histday.GE.2
+c=================================================================
+      IF(lev_histday.GE.3) THEN
+c=================================================================
+c   INITIALISATION DES CHAMPS 3D
+c=================================================================
+c=================================================================
+c=================================================================
+c Champs 3D:
+c
+         CALL histdef(nid_day, "temp", "Air temperature", "K",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,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)
+c
+         CALL histdef(nid_day, "vitu", "Zonal wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,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", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "pres", "Air pressure", "Pa",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+c
+c=================================================================
+c   FIN INITIALISATION DES CHAMPS 3D
+c=================================================================
+      ENDIF !  lev_histday.GE.3
+c
+      IF (lev_histday.GE.4) THEN
+c=================================================================
+c
 c   INITIALISATION DES CHAMPS SUR LES SOUS SURFACES
-c=================================================================
+c
+c=================================================================
+c
+         CALL histdef(nid_day, "SWupTOA", "SWup at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "SWupSFC", "SWup at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_day, "SWdnTOA", "SWdn at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zsto,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)
 
+         CALL histdef(nid_day, "SWupSFCclr",
+     .                "SWup clear sky at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zsto,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)
+
+         CALL histdef(nid_day, "SWdnSFCclr",
+     .                "SWdn clear sky at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zsto,zout)
+c
+c=================================================================
+c=================================================================
+c=================================================================
+c   INITIALISATION DES CHAMPS SUR LES SOUS SURFACES
+c=================================================================
+c
          CALL histdef(nid_day, "tter", "Surface Temperature", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
@@ -273,6 +353,4 @@
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
-c
-cccIM
 c
          CALL histdef(nid_day, "t2mter", "Temp.terre 2m", "K",
@@ -334,7 +412,4 @@
      .                "ave(X)", zsto,zout)
 c
-c
-CXXX PB flux pour chaque sous surface
-C
          DO nsrf = 1, nbsrf
 C
@@ -378,56 +453,15 @@
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
      $         "ave(X)", zsto,zout)
-
-CXXX
+C
          END DO 
-           
-c=================================================================
-c   FIN DES CHAMPS SUR LES SOUS SURFACES
-c=================================================================
-c=================================================================
-c   FIN INITIALISATION DES CHAMPS 3D
-c=================================================================
-
-c Champs 3D:
-c
-         CALL histdef(nid_day, "temp", "Air temperature", "K",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,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)
-c
-         CALL histdef(nid_day, "vitu", "Zonal wind", "m/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,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", "m/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_day, "pres", "Air pressure", "Pa",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-c
-c=================================================================
-c   FIN INITIALISATION DES CHAMPS 3D
-c=================================================================
-
-
-c=================================================================
-c=================================================================
-      endif !  lev_histday.gt.1
-c=================================================================
-
+C           
+c=================================================================
+c
+c   FIN INITIALISATION DES CHAMPS SUR LES SOUS SURFACES
+c
+c=================================================================
+      ENDIF !lev_histday.GE.4
+c=================================================================
+c
          CALL histend(nid_day)
 c
Index: /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histhf.h
===================================================================
--- /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histhf.h	(revision 505)
+++ /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histhf.h	(revision 506)
@@ -2,9 +2,29 @@
       IF (ok_hf) THEN
 c
-         PRINT*, 'La frequence de sortie instant. est de ', ecrit_hf
-
-cccIM    CALL ymds2ju(anne_ini, 1, 1, 0.0, zjulian)
+       IF(region.EQ.'3d') 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
+       ELSEIF(region.EQ.'1d') THEN 
+c
+c   pour les champs instantannes, il faut mettre la meme valeur pour
+c   zout et tsto.
+c   dtime est passe par ailleurs a histbeg
+         zsto = dtime
+c        zout = dtime
+         zout = dtime *4. 
+       ENDIF 
+       print*,'zout,zsto=',zout,zsto
+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
@@ -19,19 +39,18 @@
 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, 
+cIM cf LF    .                 1,iim,1,jjmp1, 0, zjulian, dtime, 
+c071103
+c    .                 1,iim,1,jjmp1, 
+     .                 imin_debut,nbpti,
+     .                 jmin_debut,nbptj,
+c071103
+     .                 itau_phy, zjulian, dtime, 
      .                 nhori, nid_hf)
 
          CALL histvert(nid_hf, "presnivs", "Vertical levels", "mb",
      .                 klev, presnivs, nvert)
-         zsto = dtime
-
-c   pour les champs instantannes, il faut mettre la meme valeur pour
-c   zout et tsto.
-c   dtime est passe par ailleurs a histbeg
-
-         zout = dtime * REAL(NINT(86400./dtime*ecrit_hf))
-         zsto = zout
-         print*,'zout,zsto=',zout,zsto
-
+c
+
+      IF(lev_histhf.GE.1) THEN
 c
 c        CALL histdef(nid_hf, "phis", "Surface geop. height", "-",
@@ -43,8 +62,24 @@
 c    .                "once", zsto,zout)
 c
+         CALL histdef(nid_hf, "aireTER","Grid area CONT","-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "once", zsto,zout)
+c
+         CALL histdef(nid_hf, "contfracATM","% sfce ter+lic ","-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "once", zsto,zout)
+c
+         CALL histdef(nid_hf, "contfracOR","% sfce terre OR", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "once", zsto,zout)
+c
 c Champs 2D:
 c
-         CALL histdef(nid_hf, "tsol", "Surface Temperature", "K",
+         CALL histdef(nid_hf, "t2m", "Temperature 2m", "K",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_hf, "q2m", "Specific humidity", "kg/kg",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "inst(X)", zsto,zout)
 c
@@ -55,55 +90,126 @@
          print*,'ATTENTION METTRE AVE(X) POUR LES PRECIPS'
 
-         CALL histdef(nid_hf, "rain", "Precipitation", "mm/d",
+         CALL histdef(nid_hf, "rain", "Precipitation", "kg/m^2s",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
-c
-         CALL histdef(nid_hf, "u850", "Zonal wind 850mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
-
-         CALL histdef(nid_hf, "v850", "Meridional wind 850mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
-c
-         CALL histdef(nid_hf, "u500", "Zonal wind 500mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
-
-         CALL histdef(nid_hf, "v500", "Meridional wind 500mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
-
-         CALL histdef(nid_hf, "u200", "Zonal wind 200mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
-
-         CALL histdef(nid_hf, "v200", "Meridional wind 200mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
-
-         CALL histdef(nid_hf, "phi500", "Geopotentiel a 500mb", "m2/s2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "inst(X)", zsto,zout)
-
-cIM cf FH
-         CALL histdef(nid_hf,"u1","Zonal wind at 1st layer", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
-
-         CALL histdef(nid_hf,"v1","Meridional wind at 1st layer",
-     .                "m/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "inst(X)", zsto,zout)
- 
+     .                "ave(X)", zsto1,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)
+c
+         CALL histdef(nid_hf, "slp", "Sea Level Pressure", "Pa",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+c
+         CALL histdef(nid_hf, "u10m", "Vent zonal 10m", "m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,zout)
+c
+         CALL histdef(nid_hf, "v10m", "Vent meridien 10m", "m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "inst(X)", zsto,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
+c
+      ENDIF !lev_histhf.GE.1
+c
+      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
+         CALL histdef(nid_hf, "SWdownOR",
+     .                "Sfce incident SW radiation OR", "W/m^2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto1,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)
+      ENDIF !lev_histhf.GE.2
+c
+cIM ENSEMBLES END
+c
+      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)
+          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
+c
+      ENDIF !lev_histhf.GE.3
+c
+      IF(lev_histhf.GE.4) THEN
+#define histhf3d
+#ifdef histhf3d
+#include "ini_histhf3d.h"
+#endif
+      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
Index: /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histins.h
===================================================================
--- /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histins.h	(revision 505)
+++ /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histins.h	(revision 506)
@@ -1,3 +1,12 @@
       IF (ok_instan) THEN
+c
+        IF(region.EQ.'3d') THEN
+          zsto = dtime * ecrit_ins
+          zout = dtime * ecrit_ins
+        ELSEIF(REGION.eq.'1d') THEN
+         zsto = dtime
+c        zout = dtime
+         zout = dtime *4.
+        ENDIF
 c
          idayref = day_ref
@@ -14,5 +23,10 @@
          CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
          CALL histbeg("histins", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
-     .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime,
+c071103
+c    .                 1,iim,1,jjmp1, 
+     .                 imin_debut,nbpti,
+     .                 jmin_debut,nbptj,
+c071103
+     .                 itau_phy, zjulian, dtime,
      .                 nhori, nid_ins)
          write(*,*)'Inst ', itau_phy, zjulian
@@ -23,7 +37,4 @@
 c
 c
-         zsto = dtime * ecrit_ins
-         zout = dtime * ecrit_ins
-C
          CALL histdef(nid_ins, "phis", "Surface geop. height", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
Index: /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histmth.h
===================================================================
--- /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histmth.h	(revision 505)
+++ /LMDZ.3.3/branches/rel-LF/libf/phylmd/ini_histmth.h	(revision 506)
@@ -1,3 +1,18 @@
       IF (ok_mensuel) THEN
+c
+        IF(region.EQ.'3d') THEN
+         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
+        ELSEIF(region.EQ.'1d') THEN
+          zsto = dtime
+c         zout = dtime
+          zout = dtime *4.
+        ENDIF
 c
          idayref = day_ref
@@ -14,5 +29,10 @@
          CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
          CALL histbeg("histmth.nc", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
-     .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime, 
+c071103
+c    .                 1,iim,1,jjmp1, 
+     .                 imin_debut,nbpti,
+     .                 jmin_debut,nbptj,
+c071103
+     .                 itau_phy, zjulian, dtime, 
      .                 nhori, nid_mth)
          write(*,*)'Mensuel ', itau_phy, zjulian
@@ -22,7 +42,6 @@
 c    .              klev, znivsig, nvert)
 c
-         zsto = dtime
-         zout = dtime * ecrit_mth
-c
+c
+      IF(lev_histmth.GE.1) THEN
          CALL histdef(nid_mth, "phis", "Surface geop. height", "-",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
@@ -33,4 +52,9 @@
      .                "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)
+c
 c Champs 2D:
 c
@@ -46,5 +70,30 @@
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "ave(X)", zsto,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)
+c
+         CALL histdef(nid_mth, "t2m_max", "Temp. 2m max.",
+     .                "K",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                t2maxcels, zsto,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
+         CALL histdef(nid_mth, "wind10m","10-m wind speed","m/s",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "sicf", "Sea-ice fraction", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+
+c
+c ENSEMBLES END
          CALL histdef(nid_mth, "q2m", "Specific humidity 2m", "Kg/Kg",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
@@ -58,5 +107,4 @@
      .                iim,jjmp1,nhori, 1,1,1, -99, 32,
      .                "ave(X)", zsto,zout)
-c
 c
          CALL histdef(nid_mth, "psol", "Surface Pressure", "Pa",
@@ -74,28 +122,35 @@
       endif
 c
+         CALL histdef(nid_mth, "ndayrain", 
+     .                "Number of day with rain (liq+sol)", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "inst(X)", zsto1,zout)
+c
          CALL histdef(nid_mth, "precip", "Precipitation Totale liq+sol", 
-     .                "kg/(s*m2)",
+     .                "Kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "plul", "Large-scale Precip.", 
-     .   "kg/(s*m2)",
+     .   "Kg/(s*m2)",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
 c
          CALL histdef(nid_mth, "pluc", "Convective Precip.", 
-     .   "kg/(s*m2)",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,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)
-c
-         CALL histdef(nid_mth, "evap", "Evaporation", "kg/(s*m2)",
+     .   "Kg/(s*m2)",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,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)
+c
+cIM: 071003 evap(Kg/m2/s) ==> evap(mm/day)
+        CALL histdef(nid_mth, "evap", "Evaporation", "kg/(s*m2)",
+c       CALL histdef(nid_mth, "evap", "Evaporation", "mm/day", 
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
@@ -105,39 +160,121 @@
      .                "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)
+c
          CALL histdef(nid_mth, "topl", "IR rad. at TOA", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,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)
+c
+         CALL histdef(nid_mth, "SWupTOA", "SWup at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zsto2,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)
+c
+         CALL histdef(nid_mth, "SWdnTOA", "SWdn at TOA","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zsto2,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)
+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)
+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)
+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)
+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)
+c
          CALL histdef(nid_mth, "sols", "Solar rad. at surf.", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,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)
+c
          CALL histdef(nid_mth, "soll", "IR rad. at surface", "W/m2",
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
-cIM: 071003
+c
+         CALL histdef(nid_mth, "soll0", "IR rad. at surface", "W/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "SWupSFC", "SWup at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zsto2,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)
+c
+         CALL histdef(nid_mth, "SWdnSFC", "SWdn at surface","W/m2",
+     .                iim,jjmp1,nhori, 1,1,1,-99,
+     .                32, "ave(X)", zsto2,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)
+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)
+c
          CALL histdef(nid_mth,"LWdnSFC","Down. IR rad. at surface", 
      .                "W/m2", iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-cIM: 071003
-         CALL histdef(nid_mth,"LWupSFC","Upwd. IR rad. at surface", 
+     .                "ave(X)", zsto2,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)", 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)
-c
-         CALL histdef(nid_mth, "topl0", "IR rad. at TOA", "W/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,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)
-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)", zsto2,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)
 c
          CALL histdef(nid_mth, "bils", "Surf. total heat flux", "W/m2",
@@ -166,13 +303,29 @@
 c
          CALL histdef(nid_mth, "fqcalving","Ice Calving",
-     .                "kg/m2/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
+     .                "Kg/m2/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+cIM: 171003
+         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)
+
+           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)
+         ENDDO
+cIM: 171003
+c
+cIM       if ( lev_histday.gt.1 ) then
          DO nsrf = 1, nbsrf
 C
+          IF(nsrf.GT.1) 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
 C
            call histdef(nid_mth, "tsol_"//clnsurf(nsrf), 
@@ -194,10 +347,10 @@
      $         "LW "//clnsurf(nsrf), "W/m2",
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "ave(X)", zsto2,zout)
 c
            call histdef(nid_mth, "fsw_"//clnsurf(nsrf),
      $         "SW "//clnsurf(nsrf), "W/m2",
      $         iim,jjmp1,nhori, 1,1,1, -99, 32,
-     $         "ave(X)", zsto,zout)
+     $         "ave(X)", zsto2,zout)
 C
            call histdef(nid_mth, "wbils_"//clnsurf(nsrf),
@@ -206,13 +359,194 @@
      $         "ave(X)", zsto,zout)
 C
-           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)
-
-           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)
+         END DO
+cIM         endif !lev_histday
+c
+         CALL histdef(nid_mth, "cdrm", "Momentum drag coef.", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "cdrh", "Heat drag coef.", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "cldl", "Low-level cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "cldm", "Mid-level cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "cldh", "High-level cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "cldt", "Total cloudiness", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,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
+         CALL histdef(nid_mth,"lwp","Cloud water path","Kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,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
+c
+         CALL histdef(nid_mth, "ue", "Zonal energy transport", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "ve", "Merid energy transport", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "uq", "Zonal humidity transport", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "vq", "Merid humidity transport", "-",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
+     .                "ave(X)", zsto,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)", 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)
+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)
+c
+         CALL histdef(nid_mth, "prw", "Precipitable water", "Kg/m2",
+     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
+     .                "ave(X)", zsto,zout)
+c
+      ENDIF !iflag_con .GE. 3
+c34EK
+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","m/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
+      ENDIF !lev_histmth.GE.1
+c
+      IF(lev_histmth.GE.2) THEN
+c
+c Champs 3D:
+c
+c
+         CALL histdef(nid_mth,"lwcon","Cloud water content","Kg/Kg",
+     .                iim,jjmp1,nhori, klev,1,klev, nvert, 32, 
+     .                "ave(X)", zsto,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)
+c
+         CALL histdef(nid_mth, "temp", "Air temperature", "K",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "ovap", "Specific humidity", "Kg/Kg",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,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
+         CALL histdef(nid_mth, "vitu", "Zonal wind", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,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", "m/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "pres", "Air pressure", "Pa",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+c
+        CALL histdef(nid_mth, "rneb", "Cloud fraction", "-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,zout)
+c
+         CALL histdef(nid_mth, "rnebcon", "Convective Cloud Fraction"
+     .                , "-",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,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)
+c
+         CALL histdef(nid_mth, "upwd", "saturated updraft", "Kg/m2/s",
+     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
+     .                "ave(X)", zsto,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
+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), 
@@ -229,10 +563,6 @@
      .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
      .                "ave(X)", zsto,zout)
-
-         END DO
-C
-c        CALL histdef(nid_mth, "sicf", "Sea-ice fraction", "-",
-c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-c    .                "ave(X)", zsto,zout)
+c
+	 ENDDO !nsrf=1, nbsrf
 c
          CALL histdef(nid_mth, "albs", "Surface albedo", "-",
@@ -243,84 +573,15 @@
      .                "ave(X)", zsto,zout)
 c
-         CALL histdef(nid_mth, "cdrm", "Momentum drag coef.", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "cdrh", "Heat drag coef.", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "cldl", "Low-level cloudiness", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "cldm", "Mid-level cloudiness", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "cldh", "High-level cloudiness", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "cldt", "Total cloudiness", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,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
-         CALL histdef(nid_mth,"lwp","Cloud water path","Kg/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,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
-         CALL histdef(nid_mth,"lwcon","Cloud water content","Kg/Kg",
-     .                iim,jjmp1,nhori, klev,1,klev, nvert, 32, 
-     .                "ave(X)", zsto,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)
-c
-         CALL histdef(nid_mth, "ue", "Zonal energy transport", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "ve", "Merid energy transport", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "uq", "Zonal humidity transport", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "vq", "Merid humidity transport", "-",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
-     .                "ave(X)", zsto,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)", 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)
-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)
-c
-c
-         CALL histdef(nid_mth, "upwd", "saturated updraft", "Kg/m2/s",
+      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)", zsto,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)
@@ -331,75 +592,4 @@
 c
          CALL histdef(nid_mth, "dnwd0", "unsat. downdraft", "Kg/m2/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,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, "prw", "Precipitable water", "kg/m2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-      ENDIF
-c34EK
-c
-c Champs 3D:
-c
-         CALL histdef(nid_mth, "temp", "Air temperature", "K",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "ovap", "Specific humidity", "Kg/Kg",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-cIM: 071003
-         CALL histdef(nid_mth,"wvap","Water vapor mixing ratio","Kg/Kg",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "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
-         CALL histdef(nid_mth, "vitu", "Zonal wind", "m/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,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", "m/s",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "pres", "Air pressure", "Pa",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "rneb", "Cloud fraction", "-",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "rnebcon", "Convective Cloud Fraction"
-     .                , "-",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,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, "clwcon", "Cloud Liquid water content"
-     .                , "kg/kg",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "oliq", "Liquid water content", "kg/kg",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "dtphy", "Physics dT", "K/s",
      .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
      .                "ave(X)", zsto,zout)
@@ -519,8 +709,4 @@
          ENDIF
 C
-         CALL histdef(nid_mth, "ozone", "Ozone concentration", "-",
-     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
-     .                "ave(X)", zsto,zout)
-c
          if (nqmax.GE.3) THEN
          DO iq=1,nqmax-2
@@ -537,73 +723,5 @@
          ENDIF
 c
-         CALL histdef(nid_mth, "SWupTOA", "SWup at TOA","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "SWupSFC", "SWup at surface","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "SWdnTOA", "SWdn at TOA","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "SWdnSFC", "SWdn at surface","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "SWupTOAclr", 
-     .                "SWup clear sky at TOA","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "SWupSFCclr", 
-     .                "SWup clear sky at surface","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "SWdnTOAclr", 
-     .                "SWdn clear sky at TOA","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "SWdnSFCclr", 
-     .                "SWdn clear sky at surface","W/m2",
-     .                iim,jjmp1,nhori, 1,1,1,-99,
-     .                32, "ave(X)", zsto,zout)
-
-c Champs interpolles sur des niveaux de pression
-
-         CALL histdef(nid_mth, "u850", "Zonal wind 850mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_mth, "v850", "Meridional wind 850mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-c
-         CALL histdef(nid_mth, "u500", "Zonal wind 500mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_mth, "v500", "Meridional wind 500mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_mth, "u200", "Zonal wind 200mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_mth, "v200", "Meridional wind 200mb", "m/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_mth, "phi500","Geopotentiel à 500mb","m2/s2",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
-
-         CALL histdef(nid_mth, "w500", "Vertical wind 500mb", "Pa/s",
-     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
-     .                "ave(X)", zsto,zout)
+      ENDIF !lev_histmth.GE.4
 c
          CALL histend(nid_mth)
Index: /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histday.h
===================================================================
--- /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histday.h	(revision 505)
+++ /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histday.h	(revision 506)
@@ -12,10 +12,11 @@
          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 histwrite(nid_day,"phis",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
          varname = 'phis'
          vartitle= 'Surface geop. height'
          varunits= '-'
-c        call writephy(fid_day,prof2d_on,varname,pphis,vartitle,
-c    .                                                    varunits)
 c
          i = NINT(zout/zsto)
@@ -25,17 +26,63 @@
          vartitle= 'Grid area'
          varunits= '-'
-c        call writephy(fid_day,prof2d_on,varname,paire,vartitle,
-c    .                                                    varunits)
-C
+c
+      DO i=1, klon
+       zx_tmp_fi2d(i)=pctsrf(i,is_ter)+pctsrf(i,is_lic)
+      ENDDO
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
+      CALL histwrite(nid_day,"contfracATM",itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,pctsrf_new(:,is_ter),zx_tmp_2d)
+      CALL histwrite(nid_day,"contfracOR",itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
       CALL histwrite(nid_day,"tsol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'tsol',zxtsol,
-c    .              'Surface Temperature','K')
-c
-C
 C
       CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
       CALL histwrite(nid_day,"t2m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
+c   En attendant un eventuel debugage.
+
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
+      CALL histwrite(nid_day,"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_day,"t2m_max",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_day,"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_day,"pluc",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_lsc,zx_tmp_2d)
+      CALL histwrite(nid_day,"snowl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      IF(1.EQ.0) THEN
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_con,zx_tmp_2d)
+      CALL histwrite(nid_day,"snowc",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+      ENDIF
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfluxlat,zx_tmp_2d)
+      CALL histwrite(nid_day,"flat",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      DO i = 1, klon
+         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
+      ENDDO
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"sicf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
       CALL gr_fi_ecrit(1,klon,iim,jjmp1,zq2m,zx_tmp_2d)
       CALL histwrite(nid_day,"q2m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
@@ -49,253 +96,231 @@
      .               ndex2d)
 c
-      DO i = 1, klon
+      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_day,"wind10m",itau_w,zx_tmp_2d,
+     $     iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"wind10max",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_day,"psol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c Essai writephys
-      varname = 'psol'
-      vartitle= 'pression au sol'
-      varunits= 'hPa'
-c     call writephy(fid_day,prof2d_av,varname,zx_tmp_fi2d,vartitle,
-c    .                                                    varunits)
-c
-      DO i = 1, klon
+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_day,"precip",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'rain',zx_tmp_fi2d,
-c    .              'Precipitation','mm/day')
-
-
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_fall,zx_tmp_2d)
-      CALL histwrite(nid_day,"snow",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'snow',snow_fall,
-c    .              'Snow','mm/day')
+      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)
-c     call writephy(fid_day,prof2d_av,'snow_mass',zxsnow,
-c    .              'Snow cover','mm')
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
       CALL histwrite(nid_day,"evap",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'evap',evap,
-c    .              'Evaporation','mm/day')
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
       CALL histwrite(nid_day,"tops",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'tops',topsw,
-c    .              'Solar rad. at TOA','W/m2')
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
       CALL histwrite(nid_day,"topl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'topl',toplw,
-c    .              'IR rad. at TOA','W/m2')
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw,zx_tmp_2d)
       CALL histwrite(nid_day,"sols",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'sols',solsw,
-c    .              'Solar rad. at surf.','W/m2')
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw,zx_tmp_2d)
       CALL histwrite(nid_day,"soll",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'soll',sollw,
-c    .              'IR rad. at surface','W/m2')
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldl,zx_tmp_2d)
+      CALL histwrite(nid_day,"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_day,"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_day,"cldh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
+      CALL histwrite(nid_day,"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_day,"cldq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, prw,zx_tmp_2d)
+      CALL histwrite(nid_day,"prw",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
+
+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,
+     $       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,
+     $       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 
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
+      CALL histwrite(nid_day,"slp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,cape,zx_tmp_2d)
+      CALL histwrite(nid_day,"cape_max",itau_w,zx_tmp_2d,
+     .               iim*jjmp1,ndex2d)
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdown,zx_tmp_2d)
       CALL histwrite(nid_day,"solldown",itau_w,zx_tmp_2d,iim*jjmp1,
      .               ndex2d)
-c     call writephy(fid_day,prof2d_av,'solldown',sollwdown,
-c    .              'Down. IR rad. at surface','W/m2')
+c
+      DO i=1, klon
+        zx_tmp_fi2d(i)=-1*sens(i)
+      ENDDO
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+      CALL histwrite(nid_day,"sens",itau_w,zx_tmp_2d,iim*jjmp1,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_day, "SWdnSFC",itau_w,zx_tmp_2d,
+     .                               iim*jjmp1,ndex2d)
+c
+      ENDIF !lev_histday.GE.1
+c
+      IF(lev_histday.GE.2) THEN
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, bils,zx_tmp_2d)
       CALL histwrite(nid_day,"bils",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'bils',bils,
-c    .              'Surf. total heat flux','W/m2')
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sens,zx_tmp_2d)
-      CALL histwrite(nid_day,"sens",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'sens',sens,
-c    .              'Sensible heat flux','W/m2')
 c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, fder,zx_tmp_2d)
       CALL histwrite(nid_day,"fder",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'fder',fder,
-c    .              'Heat flux derivation','W/m2')
-c
-c
-cXXX      DO i = 1, klon
-cXXX         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
-cXXX      ENDDO
-cXXX      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
-cXXX      CALL histwrite(nid_day,"sicf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldl,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'cldl',cldl,
-c    .              'Low-level cloudiness','-')
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldm,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldm",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'cldm',cldm,
-c    .              'Mid-level cloudiness','-')
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldh,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'cldh',cldh,
-c    .              'High-level cloudiness','-')
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'cldt',cldt,
-c    .              'Total cloudiness','-')
-c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldq,zx_tmp_2d)
-      CALL histwrite(nid_day,"cldq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'cldq',cldq,
-c    .              'Cloud liquid water path','-')
-c
-c     zx_tmp_fi2d(1 : klon) = ZFSUP( 1 : klon, klevp1)
-      zx_tmp_fi2d(1 : klon) = swup( 1 : klon, 2 )
-
+c
+      ENDIF !lev_histday.GE.2
+c
+      IF(lev_histday.GE.3) THEN
+c=================================================================
+c   ECRITURE DES CHAMPS 3D
+c=================================================================
+
+c
+c Champs 3D:
+c
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
+      CALL histwrite(nid_day,"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_day,"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_day,"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_day,"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_day,"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_day,"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_day,"pres",itau_w,zx_tmp_3d,
+     .                                   iim*jjmp1*klev,ndex3d)
+c
+      ENDIF !lev_histday.GE.3
+c=================================================================
+c   FIN ECRITURE DES CHAMPS 3D
+c=================================================================
+      IF(lev_histday.ge.4) THEN
+c=================================================================
+c
+c   ECRITURE DES CHAMPS SUR LES SOUS SURFACES
+c
+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_day, "SWupTOA",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_day, "SWupSFC",itau_w,zx_tmp_2d,
      .                               iim*jjmp1,ndex2d)
 c
-c      zx_tmp_fi2d(1 : klon) = ZFSDN( 1 : klon, klevp1)
-      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)
       CALL histwrite(nid_day, "SWdnTOA",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_day, "SWdnSFC",itau_w,zx_tmp_2d,
-     .                               iim*jjmp1,ndex2d)
-
-c      zx_tmp_fi2d(1 : klon) = ZFSUP0( 1 : klon, klevp1)
-      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)
       CALL histwrite(nid_day, "SWupTOAclr",itau_w,zx_tmp_2d,
      .                               iim*jjmp1,ndex2d)
-
-c      zx_tmp_fi2d(1 : klon) = ZFSUP0( 1 : klon, 1)
+c
       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_day, "SWupSFCclr",itau_w,zx_tmp_2d,
      .                               iim*jjmp1,ndex2d)
- 
-c      zx_tmp_fi2d(1 : klon) = ZFSDN0( 1 : klon, klevp1)
-      zx_tmp_fi2d(1 : klon) = swdn0( 1 : klon, 2 )
-
+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_day, "SWdnTOAclr",itau_w,zx_tmp_2d,
      .                               iim*jjmp1,ndex2d)
- 
-c      zx_tmp_fi2d(1 : klon) = ZFSDN0( 1 : klon, 1)
+c 
       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_day, "SWdnSFCclr",itau_w,zx_tmp_2d,
      .                               iim*jjmp1,ndex2d)
-cIM
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, prw,zx_tmp_2d)
-      CALL histwrite(nid_day,"prw",itau_w,zx_tmp_2d,
-     .               iim*jjmp1,ndex2d)
-
-c   Ecriture de champs dynamiques sur des niveaux de pression
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, u850,zx_tmp_2d)
-      CALL histwrite(nid_day,"u850",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, v850,zx_tmp_2d)
-      CALL histwrite(nid_day,"v850",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, u500,zx_tmp_2d)
-      CALL histwrite(nid_day,"u500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, v500,zx_tmp_2d)
-      CALL histwrite(nid_day,"v500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, u200,zx_tmp_2d)
-      CALL histwrite(nid_day,"u200",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, v200,zx_tmp_2d)
-      CALL histwrite(nid_day,"v200",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, phi500,zx_tmp_2d)
-      CALL histwrite(nid_day,"phi500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
-      CALL histwrite(nid_day,"slp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1,klon,iim,jjmp1,cape,zx_tmp_2d)
-      CALL histwrite(nid_day,"cape_max",itau_w,zx_tmp_2d,
-     .               iim*jjmp1,ndex2d)
-
-
-c
-c=================================================================
-c   CI DESSOUS, SORTIES A UTILISER EN DEBUG
-c=================================================================
-      if ( lev_histday.gt.1 ) then
-
-c   En attendant un eventuel debugage.
-
-      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
-      CALL histwrite(nid_day,"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_day,"t2m_max",itau_w,zx_tmp_2d,
-     .               iim*jjmp1,ndex2d)
-c
-c=================================================================
-c=================================================================
-c=================================================================
-c   ECRITURE DES CHAMPS SUR LES SOUS SURFACES
-c=================================================================
-
+c
       zx_tmp_fi2d(1 : klon) = ftsol(1 : klon, is_ter)
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d ,zx_tmp_2d)
       CALL histwrite(nid_day,"tter",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'tter',ftsol(1 : klon, is_ter),
-c    .              'Surface Temperature','K')
-C
+c
       zx_tmp_fi2d(1 : klon) = ftsol(1 : klon, is_lic)
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day,"tlic",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'tlic',ftsol(1 : klon, is_lic),
-c    .              'Surface Temperature','K')
-C
+c
       zx_tmp_fi2d(1 : klon) = ftsol(1 : klon, is_oce)
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day,"toce",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'toce',ftsol(1 : klon, is_oce),
-c    .              'Surface Temperature','K')
-C
+c
       zx_tmp_fi2d(1 : klon) = ftsol(1 : klon, is_sic)
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
       CALL histwrite(nid_day,"tsic",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-c     call writephy(fid_day,prof2d_av,'tsic',ftsol(1 : klon, is_sic),
-c    .              'Surface Temperature','K')
-C
-cccIM
+c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
       CALL histwrite(nid_day,"t2mter",itau_w,zx_tmp_2d,iim*jjmp1,
@@ -368,12 +393,9 @@
 C
       DO nsrf = 1, nbsrf
-CXXX
+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,
      $      zx_tmp_2d,iim*jjmp1,ndex2d) 
-c       call writephy(fid_day,prof2d_av,'pourc_'//clnsurf(nsrf),
-c    .                pctsrf( 1 : klon, nsrf),
-c    .                'Fraction'//clnsurf(nsrf),'-')
 C
         zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
@@ -381,7 +403,4 @@
         CALL histwrite(nid_day,"tsol_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d) 
-c       call writephy(fid_day,prof2d_av,'tsol_'//clnsurf(nsrf),
-c    .                ftsol( 1 : klon, nsrf),
-c    .                'Surf. Temp'//clnsurf(nsrf),'K')
 C 
         zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
@@ -389,7 +408,4 @@
         CALL histwrite(nid_day,"sens_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d) 
-c       call writephy(fid_day,prof2d_av,'sens_'//clnsurf(nsrf),
-c    .                fluxt( 1 : klon, 1, nsrf),
-c    .                'Sensible heat flux '//clnsurf(nsrf),'W/m2')
 C  
         zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
@@ -397,7 +413,4 @@
         CALL histwrite(nid_day,"lat_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d) 
-c       call writephy(fid_day,prof2d_av,'lat_'//clnsurf(nsrf),
-c    .                fluxlat( 1 : klon, nsrf),
-c    .                'Latent heat flux '//clnsurf(nsrf),'W/m2')
 C
         zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
@@ -405,7 +418,4 @@
         CALL histwrite(nid_day,"taux_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d) 
-c       call writephy(fid_day,prof2d_av,'taux_'//clnsurf(nsrf),
-c    .                fluxu( 1 : klon, 1, nsrf),
-c    .                'Zonal wind stress '//clnsurf(nsrf),'Pa')
 C      
         zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
@@ -413,7 +423,4 @@
         CALL histwrite(nid_day,"tauy_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d)
-c       call writephy(fid_day,prof2d_av,'tauy_'//clnsurf(nsrf),
-c    .                fluxv( 1 : klon, 1, nsrf),
-c    .                'Meridional wind stress '//clnsurf(nsrf),'Pa')
 C
         zx_tmp_fi2d(1 : klon) = falbe( 1 : klon, nsrf)
@@ -421,10 +428,4 @@
         CALL histwrite(nid_day,"albe_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d) 
-c       call writephy(fid_day,prof2d_av,'albe_'//clnsurf(nsrf),
-c    .                falbe( 1 : klon, nsrf),
-c    .                'Albedo surf. SW'//clnsurf(nsrf),'-')
-c       call writephy(fid_day,prof2d_av,'alblw_'//clnsurf(nsrf),
-c    .                falblw( 1 : klon, nsrf),
-c    .                'Albedo surf. LW'//clnsurf(nsrf),'-')
 C
         zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
@@ -432,7 +433,4 @@
         CALL histwrite(nid_day,"rugs_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d) 
-c       call writephy(fid_day,prof2d_av,'rugs_'//clnsurf(nsrf),
-c    .                frugs( 1 : klon, nsrf),
-c    .                'Rugosity '//clnsurf(nsrf),' - ')
 C 
       END DO  
@@ -440,70 +438,11 @@
 c   FIN ECRITURE DES CHAMPS SUR LES SOUS SURFACES
 c=================================================================
-
-c=================================================================
-c   ECRITURE DES CHAMPS 3D
-c=================================================================
-
-c
-c Champs 3D:
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
-      CALL histwrite(nid_day,"temp",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c Essai writephys
-      varname = 'temp'
-      vartitle= 'temperature 3D'
-      varunits= 'K'
-c     call writephy(fid_day,prof3d_av,varname,t_seri,vartitle,varunits)
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
-      CALL histwrite(nid_day,"ovap",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c     call writephy(fid_day,prof3d_av,'ovap',qx(1,1,ivap),
-c    .              'Specific humidity','Kg/Kg')
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
-      CALL histwrite(nid_day,"geop",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c     call writephy(fid_day,prof3d_av,'geop',zphi,
-c    .              'Geopotential height','m')
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
-      CALL histwrite(nid_day,"vitu",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c     call writephy(fid_day,prof3d_av,'vitu',u_seri,
-c    .              'Zonal wind','m/s')
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
-      CALL histwrite(nid_day,"vitv",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c     call writephy(fid_day,prof3d_av,'vitv',v_seri,
-c    .              'Meridional wind','m/s')
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
-      CALL histwrite(nid_day,"vitw",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c     call writephy(fid_day,prof3d_av,'vitw',omega,
-c    .              'Vertical wind','m/s')
-c
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
-      CALL histwrite(nid_day,"pres",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c     call writephy(fid_day,prof3d_av,'pres',pplay,
-c    .              'Air pressure','Pa')
-cccIM
-
-c=================================================================
-c   FIN ECRITURE DES CHAMPS 3D
-c=================================================================
-
-c=================================================================
-c=================================================================
-      endif !  lev_histday.gt.1
-c=================================================================
-
-
+      ENDIF !lev_histday.GE.4
+c
+c=================================================================
+c=================================================================
+c=================================================================
+c
       if (ok_sync) then
-c       call writephy_sync(fid_day)
         call histsync(nid_day)
       endif
Index: /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histhf.h
===================================================================
--- /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histhf.h	(revision 505)
+++ /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histhf.h	(revision 506)
@@ -3,10 +3,13 @@
 c   Comprendre comment marche el i=nint(zout/zsto)
 c
-c$$$      print*,'ACRITURE HF !!! ACRITURE HF !!! ACRITURE HF !!! '
+c     print*,'ACRITURE HF !!! ACRITURE HF !!! ACRITURE HF !!! '
       ndex2d = 0
       ndex3d = 0
-
-      itau_w =  itau_phy + itap
 c
+      zsto = dtime
+      zout = dtime * ecrit_hf
+      itau_w = itau_phy + itap
+c
+      IF(lev_histhf.GE.1) THEN
 c
 c     i = NINT(zout/zsto)
@@ -18,6 +21,27 @@
 c     CALL histwrite(nid_hf,"aire",i,zx_tmp_2d,iim*jjmp1,ndex2d)
 C
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
-      CALL histwrite(nid_hf,"tsol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, paire_ter, zx_tmp_2d)
+      CALL histwrite(nid_hf,"aireTER",itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      DO i=1, klon
+       zx_tmp_fi2d(i)=pctsrf(i,is_ter)+pctsrf(i,is_lic)
+      ENDDO
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
+      CALL histwrite(nid_hf,"contfracATM",itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      CALL gr_fi_ecrit(1,klon,iim,jjmp1,pctsrf_new(:,is_ter),zx_tmp_2d)
+      CALL histwrite(nid_hf,"contfracOR",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
@@ -25,5 +49,6 @@
       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)
+      CALL histwrite(nid_hf,"psol",itau_w,zx_tmp_2d,iim*jjmp1,
+     .               ndex2d)
 c
       DO i = 1, klon
@@ -32,33 +57,87 @@
       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 gr_fi_ecrit(1, klon,iim,jjmp1, u850,zx_tmp_2d)
-      CALL histwrite(nid_hf,"u850",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, v850,zx_tmp_2d)
-      CALL histwrite(nid_hf,"v850",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, u500,zx_tmp_2d)
-      CALL histwrite(nid_hf,"u500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, v500,zx_tmp_2d)
-      CALL histwrite(nid_hf,"v500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, u200,zx_tmp_2d)
-      CALL histwrite(nid_hf,"u200",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, v200,zx_tmp_2d)
-      CALL histwrite(nid_hf,"v200",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, phi500,zx_tmp_2d)
-      CALL histwrite(nid_hf,"phi500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-cIM cf FH
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, u_seri(:,1),zx_tmp_2d)
-      CALL histwrite(nid_hf,"u1",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, v_seri(:,1),zx_tmp_2d)
-      CALL histwrite(nid_hf,"v1",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c ENSEMBLES BEG
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
+      CALL histwrite(nid_hf,"tsol",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
+      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
+      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_hf,"wind10m",itau_w,zx_tmp_2d,
+     $     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"
+      ENDDO
+c
+      ENDIF !lev_histhf.GE.1
+c
+      IF(lev_histhf.GE.2) THEN
+c
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
+      CALL histwrite(nid_hf,"cldt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, is_ter)
+      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
+      CALL histwrite(nid_hf,"SWdownOR",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,"LWdownOR",itau_w,zx_tmp_2d,iim*jjmp1,
+     $     ndex2d) 
+c
+c
+      ENDIF !lev_histhf.GE.2
+c
+      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
+      ENDDO !nlevENS
+c
+      IF(1.EQ.0) THEN
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragm,zx_tmp_2d)
       CALL histwrite(nid_hf,"cdrm",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
@@ -66,5 +145,17 @@
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragh,zx_tmp_2d)
       CALL histwrite(nid_hf,"cdrh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
+      ENDIF !(1.EQ.0) THEN
+c
+      ENDIF !lev_histhf.GE.3
+c
+      IF(lev_histhf.GE.4) THEN 
+c
+#define histhf3d
+#ifdef histhf3d
+#include "write_histhf3d.h"
+#endif
+c
+      ENDIF !lev_histhf.GE.4
+c
       if (ok_sync) then
         call histsync(nid_hf)
Index: /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histins.h
===================================================================
--- /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histins.h	(revision 505)
+++ /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histins.h	(revision 506)
@@ -85,5 +85,7 @@
       CALL histwrite(nid_ins,"bils",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sens,zx_tmp_2d)
+      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_ins,"sens",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
 c
Index: /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histmth.h
===================================================================
--- /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histmth.h	(revision 505)
+++ /LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histmth.h	(revision 506)
@@ -3,7 +3,5 @@
       ndex2d = 0
       ndex3d = 0
-c
-c Champs 2D:
-c
+
          zsto = dtime
          zout = dtime * ecrit_mth
@@ -11,4 +9,9 @@
 
       i = NINT(zout/zsto)
+c
+      IF(lev_histmth.GE.1) THEN
+c
+c Champs 2D:
+c
       CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
       CALL histwrite(nid_mth,"phis",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
@@ -17,5 +20,10 @@
       CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,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)
+      CALL histwrite(nid_mth,"pourc_"//clnsurf(is_ter),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d)
+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)
@@ -27,4 +35,38 @@
       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)
@@ -57,4 +99,8 @@
       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)
@@ -77,6 +123,7 @@
 c
 cIM: 071003
-      zx_tmp_fi2d(1:klon)=evap(1:klon)*86400.
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
+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)
+      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
@@ -84,38 +131,141 @@
       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
+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)
+      CALL histwrite(nid_mth, "SWupTOA",itau_w,zx_tmp_2d,
+     .                               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)
+      CALL histwrite(nid_mth, "SWupTOAclr",itau_w,zx_tmp_2d,
+     .                               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)
+      CALL histwrite(nid_mth, "SWdnTOA",itau_w,zx_tmp_2d,
+     .                               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)
+      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, sollwdown,zx_tmp_2d)
-      CALL histwrite(nid_mth,"LWdnSFC",itau_w,zx_tmp_2d,iim*jjmp1,
-     .               ndex2d)
-cIM: 071003
+      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
       zx_tmp_fi2d(1:klon)=sollw(1:klon)+sollwdown(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)
-cLWupSFC
-      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, toplw0,zx_tmp_2d)
-      CALL histwrite(nid_mth,"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_mth,"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_mth,"soll0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+c
+      zx_tmp_fi2d(1:klon)=sollw0(1:klon)+sollwdownclr(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
+      DO i=1, klon
+       sollwdownclr(i)=lwdn0(i,1)
+      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
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sens,zx_tmp_2d)
+      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
@@ -144,43 +294,6 @@
        CALL histwrite(nid_mth,"fqcalving",itau_w,zx_tmp_2d,iim*jjmp1,
      $                ndex2d)
-c
-
-      DO nsrf = 1, nbsrf
-CYYY
-        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,"pourc_"//clnsurf(nsrf),itau_w,
-     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
-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
+cIM: 171003
+       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)
@@ -192,5 +305,224 @@
         CALL histwrite(nid_mth,"tauy_"//clnsurf(nsrf),itau_w,
      $      zx_tmp_2d,iim*jjmp1,ndex2d)
+       ENDDO
+cIM: 171003
+c
+cIM      if ( lev_histday.gt.1 ) then
+      DO nsrf = 1, nbsrf
+CYYY
+       IF(nsrf.GT.1) THEN
+        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,"pourc_"//clnsurf(nsrf),itau_w,
+     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
+       ENDIF !nsrf.GT.1
 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
+
+      END DO  
+cIM      endif !lev_histday
+
+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,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
+c
+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,
+     $       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,
+     $       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
+      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
+cIM: 071003
+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, 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
+      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, wo, 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,
+     .                                   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)
+cIM 22.03.04 END
+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)
@@ -207,79 +539,25 @@
       CALL histwrite(nid_mth,"ages_"//clnsurf(nsrf),itau_w
      $    ,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      END DO  
-cXXX      DO i = 1, klon
-cXXX         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
-cXXX      ENDDO
-cXXX      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
-cXXX      CALL histwrite(nid_mth,"sicf",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
-      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,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(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(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)
+      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)
@@ -295,74 +573,4 @@
      .                                   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(1, klon,iim,jjmp1, prw,zx_tmp_2d)
-      CALL histwrite(nid_mth,"prw",itau_w,zx_tmp_2d,
-     .               iim*jjmp1,ndex2d)
-c
-      ENDIF
-c34EK
-c
-c Champs 3D:
-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
-      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)
-cIM: 071003
-      zx_tmp_fi3d(1:klon,1:klev)=qx(1:klon,1:klev,ivap)/
-     .                         (1-qx(1:klon,1:klev,ivap))
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
-      CALL histwrite(nid_mth,"wvap",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_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, 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
-      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, cldliq, zx_tmp_3d)
-      CALL histwrite(nid_mth,"oliq",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_t_dyn, zx_tmp_3d)
@@ -504,8 +712,4 @@
       ENDIF
 C
-      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, wo, zx_tmp_3d)
-      CALL histwrite(nid_mth,"ozone",itau_w,zx_tmp_3d,
-     .                                   iim*jjmp1*klev,ndex3d)
-c
       IF (nqmax.GE.3) THEN
       DO iq=1,nqmax-2
@@ -522,77 +726,5 @@
       ENDIF
 c
-c     zx_tmp_fi2d(1 : klon) = ZFSUP( 1 : klon, klevp1)
-      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 2 )
-      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) = 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) = ZFSDN( 1 : klon, klevp1)
-      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 2 )
-      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
-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) = ZFSUP0( 1 : klon, klevp1)
-      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 2 )
-      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
-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) = ZFSDN0( 1 : klon, klevp1)
-      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 2 )
-      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
-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
-c  Champs interpolles sur des niveaux de pression
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, u850,zx_tmp_2d)
-      CALL histwrite(nid_mth,"u850",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, v850,zx_tmp_2d)
-      CALL histwrite(nid_mth,"v850",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, u500,zx_tmp_2d)
-      CALL histwrite(nid_mth,"u500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, v500,zx_tmp_2d)
-      CALL histwrite(nid_mth,"v500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, u200,zx_tmp_2d)
-      CALL histwrite(nid_mth,"u200",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, v200,zx_tmp_2d)
-      CALL histwrite(nid_mth,"v200",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, phi500,zx_tmp_2d)
-      CALL histwrite(nid_mth,"phi500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
-
-      CALL gr_fi_ecrit(1, klon,iim,jjmp1, w500,zx_tmp_2d)
-      CALL histwrite(nid_mth,"w500",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
+      ENDIF !lev_histmth.GE.4
 c
       if (ok_sync) then
