SUBROUTINE SPEC_IMZERO(YDSP)

!   Purpose.
!   --------
!     Set/check imaginary coef M=0 to 0.

!   Author.
!   -------
!     Y. Tremolet

!   Modifications.
!   --------------
!     Original   08-Jul-2005
!     L. Auger   08-Jul-2005 add ALADIN case
!     R. El Khatib: 31-Aug-2007 Protection against aggressive optimisation on NEC
!     B. Chapnik 29-aug-2007 bugfix
! ------------------------------------------------------------------

USE PARKIND1, ONLY: JPIM, JPRB
USE YOMHOOK , ONLY: LHOOK, DR_HOOK
USE YOMCT0  , ONLY: LELAM
USE SPECTRAL_FIELDS_MOD

IMPLICIT NONE
TYPE(SPECTRAL_FIELD), INTENT(INOUT) :: YDSP

INTEGER(KIND=JPIM) :: JF, JN, JL, II
REAL(KIND=JPRB) :: ZHOOK_HANDLE

! ------------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('SPEC_IMZERO',0,ZHOOK_HANDLE)

IF (LELAM) THEN
  IF (YDSP%NESM0(0) > 0) THEN
!   Set div, vor mean value to zero.
    IF (ASSOCIATED(YDSP%DIV)) YDSP%DIV(:,YDSP%NESM0(0))=0.0_JPRB
    IF (ASSOCIATED(YDSP%VOR)) YDSP%VOR(:,YDSP%NESM0(0))=0.0_JPRB
  ENDIF
ELSE
  IF (YDSP%NASM0(0) > 0) THEN
    DO jn=0,YDSP%NSMAX
      II=YDSP%NASM0(0)+1+2*JN
      DO JF=1,YDSP%ns2d
        YDSP%SP2D(II,JF)=0.0_JPRB
      ENDDO
      DO JF=1,YDSP%NS3D
        DO JL=1,YDSP%NFLEVL
          YDSP%SP3D(JL,II,JF)=0.0_JPRB
        ENDDO
      ENDDO
    ENDDO
!   Set div, vor mean value to zero.
    IF (ASSOCIATED(YDSP%DIV)) YDSP%DIV(:,YDSP%NASM0(0))=0.0_JPRB
    IF (ASSOCIATED(YDSP%VOR)) YDSP%VOR(:,YDSP%NASM0(0))=0.0_JPRB

  ENDIF
ENDIF

IF (LHOOK) CALL DR_HOOK('SPEC_IMZERO',1,ZHOOK_HANDLE)
END SUBROUTINE SPEC_IMZERO
