SUBROUTINE OBSVAD
!-----------------------------------------------------------------------
!**** *OBSVAD* - VERTICAL PART OF THE OBSERVATION OPERATORS(adjoint).
!**
!**   PURPOSE.
!**   -------
!**   MULTITASKING OF THE COMPUTATION OF THE OBS OPERATORS.
!**
!**   INTERFACE.
!**   ---------
!**   *CALL* * OBSV(CDOBJOB)*
!**         CDOBJOB = switch to select direct/TL/AD obs computations
!**         THE COMMON YOMOBA IS AN IMPLICIT INPUT OF OBSV BECAUSE
!**         OF THE DIFFERENT POINTERS NEEDED TO FETCH THE OBS NUMBERS.

!     AUTHOR: Mats Hamrud (From OBSV adjoint option) 
!     DATE  : 97-02-21

!     MODIFICATIONS
!     -------------
!     Erik Andersson - 990615 : Remove JO from adjoint
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!-----------------------------------------------------------------------

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

USE YOMCT0   , ONLY : NCONF
USE YOMOBSET , ONLY : NSETOT
USE YOMVAR   , ONLY : NSIM4D   ,NDIAG    ,NSIM4DL
IMPLICIT NONE

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

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

REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "prtgom.intfb.h"
#include "taskobad.intfb.h"
IF (LHOOK) CALL DR_HOOK('OBSVAD',0,ZHOOK_HANDLE)
CALL GSTATS(42,0)

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

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

!*      1.1. COMPUTATION OF THE OBSERVATION SETS

IF(NCONF/100==1.AND. NDIAG/=0.AND. NSIM4D==0 ) THEN
  CALL PRTGOM(1,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 TASKOBAD

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

!*    3. WRITE OUT THE COST FUNCTION
!        ---------------------------

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

!*    4. No JO in adjoint
!        ----------------

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

!*    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
!        ---------------------------------------------------------

CALL GSTATS(42,1)
IF(NCONF/100 == 1.AND. NDIAG /= 0.AND.&
   & (NSIM4D == 0.OR. NSIM4D == NSIM4DL) ) THEN  
  CALL PRTGOM(1,NSETOT)
ENDIF

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