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
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis,zx_tmp_2d)
      CALL histwrite(nid_mth,"phis",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
C
cIM 310804   CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
      CALL histwrite(nid_mth,"aire",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)* 100.
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"pourc_"//clnsurf(is_ter),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"fract_"//clnsurf(is_ter),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
      CALL histwrite(nid_mth,"slp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)

      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
      CALL histwrite(nid_mth,"tsol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zt2m,zx_tmp_2d)
      CALL histwrite(nid_mth,"t2m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c ENSEMBLES BEG
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite(nid_mth,"t2m_min",itau_w,zx_tmp_2d,
     .               iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite(nid_mth,"t2m_max",itau_w,zx_tmp_2d,
     .               iim*jjmp1,ndex2d)
c
c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,ftsoil(:,1,is_ter),zx_tmp_2d)
c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,ftsol(:,is_ter),zx_tmp_2d)
c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,ztsol,zx_tmp_2d)
c     CALL histwrite(nid_mth,"tsoil",itau_w,zx_tmp_2d,
c    .               iim*jjmp1,ndex2d)
c
      DO i=1, klon
       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
      ENDDO 
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"wind10m",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"sicf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
c     CALL histwrite(nid_mth,"temp",itau_w,zx_tmp_3d,
c    .                                   iim*jjmp1*klev,ndex3d)
c
c ENSEMBLES END
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zq2m,zx_tmp_2d)
      CALL histwrite(nid_mth,"q2m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zu10m,zx_tmp_2d)
      CALL histwrite(nid_mth,"u10m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
C
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zv10m,zx_tmp_2d)
      CALL histwrite(nid_mth,"v10m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
C
      DO i = 1, klon
         zx_tmp_fi2d(i) = paprs(i,1)
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"psol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxqsurf,zx_tmp_2d)
      CALL histwrite(nid_mth,"qsurf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      if (.not. ok_veget) then
          CALL gr_fi_ecrit(1, klon,iim,jjmp1, qsol,zx_tmp_2d)
          CALL histwrite(nid_mth,"qsol",itau_w,zx_tmp_2d,iim*jjmp1
     $        ,ndex2d)
      endif
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"precip",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, nday_rain,zx_tmp_2d)
      CALL histwrite(nid_mth,"ndayrain",itau_w,zx_tmp_2d,
     $               iim*jjmp1,ndex2d)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"plul",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"pluc",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_fall,zx_tmp_2d)
      CALL histwrite(nid_mth,"snow",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
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
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
      CALL histwrite(nid_mth,"evap",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
      CALL histwrite(nid_mth,"tops",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw0,zx_tmp_2d)
      CALL histwrite(nid_mth,"tops0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
      CALL histwrite(nid_mth,"topl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw0,zx_tmp_2d)
      CALL histwrite(nid_mth,"topl0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWupTOA",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWupTOAclr",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWdnTOA",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWdnTOAclr",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWup200,zx_tmp_2d)
      CALL histwrite(nid_mth,"SWup200",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWup200clr,zx_tmp_2d)
      CALL histwrite(nid_mth,"SWup200clr",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWdn200,zx_tmp_2d)
      CALL histwrite(nid_mth,"SWdn200",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWdn200clr,zx_tmp_2d)
      CALL histwrite(nid_mth,"SWdn200clr",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, LWup200,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWup200",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, LWup200clr,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWup200clr",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon)=-1*LWdn200(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWdn200",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon)=-1*LWdn200clr(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWdn200clr",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
c200 END 
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw,zx_tmp_2d)
      CALL histwrite(nid_mth,"sols",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw0,zx_tmp_2d)
      CALL histwrite(nid_mth,"sols0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw,zx_tmp_2d)
      CALL histwrite(nid_mth,"soll",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw0,zx_tmp_2d)
      CALL histwrite(nid_mth,"soll0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSUP( 1 : klon, 1)
      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWupSFC",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSUP0( 1 : klon, 1)
      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWupSFCclr",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSDN( 1 : klon, 1)
      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWdnSFC",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSDN0( 1 : klon, 1)
      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWdnSFCclr",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
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)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_mth,"LWupSFC",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
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)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_mth,"LWupSFCclr",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdown,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWdnSFC",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
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
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdownclr,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWdnSFCclr",itau_w,zx_tmp_2d,
     $               iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, bils,zx_tmp_2d)
      CALL histwrite(nid_mth,"bils",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, sens,zx_tmp_2d)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"sens",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, fder,zx_tmp_2d)
      CALL histwrite(nid_mth,"fder",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
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
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxffonte,zx_tmp_2d)
       CALL histwrite(nid_mth,"ffonte",itau_w,zx_tmp_2d,iim*jjmp1,
     $                ndex2d)
c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfqcalving,zx_tmp_2d)
       CALL histwrite(nid_mth,"fqcalving",itau_w,zx_tmp_2d,iim*jjmp1,
     $                ndex2d)
c
       DO nsrf = 1, nbsrf
        zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"taux_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
C      
        zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"tauy_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
       ENDDO
c
      DO nsrf = 1, nbsrf
CYYY
       IF(nsrf.GT.2) THEN
        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)*100.
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"pourc_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
c
        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"fract_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
       ENDIF !nsrf.GT.2
C 
        zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"tsol_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"sens_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"lat_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
C
        zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"flw_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
        zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"fsw_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"wbils_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
       IF(1.EQ.0) THEN
C
        zx_tmp_fi2d(1:klon) = fevap(1:klon,nsrf)*pctsrf(1:klon,nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"evapour_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1:klon) = (rain_fall(1:klon) + snow_fall(1:klon))
     $                        *pctsrf(1:klon,nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"prepour_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
       ENDIF !(1.EQ.0) THEN
C
      END DO  
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragm,zx_tmp_2d)
      CALL histwrite(nid_mth,"cdrm",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragh,zx_tmp_2d)
      CALL histwrite(nid_mth,"cdrh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldl,zx_tmp_2d)
      CALL histwrite(nid_mth,"cldl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldm,zx_tmp_2d)
      CALL histwrite(nid_mth,"cldm",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldh,zx_tmp_2d)
      CALL histwrite(nid_mth,"cldh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt,zx_tmp_2d)
      CALL histwrite(nid_mth,"cldt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldq,zx_tmp_2d)
      CALL histwrite(nid_mth,"cldq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon) = flwp(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"lwp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon) = fiwp(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"iwp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ue,zx_tmp_2d)
      CALL histwrite(nid_mth,"ue",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ve,zx_tmp_2d)
      CALL histwrite(nid_mth,"ve",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, uq,zx_tmp_2d)
      CALL histwrite(nid_mth,"uq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, vq,zx_tmp_2d)
      CALL histwrite(nid_mth,"vq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
cKE43
      IF (iflag_con.GE.3) THEN ! sb
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cape,zx_tmp_2d)
      CALL histwrite(nid_mth,"cape",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,pbase,zx_tmp_2d)
      CALL histwrite(nid_mth,"pbase",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_pct,zx_tmp_2d)
      CALL histwrite(nid_mth,"ptop",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_cbmf,zx_tmp_2d)
      CALL histwrite(nid_mth,"fbase",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c34EK
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, prw,zx_tmp_2d)
      CALL histwrite(nid_mth,"prw",itau_w,zx_tmp_2d,
     .               iim*jjmp1,ndex2d)
c
      ENDIF !iflag_con.GE.3
c
c
cIM cf. AM 081204 BEG
cHBTM2
c
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblh,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_pblh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblt,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_pblt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_lcl,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_lcl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_capCL,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_capCL",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_oliqCL,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_oliqCL",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_cteiCL,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_cteiCL",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_therm,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_therm",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb1,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_trmb1",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb2,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_trmb2",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb3,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_trmb3",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
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
        CALL gr_fi_ecrit(1, klon,iim,jjmp1,usumSTD(:,k,2),zx_tmp_2d)
        CALL histwrite(nid_mth,"u"//bb2,itau_w,zx_tmp_2d,
     $       iim*jjmp1,ndex2d)
c
        CALL gr_fi_ecrit(1, klon,iim,jjmp1,vsumSTD(:,k,2),zx_tmp_2d)
        CALL histwrite(nid_mth,"v"//bb2,itau_w,zx_tmp_2d,
     $       iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,wsumSTD(:,k,2),zx_tmp_2d)
      CALL histwrite(nid_mth,"w"//bb2,itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,phisumSTD(:,k,2),zx_tmp_2d)
      CALL histwrite(nid_mth,"phi"//bb2,itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
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) = 1.E+20
       ENDIF
      ENDDO
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"fluxo",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      DO i=1, klon
       IF (pctsrf(i,is_sic).GT.epsfra) THEN
        zx_tmp_fi2d(i) = fluxg(i)
       ELSE
        zx_tmp_fi2d(i) = 1.E+20
       ENDIF
      ENDDO
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"fluxg",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      IF (OCEAN.EQ.'force ') THEN
c
      DO i=1, klon
      IF((pctsrf(i,is_oce).GT.epsfra).OR.
     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
     .                  fluxg(i)*pctsrf(i,is_sic)
      ELSE
       zx_tmp_fi2d(i) = 1.E+20
      ENDIF
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"lmt_bils",itau_w,
     .     zx_tmp_2d,iim*jjmp1,ndex2d)
c
      ELSE IF (OCEAN.EQ.'slab  ') THEN
c
      DO i=1, klon
      IF((pctsrf(i,is_oce).GT.epsfra).OR.
     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
     .                  fluxg(i)*pctsrf(i,is_sic)
      ELSE
       zx_tmp_fi2d(i) = 1.E+20
      ENDIF
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"slab_bils",itau_w,
     .     zx_tmp_2d,iim*jjmp1,ndex2d)
c
      DO i=1, klon
       IF(pctsrf(i,is_oce).GT.epsfra.OR.
     $    pctsrf(i,is_sic).GT.epsfra) THEN
        zx_tmp_fi2d(i)=tslab(i)
       ELSE
        zx_tmp_fi2d(i) = 1.E+20
       ENDIF
      ENDDO !i=1, klon
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"tslab",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice,zx_tmp_2d)
      CALL histwrite(nid_mth,"seaice",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice/1000.,zx_tmp_2d)
      CALL histwrite(nid_mth,"siceh",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
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
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, flwc,zx_tmp_3d)
      CALL histwrite(nid_mth,"lwcon",itau_w,zx_tmp_3d,
     .               iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, fiwc,zx_tmp_3d)
      CALL histwrite(nid_mth,"iwcon",itau_w,zx_tmp_3d,
     .               iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
      CALL histwrite(nid_mth,"temp",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
c#ifdef histmthNMC
c#include "write_histmthNMC.h"
c#endif
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
      CALL histwrite(nid_mth,"ovap",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
c     zx_tmp_fi3d(1:klon,1:klev)=qx(1:klon,1:klev,ivap)/
c    .                         (1-qx(1:klon,1:klev,ivap))
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
c     CALL histwrite(nid_mth,"wvap",itau_w,zx_tmp_3d,
c    .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
      CALL histwrite(nid_mth,"geop",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
      CALL histwrite(nid_mth,"vitu",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
      CALL histwrite(nid_mth,"vitv",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
      CALL histwrite(nid_mth,"vitw",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
      CALL histwrite(nid_mth,"pres",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldfra, zx_tmp_3d)
      CALL histwrite(nid_mth,"rneb",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, rnebcon, zx_tmp_3d)
      CALL histwrite(nid_mth,"rnebcon",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_rh, zx_tmp_3d)
      CALL histwrite(nid_mth,"rhum",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      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)
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"ozone",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t, zx_tmp_3d)
      CALL histwrite(nid_mth,"dtphy",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_qx(:,:,ivap), 
     .                 zx_tmp_3d)
      CALL histwrite(nid_mth,"dqphy",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      ENDIF !lev_histmth.GE.2
c
      IF(lev_histmth.GE.3) THEN
c
       DO nsrf=1, nbsrf
c
        zx_tmp_fi2d(1 : klon) = falbe( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"albe_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"rugs_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, agesno,zx_tmp_2d)
      CALL histwrite(nid_mth,"ages_"//clnsurf(nsrf),itau_w
     $    ,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      ENDDO !nsrf=1, nbsrf
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsol,zx_tmp_2d)
      CALL histwrite(nid_mth,"albs",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsollw,zx_tmp_2d)
      CALL histwrite(nid_mth,"albslw",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      ENDIF !lev_histmth.GE.3
c
c
      IF(lev_histmth.GE.4) THEN
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, clwcon0, zx_tmp_3d)
      CALL histwrite(nid_mth,"clwcon",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      IF (iflag_con.GE.3) THEN
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, Ma, zx_tmp_3d)
      CALL histwrite(nid_mth,"Ma",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd, zx_tmp_3d)
      CALL histwrite(nid_mth,"dnwd",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd0, zx_tmp_3d)
      CALL histwrite(nid_mth,"dnwd0",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      ENDIF !iflag_con.GE.3
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_dyn, zx_tmp_3d)
      CALL histwrite(nid_mth,"dtdyn",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_dyn, zx_tmp_3d)
      CALL histwrite(nid_mth,"dqdyn",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_con(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtcon",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqcon",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_lsc(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtlsc",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
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
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
      CALL histwrite(nid_mth,"dtlschr",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqlsc",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtvdf",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqvdf",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dteva",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqeva",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zpt_conv = 0.
      where (ptconv) zpt_conv = 1.
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zpt_conv, zx_tmp_3d)
      CALL histwrite(nid_mth,"ptconv",itau_w,zx_tmp_3d,
     .                                   iim*(jjmp1)*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, ratqs, zx_tmp_3d)
      CALL histwrite(nid_mth,"ratqs",itau_w,zx_tmp_3d,
     .                                   iim*(jjmp1)*klev,ndex3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_ajs(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtajs",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqajs",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/day ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY 
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtswr",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtsw0",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtlwr",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtlw0",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : deja en K/s      
      zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtec",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"duvdf",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dvvdf",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      IF (ok_orodr) THEN
      zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"duoro",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dvoro",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      ENDIF
C
      IF (ok_orolf) THEN
      zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dulif",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dvlif",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
      ENDIF
C
      IF (nqmax.GE.3) THEN
      DO iq=3,nqmax
         CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,iq), zx_tmp_3d)
         CALL histwrite(nid_mth,tnom(iq),itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
      ENDDO
      ENDIF
c
      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
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,pphis/RG,zx_tmp_2d)
      CALL histwrite(nid_mth,"phis",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
C
cIM 310804   CALL gr_fi_ecrit(1,klon,iim,jjmp1,paire,zx_tmp_2d)
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,airephy,zx_tmp_2d)
      CALL histwrite(nid_mth,"aire",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)* 100.
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_mth,"pourc_"//clnsurf(is_ter),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_ter)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_mth,"fract_"//clnsurf(is_ter),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_lic)* 100.
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_mth,"pourc_"//clnsurf(is_lic),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_lic)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_mth,"fract_"//clnsurf(is_lic),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_sic)* 100.
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"pourc_"//clnsurf(is_sic),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = pctsrf(1 : klon, is_sic)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"fract_"//clnsurf(is_sic),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfluxlat,zx_tmp_2d)
      CALL histwrite(nid_mth,"flat",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = topsw(1:klon)-toplw(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
      CALL histwrite(nid_mth,"bilTOA",itau_w,
     .               zx_tmp_2d,iim*jjmp1,ndex2d)
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(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
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtdia",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
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
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtsw",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
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
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtlw",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
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
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtcon",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
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
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtajs",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
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
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtlsc",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
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
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1, zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqdia",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
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
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_u_oli,zx_tmp_3d)
      CALL histwrite(nid_mth,"duoli",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_v_oli,zx_tmp_3d)
      CALL histwrite(nid_mth,"dvoli",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_u_con(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"ducon",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_con(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dvcon",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_u,zx_tmp_3d)
      CALL histwrite(nid_mth,"dutot",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev, klon,iim,jjmp1,d_v,zx_tmp_3d)
      CALL histwrite(nid_mth,"dvtot",itau_w,zx_tmp_3d,
     $       iim*jjmp1*klev,ndex3d)

cEND 210404 END
c
c cldtrue
c     CALL gr_fi_ecrit(klev, klon,iim,jjmp1,cldtrue,zx_tmp_3d)
c     CALL histwrite(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(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(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
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"GWDtaux",
     $               itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
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
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"GWDtauy",
     $               itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c220404 END
cAMIP2 END
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, slp,zx_tmp_2d)
      CALL histwrite(nid_mth,"slp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)

      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxtsol,zx_tmp_2d)
      CALL histwrite(nid_mth,"tsol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zt2m,zx_tmp_2d)
      CALL histwrite(nid_mth,"t2m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c ENSEMBLES BEG
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite(nid_mth,"t2m_min",itau_w,zx_tmp_2d,
     .               iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zt2m,zx_tmp_2d)
      CALL histwrite(nid_mth,"t2m_max",itau_w,zx_tmp_2d,
     .               iim*jjmp1,ndex2d)
c
c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,ftsoil(:,1,is_ter),zx_tmp_2d)
c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,ftsol(:,is_ter),zx_tmp_2d)
c     CALL gr_fi_ecrit(1,klon,iim,jjmp1,ztsol,zx_tmp_2d)
c     CALL histwrite(nid_mth,"tsoil",itau_w,zx_tmp_2d,
c    .               iim*jjmp1,ndex2d)
c
      DO i=1, klon
       zx_tmp_fi2d(i)=SQRT(zu10m(i)*zu10m(i)+zv10m(i)*zv10m(i))
      ENDDO 
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"wind10m",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = pctsrf(i,is_sic)
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"sicf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
c     CALL histwrite(nid_mth,"temp",itau_w,zx_tmp_3d,
c    .                                   iim*jjmp1*klev,ndex3d)
c
c ENSEMBLES END
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zq2m,zx_tmp_2d)
      CALL histwrite(nid_mth,"q2m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zu10m,zx_tmp_2d)
      CALL histwrite(nid_mth,"u10m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
C
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zv10m,zx_tmp_2d)
      CALL histwrite(nid_mth,"v10m",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
C
      DO i = 1, klon
         zx_tmp_fi2d(i) = paprs(i,1)
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"psol",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxqsurf,zx_tmp_2d)
      CALL histwrite(nid_mth,"qsurf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      if (.not. ok_veget) then
          CALL gr_fi_ecrit(1, klon,iim,jjmp1, qsol,zx_tmp_2d)
          CALL histwrite(nid_mth,"qsol",itau_w,zx_tmp_2d,iim*jjmp1
     $        ,ndex2d)
      endif
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = rain_fall(i) + snow_fall(i)
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"precip",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, nday_rain,zx_tmp_2d)
      CALL histwrite(nid_mth,"ndayrain",itau_w,zx_tmp_2d,
     $               iim*jjmp1,ndex2d)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = rain_lsc(i) + snow_lsc(i)
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"plul",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      DO i = 1, klon
         zx_tmp_fi2d(i) = rain_con(i) + snow_con(i)
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"pluc",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, snow_fall,zx_tmp_2d)
      CALL histwrite(nid_mth,"snowf",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
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
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, evap,zx_tmp_2d)
      CALL histwrite(nid_mth,"evap",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw,zx_tmp_2d)
      CALL histwrite(nid_mth,"tops",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, topsw0,zx_tmp_2d)
      CALL histwrite(nid_mth,"tops0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw,zx_tmp_2d)
      CALL histwrite(nid_mth,"topl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, toplw0,zx_tmp_2d)
      CALL histwrite(nid_mth,"topl0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, klevp1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWupTOA",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
c
      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, klevp1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWupTOAclr",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, klevp1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWdnTOA",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, klevp1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWdnTOAclr",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWup200,zx_tmp_2d)
      CALL histwrite(nid_mth,"SWup200",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWup200clr,zx_tmp_2d)
      CALL histwrite(nid_mth,"SWup200clr",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWdn200,zx_tmp_2d)
      CALL histwrite(nid_mth,"SWdn200",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, SWdn200clr,zx_tmp_2d)
      CALL histwrite(nid_mth,"SWdn200clr",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, LWup200,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWup200",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, LWup200clr,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWup200clr",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon)=-1*LWdn200(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWdn200",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon)=-1*LWdn200clr(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWdn200clr",itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
c200 END 
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw,zx_tmp_2d)
      CALL histwrite(nid_mth,"sols",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, solsw0,zx_tmp_2d)
      CALL histwrite(nid_mth,"sols0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw,zx_tmp_2d)
      CALL histwrite(nid_mth,"soll",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollw0,zx_tmp_2d)
      CALL histwrite(nid_mth,"soll0",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSUP( 1 : klon, 1)
      zx_tmp_fi2d(1 : klon) = swup ( 1 : klon, 1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWupSFC",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSUP0( 1 : klon, 1)
      zx_tmp_fi2d(1 : klon) = swup0 ( 1 : klon, 1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWupSFCclr",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSDN( 1 : klon, 1)
      zx_tmp_fi2d(1 : klon) = swdn ( 1 : klon, 1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWdnSFC",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
c      zx_tmp_fi2d(1 : klon) = ZFSDN0( 1 : klon, 1)
      zx_tmp_fi2d(1 : klon) = swdn0 ( 1 : klon, 1 )
      CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth, "SWdnSFCclr",itau_w,zx_tmp_2d,
     .                               iim*jjmp1,ndex2d)
c
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)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_mth,"LWupSFC",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
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)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d, zx_tmp_2d)
      CALL histwrite(nid_mth,"LWupSFCclr",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdown,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWdnSFC",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
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
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, sollwdownclr,zx_tmp_2d)
      CALL histwrite(nid_mth,"LWdnSFCclr",itau_w,zx_tmp_2d,
     $               iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, bils,zx_tmp_2d)
      CALL histwrite(nid_mth,"bils",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon)=-1*sens(1:klon)
c     CALL gr_fi_ecrit(1, klon,iim,jjmp1, sens,zx_tmp_2d)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"sens",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, fder,zx_tmp_2d)
      CALL histwrite(nid_mth,"fder",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
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
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxffonte,zx_tmp_2d)
       CALL histwrite(nid_mth,"ffonte",itau_w,zx_tmp_2d,iim*jjmp1,
     $                ndex2d)
c
       CALL gr_fi_ecrit(1, klon,iim,jjmp1, zxfqcalving,zx_tmp_2d)
       CALL histwrite(nid_mth,"fqcalving",itau_w,zx_tmp_2d,iim*jjmp1,
     $                ndex2d)
c
       DO nsrf = 1, nbsrf
        zx_tmp_fi2d(1 : klon) = fluxu( 1 : klon, 1, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"taux_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
C      
        zx_tmp_fi2d(1 : klon) = fluxv( 1 : klon, 1, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"tauy_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
       ENDDO
c
        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, is_oce)*100.
        CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
        CALL histwrite(nid_mth,"pourc_"//clnsurf(is_oce),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
c
        zx_tmp_fi2d(1 : klon) = pctsrf( 1 : klon, is_oce)
        CALL gr_fi_ecrit(1,klon,iim,jjmp1,zx_tmp_fi2d,zx_tmp_2d)
        CALL histwrite(nid_mth,"fract_"//clnsurf(is_oce),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
c
      DO nsrf = 1, nbsrf
CYYY
C 
        zx_tmp_fi2d(1 : klon) = ftsol( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"tsol_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1 : klon) = fluxt( 1 : klon, 1, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"sens_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1 : klon) = fluxlat( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"lat_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d) 
C
        zx_tmp_fi2d(1 : klon) = fsollw( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"flw_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
        zx_tmp_fi2d(1 : klon) = fsolsw( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"fsw_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1 : klon) = wfbils( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"wbils_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
       IF(1.EQ.0) THEN
C
        zx_tmp_fi2d(1:klon) = fevap(1:klon,nsrf)*pctsrf(1:klon,nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"evapour_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1:klon) = (rain_fall(1:klon) + snow_fall(1:klon))
     $                        *pctsrf(1:klon,nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"prepour_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
       ENDIF !(1.EQ.0) THEN
C
      END DO  
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragm,zx_tmp_2d)
      CALL histwrite(nid_mth,"cdrm",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cdragh,zx_tmp_2d)
      CALL histwrite(nid_mth,"cdrh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldl,zx_tmp_2d)
      CALL histwrite(nid_mth,"cldl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldm,zx_tmp_2d)
      CALL histwrite(nid_mth,"cldm",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldh,zx_tmp_2d)
      CALL histwrite(nid_mth,"cldh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldt*100.,zx_tmp_2d)
      CALL histwrite(nid_mth,"cldt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cldq,zx_tmp_2d)
      CALL histwrite(nid_mth,"cldq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon) = flwp(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"lwp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1:klon) = fiwp(1:klon)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"iwp",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ue,zx_tmp_2d)
      CALL histwrite(nid_mth,"ue",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, ve,zx_tmp_2d)
      CALL histwrite(nid_mth,"ve",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, uq,zx_tmp_2d)
      CALL histwrite(nid_mth,"uq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, vq,zx_tmp_2d)
      CALL histwrite(nid_mth,"vq",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
cKE43
      IF (iflag_con.GE.3) THEN ! sb
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, cape,zx_tmp_2d)
      CALL histwrite(nid_mth,"cape",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,pbase,zx_tmp_2d)
      CALL histwrite(nid_mth,"pbase",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_pct,zx_tmp_2d)
      CALL histwrite(nid_mth,"ptop",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,ema_cbmf,zx_tmp_2d)
      CALL histwrite(nid_mth,"fbase",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
c34EK
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, prw,zx_tmp_2d)
      CALL histwrite(nid_mth,"prw",itau_w,zx_tmp_2d,
     .               iim*jjmp1,ndex2d)
c
      ENDIF !iflag_con.GE.3
c
cIM cf. AM 081204 BEG
cHBTM2
c
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblh,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_pblh",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_pblt,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_pblt",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_lcl,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_lcl",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_capCL,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_capCL",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_oliqCL,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_oliqCL",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_cteiCL,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_cteiCL",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_therm,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_therm",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb1,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_trmb1",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb2,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_trmb2",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, s_trmb3,zx_tmp_2d)
      CALL histwrite(nid_mth,"s_trmb3",itau_w,zx_tmp_2d,iim*jjmp1,
     .               ndex2d)
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
        CALL gr_fi_ecrit(1, klon,iim,jjmp1,usumSTD(:,k,2),zx_tmp_2d)
        CALL histwrite(nid_mth,"u"//bb2,itau_w,zx_tmp_2d,
     $       iim*jjmp1,ndex2d)
c
        CALL gr_fi_ecrit(1, klon,iim,jjmp1,vsumSTD(:,k,2),zx_tmp_2d)
        CALL histwrite(nid_mth,"v"//bb2,itau_w,zx_tmp_2d,
     $       iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,wsumSTD(:,k,2),zx_tmp_2d)
      CALL histwrite(nid_mth,"w"//bb2,itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1,phisumSTD(:,k,2),zx_tmp_2d)
      CALL histwrite(nid_mth,"phi"//bb2,itau_w,zx_tmp_2d,
     $     iim*jjmp1,ndex2d)
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) = 1.E+20
       ENDIF
      ENDDO
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"fluxo",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      DO i=1, klon
       IF (pctsrf(i,is_sic).GT.epsfra) THEN
        zx_tmp_fi2d(i) = fluxg(i)
       ELSE
        zx_tmp_fi2d(i) = 1.E+20
       ENDIF
      ENDDO
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"fluxg",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      IF (OCEAN.EQ.'force ') THEN
c
      DO i=1, klon
      IF((pctsrf(i,is_oce).GT.epsfra).OR.
     .   (pctsrf(i,is_sic).GT.epsfra)) THEN
       zx_tmp_fi2d(i) = (radsol(i) + fluxo(i))*pctsrf(i,is_oce)+
     .                  fluxg(i)*pctsrf(i,is_sic)
      ELSE
       zx_tmp_fi2d(i) = 1.E+20
      ENDIF
      ENDDO
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"lmt_bils",itau_w,
     .     zx_tmp_2d,iim*jjmp1,ndex2d)
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
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"slab_bils",itau_w,
     .     zx_tmp_2d,iim*jjmp1,ndex2d)
c
      DO i=1, klon
       IF(pctsrf(i,is_oce).GT.epsfra.OR.
     $    pctsrf(i,is_sic).GT.epsfra) THEN
        zx_tmp_fi2d(i)=tslab(i)
       ELSE
        zx_tmp_fi2d(i) = 1.E+20
       ENDIF
      ENDDO !i=1, klon
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d,zx_tmp_2d)
      CALL histwrite(nid_mth,"tslab",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice,zx_tmp_2d)
      CALL histwrite(nid_mth,"seaice",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, seaice/1000.,zx_tmp_2d)
      CALL histwrite(nid_mth,"siceh",itau_w,zx_tmp_2d,
     .     iim*jjmp1,ndex2d)
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
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, flwc,zx_tmp_3d)
      CALL histwrite(nid_mth,"lwcon",itau_w,zx_tmp_3d,
     .               iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, fiwc,zx_tmp_3d)
      CALL histwrite(nid_mth,"iwcon",itau_w,zx_tmp_3d,
     .               iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, t_seri, zx_tmp_3d)
      CALL histwrite(nid_mth,"temp",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
c#ifdef histmthNMC
c#include "write_histmthNMC.h"
c#endif
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,ivap), zx_tmp_3d)
      CALL histwrite(nid_mth,"ovap",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
c     zx_tmp_fi3d(1:klon,1:klev)=qx(1:klon,1:klev,ivap)/
c    .                         (1-qx(1:klon,1:klev,ivap))
c     CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
c     CALL histwrite(nid_mth,"wvap",itau_w,zx_tmp_3d,
c    .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zphi, zx_tmp_3d)
      CALL histwrite(nid_mth,"geop",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, u_seri, zx_tmp_3d)
      CALL histwrite(nid_mth,"vitu",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, v_seri, zx_tmp_3d)
      CALL histwrite(nid_mth,"vitv",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, omega, zx_tmp_3d)
      CALL histwrite(nid_mth,"vitw",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, pplay, zx_tmp_3d)
      CALL histwrite(nid_mth,"pres",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, cldfra*100., zx_tmp_3d)
      CALL histwrite(nid_mth,"rneb",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, rnebcon, zx_tmp_3d)
      CALL histwrite(nid_mth,"rnebcon",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_rh, zx_tmp_3d)
      CALL histwrite(nid_mth,"rhum",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      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)
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"ozone",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t, zx_tmp_3d)
      CALL histwrite(nid_mth,"dtphy",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_qx(:,:,ivap), 
     .                 zx_tmp_3d)
      CALL histwrite(nid_mth,"dqphy",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      ENDIF !lev_histmth.GE.2
c
      IF(lev_histmth.GE.3) THEN
c
       DO nsrf=1, nbsrf
c
        zx_tmp_fi2d(1 : klon) = falbe( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"albe_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
C
        zx_tmp_fi2d(1 : klon) = frugs( 1 : klon, nsrf)
        CALL gr_fi_ecrit(1, klon,iim,jjmp1, zx_tmp_fi2d , zx_tmp_2d)
        CALL histwrite(nid_mth,"rugs_"//clnsurf(nsrf),itau_w,
     $      zx_tmp_2d,iim*jjmp1,ndex2d)
c
      zx_tmp_fi2d(1 : klon) = agesno( 1 : klon, nsrf)
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, agesno,zx_tmp_2d)
      CALL histwrite(nid_mth,"ages_"//clnsurf(nsrf),itau_w
     $    ,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      ENDDO !nsrf=1, nbsrf
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsol,zx_tmp_2d)
      CALL histwrite(nid_mth,"albs",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      CALL gr_fi_ecrit(1, klon,iim,jjmp1, albsollw,zx_tmp_2d)
      CALL histwrite(nid_mth,"albslw",itau_w,zx_tmp_2d,iim*jjmp1,ndex2d)
c
      ENDIF !lev_histmth.GE.3
c
c
      IF(lev_histmth.GE.4) THEN
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, clwcon0, zx_tmp_3d)
      CALL histwrite(nid_mth,"clwcon",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      IF (iflag_con.GE.3) THEN
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, Ma, zx_tmp_3d)
      CALL histwrite(nid_mth,"Ma",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, upwd, zx_tmp_3d)
      CALL histwrite(nid_mth,"upwd",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd, zx_tmp_3d)
      CALL histwrite(nid_mth,"dnwd",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, dnwd0, zx_tmp_3d)
      CALL histwrite(nid_mth,"dnwd0",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      ENDIF !iflag_con.GE.3
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_t_dyn, zx_tmp_3d)
      CALL histwrite(nid_mth,"dtdyn",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, d_q_dyn, zx_tmp_3d)
      CALL histwrite(nid_mth,"dqdyn",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/30min ==> K/s
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_con(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqcon",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
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
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zx_tmp_fi3d, zx_tmp_3d)
      CALL histwrite(nid_mth,"dtlschr",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_lsc(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqlsc",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_vdf(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtvdf",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_vdf(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqvdf",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/30min ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=d_t_eva(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dteva",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_eva(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqeva",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zpt_conv = 0.
      where (ptconv) zpt_conv = 1.
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, zpt_conv, zx_tmp_3d)
      CALL histwrite(nid_mth,"ptconv",itau_w,zx_tmp_3d,
     .                                   iim*(jjmp1)*klev,ndex3d)
c
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1, ratqs, zx_tmp_3d)
      CALL histwrite(nid_mth,"ratqs",itau_w,zx_tmp_3d,
     .                                   iim*(jjmp1)*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_q_ajs(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dqajs",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/day ==> K/s
      zx_tmp_fi3d(1:klon,1:klev)=heat(1:klon,1:klev)/RDAY 
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtswr",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=heat0(1:klon,1:klev)/RDAY
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtsw0",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool(1:klon,1:klev)/RDAY
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtlwr",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : K/day ==> K/s      
      zx_tmp_fi3d(1:klon,1:klev)=-1.*cool0(1:klon,1:klev)/RDAY
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtlw0",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
cIM: 101003 : deja en K/s      
      zx_tmp_fi3d(1:klon,1:klev)=d_t_ec(1:klon,1:klev)
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dtec",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_u_vdf(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"duvdf",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_vdf(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dvvdf",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      IF (ok_orodr) THEN
      zx_tmp_fi3d(1:klon,1:klev)=d_u_oro(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"duoro",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_oro(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dvoro",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      ENDIF
C
      IF (ok_orolf) THEN
      zx_tmp_fi3d(1:klon,1:klev)=d_u_lif(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dulif",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
c
      zx_tmp_fi3d(1:klon,1:klev)=d_v_lif(1:klon,1:klev)/pdtphys
      CALL gr_fi_ecrit(klev,klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
      CALL histwrite(nid_mth,"dvlif",itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
      ENDIF
C
      IF (nqmax.GE.3) THEN
      DO iq=3,nqmax
         CALL gr_fi_ecrit(klev,klon,iim,jjmp1, qx(1,1,iq), zx_tmp_3d)
         CALL histwrite(nid_mth,tnom(iq),itau_w,zx_tmp_3d,
     .                                   iim*jjmp1*klev,ndex3d)
      ENDDO
      ENDIF
c
      ENDIF !lev_histmth.GE.4
c
      ENDIF !(type_run.EQ."AMIP")
c
      if (ok_sync) then
        call histsync(nid_mth)
      endif
c
      ENDIF !ok_mensuel
