SUBROUTINE SU1YOM

!**** *SU1YOM*  - Initialize level 1 commons and some higher

!     Purpose.
!     --------
!           Initialize level 1 commons
!            and some higher level commons.
!**   Interface.
!     ----------
!        *CALL* *SU1YOM

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

!        Implicit arguments :   Common YOMCT1
!        --------------------

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

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

!        SUSPEC   -
!        SUVAZX   - INITIALSE CONTROL VARIABLE
!        SUCNTVVA - INITIALSE CONTROL VARIABLE
!        SUCOS    - INITIALISE COST FUNCTION (SIMULATED OBS.)
!        ABORT

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

!     Author.
!     -------
!        Mats Hamrud and Philippe Courtier  *ECMWF*

!     Modifications.
!     --------------
!        Original : 87-10-15
!        MODIFIED BY D. VASILJEVIC : 90-11-13
!        Modified by L.Labbe : 93-04-15 - Initializations for NCONF=8xx
!        Modified by R. EL Khatib : 93-04-02 Set-up defaults controled by LECMWF
!        Modified by A. Horanyi: 95-07-20 for ALADIN
!        M. Hamrud  :  95-10-01 - Interface block for SUSPEC
!        F. Rabier  :  96-10-01 - No overwriting of SPA3 by INIT files (L801TL)
!        Modified by R. EL Khatib : 97-08-21 N1ISP, N1MASS, N1XFU and N1RES 
!                                   + prints 
!        Modified by R. EL Khatib : 98-04-02 Cleanup arguments to SUSPEC
!        E. Holm    :  97-12-01 - Call to SUSPEC changed (incl. ozone)
!        M.Hamrud   :  98-03-08 - Remove call to SUCNTVVA
!        Y.Tremolet :  00-08-09 - Remove NTRAJE, use module TRAJECTORY
!        P.Smolikova 02-09-30 -  Interface to SUSPEC for d4 in NH
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        M.Hamrud      10-Jan-2004 CY28R1 Cleaning
!        M.Hamrud      01-Dec-2005 Generalized IO scheme
!        K.Yessad  : June 2006   Possibility to read purely gp ARPEGE files
!        R. El Khatib  26-Nov-2008  Cleaning
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMLUN   , ONLY : NULOUT   ,NULNAM
USE YOMCT0   , ONLY : NCONF    ,LSIMOB   ,NPRINTLEV,LARPEGEF_RDGP_INIT
USE YOMCT0B  , ONLY : LECMWF
USE YOMCT1   , ONLY : N1POS    ,N1HIS    ,N1GDI    ,&
 & N1SDI    ,N1DHP    ,N1ISP    ,N1RES    ,N1XFU    ,&
 & N1MASS   ,N1DHFG   ,N1DHFZ   ,N1DHFD   ,N1CFU    ,&
 & LRFILAF  
USE YOMSP    , ONLY : SPA3, SPA2, SPA1, SPOR
USE YOMLDDH  , ONLY : LSDDH    ,LHDPR    ,LHDEFG   ,LHDEFZ   ,LHDEFD
USE YOMVRTL  , ONLY : L801TL
USE YOM_YGFL , ONLY : YGFL

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

IMPLICIT NONE

INTEGER(KIND=JPIM) :: ICONF

LOGICAL :: LLINOR, LLSPOR
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "namct1.h"

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

#include "posnam.intfb.h"
#include "sucos.intfb.h"
#include "sugridf.intfb.h"
#include "sugridu.intfb.h"
#include "suinif.intfb.h"
#include "suspec.intfb.h"
#include "suvazx.intfb.h"

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

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

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

!*       1.    Initialize control variable (first step of the descent)
!              -------------------------------------------------------

ICONF=NCONF/100
IF (ANY(SPREAD(ICONF,1,5) == (/1,4,5,6,8/))) THEN

  IF (.NOT.LSIMOB) THEN  ! REAL observations

    IF (NCONF/=131) THEN
      ! ky: for the time being LDRDGRIDSP is let to F in this call to SUINIF
      !     (not called in conf 1 or 131).
      CALL SUINIF(0)
      IF (NPRINTLEV >=2) THEN
        WRITE(NULOUT,*) ' SU1YOM: SUINIF(0) called '
        CALL FLUSH(NULOUT)
      ENDIF
      CALL SUVAZX
      IF (NPRINTLEV >=2) THEN
        WRITE(NULOUT,*) ' SU1YOM: SUVAZX (case .NOT.LSIMOB) called '
        CALL FLUSH(NULOUT)
      ENDIF
    ELSE
      WRITE(NULOUT,*)'MODEL FIELDS ARE INITIALIZED BY SU1YOM'
      CALL SUINIF(1,LDRDGRIDSP=LARPEGEF_RDGP_INIT)
      IF (NPRINTLEV >=2) THEN
        WRITE(NULOUT,*) ' SU1YOM: SUINIF(1) called '
        CALL FLUSH(NULOUT)
      ENDIF
      CALL SUVAZX
    ENDIF

  ELSE
    CALL SUVAZX
    IF (NPRINTLEV >=2) THEN
      WRITE(NULOUT,*) ' SU1YOM: SUVAZX (case LSIMOB) called '
      CALL FLUSH(NULOUT)
    ENDIF

    LLINOR=.TRUE.
    IF (.NOT.L801TL) THEN
      CALL SUSPEC(SPA3,SPA2,SPA1,KFILE=0, &
       & LDRDGRIDSP=LARPEGEF_RDGP_INIT,LDINOR=LLINOR,LDSPOR=LLSPOR)  
      IF (NPRINTLEV >=2) THEN
        WRITE(NULOUT,*) ' SU1YOM: SUSPEC called '
        CALL FLUSH(NULOUT)
      ENDIF

      IF(.NOT.LLSPOR) THEN
        CALL SUGRIDF(0,SPOR,LLSPOR)
      ENDIF
      IF( YGFL%NUMGPFLDS>0 ) THEN
        CALL SUGRIDU(0)
      ENDIF
    ENDIF
  ENDIF
ENDIF
!     ------------------------------------------------------------------

!*       2.    Initialize YOMCT1.
!              ------------------

!        2.1 Set implicit default values

N1POS=1
N1HIS=1
N1GDI=1
N1SDI=1
N1DHP=0
N1DHFG=0
N1DHFZ=0
N1DHFD=0
N1CFU=1
N1XFU=1
N1ISP=0
N1MASS=1
N1RES=1
LRFILAF=.TRUE.

!        2.2 Modify default values according to LECMWF

IF (LECMWF) THEN
  LRFILAF=.FALSE.
  N1ISP=0
ELSE
  N1ISP=1
ENDIF

!*       2.3   READ NAMELIST.

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

!*       2.4    CONTROLE SORTIES DDH

IF ( LSDDH ) THEN
  IF ( LHDPR ) N1DHP = 1
  IF (LHDEFG) N1DHFG=1
  IF (LHDEFZ) N1DHFZ=1
  IF (LHDEFD) N1DHFD=1
ELSE
  N1DHP = 0
  N1DHFG=0
  N1DHFZ=0
  N1DHFD=0
ENDIF

!*       2.5   PRINT VALUES

WRITE(UNIT=NULOUT,FMT='('' N1POS = '',I1,'' N1HIS = '',I1,&
 & '' N1GDI = '',I1,'' N1SDI = '',I1,'' N1DHP = '',I1,&
 & '' N1DHFG= '',I1,'' N1DHFZ= '',I1,'' N1DHFD= '',I1,&
 & '' N1CFU = '',I1,'' N1XFU = '',I1,'' N1ISP = '',I1,&
 & '' N1MASS= '',I1,'' N1RES = '',I1)') &
 & N1POS,N1HIS,N1GDI,N1SDI,N1DHP,N1DHFG,N1DHFZ,N1DHFD,N1CFU,N1XFU,&
 & N1ISP,N1MASS,N1RES  
WRITE(UNIT=NULOUT,FMT='('' LRFILAF = '',L2)') LRFILAF

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

!*       3.    Initialize cost-function.
!              -------------------------

IF(NCONF/100 == 1.OR.NCONF/100 == 7.OR.NCONF/100 == 8)THEN
  CALL SUCOS
ENDIF

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

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