SUBROUTINE RDPINMI(KMODES,PFP,PFQ,PB,PLOW,PUP,PC,PDIAG)

!**** *RDPINMI*  - read in help arrays for implicit NMI

!     Purpose.
!     --------
!                 Reading in help arrays for implicit NMI

!**   Interface.
!     ----------
!        *CALL* *RDPINMI(...)

!        Explicit arguments :
!        --------------------
!                              KMODES: Number of vertical modes to be read

!        Implicit arguments :  None
!        --------------------

!     Method.
!     -------
!        See documentation

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

!     Reference.
!     ----------
!        ECMWF Research Department documentation of the IFS

!     Author.
!     -------
!        M. HAMRUD      *ECMWF*

!     Modifications.
!     --------------
!        Original : 93-02-08
!        Modified : 95-06-06 L.Isaksen   Reordering of spectral arrays
!        Modified : 97-07-07 L.Isaksen   Arrays distributed
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

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

USE YOMDIM   , ONLY : NCPEC    ,NCPEC2
USE YOMNMIA  , ONLY : NVMODM
USE YOMPINB  , ONLY : RPINBUF  ,NSTAPINB

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KMODES 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFP(NCPEC) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFQ(NCPEC) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PB(NCPEC2) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PLOW(NCPEC2) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PUP(NCPEC2) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PC(NCPEC2,NVMODM) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDIAG(NCPEC2,NVMODM) 
!***********************************************************
!**  ARRAYS ON THE T"NCMAX" OF THE REAL GEOGRAPHIC SPHERE **
!***********************************************************
INTEGER(KIND=JPIM) ::   IREC, IRLEN, J, JK
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

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

!         1    READ OF HELP ARRAYS FOR IMPLICIT NMI SCHEME
!              --------------------------------------------

IF (LHOOK) CALL DR_HOOK('RDPINMI',0,ZHOOK_HANDLE)
IF (KMODES > NVMODM) CALL ABOR1(&
 & 'RDPINMI: ERROR IN *RDPINMI*, TOO MANY MODES REQUESTED')  

IRLEN=((NCPEC-1)/512+1)*512
IREC=1
DO J=1,NCPEC
  PFP(J)=RPINBUF(NSTAPINB(IREC)+J)
ENDDO
IREC=2
DO J=1,NCPEC
  PFQ(J)=RPINBUF(NSTAPINB(IREC)+J)
ENDDO

IRLEN=((NCPEC2-1)/512+1)*512
IREC=3
DO J=1,NCPEC2
  PB(J)=RPINBUF(NSTAPINB(IREC)+J)
ENDDO

IREC=4
DO J=1,NCPEC2
  PLOW(J)=RPINBUF(NSTAPINB(IREC)+J)
ENDDO

IREC=5
DO J=1,NCPEC2
  PUP(J)=RPINBUF(NSTAPINB(IREC)+J)
ENDDO

DO JK=1,KMODES
  IREC=IREC+1
  DO J=1,NCPEC2
    PC(J,JK)=RPINBUF(NSTAPINB(IREC)+J)
  ENDDO
  IREC=IREC+1
  DO J=1,NCPEC2
    PDIAG(J,JK)=RPINBUF(NSTAPINB(IREC)+J)
  ENDDO
ENDDO

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

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