SUBROUTINE GPNORM2(KFIELDS,KSTAF,PGP,CDLABEL)

!**** *GPNORM2*  - ROUTINE FOR CALCULATING GRID POINT NORM OF 2-D FILEDS
!                  

!     PURPOSE.
!     --------

!**   INTERFACE.
!     ----------

!        *CALL* *GPNORM2(...)*

!        INPUT:

!        KFIELDS   - number of fields 
!        KSTAF     - first field 
!        PGP       - field

!     METHOD.
!     -------

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

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

!        ECMWF Research Department documentation of the IFS

!     AUTHOR.
!     -------

!        L. Isaksen *ECMWF*

!     MODIFICATIONS.
!     --------------
!       Original : 96-07-07  Based on extgpf.F
!       Y.Tremolet: 03-11-19 Special case when buffer not filled.
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        M.Hamrud      10-Jan-2004 CY28R1 Cleaning
!        M.Hamrud      01-Jul-2006 Revised surface fields
!        G.Mozdzynski  19-Sept-2008 gpnorm optimisations
!     -----------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMDIM   , ONLY : NPROMA, NGPBLKS
USE YOMGEM   , ONLY : NGPTOT

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KFIELDS 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTAF 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGP(:,:,:)
CHARACTER(LEN=*)  ,INTENT(IN),OPTIONAL :: CDLABEL
REAL(KIND=JPRB) :: ZGP(NPROMA,KFIELDS,NGPBLKS)

INTEGER(KIND=JPIM) ::  IEND, IST, JF, JL, JKGLO, IBL
LOGICAL :: LLEVELS
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "gpnorm1.intfb.h"

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

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

!--- LOOP OVER NPROMA PACKETS

CALL GSTATS(1216,0)
!$OMP PARALLEL DO SCHEDULE(STATIC) PRIVATE(JKGLO,IST,IEND,IBL,JF,JL)
DO JKGLO=1,NGPTOT,NPROMA
  IST=1
  IEND=MIN(NPROMA,NGPTOT-JKGLO+1)
  IBL=(JKGLO-1)/NPROMA+1
  DO JF=1,KFIELDS
    DO JL=IST,IEND
      ZGP(JL,JF,IBL) = PGP(JL,JF+KSTAF-1,IBL)
    ENDDO
  ENDDO
ENDDO
!$OMP END PARALLEL DO
CALL GSTATS(1216,1)

LLEVELS=.TRUE.
CALL GPNORM1(ZGP,KFIELDS,LLEVELS,CDLABEL)

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

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