FUNCTION CLASS_GRIB(CDCLASS)

!**** *CLASS_GRIB*  - CLASS code to GRIB code

!     Purpose.  To provide GRIB header code for given CLASS code.
!     --------

!**   Interface.
!     ----------
!        IGRIB=CLASS_GRIB(CDCLASS)

!        Explicit arguments :   CDCLASS - CLASS code - 2 characters (input)
!        --------------------             can be either upper or lower case
!                               CLASS_GRIB return value is the integer GRIB code
!                                     for ECMWF local GRIB usage of KSEC1(38)

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

!     Method.
!     -------
!        Table look up     

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

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

!     Author.
!     -------
!        David Dent  *ECMWF*

!     Modifications.
!     --------------
!       Original  : 98-08-10
!       D.Salmond : 03-10-02  Change to include 'test'
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

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

USE YOMLUN   , ONLY : NULOUT

IMPLICIT NONE

CHARACTER (LEN = 2),INTENT(IN) ::  CDCLASS

INTEGER(KIND=JPIM) :: CLASS_GRIB

INTEGER(KIND=JPIM) :: JPCLASS_LIST

PARAMETER (JPCLASS_LIST=28)
CHARACTER (LEN = 2) ::  CLASSES(56)
DATA CLASSES/'OD','RD','ER','CS','E4','AT','BE','HR','DK','FI',&
 & 'FR','DE','GR','HU','IS','IE','IT','NL','NO','PT',&
 & 'SI','ES','SE','CH','TR','UK','TE','EI',&
 & 'od','rd','er','cs','e4','at','be','hr','dk','fi',&
 & 'fr','de','gr','hu','is','ie','it','nl','no','pt',&
 & 'si','es','se','ch','tr','uk','te','ei'/  
INTEGER(KIND=JPIM) :: I_GRIBCODES(28)
DATA I_GRIBCODES/ 1,   2,   3,   4,   5, 100, 101, 102, 103, 104,&
 & 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,&
 & 115, 116, 117, 118, 119, 120, 99, 14/  

INTEGER(KIND=JPIM) :: ICODE, JL
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

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

!*       1.    SEARCH CLASS LIST.
!              -----------------

IF (LHOOK) CALL DR_HOOK('CLASS_GRIB',0,ZHOOK_HANDLE)
ICODE=0
DO JL=1,JPCLASS_LIST

  IF(CDCLASS == CLASSES(JL).OR.CDCLASS == CLASSES(JL+JPCLASS_LIST)) THEN
    ICODE=I_GRIBCODES(JL)
    EXIT
  ENDIF
ENDDO
IF(ICODE /= 0) THEN
  CLASS_GRIB=ICODE
ELSE
  WRITE(NULOUT,*)' CLASS_GRIB CANNOT FIND CLASS ',CDCLASS
  CALL ABOR1(' CLASS_GRIB CANNOT FIND CLASS')
ENDIF

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

IF (LHOOK) CALL DR_HOOK('CLASS_GRIB',1,ZHOOK_HANDLE)
END FUNCTION CLASS_GRIB
