Index: LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histday.h
===================================================================
--- LMDZ.3.3/branches/rel-LF/libf/phylmd/write_histday.h	(revision 467)
+++ 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
