SUBROUTINE SURLX(KULOUT)

!**** *SURLX* * - ROUTINE TO INITIALIZE COEFS FOR RELAXATION

!     PURPOSE.
!     --------
!        SET DEFAULT VALUES, THEN READS NAMELIST NAMRLX

!**   INTERFACE.
!     ----------
!        *CALL* *SURLX(KULOUT)*

!     EXPLICIT ARGUMENTS :  KULOUT
!     --------------------

!     IMPLICIT ARGUMENTS :
!     --------------------
!        COMMON  YOMRLX

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

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

!     AUTHOR.
!     -------
!        Thomas Jung

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 06-07-28 
!-----------------------------------------------------------------------

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

USE YOMLUN   , ONLY : NULNAM
USE YOMCT0   , ONLY : NSTOP
USE YOMARG   , ONLY : UTSTEP
USE YOMDIM   , ONLY : NFLEVG
USE YOMDYN   , ONLY : TSTEP
USE YOMRLX   , ONLY : LRLXG   ,NRLXAN   ,&
 & NFRLXG   ,NFRLXU   ,NPRLX3D   ,NPRLX2D   ,&
 & LRLXVO   ,LRLXDI   ,LRLXTE,LRLXQ   ,LRLXLP   ,&
 & LRLXQI   ,LRLXQL   ,LRLXQC   ,&
 & XRLXVO   ,XRLXDI   ,XRLXTE,XRLXQ   ,XRLXLP ,&
 & ALATRLX1 ,ALATRLX2 ,ALONRLX1 ,ALONRLX2 ,&
 & NRLXLMIN ,NRLXLMAX ,AXRLX ,AYRLX ,AZRLX
USE YOMCST   , ONLY : RPI

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KULOUT 
INTEGER(KIND=JPIM) :: IC

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

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "namrlx.h"

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

#include "abor1.intfb.h"
#include "posnam.intfb.h"

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

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

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

!*       1.    SET DEFAULT VALUES.
!              -------------------

!        1.1 Set implicit default values

LRLXG= .FALSE.

LRLXVO=.FALSE.
LRLXDI=.FALSE.
LRLXTE=.FALSE.
LRLXQ=.FALSE.
LRLXQI=.FALSE.
LRLXQL=.FALSE.
LRLXQC=.FALSE.
LRLXLP=.FALSE.

NFRLXG=2
NFRLXU=6

XRLXVO =0._JPRB
XRLXDI =0._JPRB
XRLXTE =0._JPRB
XRLXQ =0._JPRB
XRLXLP =0._JPRB

NPRLX3D = 0

! default values in degrees
ALATRLX1=90._JPRB
ALATRLX2=-90._JPRB
ALATRLX1=0._JPRB
ALATRLX2=360._JPRB

AXRLX=-0.5_JPRB
AYRLX=-0.5_JPRB
AZRLX=1.0_JPRB

NRLXLMIN=1
NRLXLMAX=NFLEVG

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

!*       2.    MODIFIES DEFAULT VALUES.
!              ------------------------

CALL POSNAM(NULNAM,'NAMRLX')
READ       (NULNAM, NAMRLX)

LRLXG=(LRLXG.AND.(LRLXVO.OR.LRLXDI.OR.LRLXTE &
 & .OR.LRLXLP ))   

! count the number of 3D and 2D fields, respectively, being relaxed
IF(LRLXVO) NPRLX3D = NPRLX3D + 1
IF(LRLXDI) NPRLX3D = NPRLX3D + 1
IF(LRLXTE) NPRLX3D = NPRLX3D + 1
IF(LRLXQ)  NPRLX3D = NPRLX3D + 1
IF(LRLXQI)  NPRLX3D = NPRLX3D + 1
IF(LRLXQL)  NPRLX3D = NPRLX3D + 1
IF(LRLXQC)  NPRLX3D = NPRLX3D + 1
IF(LRLXLP) NPRLX2D = NPRLX2D + 1

! total number of events for which reference fields are available
WRITE(KULOUT,*)NSTOP,TSTEP,NFRLXU
NRLXAN=(NSTOP*TSTEP)/(NFRLXU*3600.0_JPRB)
NRLXAN=NRLXAN+1

! convert to radians
ALATRLX1=ALATRLX1*RPI/180._JPRB
ALATRLX2=ALATRLX2*RPI/180._JPRB
ALONRLX1=ALONRLX1*RPI/180._JPRB
ALONRLX2=ALONRLX2*RPI/180._JPRB

! set surface pressure relaxation to zero if necessary
IF (NRLXLMAX /= NFLEVG) THEN
  XRLXLP=0._JPRB
  WRITE(UNIT=KULOUT,FMT='('' WARNING: XRLXLP SET TO ZERO '')')
ENDIF

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

!*       3.    PRINTS FINAL VALUES.
!              --------------------

WRITE(UNIT=KULOUT,FMT='('' COMMON YOMRLX '')')
WRITE(UNIT=KULOUT,FMT='(&
 & '' LRLXG  ='',L2,9X,/,&
 & '' XRLXVO ='',E11.4,'' XRLXDI ='',E11.4,'' XRLXTE ='',E11.4, &
 & '' XRLXQ ='',E11.4,/,'' XRLXLP ='',E11.4,/,&
 & '' LRLXVO ='',L2,9X,'' LRLXDI ='',L2,9X,'' LRLXTE ='',L2,9X, &
 & '' LRLXQ ='',L2,9X,'' LRLXLP ='',L2, &
 & '' LRLXQI ='',L2,9X,'' LRLXQL ='',L2,9X,'' LRLXQC ='',L2,9X &
 & )')&
 & LRLXG,&
 & XRLXVO, XRLXDI, XRLXTE,XRLXQ, XRLXLP,&
 & LRLXVO, LRLXDI, LRLXTE,LRLXQ, LRLXLP,&
 & LRLXQI,LRLXQL,LRLXQC
WRITE(UNIT=KULOUT,FMT='('' NFRLXU ='',I3,1X,'' NRLXAN ='',I3,1X)') &
 & NFRLXU, NRLXAN
WRITE(UNIT=KULOUT,FMT='('' NPRLX3D ='',I3,1X,'' NPRLX2D ='',I3,1X)') &
 & NPRLX3D, NPRLX2D
WRITE(KULOUT,*)'ALATRLX1 (deg): ',ALATRLX1*180._JPRB/RPI
WRITE(KULOUT,*)'ALATRLX2 (deg): ',ALATRLX2*180._JPRB/RPI
WRITE(KULOUT,*)'ALONRLX1 (deg): ',ALONRLX1*180._JPRB/RPI
WRITE(KULOUT,*)'ALONRLX2 (deg): ',ALONRLX2*180._JPRB/RPI

WRITE(KULOUT,*)'AXRLX: ',AXRLX
WRITE(KULOUT,*)'AYRLX: ',AYRLX
WRITE(KULOUT,*)'AZRLX: ',AZRLX

WRITE(KULOUT,*)'NRLXLMIN: ',NRLXLMIN
WRITE(KULOUT,*)'NRLXLMAX: ',NRLXLMAX

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

!*       4.    VARIOUS CHECKS.
!              ------------------

IF (LRLXG.AND.(NFRLXG /= 2)) THEN
  WRITE(KULOUT,FMT='('' WHEN RELAXATION, NFRLXG MUST BE =2 '')')
  WRITE(KULOUT,FMT='('' LINEAR INTERPOLATION ONLY '')')
  CALL ABOR1('SURLX: ABOR1 CALLED')
ENDIF

!IF(LRLXG.AND.(NFRLXG == 0)) THEN
!  WRITE(KULOUT,FMT='('' WHEN RELAXATION, NFRLXG MUST BE >0 '')')
!  CALL ABOR1('SURLX: ABOR1 CALLED')
!ENDIF

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

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

