!
! $Header$
!
      IF (ok_mensuel) THEN
c
       zstophy = dtime
       zstohf = ecrit_hf
       zstomth = ecrit_mth
       zout = ecrit_mth
c
         idayref = day_ref
         CALL ymds2ju(annee_ref, 1, idayref, 0.0, zjulian)
c
         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlon,zx_lon)
         DO i = 1, iim
            zx_lon(i,1) = rlon(i+1)
            zx_lon(i,jjmp1) = rlon(i+1)
         ENDDO
         DO ll=1,klev
            znivsig(ll)=float(ll)
         ENDDO
         CALL gr_fi_ecrit(1,klon,iim,jjmp1,rlat,zx_lat)
         CALL histbeg("histNMC.nc", iim,zx_lon(:,1), jjmp1,zx_lat(1,:),
     .                 1,iim,1,jjmp1, itau_phy, zjulian, dtime, 
     .                 nhori, nid_nmc)
c
         CALL histvert(nid_nmc, "presnivs", "Vertical levels", "mb",
     .                 nlevSTD, rlevSTD/100., nvert)
ccc
ccc Champs 3D interpolles sur des niveaux de pression du NMC
ccc
      IF(type_run.EQ."ENSP".OR.type_run.EQ."CLIM") THEN
c
          CALL histdef(nid_nmc, "temp",
     .                 "Temperature","K",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
         CALL histdef(nid_nmc, "phi",
     .                "Geopotential", "m",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "q",
     .                 "Specific humidity","kg/kg",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
         CALL histdef(nid_nmc, "rh",
     .                 "Relative humidity", "%",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "u",
     .                 "Zonal wind","m/s",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "v",
     .                 "Meridional wind","m/s",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
c
c ATTENTION : pour AMIP2 on interpole t,u,v,wphi,q,rh
c             sur les niveaux du NMC et on somme & moyenne
c             toutes les 6 heures par des routines undefSTD et
c             moy_undefSTD pour eliminer les valeurs "undef"
c             de la moyenne mensuelle
c ======> le "inst(X)" ci-dessous est par consequence factice !
c
          CALL histdef(nid_nmc, "temp",
     .                 "Temperature","K",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
         CALL histdef(nid_nmc, "phi",
     .                "Geopotential ", "m",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "q",
     .                 "Specific humidity","kg/kg",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
         CALL histdef(nid_nmc, "rh",
     .                 "Relative humidity", "%",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "u",
     .                 "Zonal wind","m/s",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "v",
     .                 "Meridional wind","m/s",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "w",
     .                 "Vertical motion","Pa/s",
     .                iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .                "inst(X)", zout,zout)
c
c ATTENTION : pour AMIP2 on interpole t,u,v,wphi,q,rh
c             sur les niveaux du NMC et on somme & moyenne
c             toutes les 6 heures par des routines undefSTD et
c             moy_undefSTD pour eliminer les valeurs "undef"
c             de la moyenne mensuelle
c ======> le "inst(X)" ci-dessus est par consequence factice !
c
c
          CALL histdef(nid_nmc, "psbg",
     .         "Pressure sfce below ground","%",
     .         iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .         "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "uv",
     .         "uv ",
     .         "m2/s2",iim,jjmp1,nhori, nlevSTD,1,nlevSTD, nvert, 32,
     .         "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "vq",
     .         "vq ",
     .         "m/s * (kg/kg)",iim,jjmp1,nhori, 
     .          nlevSTD,1,nlevSTD, nvert, 32,
     .         "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "vT",
     .         "vT ", 
     .         "mK/s",iim,jjmp1,nhori, 
     .          nlevSTD,1,nlevSTD, nvert, 32,
     .         "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "wq",
     .         "wq ", 
     .         "(Pa/s)*(kg/kg)",iim,jjmp1,nhori,
     .          nlevSTD,1,nlevSTD, nvert, 32,
     .         "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "vphi",
     .         "vphi ", 
     .         "m2/s",iim,jjmp1,nhori, 
     .          nlevSTD,1,nlevSTD, nvert, 32,
     .         "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "wT",
     .         "wT ", 
     .         "K*Pa/s",iim,jjmp1,nhori,
     .          nlevSTD,1,nlevSTD, nvert, 32,
     .         "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "uxu",
     .         "u2 ", 
     .         "m2/s2",iim,jjmp1,nhori,
     .          nlevSTD,1,nlevSTD, nvert, 32,
     .         "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "vxv",
     .         "v2 ", 
     .         "m2/s2",iim,jjmp1,nhori,
     .          nlevSTD,1,nlevSTD, nvert, 32,
     .         "inst(X)", zout,zout)
c
          CALL histdef(nid_nmc, "TxT",
     .         "T2 ", 
     .         "K2",iim,jjmp1,nhori,
     .          nlevSTD,1,nlevSTD, nvert, 32,
     .         "inst(X)", zout,zout)
c
      ENDIF !(type_run.EQ."AMIP")

         CALL histend(nid_nmc)
c
      ENDIF ! fin de test sur ok_mensuel
