      IF (ok_mensuel) THEN
c
         zsto = dtime
         zout = dtime * FLOAT(ecrit_mth)
c zsto1: pour des flux radiatifs calcules tous les radpas appels physiq
         zsto1= dtime * FLOAT(radpas)
c
         idayref = day_ref
         CALL ymds2ju(annee_ref, 1, idayref, zero, zjulian)
c
         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlond,zx_lon)
         DO i = 1, iim
            zx_lon(i,1) = rlond(i+jjmp1-jjm)
            zx_lon(i,jjmp1) = rlond(i+jjmp1-jjm)
         ENDDO
         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlatd,zx_lat)
         CALL histbeg("histmth", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
     .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime, 
     .                 nhori, nid_mth)
         write(*,*)'Journee ', itau_phy, zjulian
         CALL histvert(nid_mth, "presnivs", "Vertical levels", "mb",
     .                 klev, presnivs, nvert)

c-------------------------------------------------------
      IF(lev_histmth.GE.1) THEN
c
ccccccccccccc 2D fields, invariables
c
         CALL histdef(nid_mth, "phis", "Surface geop. height", "-",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "once",  zsto,zout)
c
         CALL histdef(nid_mth, "aire", "Grid area", "-",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "once",  zsto,zout)
c
ccccccc axe Ls
         CALL histdef(nid_mth, "ls", "Solar longitude", "degrees",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "ave(X)", zsto,zout)
c
ccccccccccccc 2D fields, variables
c
         CALL histdef(nid_mth, "tsol", "Surface Temperature", "K",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "psol", "Surface Pressure", "Pa",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "ave(X)", zsto,zout)
c
c        CALL histdef(nid_mth, "ue", "Zonal energy transport", "-",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "ave(X)", zsto,zout)
c
c        CALL histdef(nid_mth, "ve", "Merid energy transport", "-",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "ave(X)", zsto,zout)
c
c        CALL histdef(nid_mth, "cdragh", "Drag coef on T", "-",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "ave(X)", zsto,zout)
c
c        CALL histdef(nid_mth, "cdragm", "Drag coef on U", "-",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "ave(X)", zsto,zout)
c
      ENDIF !lev_histmth.GE.1
c
c-------------------------------------------------------
      IF(lev_histmth.GE.2) THEN
c
ccccccccccccc 3D fields, basics
c
         CALL histdef(nid_mth, "temp", "Air temperature", "K",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "pres", "Air pressure", "Pa",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "geop", "Geopotential height", "m",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "vitu", "Zonal wind", "m/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "vitv", "Meridional wind", "m/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "vitw", "Vertical wind", "Pa/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
c        CALL histdef(nid_mth, "Kz", "vertical diffusion coef", "m2/s",
c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
c    .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "tops", "Solar rad. at TOA", "W/m2",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "ave(X)", zsto1,zout)
c
cccccccccccccccccc  Tracers
c
         if (iflag_trac.eq.1) THEN
          if (microfi.ge.1) then
c           DO iq=1,nmicro
c             CALL histdef(nid_mth, tname(iq), ttext(iq), "n/m2",
c     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
c     .                "ave(X)", zsto,zout)
c           ENDDO
             CALL histdef(nid_mth, "qaer","nb tot aer" , "n/m2",
     .                    iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                    "ave(X)", zsto,zout)

            if (clouds.eq.1) then
             CALL histdef(nid_mth, "qnoy","nb tot noy" , "n/m2",
     .                    iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                    "ave(X)", zsto,zout)
             CALL histdef(nid_mth, "qgl1","V tot gl1" , "m3/m2",
     .                    iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                    "ave(X)", zsto,zout)
             CALL histdef(nid_mth, "qgl2","V tot gl2" , "m3/m2",
     .                    iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                    "ave(X)", zsto,zout)
             CALL histdef(nid_mth, "qgl3","V tot gl3" , "m3/m2",
     .                    iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                    "ave(X)", zsto,zout)
c--------------
c ----- SATURATION ESP NUAGES
               CALL histdef(nid_mth,"ch4sat", "saturation CH4", "--",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
               CALL histdef(nid_mth,"c2h6sat", "saturation C2H6", "--",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
               CALL histdef(nid_mth,"c2h2sat", "saturation C2H2", "--",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c --------------
c ----- RESERVOIR DE SURFACE
               CALL histdef(nid_mth, "reserv", "Reservoir surface","m",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
     .                "ave(X)", zsto,zout)
c --------------
c ----- ECHANGE GAZ SURF/ATM (evaporation)
               CALL histdef(nid_mth, "evapch4", "Evaporation CH4","m",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
     .                "ave(X)", zsto,zout)
c --------------
c ----- PRECIPITATIONS (precipitations moyennes)
               CALL histdef(nid_mth,"prech4","Precip CH4","um/s",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32,
     .                "ave(X)", zsto,zout)
               CALL histdef(nid_mth,"prec2h6","Precip C2H6",
     .                "um/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
     .                "ave(X)", zsto,zout)
               CALL histdef(nid_mth,"prec2h2","Precip C2H2",
     .                "um/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
     .                "ave(X)", zsto,zout)
               CALL histdef(nid_mth,"prenoy","Precip NOY",
     .                "um/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
     .                "ave(X)", zsto,zout)
               CALL histdef(nid_mth,"preaer","Precip AER",
     .                "um/s",iim,jjmp1,nhori, 1,1,1, -99, 32,
     .                "ave(X)", zsto,zout)
c --------------
c ----- FLUX GLACE
               CALL histdef(nid_mth,"flxgl1", "flux gl CH4",
     .              "kg/m2/s",iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .              "ave(X)", zsto,zout)
               CALL histdef(nid_mth,"flxgl2", "flux gl C2H6",
     .              "kg/m2/s",iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .              "ave(X)", zsto,zout)
               CALL histdef(nid_mth,"flxgl3", "flux gl C2H2",
     .              "kg/m2/s",iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .              "ave(X)", zsto,zout)
c --------------
c ----- Source/puits GLACE
               CALL histdef(nid_mth,"solch4", "dQ gl CH4",
     .              "m3/m3",iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .              "ave(X)", zsto,zout)
               CALL histdef(nid_mth,"solc2h6", "dQ gl C2H6",
     .              "m3/m3",iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .              "ave(X)", zsto,zout)
               CALL histdef(nid_mth,"solc2h2", "dQ gl C2H2",
     .              "m3/m3",iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .              "ave(X)", zsto,zout)
c --------------
c ----- RAYON DES GOUTTES
               CALL histdef(nid_mth,"rcldbar", "rayon moyen goutte",
     .                "m",iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
            endif
	  endif
c --------------
c ----- TRACEURS CHIMIQUES
	  if (nmicro.lt.nqmax) then
           DO iq=nmicro+1,nqmax
         CALL histdef(nid_mth, tname(iq), ttext(iq), "ppm",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
           ENDDO
c Condensation:
c          DO iq=nmicro+1,nqmax
c        CALL histdef(nid_mth, "c_"//tname(iq), "c_"//ttext(iq),
c    .        "ppm/s",iim,jjmp1,nhori, klev,1,klev,nvert, 32,
c    .                "ave(X)", zsto,zout)
c          ENDDO
	  endif
         endif
c
      ENDIF !lev_histmth.GE.2
c
c-------------------------------------------------------
      IF(lev_histmth.GE.3) THEN
c
cccccccccccccccccc  Radiative transfer
c
c 2D
c
         CALL histdef(nid_mth, "topl", "IR rad. at TOA", "W/m2",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "ave(X)", zsto1,zout)
c
         CALL histdef(nid_mth, "sols", "Solar rad. at surf.", "W/m2",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "ave(X)", zsto1,zout)
c
         CALL histdef(nid_mth, "soll", "IR rad. at surface", "W/m2",
     .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
     .                "ave(X)", zsto1,zout)
c
c 3D
c
         CALL histdef(nid_mth, "SWnet", "Net SW flux","W/m2",
     .                iim,jjmp1,nhori, klev,1,klev,nvert,
     .                32, "ave(X)", zsto1,zout)
c
         CALL histdef(nid_mth, "LWnet", "Net LW flux","W/m2",
     .                iim,jjmp1,nhori, klev,1,klev,nvert,
     .                32, "ave(X)", zsto1,zout)
c
c --------------
c ----- OPACITE BRUME
         DO k=7,NSPECV,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_mth,"thv"//str1,"Haze Opa Vis",
     .                "--",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ave(X)",zsto1,zout)
         ENDDO
c
         DO k=8,NSPECI,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_mth,"thi"//str1,"Haze Opa IR",
     .                "--",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ave(X)",zsto1,zout)
         ENDDO
c
c --------------
c ----- EXTINCTION BRUME
         DO k=7,NSPECV,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_mth,"khv"//str1,"Haze ext Vis ",
     .                "m-1",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ave(X)",zsto1,zout)
         ENDDO
c
         DO k=8,NSPECI,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_mth,"khi"//str1,"Haze ext IR ",
     .                "m-1",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ave(X)",zsto1,zout)
         ENDDO
c
c --------------
c ----- OPACITE GAZ
         DO k=7,NSPECV,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_mth,"tgv"//str1,"Gas Opa Vis",
     .                "--",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ave(X)",zsto1,zout)
         ENDDO
c
         DO k=8,NSPECI,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_mth,"tgi"//str1,"Haze Opa IR",
     .                "--",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ave(X)",zsto1,zout)
         ENDDO
c
c --------------
c ----- EXTINCTION GAZ
         DO k=7,NSPECV,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_mth,"kgv"//str1,"Gas ext Vis ",
     .                "m-1",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ave(X)",zsto1,zout)
         ENDDO
c
         DO k=8,NSPECI,10
           write(str1,'(i2.2)') k
         CALL histdef(nid_mth,"kgi"//str1,"Gas ext IR ",
     .                "m-1",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ave(X)",zsto1,zout)
         ENDDO
c
c --------------
c ----- OPACITE NUAGES
         if (clouds.eq.1) then
           CALL histdef(nid_mth,"tcld","Cld Opa proxy",
     .                "--",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ave(X)",zsto,zout)
c
c --------------
c ----- EXTINCTION NUAGES
           CALL histdef(nid_mth,"kcld","Cld Ext proxy",
     .                "m-1",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .                "ave(X)",zsto,zout)
         endif
c
c --------------
c ----- OCCURENCE NUAGES
           do k=1,12
             write(str1,'(i2.2)') k
             CALL histdef(nid_mth,"occcld"//str1,"occ cld",
     .       "--",iim,jjmp1,nhori,klev,1,klev,nvert,32,
     .       "ave(X)",zsto,zout)
           enddo
c
      ENDIF !lev_histmth.GE.3
c
c-------------------------------------------------------
      IF(lev_histmth.GE.4) THEN
c
         CALL histdef(nid_mth, "dtdyn", "Dynamics dT", "K/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "dtphy", "Physics dT", "K/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "dtvdf", "Boundary-layer dT", "K/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "dtajs", "Dry adjust. dT", "K/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "dtswr", "SW radiation dT", "K/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "dtlwr", "LW radiation dT", "K/s",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
c        CALL histdef(nid_mth, "dtec", "Cinetic dissip dT", "K/s",
c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
c    .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "duvdf", "Boundary-layer dU", "m/s2",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
         CALL histdef(nid_mth, "dudyn", "Dynamics dU", "m/s2",
     .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
     .                "ave(X)", zsto,zout)
c
c        CALL histdef(nid_mth, "dvvdf", "Boundary-layer dV", "m/s2",
c    .                iim,jjmp1,nhori, klev,1,klev,nvert, 32,
c    .                "ave(X)", zsto,zout)
c
      ENDIF !lev_histmth.GE.4
c
c-------------------------------------------------------
      IF(lev_histmth.GE.5) THEN
c
c
c        call histdef(nid_mth, "taux", 
c    $         "Zonal wind stress", "Pa",  
c    $         iim,jjmp1,nhori, 1,1,1, -99, 32,
c    $         "ave(X)", zsto,zout)
c
c        call histdef(nid_mth, "tauy", 
c    $         "Meridional xind stress", "Pa",  
c    $         iim,jjmp1,nhori, 1,1,1, -99, 32,
c    $         "ave(X)", zsto,zout)
c
c        CALL histdef(nid_mth, "cdrm", "Momentum drag coef.", "-",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "ave(X)", zsto,zout)
c
c        CALL histdef(nid_mth, "cdrh", "Heat drag coef.", "-",
c    .                iim,jjmp1,nhori, 1,1,1, -99, 32, 
c    .                "ave(X)", zsto,zout)
c
      ENDIF !lev_histmth.GE.5
c-------------------------------------------------------
c
         CALL histend(nid_mth)
c
         ndex2d = 0
         ndex3d = 0
c
      ENDIF ! fin de test sur ok_journe
