SUBROUTINE ISNDGPF(PSND,PFLD)

!     Purpose.
!     --------
!     Distribute and send an input grid point field to the required
!     processors

!     Explicit arguments :
!     --------------------
!     PSND   : grid point field to distribute
!     PFLD   : if nproc is 1 then PFLD is the distributed field

!     Author.
!     -------
!        MPP Group *ECMWF*

!     Modifications.
!     --------------
!        Original : 96-03-19
!        R. El Khatib : 99-12-28 remove poles rows
!        D.Dent   : 00-09-01  MPE to MPL conversion
!        Y.Tremolet: 01-01-19 cleaning
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

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

USE YOMMP    , ONLY : NPRCIDS  ,NSTA     ,NONL     ,NPTRFRSTLAT,&
 & NFRSTLAT ,NLSTLAT ,NGPSET2PE
USE YOMTAG   , ONLY : MTAGDISTGP
USE YOMCT0   , ONLY : NPROC    ,N_REGIONS ,N_REGIONS_NS
USE YOMGEM   , ONLY : NLOENG   ,NGPTOTMX ,NGPTOTG
USE MPL_MODULE

IMPLICIT NONE

REAL(KIND=JPRB)   ,INTENT(IN)    :: PSND(NGPTOTG) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PFLD(NGPTOTMX) 
INTEGER(KIND=JPIM) :: IGL1, IGL2, IGLOFF, ILAST, ILEN, ILOFF,&
 & IOFF, ISND, ITAG, J, JA, JB, JGL, JLON  
REAL(KIND=JPRB) :: ZHOOK_HANDLE


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

IF (LHOOK) CALL DR_HOOK('ISNDGPF',0,ZHOOK_HANDLE)
CALL GSTATS(526,0)
DO JA=1,N_REGIONS_NS

  IGLOFF=NPTRFRSTLAT(JA)
  IGL1 = NFRSTLAT(JA)
  IGL2 = NLSTLAT(JA)

  IOFF=0
  IF(JA > 1) THEN
    IF( NLSTLAT(JA-1) == NFRSTLAT(JA) )THEN
      ILAST=NLSTLAT(JA-1)-1
    ELSE
      ILAST=NLSTLAT(JA-1)
    ENDIF
    DO J=NFRSTLAT(1),ILAST
      IOFF=IOFF+NLOENG(J)
    ENDDO
  ENDIF

  DO JB=1,N_REGIONS(JA)
    ILEN = 0
    ILOFF = 0
    DO JGL=IGL1,IGL2
      DO JLON=1,NONL(IGLOFF+JGL-IGL1,JB)
        PFLD(ILEN+JLON)=PSND(IOFF+ILOFF+NSTA(IGLOFF+JGL-IGL1,JB)+JLON-1)
      ENDDO
      ILEN = ILEN + NONL(IGLOFF+JGL-IGL1,JB)
      ILOFF = ILOFF + NLOENG(JGL)
    ENDDO

    IF( ILEN > 0 )THEN
      ISND=NGPSET2PE(JA,JB)
      ITAG=MTAGDISTGP
      IF( NPROC > 1 )THEN
        IF(ISND==1)THEN
          CALL MPL_SEND(PFLD(1:ILEN),KDEST=NPRCIDS(ISND),KTAG=ITAG, &
           & CDSTRING='ISNDGPF:')  
        ELSE
          CALL MPL_SEND(PFLD(1:ILEN),KDEST=NPRCIDS(ISND),KTAG=ITAG, &
           & KMP_TYPE=JP_BLOCKING_STANDARD, &
           & CDSTRING='ISNDGPF:')  
        ENDIF
      ENDIF
    ENDIF

  ENDDO
ENDDO
CALL GSTATS(526,1)

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