!
! $Header$
!
      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
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,tsumSTD(:,:,2),
cym     $      zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"temp",itau_w,tsumSTD(:,:,2))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,phisumSTD(:,:,2),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"phi",itau_w,phisumSTD(:,:,2))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,qsumSTD(:,:,2),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"q",itau_w,qsumSTD(:,:,2))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,rhsumSTD(:,:,2),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"rh",itau_w,rhsumSTD(:,:,2))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,usumSTD(:,:,2),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"u",itau_w,usumSTD(:,:,2))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vsumSTD(:,:,2),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"v",itau_w,vsumSTD(:,:,2))
ccc
      ELSE IF(type_run.EQ."AMIP".OR.type_run.EQ."CFMI") THEN
ccc
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,tsumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"temp",itau_w,tsumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,phisumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"phi",itau_w,phisumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,qsumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"q",itau_w,qsumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,rhsumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"rh",itau_w,rhsumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,usumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"u",itau_w,usumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vsumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"v",itau_w,vsumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,wsumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"w",itau_w,wsumSTD(:,:,3))
c
       DO k=1, nlevSTD
        DO i=1, klon
         IF(tnondef(i,k,3).NE.1.E+20) THEN
          zx_tmp_fiNC(i,k) = (100.*tnondef(i,k,3))/ecrit_hf2mth
         ELSE
          zx_tmp_fiNC(i,k) = 1.E+20
         ENDIF
        ENDDO
       ENDDO !k=1, nlevSTD
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,zx_tmp_fiNC,zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"psbg",itau_w,zx_tmp_fiNC)
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,uvsumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"uv",itau_w,uvsumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vqsumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"vq",itau_w,vqsumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vTsumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"vT",itau_w,vTsumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1, wqsumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"wq",itau_w,wqsumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,vphisumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"vphi",itau_w,vphisumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,wTsumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"wT",itau_w,wTsumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,u2sumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"uxu",itau_w,u2sumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,v2sumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"vxv",itau_w,v2sumSTD(:,:,3))
c
cym       CALL gr_fi_ecrit(nlevSTD, klon,iim,jjmp1,T2sumSTD(:,:,3),
cym     $     zx_tmp_NC)
       CALL histwrite_phy(nid_nmc,"TxT",itau_w,T2sumSTD(:,:,3))
c
      ENDIF !type_run
c
      if (ok_sync) then
c$OMP MASTER
        call histsync(nid_nmc)
c$OMP END MASTER
      endif

      ENDIF
