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 histwrite_phy(nid_day,"phis",itau_w,pphis)
 
c
       CALL histwrite_phy(nid_day,"aire",itau_w,airephy)
c
      DO i=1, klon
       zx_tmp_fi2d(i)=pctsrf(i,is_ter)+pctsrf(i,is_lic)
      ENDDO
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"contfracATM",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,pctsrf_new(:,is_ter),zx_tmp_2d)
      CALL histwrite_phy(nid_day,"contfracOR",itau_w,
     &                   pctsrf_new(:,is_ter))
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"tsol",itau_w,zxtsol)
C
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"t2m",itau_w,zt2m)
c
c   En attendant un eventuel debugage.

cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"t2m_min",itau_w,zt2m)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"t2m_max",itau_w,zt2m)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"plul",itau_w,zx_tmp_fi2d)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"pluc",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_lsc,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"snowl",itau_w,snow_lsc)
c
      IF(1.EQ.0) THEN
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_con,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"snowc",itau_w,snow_con)
      ENDIF
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfluxlat,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"flat",itau_w,zxfluxlat)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
      ENDDO
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"sicf",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zq2m,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"q2m",itau_w,zq2m)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zu10m,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"u10m",itau_w,zu10m)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zv10m,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"v10m",itau_w,zv10m)
c
      DO i=1, klon
       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)     
      CALL histwrite_phy(nid_day,"wind10m",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"wind10max",itau_w,zx_tmp_fi2d)
c
      DO i=1, klon
         zx_tmp_fi2d(i) = paprs(i,1)
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"psol",itau_w,zx_tmp_fi2d)
c
      DO i=1, klon
         zx_tmp_fi2d(i) = (rain_fall(i) + snow_fall(i))
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"precip",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_fall,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"snowf",itau_w,snow_fall)
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
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"evap",itau_w,evap)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"tops",itau_w,topsw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"topl",itau_w,toplw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"sols",itau_w,solsw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"soll",itau_w,sollw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, radsol,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"radsol",itau_w,radsol)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldl,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"cldl",itau_w,cldl)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldm,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"cldm",itau_w,cldm)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldh,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"cldh",itau_w,cldh)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"cldt",itau_w,cldt)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldq,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"cldq",itau_w,cldq)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, prw,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"prw",itau_w,prw)

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
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1,usumSTD(:,k,1),zx_tmp_2d)
        CALL histwrite_phy(nid_day,"u"//bb2,itau_w,usumSTD(:,k,1))
c
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1,vsumSTD(:,k,1),zx_tmp_2d)
        CALL histwrite_phy(nid_day,"v"//bb2,itau_w,vsumSTD(:,k,1))
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
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,wsumSTD(:,k,1),zx_tmp_2d)
      CALL histwrite_phy(nid_day,"w"//bb2,itau_w,wsumSTD(:,k,1))
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,phisumSTD(:,k,1),zx_tmp_2d)
      CALL histwrite_phy(nid_day,"phi"//bb2,itau_w,phisumSTD(:,k,1))

      ENDIF !(bb2.EQ."500") THEN
c
      ENDDO !nlevSTD
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"slp",itau_w,slp)

cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,cape,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"cape_max",itau_w,cape)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdown,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"solldown",itau_w,sollwdown)
c
      DO i=1, klon
        zx_tmp_fi2d(i)=-1*sens(i)
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"sens",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = swdn(1 : klon, 1)

cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day, "SWdnSFC",itau_w,zx_tmp_fi2d)
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
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"lmt_bils",itau_w, zx_tmp_fi2d)
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
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"slab_bils",itau_w,zx_tmp_fi2d)
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
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"tslab",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"seaice",itau_w,seaice)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice/1000.,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"siceh",itau_w,seaice/1000.)
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) = 0.
       ENDIF
      ENDDO
c
cym     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"fluxo",itau_w,zx_tmp_fi2d)
c
      DO i=1, klon
       IF (pctsrf(i,is_sic).GT.epsfra) THEN
        zx_tmp_fi2d(i) = fluxg(i)
       ELSE
        zx_tmp_fi2d(i) = 0.
       ENDIF
      ENDDO
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"fluxg",itau_w,zx_tmp_fi2d)
c
      ENDIF !lev_histday.GE.1
c
      IF(lev_histday.GE.2) THEN
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, bils,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"bils",itau_w, bils)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, fder,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"fder",itau_w,fder)
c
      DO i=1, klon
       zx_tmp_fi2d(i)=MIN(100.,rh2m(i)*100.)
      ENDDO
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1, zx_tmp_2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"rh2m",itau_w,zx_tmp_fi2d)
      zx_tmp_fi2d(1 : klon) = swup( 1 : klon, klevp1 )
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day, "SWupTOA",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = swup( 1 : klon, 1 )
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day, "SWupSFC",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = swdn( 1 : klon, klevp1 )
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day, "SWdnTOA",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = swup0( 1 : klon, klevp1 )
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day, "SWupTOAclr",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = swup0( 1 : klon, 1 )
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day, "SWupSFCclr",itau_w,zx_tmp_fi2d)
c 
      zx_tmp_fi2d(1 : klon) = swdn0( 1 : klon, klevp1 )
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day, "SWdnTOAclr",itau_w,zx_tmp_fi2d)
c 
      zx_tmp_fi2d(1 : klon) = swdn0( 1 : klon, 1 )
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day, "SWdnSFCclr",itau_w,zx_tmp_fi2d)
c
cIM AMMA-MIP
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdown,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"LWdnSFC",itau_w,sollwdown)
c
      zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"LWupSFC",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1:klon) = flwp(1:klon)
cym     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"lwp",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1:klon) = fiwp(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"iwp",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = zxfluxu(1 : klon, 1)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
      CALL histwrite_phy(nid_day,"taux",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = zxfluxv(1 : klon, 1)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
      CALL histwrite_phy(nid_day,"tauy",itau_w,zx_tmp_fi2d)
c
cIM   IF (iflag_con.GE.3) THEN
cIM ema_pct= 0.     CALL gr_fi_ecrit(1, klon,iim,jjmp1, ema_pct,zx_tmp_2d)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, meanptop(:,1),zx_tmp_2d)
        IF (ok_isccp) THEN
          CALL histwrite_phy(nid_day,"ptop",itau_w,meanptop(:,1))
	ENDIF
cIM   ENDIF
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
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
      CALL histwrite_phy(nid_day,"temp",itau_w,t_seri)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
      CALL histwrite_phy(nid_day,"ovap",itau_w,qx(:,:,ivap))
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
      CALL histwrite_phy(nid_day,"geop",itau_w,zphi)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
      CALL histwrite_phy(nid_day,"vitu",itau_w,u_seri)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
      CALL histwrite_phy(nid_day,"vitv",itau_w,v_seri)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
      CALL histwrite_phy(nid_day,"vitw",itau_w,omega)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
      CALL histwrite_phy(nid_day,"pres",itau_w,pplay)
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) = ftsol(1 : klon, is_ter)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d ,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"tter",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = ftsol(1 : klon, is_lic)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"tlic",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = ftsol(1 : klon, is_oce)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"toce",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = ftsol(1 : klon, is_sic)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"tsic",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_ter)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"t2mter",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_ter)
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"t2mter_min",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_ter)
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"t2mter_max",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_lic)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"t2mlic",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_oce)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"t2moce",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = t2m(1 : klon, is_sic)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"t2msic",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, is_ter)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"u10mter",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, is_ter)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"v10mter",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, is_lic)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"u10mlic",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, is_lic)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"v10mlic",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, is_oce)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"u10moce",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, is_oce)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"v10moce",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = u10m(1 : klon, is_sic)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"u10msic",itau_w,zx_tmp_fi2d)
C
      zx_tmp_fi2d(1 : klon) = v10m(1 : klon, is_sic)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_day,"v10msic",itau_w,zx_tmp_fi2d)
C
      DO nsrf = 1, nbsrf
C
        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_day,"pourc_"//clnsurf(nsrf),itau_w,
     &                     zx_tmp_fi2d) 
C
        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_day,"fract_"//clnsurf(nsrf),itau_w,
     &                     zx_tmp_fi2d) 
C
        zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_day,"tsol_"//clnsurf(nsrf),itau_w,
     $                     zx_tmp_fi2d) 
C 
        zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_day,"sens_"//clnsurf(nsrf),itau_w,
     $                     zx_tmp_fi2d) 
C  
        zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_day,"lat_"//clnsurf(nsrf),itau_w,
     $                     zx_tmp_fi2d) 
C
        zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_day,"taux_"//clnsurf(nsrf),itau_w,
     $                     zx_tmp_fi2d) 
C      
        zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_day,"tauy_"//clnsurf(nsrf),itau_w,
     $                     zx_tmp_fi2d)
C
        zx_tmp_fi2d(1 : klon) = falbe( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_day,"albe_"//clnsurf(nsrf),itau_w,
     $                     zx_tmp_fi2d) 
C
        zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_day,"rugs_"//clnsurf(nsrf),itau_w,
     $                     zx_tmp_fi2d) 
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
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw0,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"tops0",itau_w,topsw0)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw0,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"topl0",itau_w,toplw0)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw0,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"sols0",itau_w,solsw0)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw0,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"soll0",itau_w, sollw0)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldfra, zx_tmp_3d)
      CALL histwrite_phy(nid_day,"rneb",itau_w,cldfra)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, rnebcon, zx_tmp_3d)
      CALL histwrite_phy(nid_day,"rnebcon",itau_w,rnebcon)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, flwc,zx_tmp_3d)
      CALL histwrite_phy(nid_day,"lwcon",itau_w,flwc)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, fiwc,zx_tmp_3d)
      CALL histwrite_phy(nid_day,"iwcon",itau_w,fiwc)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1, meantaucld,zx_tmp_2d)
      IF (ok_isccp) THEN
      CALL histwrite_phy(nid_day,"meantaucld",itau_w,meantaucld)
      ENDIF
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldtau,zx_tmp_3d)
      CALL histwrite_phy(nid_day,"cldtau",itau_w,cldtau)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldemi,zx_tmp_3d)
      CALL histwrite_phy(nid_day,"cldemi",itau_w,cldemi)
c
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_day,"dtcon",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_day,"dqcon",itau_w,zx_tmp_fi3d)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1, qsat2m,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"qsat2m",itau_w,qsat2m)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1, tpot,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"tpot",itau_w,tpot)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1, tpote,zx_tmp_2d)
      CALL histwrite_phy(nid_day,"tpote",itau_w,tpote)
c
      ENDIF !lev_histday.GE.5
c=================================================================
c=================================================================
c=================================================================
c
      if (ok_sync) then
c$OMP MASTER
        call histsync(nid_day)
c$OMP END MASTER
      endif

      ENDIF
