SUBROUTINE SCNORM(KM,KXMAX,KORDR,PWHOU,POM2,PHIMO)

!**** *SCNORM* - Normalize normal modes.

!     Purpose.   Normalize normal modes with the pseudo-energy
!     --------

!**   Interface.
!     ----------
!        *CALL* *SCNORM(KM,KXMAX,KORDR,PWHOU,POM2,PHIMO)

!        Explicit arguments :  KM   - zonal wave number
!        --------------------  KXMAX - truncation
!                              KORDR - 3*(KXMAX+1-KM)
!                              PWHOU - eigen-vector matrix for KM
!                              POM2  - omega*2
!                              PHIMO - reference geopotential

!        Implicit arguments :  NONE.
!        --------------------

!     Method.
!     -------

!     Externals.  NONE.
!     ----------

!     Reference.
!     ----------
!        ECMWF Research Department documentation of the IFS
!      P.Courtier and J.F. Geleyn: A global model with varaible
!      resolution. Application to a shallow-water model.
!      Qua.J.Roi.Met.Soc. 1988.

!     Author.
!     -------
!        Mats Hamrud and Philippe Courtier  *ECMWF*

!     Modifications.
!     --------------
!        Original : 88-05-25
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMLUN   , ONLY : NULOUT

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KORDR 
INTEGER(KIND=JPIM),INTENT(IN)    :: KM 
INTEGER(KIND=JPIM),INTENT(IN)    :: KXMAX 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PWHOU(KORDR,KORDR) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POM2 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PHIMO 
INTEGER(KIND=JPIM) :: IN, J1, J2

REAL(KIND=JPRB) :: ZNORM
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*       1.    COMPUTATION OF THE NORM.
!              ------------------------

IF (LHOOK) CALL DR_HOOK('SCNORM',0,ZHOOK_HANDLE)
DO J1=1,KORDR
  ZNORM=0.0_JPRB
  DO J2=1,KXMAX-KM+1
    IN=KM-1+J2

!     * PWHOU(1+..) IS VORTICITY, PWHOU(2+..) IS DIVERGENCE AND
!       PWHOU(3+..) IS GEOPOTENTIAL *

    IF (IN /= 0) THEN
      ZNORM=ZNORM+(PWHOU(1+3*(J2-1),J1)**2+PWHOU(2+3*(J2-1),J1)**2 &
       & +PWHOU(3+3*(J2-1),J1)**2)/REAL(IN*(IN+1),JPRB)  
    ELSE
      ZNORM=ZNORM+(PWHOU(1+3*(J2-1),J1)**2+PWHOU(2+3*(J2-1),J1)**2 &
       & +PWHOU(3+3*(J2-1),J1)**2)  
    ENDIF
  ENDDO
  ZNORM=ZNORM*POM2**2*PHIMO
  ZNORM=SQRT(ZNORM)
  IF (ZNORM <= 0.0_JPRB) THEN
    WRITE(NULOUT,FMT='('' NORM OF EIGENMODE IS 0 , J= '',I6)') J1
    ZNORM=1.0_JPRB
    WRITE(NULOUT,FMT='(14(1X,E8.2))')(PWHOU(J2,J1),J2=1,KORDR)
  ENDIF

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

!*       2.    NORMALISATION.
!              --------------

  DO J2=1,KORDR
    PWHOU(J2,J1)=PWHOU(J2,J1)/ZNORM
  ENDDO

ENDDO

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

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