SUBROUTINE SUCOS

!**** *SUCOS*   - Routine to initialize cost functions

!     Purpose.
!     --------
!           Initialize cost functions (jc, jg, jo and ref. j)
!**   Interface.
!     ----------
!        *CALL* *SUCOS

!     Externals.
!     ----------
!        SUJC - INITIALISE JC
!        SUJG - INITIALISE JG
!        SUJO - INITIALISE JO
!        SUJR - INITIALISE JR
!     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-15
!        Modified by W. Heckley    : 91-09-17
!        Modified by L. Labbe      : 93-04-15 - Jref for S.W.
!        Modified by L. Isaksen    : 96-04-04 - SUCOSJG --> SUCOSJB
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        V. Guidard and C. Fischer 05-11-03: introduction of LEJK
!        Y.Tremolet    29-May-2008 Print Jo table by bins
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMCT0   , ONLY : NCONF    ,LSIMOB
USE YOMCOSJB , ONLY : FJBCOST
USE YOMCOSJO , ONLY : JOT      ,FJOS
USE YOMCMA   , ONLY : NMXOTP
USE YOMJQ    , ONLY : FJQCOST
USE YOMVAR   , ONLY : LAVARC
USE YEMJK   , ONLY : LEJK

IMPLICIT NONE
INTEGER(KIND=JPIM) :: JOTP,JCTP
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "sujc.intfb.h"
#include "sujr.intfb.h"

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

!*       1.    SETUP OF JC
IF (LHOOK) CALL DR_HOOK('SUCOS',0,ZHOOK_HANDLE)
IF(NCONF/100 == 1) CALL SUJC

!*       2.    SETUP OF JB
FJBCOST=0.0_JPRB

!*       3.    SETUP OF JO
IF(.NOT.LSIMOB) THEN
  FJOS(:) = 0.0_JPRB

  DO JOTP=1,NMXOTP
    DO JCTP=1,JOT(JOTP)%size
      JOT(JOTP)%jost(JCTP)%cost(:,:)=0.0_JPRB
      JOT(JOTP)%jost(JCTP)%count(:,:)=0
      JOT(JOTP)%jost(JCTP)%obserr(:)=0.0_JPRB
      JOT(JOTP)%jost(JCTP)%bgerr(:)=0.0_JPRB
      JOT(JOTP)%jost(JCTP)%obimpact(:,:)=0.0_JPRB
    ENDDO
  ENDDO

ENDIF

!*       4.    SETUP OF SPECTRAL OBS J
IF(LSIMOB.OR.LAVARC.OR.LEJK)THEN
  CALL SUJR
ENDIF

!*       5.    SETUP OF JQ
FJQCOST=0.0_JPRB

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

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