!
! $Header$
!
c     IF (ok_mensuelNMC) THEN
      IF (ok_mensuel) THEN
c
       ndex3d = 0
       itau_w = itau_phy + itap
ccc
c  Champs interpolles sur des niveaux de pression du NMC
c
c     PARAMETER(nout=3) !nout=1 : day; =2 : mth; =3 : NMC
ccc
      IF(type_run.EQ."CLIM".OR.type_run.EQ."ENSP") THEN
ccc
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,tsumSTD(:,:,2),
     $      zx_tmp_3d)
       CALL histwrite(nid_nmc,"temp",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,phisumSTD(:,:,2),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"phi",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,qsumSTD(:,:,2),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"q",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,rhsumSTD(:,:,2),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"rh",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,usumSTD(:,:,2),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"u",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vsumSTD(:,:,2),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"v",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
ccc
      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
ccc
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,tsumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"temp",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,phisumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"phi",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,qsumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"q",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,rhsumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"rh",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,usumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"u",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vsumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"v",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,wsumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"w",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       DO k=1, nlevSTD
        DO i=1, klon
         IF(tnondef(i,k,3).NE.1.E+20) THEN
          zx_tmp_fi3d(i,k) = (100.*tnondef(i,k,3))/ecrit_hf2mth
         ELSE
          zx_tmp_fi3d(i,k) = 1.E+20
         ENDIF
        ENDDO
       ENDDO !k=1, nlevSTD
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,zx_tmp_fi3d,zx_tmp_3d)
       CALL histwrite(nid_nmc,"psbg",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,uvsumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"uv",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vqsumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"vq",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vTsumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"vT",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1, wqsumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"wq",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vphisumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"vphi",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,wTsumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"wT",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,u2sumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"uxu",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,v2sumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"vxv",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,T2sumSTD(:,:,3),
     $     zx_tmp_3d)
       CALL histwrite(nid_nmc,"TxT",itau_w,zx_tmp_3d,
     $       iim*jjmp1*nlevSTD,ndex3d)
c
      ENDIF !type_run
c
      if (ok_sync) then
        call histsync(nid_nmc)
      endif

      ENDIF
