c
c $Header$
c
      if (ok_journe) THEN
c
      ndex2d = 0
      ndex3d = 0
c
c Champs 2D:
c
         itau_w = itau_phy + itap

c
      IF(lev_histday.GE.1) THEN
c
       CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
       CALL histwrite(nid_day,"phis",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
cIM 310804      CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
         CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
       CALL histwrite(nid_day,"aire",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
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 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)
c
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zu10m,zx_tmp_2d)
      CALL histwrite(nid_day,"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_day,"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_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
      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 gr_fi_ecrit(1, klon,iim,jjmp1, snow_fall,zx_tmp_2d)
      CALL histwrite(nid_day,"snowf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
cIM: 140404   CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxsnow,zx_tmp_2d)
c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zsnow_mass,zx_tmp_2d)
c     CALL histwrite(nid_day,"snow_mass",itau_w,zx_tmp_2d,iim*jjmp1,
c    .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
      CALL histwrite(nid_day,"evap",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
      CALL histwrite(nid_day,"tops",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
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 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 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 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
c     DO k=1, nlevENS
      DO k=1, nlevSTD
c
c        bb=clevSTD(k)
c
         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
c         aa=clevSTD(k)
c         bb=aa(1:lnblnk1(aa))
c        ENDIF
c
      IF(bb2.EQ."850".OR.bb2.EQ."700"
     $   .OR.bb2.EQ."500".OR.bb2.EQ."200") THEN
c
        CALL gr_fi_ecrit(1, klon,iim,jjmp1,usumSTD(:,k,1),zx_tmp_2d)
        CALL histwrite(nid_day,"u"//bb2,itau_w,zx_tmp_2d,
     $       iim*jjmp1,ndex2d)
c
        CALL gr_fi_ecrit(1, klon,iim,jjmp1,vsumSTD(:,k,1),zx_tmp_2d)
        CALL histwrite(nid_day,"v"//bb2,itau_w,zx_tmp_2d,
     $       iim*jjmp1,ndex2d)
c
      ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.bb2.EQ."500".OR.bb2.EQ."200") THEN
c
c w500
c
      IF(bb2.EQ."500") THEN
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,wsumSTD(:,k,1),zx_tmp_2d)
      CALL histwrite(nid_day,"w"//bb2,itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,phisumSTD(:,k,1),zx_tmp_2d)
      CALL histwrite(nid_day,"phi"//bb2,itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)

      ENDIF !(bb2.EQ."500") THEN
c
      ENDDO !nlevSTD
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
      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
      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
      IF (OCEAN.EQ.'force ') THEN
c
      DO i=1, klon
      IF((pctsrf(i,is_oce).GT.epsfra).OR.
     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
     .                  fluxg(i)*pctsrf(i,is_sic)
      ELSE
       zx_tmp_fi2d(i) = 1.E+20
      ENDIF
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_day,"lmt_bils",itau_w,
     .     zx_tmp_2d,iim*jjmp1,ndex2d)
c
      ELSE IF (OCEAN.EQ.'slab  ') THEN
c
      DO i=1, klon
      IF((pctsrf(i,is_oce).GT.epsfra).OR.
     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
     .                  fluxg(i)*pctsrf(i,is_sic)
      ELSE
       zx_tmp_fi2d(i) = 1.E+20
      ENDIF
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_day,"slab_bils",itau_w,
     .     zx_tmp_2d,iim*jjmp1,ndex2d)
c
      DO i=1, klon
       IF(pctsrf(i,is_oce).GT.epsfra.OR.
     $    pctsrf(i,is_sic).GT.epsfra) THEN
        zx_tmp_fi2d(i)=tslab(i)
       ELSE
        zx_tmp_fi2d(i) = 1.E+20
       ENDIF
      ENDDO !i=1, klon
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_day,"tslab",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice,zx_tmp_2d)
      CALL histwrite(nid_day,"seaice",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice/1000.,zx_tmp_2d)
      CALL histwrite(nid_day,"siceh",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      ENDIF !(OCEAN.EQ.'slab  ') THEN
c
      DO i=1, klon
       IF (pctsrf(i,is_oce).GT.epsfra) THEN
        zx_tmp_fi2d(i) = fluxo(i)
       ELSE
        zx_tmp_fi2d(i) = 1.E+20
       ENDIF
      ENDDO
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_day,"fluxo",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      DO i=1, klon
       IF (pctsrf(i,is_sic).GT.epsfra) THEN
        zx_tmp_fi2d(i) = fluxg(i)
       ELSE
        zx_tmp_fi2d(i) = 1.E+20
       ENDIF
      ENDDO
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_day,"fluxg",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      ENDIF !lev_histday.GE.1
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 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
      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
      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
      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
      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) = 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) = 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) = 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)
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
      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
      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
      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
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_ter)
      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,
     .               ndex2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_ter)
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_day,"t2mter_min",itau_w,zx_tmp_2d,
     .               iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_ter)
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_day,"t2mter_max",itau_w,zx_tmp_2d,
     .               iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_lic)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"t2mlic",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_oce)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"t2moce",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_sic)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"t2msic",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, is_ter)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"u10mter",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, is_ter)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"v10mter",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, is_lic)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"u10mlic",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, is_lic)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"v10mlic",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, is_oce)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"u10moce",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, is_oce)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"v10moce",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, is_sic)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"u10msic",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
C
      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, is_sic)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_day,"v10msic",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
C
      DO nsrf = 1, nbsrf
C
        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_day,"pourc_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
C
        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_day,"fract_"//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_day,"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_day,"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_day,"lat_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
C
        zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_day,"taux_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
C      
        zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_day,"tauy_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1 : klon) = falbe( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_day,"albe_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
C
        zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_day,"rugs_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
C 
      END DO  
c=================================================================
c   FIN ECRITURE DES CHAMPS SUR LES SOUS SURFACES
c=================================================================
      ENDIF !lev_histday.GE.4
c
      IF(lev_histday.GE.5) THEN !lev_histday.GE.5
c
c rajout sorties F. Aires
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw0,zx_tmp_2d)
      CALL histwrite(nid_day,"tops0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw0,zx_tmp_2d)
      CALL histwrite(nid_day,"topl0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw0,zx_tmp_2d)
      CALL histwrite(nid_day,"sols0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw0,zx_tmp_2d)
      CALL histwrite(nid_day,"soll0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldfra, zx_tmp_3d)
      CALL histwrite(nid_day,"rneb",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, rnebcon, zx_tmp_3d)
      CALL histwrite(nid_day,"rnebcon",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, flwc,zx_tmp_3d)
      CALL histwrite(nid_day,"lwcon",itau_w,zx_tmp_3d,
     .               iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, fiwc,zx_tmp_3d)
      CALL histwrite(nid_day,"iwcon",itau_w,zx_tmp_3d,
     .               iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi2d(1:klon) = flwp(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_day,"lwp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon) = fiwp(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_day,"iwp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1,klon,iim,jjmp1, meantaucld,zx_tmp_2d)
      CALL histwrite(nid_day,"meantaucld",itau_w,zx_tmp_2d,
     .               iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldtau,zx_tmp_3d)
      CALL histwrite(nid_day,"cldtau",itau_w,zx_tmp_3d,
     .               iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldemi,zx_tmp_3d)
      CALL histwrite(nid_day,"cldemi",itau_w,zx_tmp_3d,
     .               iim*jjmp1*klev,ndex3d)
c
      ENDIF !lev_histday.GE.5
c=================================================================
c=================================================================
c=================================================================
c
      if (ok_sync) then
        call histsync(nid_day)
      endif

      ENDIF
