c
c $Header$
c
      IF (ok_mensuel) THEN
c
      ndex2d = 0
      ndex3d = 0

         itau_w = itau_phy + itap

c
      IF(type_run.EQ."CLIM".OR.type_run.EQ."ENSP") THEN
c
      IF(lev_histmth.GE.1) THEN
c
c Champs 2D:
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"phis",itau_w,pphis)
C
cIM 310804   CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"aire",itau_w,airephy)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)* 100.
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"pourc_"//clnsurf(is_ter),itau_w,
     $                   zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"fract_"//clnsurf(is_ter),itau_w,
     $                   zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"slp",itau_w,slp)

cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"tsol",itau_w,zxtsol)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zt2m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"t2m",itau_w,zt2m)
c
c ENSEMBLES BEG
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"t2m_min",itau_w,zt2m)
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"t2m_max",itau_w,zt2m)
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_phy(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 
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"wind10m",itau_w,zx_tmp_fi2d)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"sicf",itau_w,zx_tmp_fi2d)
c
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
c     CALL histwrite_phy(nid_mth,"temp",itau_w,zx_tmp_3d,
c    .                                   iim*jjmp1*klev,ndex3d)
c
c ENSEMBLES END
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zq2m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"q2m",itau_w,zq2m)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zu10m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"u10m",itau_w,zu10m)
C
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zv10m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"v10m",itau_w,zv10m)
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_mth,"psol",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxqsurf,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"qsurf",itau_w,zxqsurf)
c
      if (.not. ok_veget) then
cym          CALL gr_fi_ecrit(1, klon,iim,jjmp1, qsol,zx_tmp_2d)
          CALL histwrite_phy(nid_mth,"qsol",itau_w,qsol)
      endif
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_mth,"precip",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, nday_rain,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"ndayrain",itau_w,nday_rain)
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_mth,"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_mth,"pluc",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_fall,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"snow",itau_w,snow_fall)
c
c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zsnow_mass,zx_tmp_2d)
c     CALL histwrite(nid_mth,"snow_mass",itau_w,zx_tmp_2d,iim*jjmp1,
c    .               ndex2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"evap",itau_w,evap)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"tops",itau_w,topsw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw0,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"tops0",itau_w,topsw0)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"topl",itau_w,toplw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw0,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"topl0",itau_w,toplw0)
c
      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_mth, "SWupTOA",itau_w,zx_tmp_fi2d)
c
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_mth, "SWupTOAclr",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_mth, "SWdnTOA",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_mth, "SWdnTOAclr",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWup200,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"SWup200",itau_w,SWup200)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWup200clr,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"SWup200clr",itau_w,SWup200clr)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWdn200,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"SWdn200",itau_w,SWdn200)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWdn200clr,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"SWdn200clr",itau_w,SWdn200clr)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, LWup200,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWup200",itau_w,LWup200)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, LWup200clr,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWup200clr",itau_w,LWup200clr)
c
      zx_tmp_fi2d(1:klon)=-1*LWdn200(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWdn200",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1:klon)=-1*LWdn200clr(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWdn200clr",itau_w,zx_tmp_fi2d)
c
c200 END 
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"sols",itau_w,solsw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw0,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"sols0",itau_w,solsw0)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"soll",itau_w,sollw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, radsol,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"radsol",itau_w,radsol)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw0,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"soll0",itau_w,sollw0)
c
c      zx_tmp_fi2d(1 : klon) = ZFSUP( 1 : klon, 1)
      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_mth, "SWupSFC",itau_w,zx_tmp_fi2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSUP0( 1 : klon, 1)
      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_mth, "SWupSFCclr",itau_w,zx_tmp_fi2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSDN( 1 : klon, 1)
      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_mth, "SWdnSFC",itau_w,zx_tmp_fi2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSDN0( 1 : klon, 1)
      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_mth, "SWdnSFCclr",itau_w,zx_tmp_fi2d)
c
cIM 080904   zx_tmp_fi2d(1:klon)=sollw(1:klon)+sollwdown(1:klon)
cIM 130904   zx_tmp_fi2d(1:klon)=sollw(1:klon)-sollwdown(1:klon)
      zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWupSFC",itau_w,zx_tmp_fi2d)
c
      DO i=1, klon
       sollwdownclr(i)=-1.*lwdn0(i,1)
      ENDDO !i=1, klon

cIM 080904   zx_tmp_fi2d(1:klon)=sollw0(1:klon)+sollwdownclr(1:klon)
cIM 130904   zx_tmp_fi2d(1:klon)=sollw0(1:klon)-sollwdownclr(1:klon)
      zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWupSFCclr",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdown,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWdnSFC",itau_w,sollwdown)
c
c     DO i=1, klon
cIM 080904     sollwdownclr(i)=lwdn0(i,1)
c      sollwdownclr(i)=-1.*lwdn0(i,1)
c     ENDDO !i=1, klon
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdownclr,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWdnSFCclr",itau_w,sollwdownclr)
c
c
c effets des aerosols
c
      IF (ok_ade.OR.ok_aie) THEN
      zx_tmp_fi2d(1:klon) = topswai(1:klon) - topswad(1:klon)
      CALL histwrite_phy(nid_mth,"topsad",itau_w,zx_tmp_2d)
c
      zx_tmp_fi2d(1:klon) = solswai(1:klon) - solswad(1:klon)
      CALL histwrite_phy(nid_mth,"solsad",itau_w,zx_tmp_2d)
c
      zx_tmp_fi2d(1:klon) = topsw(1:klon) - topswai(1:klon)
      CALL histwrite_phy(nid_mth,"topsai",itau_w,zx_tmp_2d)
c
      zx_tmp_fi2d(1:klon) = solsw(1:klon) - solswai(1:klon)
      CALL histwrite_phy(nid_mth,"solsai",itau_w,zx_tmp_2d)
      endif

c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, bils,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"bils",itau_w,bils)
c
      zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, sens,zx_tmp_2d)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"sens",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, fder,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"fder",itau_w,fder)
c
c
c      DO i = 1, klon
c         zx_tmp_fi2d(i) = fluxu(i,1)
c      ENDDO
c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
c      CALL histwrite(nid_mth,"frtu",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c      DO i = 1, klon
c         zx_tmp_fi2d(i) = fluxv(i,1)
c      ENDDO
c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
c      CALL histwrite(nid_mth,"frtv",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxffonte,zx_tmp_2d)
       CALL histwrite_phy(nid_mth,"ffonte",itau_w,zxffonte)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfqcalving,zx_tmp_2d)
       CALL histwrite_phy(nid_mth,"fqcalving",itau_w,zxfqcalving)

cym       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfqfonte,zx_tmp_2d)
       CALL histwrite_phy(nid_mth,"fqfonte",itau_w,zxfqfonte)

       DO nsrf = 1, nbsrf
        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_mth,"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_mth,"tauy_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
       ENDDO
c
      DO nsrf = 1, nbsrf
CYYY
       IF(nsrf.GE.2) THEN
        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_mth,"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_mth,"fract_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d) 
       ENDIF !nsrf.GE.2
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_mth,"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_mth,"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_mth,"lat_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d) 
C
        zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"flw_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
c
        zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"fsw_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
C
        zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"wbils_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
C
        zx_tmp_fi2d(1 : klon) = wfbilo( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"wbilo_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
C
       IF(1.EQ.0) THEN
C
        zx_tmp_fi2d(1:klon) = fevap(1:klon,nsrf)*pctsrf(1:klon,nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"evapour_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
C
        zx_tmp_fi2d(1:klon) = (rain_fall(1:klon) + snow_fall(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_mth,"prepour_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
C
       ENDIF !(1.EQ.0) THEN
C
      END DO  
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragm,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cdrm",itau_w,cdragm)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragh,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cdrh",itau_w,cdragh)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldl,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cldl",itau_w,cldl)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldm,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cldm",itau_w,cldm)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldh,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cldh",itau_w,cldh)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cldt",itau_w,cldt)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldq,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cldq",itau_w,cldq)
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_mth,"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_mth,"iwp",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ue,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"ue",itau_w,ue)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ve,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"ve",itau_w,ve)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, uq,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"uq",itau_w,uq)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, vq,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"vq",itau_w,vq)
cKE43
      IF (iflag_con.GE.3) THEN ! sb
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cape,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cape",itau_w,cape)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,pbase,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"pbase",itau_w,pbase)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_pct,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"ptop",itau_w,ema_pct)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_cbmf,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"fbase",itau_w,ema_cbmf)
c
c34EK
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, prw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"prw",itau_w,prw)
c
      ENDIF !iflag_con.GE.3
c
c
cIM cf. AM 081204 BEG
cHBTM2
c
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblh,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_pblh",itau_w,s_pblh)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblt,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_pblt",itau_w,s_pblt)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_lcl,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_lcl",itau_w,s_lcl)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_capCL,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_capCL",itau_w,s_capCL)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_oliqCL,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_oliqCL",itau_w,s_oliqCL)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_cteiCL,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_cteiCL",itau_w,s_cteiCL)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_therm,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_therm",itau_w,s_therm)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb1,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_trmb1",itau_w,s_trmb1)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb2,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_trmb2",itau_w,s_trmb2)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb3,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_trmb3",itau_w,s_trmb3)
c
cIM cf. AM 081204 END
c
c  Champs interpolles sur des niveaux de pression
      DO k=1, nlevSTD
c
c        bb=clevSTD(k)
c
c        IF(k.GE.2) THEN
         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
c         aa=clevSTD(k)
c         bb=aa(1:lnblnk1(aa))
c        ENDIF
c
      IF(bb2.EQ."850".OR.bb2.EQ."700".OR.
     $   bb2.EQ."500".OR.bb2.EQ."200") THEN
c
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1,usumSTD(:,k,2),zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"u"//bb2,itau_w,usumSTD(:,k,2))
c
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1,vsumSTD(:,k,2),zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"v"//bb2,itau_w,vsumSTD(:,k,2))
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,wsumSTD(:,k,2),zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"w"//bb2,itau_w,wsumSTD(:,k,2))
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,phisumSTD(:,k,2),zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"phi"//bb2,itau_w,phisumSTD(:,k,2))
c
      ENDIF !(bb2.EQ."850".OR.bb2.EQ."700".OR.
      ENDDO !nlevSTD
c
      DO i=1, klon
       IF (pctsrf(i,is_oce).GT.epsfra) THEN
        zx_tmp_fi2d(i) = fluxo(i)
       ELSE
        zx_tmp_fi2d(i) = 0.
       ENDIF
      ENDDO
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"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_mth,"fluxg",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) = (ftsol(i, is_oce) * pctsrf(i,is_oce)+ 
     .                   ftsol(i, is_sic) * pctsrf(i,is_sic))/
     .                   (pctsrf(i,is_oce)+pctsrf(i,is_sic))
       ELSE
        zx_tmp_fi2d(i) = 273.15
       ENDIF
      ENDDO
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"t_oce_sic",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_mth,"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_mth,"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_mth,"tslab",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"seaice",itau_w,seaice)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice/1000.,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"siceh",itau_w, seaice/1000.)
c
      ENDIF !OCEAN.EQ.force/slab
c
      ENDIF !lev_histmth.GE.1
c
      IF(lev_histmth.GE.2) THEN
c
c Champs 3D:
C
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, flwc,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"lwcon",itau_w,flwc)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, fiwc,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"iwcon",itau_w,fiwc)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"temp",itau_w,t_seri)
c
c#ifdef histmthNMC
c#include "write_histmthNMC.h"
c#endif
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"ovap",itau_w,qx(:,:,ivap))
c
c     zx_tmp_fi3d(1:klon,1:klev)=qx(1:klon,1:klev,ivap)/
c    .                         (1-qx(1:klon,1:klev,ivap))
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
c     CALL histwrite(nid_mth,"wvap",itau_w,zx_tmp_3d,
c    .                                   iim*jjmp1*klev,ndex3d)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"geop",itau_w,zphi)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"vitu",itau_w,u_seri)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"vitv",itau_w,v_seri)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"vitw",itau_w,omega)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"pres",itau_w,pplay)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldfra, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"rneb",itau_w,cldfra)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, rnebcon, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"rnebcon",itau_w,rnebcon)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_rh, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"rhum",itau_w,zx_rh)

      DO k=1, klev
       DO i=1, klon
cIM 151004      zx_tmp_fi3d(i,k)=MAX(wo(i,k),1.0e-12)*RG/46.6968
c    $                    /(paprs(i,k)-paprs(i,k+1))
c    $                    *(paprs(i,1)/101325.0)
c        zx_tmp2_fi3d(i,k)=MAX(wo(i,k)*1.0e+6,1.0e-6)*RG/46.6968
         zx_tmp_fi3d(i,k)=wo(i,k)*RG/46.6968
     $                    /(paprs(i,k)-paprs(i,k+1))
     $                    *(paprs(i,1)/101325.0)
       ENDDO !i
      ENDDO !k
c
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, wo, zx_tmp_3d)
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp2_fi3d,zx_tmp_3d)
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"ozone",itau_w,zx_tmp_fi3d)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtphy",itau_w,d_t)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_qx(:,:,ivap), 
cym     .                 zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqphy",itau_w, d_qx(:,:,ivap))
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)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"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_mth,"rugs_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, agesno,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"ages_"//clnsurf(nsrf),itau_w
     $    ,zx_tmp_fi2d)
c
      ENDDO !nsrf=1, nbsrf
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsol,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"albs",itau_w,albsol)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsollw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"albslw",itau_w,albsollw)
c
      ENDIF !lev_histmth.GE.3
c
c
      IF(lev_histmth.GE.4) THEN
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, clwcon0, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"clwcon",itau_w,clwcon0)

      IF (iflag_con.GE.3) THEN
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, Ma, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"Ma",itau_w,Ma)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, upwd, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"upwd",itau_w,upwd)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dnwd",itau_w,dnwd)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd0, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dnwd0",itau_w,dnwd0)
c
      ENDIF !iflag_con.GE.3
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_dyn, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtdyn",itau_w,d_t_dyn)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_dyn, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqdyn",itau_w,d_q_dyn)
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_mth,"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_mth,"dqcon",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_lsc(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtlsc",itau_w,zx_tmp_fi3d)
cIM: 071003
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+
     .                             d_t_eva(1:klon,1:klev))/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtlschr",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqlsc",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtvdf",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqvdf",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dteva",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqeva",itau_w,zx_tmp_fi3d)
c
      zpt_conv = 0.
      where (ptconv) zpt_conv = 1.
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zpt_conv, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"ptconv",itau_w,zpt_conv)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, ratqs, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"ratqs",itau_w,ratqs)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajs(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtajs",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqajs",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/day ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY 
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtswr",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtsw0",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtlwr",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtlw0",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : deja en K/s      
      zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtec",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"duvdf",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dvvdf",itau_w,zx_tmp_fi3d)
c
      IF (ok_orodr) THEN
      zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"duoro",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dvoro",itau_w,zx_tmp_fi3d)
c
      ENDIF
C
      IF (ok_orolf) THEN
      zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dulif",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dvlif",itau_w,zx_tmp_fi3d)
      ENDIF
C

#if defined(INCA_AER) && defined(CPP_COUPLE)
      CALL histwrite_phy(nid_mth,"tau",itau_w,cldtau)
      CALL histwrite_phy(nid_mth,"CCM1",itau_w,ccm(:,:,1))
      CALL histwrite_phy(nid_mth,"CCM2",itau_w,ccm(:,:,2))
      CALL histwrite_phy(nid_mth,"taupi",itau_w,cldtaupi)
      CALL histwrite_phy(nid_mth,"cldemi",itau_w,cldemi)
      CALL histwrite_phy(nid_mth,"SWTOAAS_ZERO",itau_w,topsw_inca(:,1))
      CALL histwrite_phy(nid_mth,"SWTOAAS_AER",itau_w,topsw_inca(:,2))
      CALL histwrite_phy(nid_mth,"SWTOAAS_NAT",itau_w,topsw_inca(:,3))
      CALL histwrite_phy(nid_mth,"SWTOAAS_AD",itau_w,topswad_inca(:))
      CALL histwrite_phy(nid_mth,"SWTOAAS_AI",itau_w,topswai_inca(:))
      CALL histwrite_phy(nid_mth,"SWTOACS_ZERO",itau_w,topsw0_inca(:,1))
      CALL histwrite_phy(nid_mth,"SWTOACS_AER",itau_w,topsw0_inca(:,2))
      CALL histwrite_phy(nid_mth,"SWTOACS_AD",itau_w,topswad0_inca(:))
      CALL histwrite_phy(nid_mth,"SWTOACS_NAT",itau_w,topsw0_inca(:,3))
#endif
#ifndef INCA
      IF (nqmax.GE.3) THEN
      DO iq=3,nqmax
cym         CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,iq), zx_tmp_3d)
         CALL histwrite_phy(nid_mth,tnom(iq),itau_w,qx(:,:,iq))
      ENDDO
      ENDIF
#endif
      ENDIF !lev_histmth.GE.4
c
      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
c
      IF(lev_histmth.GE.1) THEN
c
c Champs 2D:
c
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis/RG,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"phis",itau_w,pphis/RG)
C
cIM 310804   CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"aire",itau_w,airephy)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)* 100.
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"pourc_"//clnsurf(is_ter),itau_w,
     $      zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"fract_"//clnsurf(is_ter),itau_w,
     $      zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_lic)* 100.
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"pourc_"//clnsurf(is_lic),itau_w,
     $      zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_lic)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"fract_"//clnsurf(is_lic),itau_w,
     $      zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_sic)* 100.
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"pourc_"//clnsurf(is_sic),itau_w,
     $      zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_sic)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"fract_"//clnsurf(is_sic),itau_w,
     $      zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfluxlat,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"flat",itau_w,zxfluxlat)
c
      zx_tmp_fi2d(1 : klon) = topsw(1:klon)-toplw(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"bilTOA",itau_w,zx_tmp_fi2d)
c
c     IF(itap.EQ.ecrit_mth) THEN
c       DO i=1, klon
c         IF(nday_clr(i).GT.0.) THEN
c          tops01(i)=tops01(i)/nday_clr(i)
c         ELSE
c          tops01(i)=1.e+20
c         ENDIF
c       ENDDO
c       CALL gr_fi_ecrit(1, klon,iim,jjmp1, tops01,zx_tmp_2d)
c       CALL histwrite_phy(nid_mth,"tops01",itau_w,zx_tmp_2d,
c    .       iim*jjmp1,ndex2d)
c     ENDIF !itap.EQ.ecrit_mth 
c
c220404 BEG
c
c temperature tendency due to total diabatic heating
       DO l=1, klev
       DO i=1, klon
       d_t(i,l) = (t_seri(i,l)-t(i,l))/dtime
       ENDDO !i
       ENDDO !l
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtdia",itau_w,d_t)
c
c temperature tendency due to SW radiation
       DO l=1, klev
       DO i=1, klon
       zx_tmp_fi3d(i,l)=heat(i,l)/RDAY
       ENDDO !i
       ENDDO !l
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtsw",itau_w,zx_tmp_fi3d)
c
c temperature tendency due to LW radiation
       DO l=1, klev
       DO i=1, klon
        zx_tmp_fi3d(i,l)=-1*cool(i,l)/RDAY
       ENDDO !i
       ENDDO !l
c
cym      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtlw",itau_w,zx_tmp_fi3d)
c
c  temperature tendency due to moist convective processes
       DO l=1, klev
       DO i=1, klon
        zx_tmp_fi3d(i,l)=d_t_con(i,l)/pdtphys
       ENDDO !i
       ENDDO !l
c
cym      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtcon",itau_w,zx_tmp_fi3d)
c
c temperature tendency due to dry convective processes
       DO l=1, klev
       DO i=1, klon
        zx_tmp_fi3d(i,l)=d_t_ajs(i,l)/pdtphys
       ENDDO !i
       ENDDO !l
c
cym      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtajs",itau_w,zx_tmp_fi3d)
c
c  temperature tendency due to large scale precipitation
       DO l=1, klev
       DO i=1, klon
       zx_tmp_fi3d(i,l)=d_t_lsc(i,l)/pdtphys
       ENDDO !i
       ENDDO !l
c
cym      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtlsc",itau_w,zx_tmp_fi3d)
c
c  total moisture tendency due to diabatic processes
       DO l=1, klev
       DO i=1, klon
        d_qx(i,l,ivap) = ( q_seri(i,l) - qx(i,l,ivap) ) / dtime
        zx_tmp_fi3d(i,l)=d_qx(i,l,ivap)
       ENDDO !i
       ENDDO !l
c
cym      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqdia",itau_w,zx_tmp_fi3d)
c
cBEG 210404 BEG
c
      IF(ok_orodr.AND.ok_orolf) THEN
      DO k = 1, klev
      DO i = 1, klon
        d_u_oli(i,k) = (d_u_oro(i,k) + d_u_lif(i,k))/pdtphys
        d_v_oli(i,k) = (d_v_oro(i,k) + d_v_lif(i,k))/pdtphys
      ENDDO
      ENDDO
      ENDIF !(ok_orodr.AND.ok_orolf) THEN
c
cym      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_u_oli,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"duoli",itau_w,d_u_oli)
c
cym      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_v_oli,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dvoli",itau_w,d_v_oli)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_u_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_mth,"ducon",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_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_mth,"dvcon",itau_w,zx_tmp_fi3d)
c
cym      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_u,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dutot",itau_w,d_u)
c
cym      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_v,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dvtot",itau_w,d_v)

cEND 210404 END
c
c cldtrue
c     CALL gr_fi_ecrit(klev, klon,iim,jjmp1,cldtrue,zx_tmp_3d)
c     CALL histwrite_phy(nid_mth,"cldtrue",itau_w,zx_tmp_3d,
c    $       iim*jjmp1*klev,ndex3d)
c
c     CALL gr_fi_ecrit(klev, klon,iim,jjmp1,cldTOA,zx_tmp_3d)
c     CALL histwrite_phy(nid_mth,"cldTOA",itau_w,zx_tmp_3d,
c    $       iim*jjmp1*klev,ndex3d)
c
c     CALL gr_fi_ecrit(klev, klon,iim,jjmp1,cldSFC,zx_tmp_3d)
c     CALL histwrite_phy(nid_mth,"cldSFC",itau_w,zx_tmp_3d,
c    $       iim*jjmp1*klev,ndex3d)
c
      DO i=1, klon
cIM 151004    zx_tmp_fi2d(i)=GWDtaux1(i,1)-GWDtaux0(i,1)
       zx_tmp_fi2d(i)=zustrdr(i)+zustrli(i)
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"GWDtaux",itau_w,zx_tmp_fi2d)
c
      DO i=1, klon
cIM 151004    zx_tmp_fi2d(i)=GWDtauy1(i,1)-GWDtauy0(i,1)
       zx_tmp_fi2d(i)=zvstrdr(i)+zvstrli(i)
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"GWDtauy",itau_w,zx_tmp_fi2d)
c
c220404 END
cAMIP2 END
c
cym     CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"slp",itau_w,slp)

cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"tsol",itau_w,zxtsol)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zt2m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"t2m",itau_w,zt2m)
c
c ENSEMBLES BEG
cym      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"t2m_min",itau_w,zt2m)
c
cym     CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"t2m_max",itau_w,zt2m)
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_phy(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 
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"wind10m",itau_w,zx_tmp_fi2d)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"sicf",itau_w,zx_tmp_fi2d)
c
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
c     CALL histwrite_phy(nid_mth,"temp",itau_w,zx_tmp_3d,
c    .                                   iim*jjmp1*klev,ndex3d)
c
c ENSEMBLES END
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zq2m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"q2m",itau_w,zq2m)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zu10m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"u10m",itau_w,zu10m)
C
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zv10m,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"v10m",itau_w,zv10m)
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_mth,"psol",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxqsurf,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"qsurf",itau_w,zxqsurf)
c
      if (.not. ok_veget) then
cym          CALL gr_fi_ecrit(1, klon,iim,jjmp1, qsol,zx_tmp_2d)
          CALL histwrite_phy(nid_mth,"qsol",itau_w,qsol)
      endif
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_mth,"precip",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, nday_rain,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"ndayrain",itau_w,nday_rain)
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_mth,"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_mth,"pluc",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_fall,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"snowf",itau_w,snow_fall)
c
c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, zsnow_mass,zx_tmp_2d)
c     CALL histwrite_phy(nid_mth,"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_mth,"evap",itau_w,evap)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"tops",itau_w,topsw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw0,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"tops0",itau_w,topsw0)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"topl",itau_w,toplw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw0,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"topl0",itau_w,toplw0)
c
      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_mth, "SWupTOA",itau_w,zx_tmp_fi2d)
c
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_mth, "SWupTOAclr",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_mth, "SWdnTOA",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_mth, "SWdnTOAclr",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWup200,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"SWup200",itau_w,SWup200)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWup200clr,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"SWup200clr",itau_w,SWup200clr)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWdn200,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"SWdn200",itau_w,SWdn200)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWdn200clr,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"SWdn200clr",itau_w,SWdn200clr)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, LWup200,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWup200",itau_w,LWup200)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, LWup200clr,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWup200clr",itau_w,LWup200clr)
c
      zx_tmp_fi2d(1:klon)=-1*LWdn200(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWdn200",itau_w,zx_tmp_fi2d)
c
      zx_tmp_fi2d(1:klon)=-1*LWdn200clr(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWdn200clr",itau_w,zx_tmp_fi2d)
c
c200 END 
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"sols",itau_w,solsw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw0,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"sols0",itau_w,solsw0)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"soll",itau_w,sollw)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, radsol,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"radsol",itau_w,radsol)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw0,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"soll0",itau_w,sollw0)
c
c      zx_tmp_fi2d(1 : klon) = ZFSUP( 1 : klon, 1)
      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_mth, "SWupSFC",itau_w,zx_tmp_fi2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSUP0( 1 : klon, 1)
      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_mth, "SWupSFCclr",itau_w,zx_tmp_fi2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSDN( 1 : klon, 1)
      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_mth, "SWdnSFC",itau_w,zx_tmp_fi2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSDN0( 1 : klon, 1)
      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_mth, "SWdnSFCclr",itau_w,zx_tmp_fi2d)
c
cIM 080904   zx_tmp_fi2d(1:klon)=sollw(1:klon)+sollwdown(1:klon)
cIM 130904   zx_tmp_fi2d(1:klon)=sollw(1:klon)-sollwdown(1:klon)
      zx_tmp_fi2d(1:klon)=sollwdown(1:klon)-sollw(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWupSFC",itau_w,zx_tmp_fi2d)
c
      DO i=1, klon
       sollwdownclr(i)=-1.*lwdn0(i,1)
      ENDDO !i=1, klon
c
cIM 080904   zx_tmp_fi2d(1:klon)=sollw0(1:klon)+sollwdownclr(1:klon)
cIM 130904   zx_tmp_fi2d(1:klon)=sollw0(1:klon)-sollwdownclr(1:klon)
      zx_tmp_fi2d(1:klon)=sollwdownclr(1:klon)-sollw0(1:klon)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWupSFCclr",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdown,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWdnSFC",itau_w,sollwdown)
c
c     DO i=1, klon
cIM 08004    sollwdownclr(i)=lwdn0(i,1)
c      sollwdownclr(i)=-1.*lwdn0(i,1)
c     ENDDO !i=1, klon
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdownclr,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"LWdnSFCclr",itau_w,sollwdownclr)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, bils,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"bils",itau_w,bils)
c
      zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, sens,zx_tmp_2d)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"sens",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, fder,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"fder",itau_w,fder)
c
c Effets des aerosols
c
      IF (ok_ade.OR.ok_aie) THEN
        zx_tmp_fi2d(1:klon) = topswai(1:klon) - topswad(1:klon)
        CALL histwrite_phy(nid_mth,"topsad",itau_w,zx_tmp_fi2d)
c
        zx_tmp_fi2d(1:klon) = solswai(1:klon) - solswad(1:klon)
        CALL histwrite_phy(nid_mth,"solsad",itau_w,zx_tmp_fi2d)
c
        zx_tmp_fi2d(1:klon) = topsw(1:klon) - topswai(1:klon)
        CALL histwrite_phy(nid_mth,"topsai",itau_w,zx_tmp_fi2d)
c
        zx_tmp_fi2d(1:klon) = solsw(1:klon) - solswai(1:klon)
        CALL histwrite_phy(nid_mth,"solsai",itau_w,zx_tmp_fi2d)
      ENDIF
c
c
c      DO i = 1, klon
c         zx_tmp_fi2d(i) = fluxu(i,1)
c      ENDDO
c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
c      CALL histwrite_phy(nid_mth,"frtu",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c      DO i = 1, klon
c         zx_tmp_fi2d(i) = fluxv(i,1)
c      ENDDO
c      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
c      CALL histwrite_phy(nid_mth,"frtv",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c
cym       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxffonte,zx_tmp_2d)
       CALL histwrite_phy(nid_mth,"ffonte",itau_w,zxffonte)
c
cym       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfqcalving,zx_tmp_2d)
       CALL histwrite_phy(nid_mth,"fqcalving",itau_w,zxfqcalving)
c
       DO nsrf = 1, nbsrf
        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_mth,"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_mth,"tauy_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
       ENDDO
c
        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, is_oce)*100.
cym        CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"pourc_"//clnsurf(is_oce),itau_w,
     $      zx_tmp_fi2d) 
c
        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, is_oce)
cym        CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"fract_"//clnsurf(is_oce),itau_w,
     $      zx_tmp_fi2d) 
c
      DO nsrf = 1, nbsrf
CYYY
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_mth,"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_mth,"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_mth,"lat_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d) 
C
        zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"flw_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
c
        zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"fsw_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
C
        zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"wbils_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
C
        zx_tmp_fi2d(1 : klon) = wfbilo( 1 : klon, nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"wbilo_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
C
       IF(1.EQ.0) THEN
C
        zx_tmp_fi2d(1:klon) = fevap(1:klon,nsrf)*pctsrf(1:klon,nsrf)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"evapour_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
C
        zx_tmp_fi2d(1:klon) = (rain_fall(1:klon) + snow_fall(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_mth,"prepour_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
C
       ENDIF !(1.EQ.0) THEN
C
      END DO  
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragm,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cdrm",itau_w,cdragm)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragh,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cdrh",itau_w,cdragh)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldl,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cldl",itau_w,cldl)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldm,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cldm",itau_w,cldm)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldh,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cldh",itau_w,cldh)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt*100.,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cldt",itau_w,cldt*100.)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldq,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cldq",itau_w,cldq)
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_mth,"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_mth,"iwp",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ue,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"ue",itau_w,ue)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ve,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"ve",itau_w,ve)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, uq,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"uq",itau_w,uq)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, vq,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"vq",itau_w,vq)
cKE43
      IF (iflag_con.GE.3) THEN ! sb
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cape,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"cape",itau_w,cape)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,pbase,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"pbase",itau_w,pbase)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_pct,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"ptop",itau_w,ema_pct)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_cbmf,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"fbase",itau_w,ema_cbmf)
c
c34EK
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, prw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"prw",itau_w,prw)
c
      ENDIF !iflag_con.GE.3
c
cIM cf. AM 081204 BEG
cHBTM2
c
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblh,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_pblh",itau_w,s_pblh)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblt,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_pblt",itau_w,s_pblt)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_lcl,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_lcl",itau_w,s_lcl)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_capCL,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_capCL",itau_w,s_capCL)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_oliqCL,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_oliqCL",itau_w,s_oliqCL)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_cteiCL,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_cteiCL",itau_w,s_cteiCL)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_therm,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_therm",itau_w,s_therm)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb1,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_trmb1",itau_w,s_trmb1)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb2,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_trmb2",itau_w,s_trmb2)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb3,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"s_trmb3",itau_w,s_trmb3)
c
cIM cf. AM 081204 END
c
c  Champs interpolles sur des niveaux de pression
c     DO k=1, nlevENS
      DO k=1, nlevSTD
c
c        bb=clevSTD(k)
c
c        IF(k.GE.2) THEN
         IF(k.GE.2.AND.k.LE.12) bb2=clevSTD(k)
         IF(k.GE.13.AND.k.LE.17) bb3=clevSTD(k)
c         aa=clevSTD(k)
c         bb=aa(1:lnblnk1(aa))
c        ENDIF
c
       IF(bb2.EQ."850".OR.bb2.EQ."700"
     $   .OR.bb2.EQ."500".OR.bb2.EQ."200") THEN
c
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1,usumSTD(:,k,2),zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"u"//bb2,itau_w,usumSTD(:,k,2))
c
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1,vsumSTD(:,k,2),zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"v"//bb2,itau_w,vsumSTD(:,k,2))
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,wsumSTD(:,k,2),zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"w"//bb2,itau_w,wsumSTD(:,k,2))
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1,phisumSTD(:,k,2),zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"phi"//bb2,itau_w,phisumSTD(:,k,2))
c
      ENDIF !(bb2.EQ."850".OR.bb2.EQ."700"
      ENDDO !nlevSTD
c
      DO i=1, klon
       IF (pctsrf(i,is_oce).GT.epsfra) THEN
        zx_tmp_fi2d(i) = fluxo(i)
       ELSE
        zx_tmp_fi2d(i) = 0.
       ENDIF
      ENDDO
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"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_mth,"fluxg",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) = (ftsol(i, is_oce) * pctsrf(i,is_oce)+ 
     .                   ftsol(i, is_sic) * pctsrf(i,is_sic))/
     .                   (pctsrf(i,is_oce)+pctsrf(i,is_sic))
       ELSE
        zx_tmp_fi2d(i) = 273.15
       ENDIF
      ENDDO
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"t_oce_sic",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_mth,"lmt_bils",itau_w,
     .     zx_tmp_fi2d)
c
      ELSE IF (OCEAN.EQ.'slab  ') THEN
c
c
      DO i=1, klon
      IF((pctsrf(i,is_oce).GT.epsfra).OR.
     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
     .                  fluxg(i)*pctsrf(i,is_sic)
      ELSE
       zx_tmp_fi2d(i) = 1.E+20
      ENDIF
      ENDDO
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"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_mth,"tslab",itau_w,zx_tmp_fi2d)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"seaice",itau_w,seaice)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice/1000.,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"siceh",itau_w,seaice/1000.)
c
      ENDIF !OCEAN.EQ.force/slab
c
      ENDIF !lev_histmth.GE.1
c
      IF(lev_histmth.GE.2) THEN
c
c Champs 3D:
C
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, flwc,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"lwcon",itau_w,flwc)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, fiwc,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"iwcon",itau_w,fiwc)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"temp",itau_w,t_seri)
c
c#ifdef histmthNMC
c#include "write_histmthNMC.h"
c#endif
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"ovap",itau_w, qx(:,:,ivap))
c
c     zx_tmp_fi3d(1:klon,1:klev)=qx(1:klon,1:klev,ivap)/
c    .                         (1-qx(1:klon,1:klev,ivap))
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
c     CALL histwrite_phy(nid_mth,"wvap",itau_w,zx_tmp_3d,
c    .                                   iim*jjmp1*klev,ndex3d)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"geop",itau_w,zphi)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"vitu",itau_w,u_seri)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"vitv",itau_w,v_seri)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"vitw",itau_w,omega)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"pres",itau_w,pplay)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldfra*100., zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"rneb",itau_w,cldfra*100.)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, rnebcon, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"rnebcon",itau_w,rnebcon)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_rh, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"rhum",itau_w,zx_rh)
c
      DO k=1, klev
       DO i=1, klon
cIM 151004        zx_tmp_fi3d(i,k)=MAX(wo(i,k),1.0e-12)*RG/46.6968
c    $                    /(paprs(i,k)-paprs(i,k+1))
c    $                    *(paprs(i,1)/101325.0)
c        zx_tmp2_fi3d(i,k)=MAX(wo(i,k)*1.0e+6,1.0e-6)*RG/46.6968
         zx_tmp_fi3d(i,k)=wo(i,k)*RG/46.6968
     $                    /(paprs(i,k)-paprs(i,k+1))
     $                    *(paprs(i,1)/101325.0)
       ENDDO !i
      ENDDO !k
c
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, wo, zx_tmp_3d)
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp2_fi3d,zx_tmp_3d)
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"ozone",itau_w,zx_tmp_fi3d)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtphy",itau_w,d_t)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_qx(:,:,ivap),zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqphy",itau_w,d_qx(:,:,ivap))
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)
cym        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite_phy(nid_mth,"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_mth,"rugs_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_fi2d)
c
      zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, agesno,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"ages_"//clnsurf(nsrf),itau_w
     $    ,agesno)
c
      ENDDO !nsrf=1, nbsrf
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsol,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"albs",itau_w,albsol)
c
cym      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsollw,zx_tmp_2d)
      CALL histwrite_phy(nid_mth,"albslw",itau_w,albsollw)
c
      ENDIF !lev_histmth.GE.3
c
c
      IF(lev_histmth.GE.4) THEN
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, clwcon0, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"clwcon",itau_w,clwcon0)
c
      IF (iflag_con.GE.3) THEN
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, Ma, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"Ma",itau_w,Ma)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, upwd, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"upwd",itau_w,upwd)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dnwd",itau_w,dnwd)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd0, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dnwd0",itau_w,dnwd0)
c
      ENDIF !iflag_con.GE.3
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_dyn, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtdyn",itau_w,d_t_dyn)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_dyn, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqdyn",itau_w,d_q_dyn)
c
cIM: 101003 : K/30min ==> K/s
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_mth,"dqcon",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon, 1:klev)=(d_t_lsc(1:klon,1:klev)+
     .                             d_t_eva(1:klon,1:klev))/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtlschr",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqlsc",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtvdf",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqvdf",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dteva",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqeva",itau_w,zx_tmp_fi3d)
c
      zpt_conv = 0.
      where (ptconv) zpt_conv = 1.
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zpt_conv, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"ptconv",itau_w,zpt_conv)
c
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, ratqs, zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"ratqs",itau_w,ratqs)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dqajs",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/day ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY 
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtswr",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtsw0",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtlwr",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtlw0",itau_w,zx_tmp_fi3d)
c
cIM: 101003 : deja en K/s      
      zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dtec",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"duvdf",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dvvdf",itau_w,zx_tmp_fi3d)
c
      IF (ok_orodr) THEN
      zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"duoro",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dvoro",itau_w,zx_tmp_fi3d)
c
      ENDIF
C
      IF (ok_orolf) THEN
      zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dulif",itau_w,zx_tmp_fi3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
cym      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite_phy(nid_mth,"dvlif",itau_w,zx_tmp_fi3d)
      ENDIF
C
#if defined(INCA_AER) && defined(CPP_COUPLE)
      CALL histwrite_phy(nid_mth,"tau",itau_w,cldtau)
      CALL histwrite_phy(nid_mth,"CCM1",itau_w,ccm(:,:,1))
      CALL histwrite_phy(nid_mth,"CCM2",itau_w,ccm(:,:,2))
      CALL histwrite_phy(nid_mth,"taupi",itau_w,cldtaupi)
      CALL histwrite_phy(nid_mth,"cldemi",itau_w,cldemi)
      CALL histwrite_phy(nid_mth,"SWTOAAS_ZERO",itau_w,topsw_inca(:,1))
      CALL histwrite_phy(nid_mth,"SWTOAAS_AER",itau_w,topsw_inca(:,2))
      CALL histwrite_phy(nid_mth,"SWTOAAS_NAT",itau_w,topsw_inca(:,3))
      CALL histwrite_phy(nid_mth,"SWTOAAS_AD",itau_w,topswad_inca(:))
      CALL histwrite_phy(nid_mth,"SWTOAAS_AI",itau_w,topswai_inca(:))
      CALL histwrite_phy(nid_mth,"SWTOACS_ZERO",itau_w,topsw0_inca(:,1))
      CALL histwrite_phy(nid_mth,"SWTOACS_AER",itau_w,topsw0_inca(:,2))
      CALL histwrite_phy(nid_mth,"SWTOACS_AD",itau_w,topswad0_inca(:))
      CALL histwrite_phy(nid_mth,"SWTOACS_NAT",itau_w,topsw0_inca(:,3))
#endif
#ifndef INCA
      IF (nqmax.GE.3) THEN
      DO iq=3,nqmax
cym         CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,iq), zx_tmp_3d)
         CALL histwrite_phy(nid_mth,tnom(iq),itau_w,qx(:,:,iq))
      ENDDO
      ENDIF
c
#endif
      ENDIF !lev_histmth.GE.4
c
      ENDIF !(type_run.EQ."AMIP")
c
      if (ok_sync) then
c$OMP MASTER
        call histsync(nid_mth)
c$OMP END MASTER
      endif
c
      ENDIF !ok_mensuel
