SUBROUTINE JGNRS(YDSPEC)

!**** *JGNRS*    - NORMALISATION OF
!*                 BACKGROUND ERRORS IN SPECTRAL SPACE

!     PURPOSE.
!     --------

!        NORMALISATION OF
!        BACKGROUND ERRORS IN SPECTRAL SPACE

!**   INTERFACE.
!     ----------

!        *CALL* *JGNRS*

!     METHOD.
!     -------
!          Divide by sigmas (autoadjoint operator)

!     REFERENCE.
!     ----------

!        ECMWF Research Department documentation of the IFS

!     AUTHOR.
!     -------

!        W. HECKLEY    *ECMWF*

!     MODIFICATIONS.
!     --------------
!        M.Hamrud      01-Oct-2003 CY28 Cleaning

!        ORIGINAL    93-01-06
!        F.Bouttier  94-10-10  Split JGNRS->JGNRS/JGNRSI,
!                                     suppress JGNRSAD
!        L.Isaksen   95-06-06  Reordering of spectral arrays
!        Mats Hamrud 95-12-15  Remove NFGM .ne. 1, cleaning
!        L.Isaksen   96-05-05  Adapted for Message Passing
!        M. Fisher   01:08:96 - Normalize vorticity and divergence with
!                               vorticity errors rather than wind errors
!        E. Holm     97-10-28  Ozone included
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMJG    , ONLY : FCEMN3D, FCEMN2D, SPJB_VARS_INFO, N_SPJB_VARS
USE YOMMP    , ONLY : MYLEVS, NPSP
USE SPECTRAL_FIELDS_MOD

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

INTEGER(KIND=JPIM) :: ILV, JLV, JFIELD, IPTJB
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*    1.    NORMALISATION BY BACKGROUND ERRORS
!           -----------------------------------

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

DO JFIELD=1,N_SPJB_VARS
  IPTJB=SPJB_VARS_INFO(JFIELD)%IPTJB

  IF (SPJB_VARS_INFO(JFIELD)%L_IN_SPA2) THEN
    IF (NPSP == 1) THEN
      YDSPEC%SP2D(:,IPTJB) = YDSPEC%SP2D(:,IPTJB)/FCEMN2D(IPTJB)
    ENDIF
  ELSE
    DO JLV=1,YDSPEC%NFLEVL
      ILV=MYLEVS(JLV)
      YDSPEC%SP3D(JLV,:,IPTJB) = YDSPEC%SP3D(JLV,:,IPTJB)/FCEMN3D(ILV,IPTJB)
    ENDDO
  ENDIF
ENDDO

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

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