SUBROUTINE OBSVTL
!-----------------------------------------------------------------------
!**** *OBSVTL* - VERTICAL PART OF THE OBSERVATION OPERATORS(t.l.).
!**
!**   PURPOSE.
!**   -------
!**   PREPARE THE OBSERVATIONS SETS (CASTOR AND ECSET).
!**   MULTITASKING OF THE COMPUTATION OF THE OBS OPERATORS.
!**
!**   INTERFACE.
!**   ---------
!**   *CALL* * OBSVTL*
!**         THE COMMON YOMOBA IS AN IMPLICIT INPUT OF OBSV BECAUSE
!**         OF THE DIFFERENT POINTERS NEEDED TO FETCH THE OBS NUMBERS.
!**         THE COMMON YOMOBSET (SET UP BY ECSET OR CASTOR) IS THE ONE
!**         CONTAINING THE DESCRIPTION OF THE OBS SETS, FOR OI AND FOR
!**         THE NON-CORREL OBS IN VAR ANALYSIS.

!     AUTHOR: Mats Hamrud (From OBSV, tangent linear option) 
!     DATE  : 97-02-21

!     MODIFICATIONS
!     -------------
!     ERIK ANDERSSON:  97-10-02 Time correlated SYNOP obs errors
!     F. Veerse 97-12-04 : No call to SUOBAREA at low-resolution
!                          for DMN 4D-Var
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!-----------------------------------------------------------------------

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

USE YOMDIMO  , ONLY : NACTIM   ,NOBTOT
USE YOMLUN   , ONLY : NULOUT   
USE YOMCT0   , ONLY : NCONF    
USE YOMCOSJO , ONLY : LTC
USE YOMECTAB , ONLY :      NTSLOTNO
USE YOMOBSET , ONLY : NSETOT
USE YOMVAR   , ONLY : NSIM4D   ,NDIAG    ,NSIM4DL

IMPLICIT NONE

REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "comtc.intfb.h"
#include "ecset.intfb.h"
#include "prtgom.intfb.h"
#include "taskobtl.intfb.h"

!*    ------------------------------------------------------------------

!*    0 . SET UP TO 0. THE LOCAL ARRAY CONTAINING THE COST FUNCTION
!*        FOR EACH SEPARATE TASK AND SOME ADDITONAL POINTERS
!     ------------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('OBSVTL',0,ZHOOK_HANDLE)
CALL GSTATS(41,0)

!*    ------------------------------------------------------------------

!*      1 . MOST OBS TYPES
!       ------------------

!*      1.1. COMPUTATION OF THE OBSERVATION SETS

IF(NSIM4D == 0) THEN
  CALL ECSET(-1,NOBTOT,0)
  WRITE(NULOUT,*) ' Total number of observation sets: ',NSETOT
ENDIF

!*    1.2.MULTITASKED PROCESSING OF THE DIFFERENT SETS OF OBSERVATIONS

!     PRESET CURRENT OBS SET NUMBER (NUMERO)
!     THIS IS DONE BACKWARDS, BECAUSE IN THAT WAY TOVS WILL BE DONE FIRST
!     AND THE RELATIVELY INEXPENSIVE SCAT WILL BE DONE LAST

CALL TASKOBTL

CALL GSTATS(41,1)
!*    ------------------------------------------------------------------

!*    2. CORRELATED OBSERVATION ERRORS
!        -----------------------------

!*      2.1. TIME CORRELATED SYNOP/DRIBU
IF(NTSLOTNO == NACTIM .AND. NACTIM > 1 .AND. LTC) THEN
  CALL GSTATS(91,0)
  CALL COMTC
  CALL GSTATS(91,1)
ENDIF

!*    ------------------------------------------------------------------

!*    5. Diagnostic print of the GOM arrays (Useful for debugging).
!*       In the normal incremental 3D-Var this will give three
!*       sets of output:
!*       1) RMS of FG at observation points (model levels)
!*       2) RMS of gradient, first simulation
!*       3) RMS of gradient, last  simulation
!*       NDIAG.NE.0 avoids print during GRTEST
!        ---------------------------------------------------------

IF(NCONF/100 == 1.AND. NDIAG /= 0.AND.&
   & (NSIM4D == 1.OR. NSIM4D == NSIM4DL) ) THEN  
  WRITE(NULOUT,*)' - OBSVTL CALLING PRTGOM,NSIM4D=',NSIM4D
  CALL PRTGOM(1,NSETOT)
ENDIF

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('OBSVTL',1,ZHOOK_HANDLE)
END SUBROUTINE OBSVTL

