SUBROUTINE SUNUD(KULOUT)

!**** *SUNUD* * - ROUTINE TO INITIALIZE COEFS FOR NUDGING

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

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

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

!     IMPLICIT ARGUMENTS :
!     --------------------
!        COMMON  YOMNUD

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

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

!     AUTHOR.
!     -------
!        Michel Deque *CNRM*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 96-07-01
!        M. Deque 99-02-25 : Nudging in correction mode
!        M. Deque 01-06-11 : nudging with time-variable coefficients
!        P. Marquet 02-02-14 : LWNUDG in YOMNUD
!        M. Deque 05-06-20 : grid point nudging                
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        M.Hamrud      01-Jul-2006 Revised surface fields
!        A.Alias       31-Oct-2006 Modified setup of LNUDST(=LNUDG, even if XNUDST=0.0)
!        A.Alias       07-Mar-2007 nudging with wavenumber-variable coefficients(M.Deque)
!        A.Alias       19-Oct-2007 mv setup of NTOTFNUDG to sudim1
!-----------------------------------------------------------------------

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

USE YOMLUN   , ONLY : NULNAM
USE YOMNUD   , ONLY : NFNUDG   ,NTNUDG  ,LNUDG    ,LNUDDI   ,&
 & LNUDLP   ,LNUDRM   ,LNUDSD   ,LNUDSH   ,LNUDSM   ,&
 & LNUDST   ,LNUDSV   ,LNUDTE   ,LNUDVO   ,XNUDDI   ,&
 & XNUDLP   ,XNUDRM   ,XNUDSD   ,XNUDSH   ,XNUDSM   ,&
 & XNUDST   ,XNUDSV   ,XNUDTE   ,XNUDVO   ,&
 & LNDRIV   ,LWNUDG   ,&
 & LNUDTG   ,LNUDQG   ,LNUDUG   ,LNUDVG   ,LNUDPG   ,&
 & XNUDTG   ,XNUDQG   ,XNUDUG   ,XNUDVG   ,XNUDPG   ,XNUVERT,&
 & NSPNU1, NSPNU2

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

IMPLICIT NONE

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

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

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "namnud.h"

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

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

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

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

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

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

!        1.1 Set implicit default values

LNUDG= .FALSE.
LNUDST =.FALSE.
LWNUDG =.FALSE.
LNDRIV =.FALSE.
NFNUDG=0
NTNUDG=1
NSPNU1=998
NSPNU2=999
XNUDTE =0._JPRB
XNUDSH =0._JPRB
XNUDDI =0._JPRB
XNUDVO =0._JPRB
XNUDSV =0._JPRB
XNUDLP =0._JPRB
XNUDST =0._JPRB
XNUDSM =0._JPRB
XNUDRM =0._JPRB
XNUDSD =0._JPRB

XNUDTG =0._JPRB
XNUDQG =0._JPRB
XNUDUG =0._JPRB
XNUDVG =0._JPRB
XNUDPG =0._JPRB

XNUVERT =1._JPRB
!      ----------------------------------------------------------------

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

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

!ZEPS=1.E-12_JPRB

LNUDTE=(XNUDTE /= 0.0_JPRB)
LNUDSH=(XNUDSH /= 0.0_JPRB)
LNUDDI=(XNUDDI /= 0.0_JPRB)
LNUDVO=(XNUDVO /= 0.0_JPRB)
LNUDSV=(XNUDSV /= 0.0_JPRB)
LNUDLP=(XNUDLP /= 0.0_JPRB)
LNUDST=(XNUDST /= 0.0_JPRB)
LNUDSM=(XNUDSM /= 0.0_JPRB)
LNUDRM=(XNUDRM /= 0.0_JPRB)
LNUDSD=(XNUDSD /= 0.0_JPRB)

LNUDTG=(XNUDTG /= 0.0_JPRB)
LNUDQG=(XNUDQG /= 0.0_JPRB)
LNUDUG=(XNUDUG /= 0.0_JPRB)
LNUDVG=(XNUDVG /= 0.0_JPRB)
LNUDPG=(XNUDPG /= 0.0_JPRB)

LNUDG=(LNUDG.AND.(LNUDTE.OR.LNUDSH.OR.LNUDDI &
 & .OR.LNUDVO.OR.LNUDSV.OR.LNUDLP &
 & .OR.LNUDST.OR.LNUDSM.OR.LNUDRM.OR.LNUDSD  &
 & .OR.LNUDTG.OR.LNUDQG.OR.LNUDUG.OR.LNUDVG.OR.LNUDPG))  

LNUDST=LNUDG
 
!      -----------------------------------------------------------

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

WRITE(UNIT=KULOUT,FMT='('' COMMON YOMNUD '')')
WRITE(UNIT=KULOUT,FMT='(&
 & '' LNUDG  ='',L2,9X,'' NFNUDG ='',I2,9X,'' NTNUDG ='',I2,9X,/,&
 & '' XNUDDI ='',E11.4,'' XNUDLP ='',E11.4,'' XNUDRM ='',E11.4, &
 & '' XNUDSD ='',E11.4,'' XNUDSH ='',E11.4,'' XNUDSM ='',E11.4,/,&
 & '' XNUDST ='',E11.4,&
 & '' XNUDSV ='',E11.4,'' XNUDTE ='',E11.4,'' XNUDVO ='',E11.4,/,&
 & '' LNUDDI ='',L2,9X,'' LNUDLP ='',L2,9X,'' LNUDRM ='',L2,9X, &
 & '' LNUDSD ='',L2,9X,'' LNUDSH ='',L2,9X,'' LNUDSM ='',L2,9X,/,&
 & '' LNUDST ='',L2,9X,&
 & '' LNUDSV ='',L2,9X,'' LNUDTE ='',L2,9X,'' LNUDVO ='',L2,9X,/,&
 & '' LWNUDG ='',L2,9X &
 & )')&
 & LNUDG,  NFNUDG, NTNUDG,&
 & XNUDDI, XNUDLP, XNUDRM, XNUDSD, XNUDSH, XNUDSM, XNUDST,&
 & XNUDSV, XNUDTE, XNUDVO,&
 & LNUDDI, LNUDLP, LNUDRM, LNUDSD, LNUDSH, LNUDSM, LNUDST,&
 & LNUDSV, LNUDTE, LNUDVO, LWNUDG  
WRITE(UNIT=KULOUT,FMT='(&
 & '' LNDRIV  ='',L2,9X,/,&
 & '' XNUDTG ='',E11.4,'' XNUDQG ='',E11.4,'' XNUDUG ='',E11.4,&
 & '' XNUDVG ='',E11.4,'' XNUDPG ='',E11.4,/,&
 & '' LNUDTG ='',L2,9X,'' LNUDQG ='',L2,9X,'' LNUDUG ='',L2,9X,&
 & '' LNUDVG ='',L2,9X,'' LNUDPG ='',L2,9X &
 & )')&
 & LNDRIV, &
 & XNUDTG,XNUDQG,XNUDUG,XNUDVG,XNUDPG,&
 & LNUDTG,LNUDQG,LNUDUG,LNUDVG,LNUDPG  
WRITE(UNIT=KULOUT,FMT='('' XNUVERT ='')')
WRITE(UNIT=KULOUT,FMT='(4(1X,E19.12))') XNUVERT
WRITE(UNIT=KULOUT,FMT='(" NSPNU1 =",I5," NSPNU2 =",I5)')NSPNU1,NSPNU2

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

!*       4.    VARIOUS CHECKINGS.
!              ------------------

IF(LNUDG.AND.(NFNUDG == 0)) THEN
  WRITE(KULOUT,FMT='('' WHEN NUDGING, NFNUDG MUST BE >0 '')')
  CALL ABOR1('SUNUD: ABOR1 CALLED')
ENDIF

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

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