SUBROUTINE SUMODE3L(KVIMOD)

!**** *SUMODE3* - COMPUTE NORMAL MODES FOR MULTI-LEVEL MODEL

!     PURPOSE. - TO COMPUTE THE NORMAL MODES FOR A STRETCHED CO-
!     --------   ORDINATE MULTI-LEVEL MODEL ON THE SPHERE.
!              - STORING OF MATRICES OF FREQUENCIES        (EXPLICIT MODES)
!              - STORING OF "LTYPGR" ARRAYS  (EXPLICIT MODES)
!              - STORING OF HELP ARRAYS                    (IMPLICIT MODES)

!**   INTERFACE.
!     ----------
!        *CALL* *SUMODE3(KVIMOD)*

!        EXPLICIT ARGUMENTS
!        ------------------
!                          KVIMOD : Number if vertical modes to be catered for.

!        IMPLICIT ARGUMENTS :  in YOMNMI : LTYPGR,... ; FREQ, ...
!        --------------------  in YOMDYN : (SIVP(JK),JK=1,KVIMOD)
!                              in YOMLAP : NACNO(JN),...
!                              in YOMGEM : RSTRET
!                              in YOMLUN : NSPHMO,NHOUMO,NPINMI
!                              in YOMCST : ROMEGA,RA,RPI
!                              in YOMGC  : RCOR0,RCOR1
!                                       RCOR0  - EXPANSION OF CORIOLIS PARAMETER
!                                       RCOR1  - EXPANSION OF CORIOLIS PARAMETER
!                        f = 2 * ROMEGA * [ RCOR0 + (SQRT(3) * RCOR1)  * RMU ]

!     METHOD.  SEE DOCUMENTATION.
!     -------

!     EXTERNALS.   NONE 
!     ---------- 

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

!     AUTHOR.
!     -------
!        LARS ISAKSEN *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 97-05-05 (Split off from SUMODE3) 
!        M.Hamrud : 00-06-15 Remove lmessp (lots of dead code left in routine)
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ---------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NXMAX
USE YOMNMIB  , ONLY : LTYPGR

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KVIMOD 
INTEGER(KIND=JPIM) :: ICFREQ, ICVECT,&
 & INGE, INGW, INRO, IORDR, ITEST, &
 & J, JK, JM  

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

!*       2.    INITIALIZATION.
!              ---------------

IF (LHOOK) CALL DR_HOOK('SUMODE3L',0,ZHOOK_HANDLE)
ICVECT=0
ICFREQ=0

ITEST=0
DO JK=1,KVIMOD

!*        DEFINE GRAVITY MODES FOR USE IN VARIATIONAL ANALYSIS
!*        OR NMI WITHOUT FREQUENCY FILTERING

  ICFREQ=0
  DO JM=0,NXMAX
    IORDR=3*(NXMAX-JM+1)
    IF (JM == 0) THEN
      INGW = NXMAX
      INRO = NXMAX+3
      INGE = NXMAX
    ELSE
      INGW = IORDR/3
      INRO = INGW
      INGE = INGW
    ENDIF
    DO J=1,INGW
      LTYPGR(ICFREQ+2*(J-1)+1,JK) = .TRUE.
      LTYPGR(ICFREQ+2*(J-1)+2,JK) = .TRUE.
    ENDDO
    DO J=1,INRO
      LTYPGR(ICFREQ+2*(INGW+J-1)+1,JK) = .FALSE.
      LTYPGR(ICFREQ+2*(INGW+J-1)+2,JK) = .FALSE.
    ENDDO
    DO J=1,INGE
      LTYPGR(ICFREQ+2*(INGW+INRO+J-1)+1,JK) = .TRUE.
      LTYPGR(ICFREQ+2*(INGW+INRO+J-1)+2,JK) = .TRUE.
    ENDDO
    ICFREQ = ICFREQ + IORDR*2
  ENDDO
  
ENDDO

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

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