SUBROUTINE WRGP_SURF(PBUF,PGPG,KYPROC,KCOUNTW)

!**** *WRGP2FA*  - 

!     Purpose.
!     --------
!        To send data -  or gather all data if writting proc

!**   Interface.
!     ----------
!        *CALL* *WRGP_SURF*

!        Explicit arguments :
!        --------------------

!            PBUF    : gridpoint field on one PROC
!            PGPG    : gridpoint field, size NGPTOTG
!                    if writting proc : contain complete field
!                    if not : full of zero.... 
!            KYPROC  :my proc number (usefull for the externalised
!                     surface to know if I am a writting proc!)

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

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

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

!           Processor communication routines
!           DIWRGRID

!     Reference.
!     ----------
!        ECMWF Research Department documentation of the IFS
!        Note de travail ARPEGE Nr 12 et 17

!     Author.
!     -------
!         S.Malardel *METEO-FRANCE*

!     Modifications.
!     --------------
!        ORIGINAL : 22-04-04 from WRGP2FA
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

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

USE YOMGEM   , ONLY : NGPTOT   ,NGPTOTG
USE YOMMP    , ONLY : MYPROC 

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

IMPLICIT NONE

REAL(KIND=JPRB)   ,INTENT(INOUT) :: PBUF(NGPTOT) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGPG(NGPTOTG) 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KYPROC 
INTEGER(KIND=JPIM),INTENT(IN)    :: KCOUNTW 

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

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "diwrgrid_surf_ext.intfb.h"

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

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

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

!     1.    PROC NUMBER TO SEND TO THE SURFACE

KYPROC=MYPROC

!     2.    SEND FIELD!           -----------

IF (MYPROC /= 1) THEN
  CALL DIWRGRID_SURF_EXT(1,KCOUNTW,0,NGPTOT,PBUF(1))
ENDIF

!     3.    RECIEVE FIELD

IF (MYPROC == 1) THEN

  PGPG(1:NGPTOT)=PBUF(1:NGPTOT)
  CALL DIWRGRID_SURF_EXT(1,KCOUNTW,1,NGPTOTG,PGPG(1))

ENDIF

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('WRGP_SURF',1,ZHOOK_HANDLE)
END SUBROUTINE WRGP_SURF
