SUBROUTINE SUALOBS

!**** SUALOBS - Allocate the OBS. RELATED arrays

!     Purpose.
!     -------
!           Allocation of the tables needed for obs computations

!     Interface.
!     ---------
!           SUALOBS is called from routine SUALLO

!     Author: DRASKO VASILJEVIC
!     Date  : 90-03-28

!     Modifications.
!     -------------
!             JEAN PAILLEUX  90-05-10
!             D. VASILEVIC   90-11-12
!             PATRICK MOLL   28/01/91
!             JEAN PAILLEUX  91-07-26: add pointers for Ts,Ws and
!                                      snow at the observation point
!             JEAN PAILLEUX  91-09-08: add arrays for scatterometer
!    P.Courtier and M.Hamrud 91-09-26: cleaning (again!)
!             ERIK ANDERSSON 92-03-04: add lowest level u & v for TOVS
!             Ph. Caille     27-01-92: add arrays for excluded data in
!                                      the french O.I.
!             ERIK ANDERSSON 92-07-15: SATEM DZ and PWC.
!             Ph. Caille     02-04-93: CMAFOC developments
!             J.N Thepaut    29-06-93: #?!@@&%*?!? (and I am polite)
!             Mike Fisher    04-01-95: Allocate GOMMV5, etc.
!             D. Giard       06-06-95: yomdimv moved to pardimo, yomdimo
!             B. Urban       20-02-97: allocation of ECCLI*
!                                      for surface climatology
!             F. Taillefer   02-06-97: allocation of DL and DM
!             Erik Andersson 97-11-14: GOM-variables more flexible
!             Erik Andersson 98-08-18: Moved TOVS allocations to SURAD
!             F. Taillefer   97-10-09: allocation of model errors at the obs.
!                                      point (moved from SUALGES)
!             Pedro Viterbo  99-09-01: Surface tiles arrays
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        M.Hamrud      15-Feb-2005 New-style GOM arrays
!    -------------------------------------------------------------------

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

USE YOMLUN   , ONLY : NULOUT   
USE YOMCT0   , ONLY : LALLOPR
USE YOMDIMO  , ONLY : NMXSET  
USE YOMOBA   , ONLY : ROBDD1   ,ROBDD2   ,MOBDD1   ,&
 & MOBDD2     
USE YOMOBSET , ONLY : MTYPOB   ,MLNSET   ,MMXBDY   ,MTSLSET
USE YOMOBSET_THSAFE
USE YOMCMDDR , ONLY : NLEND1I  ,NLEND1R  ,NLEND2I  ,NLEND2R
USE OML_MOD, ONLY : OML_MAX_THREADS

IMPLICIT NONE

INTEGER(KIND=JPIM) :: IU, IMAX_THREADS, ITID

LOGICAL :: LLP
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "sugoms.intfb.h"

!    -------------------------------------------------------------------
!*          1.   OBS ARRAYS AND ITS RELATED TABLES
!                ---------------------------------

IF (LHOOK) CALL DR_HOOK('SUALOBS',0,ZHOOK_HANDLE)
LLP = LALLOPR
IU = NULOUT

IF (LLP) WRITE(NULOUT,'('' SUALOBS PRINTOUTS '')')

IF(.NOT.ALLOCATED(MOBDD1)) THEN
  ALLOCATE(MOBDD1(NLEND1I))
  IF(LLP)WRITE(IU,9) 'MOBDD1   ',SIZE(MOBDD1   ),SHAPE(MOBDD1   )
  ALLOCATE(MOBDD2(NLEND2I))
  IF(LLP)WRITE(IU,9) 'MOBDD2   ',SIZE(MOBDD2   ),SHAPE(MOBDD2   )
  ALLOCATE(ROBDD1(NLEND1R))
  IF(LLP)WRITE(IU,9) 'ROBDD1   ',SIZE(ROBDD1   ),SHAPE(ROBDD1   )
  ALLOCATE(ROBDD2(NLEND2R))
  IF(LLP)WRITE(IU,9) 'ROBDD2   ',SIZE(ROBDD2   ),SHAPE(ROBDD2   )
ENDIF

!    -------------------------------------------------------------------
!*          2.  ARRAYS OF MODEL VAR AT OBS POINTS
!               ---------------------------------
CALL SUGOMS

!    -------------------------------------------------------------------
!*          3. ARRAYS FOR OBSERVATION SETS (YOMOBSET) [NON (TOVS/SCATT)]
!              --------------------------------------

ALLOCATE(MTYPOB (NMXSET))
IF(LLP)WRITE(IU,9) 'MTYPOB   ',SIZE(MTYPOB   ),SHAPE(MTYPOB   )
ALLOCATE(MMXBDY (NMXSET))
IF(LLP)WRITE(IU,9) 'MMXBDY   ',SIZE(MMXBDY   ),SHAPE(MMXBDY   )
ALLOCATE(MLNSET (NMXSET))
IF(LLP)WRITE(IU,9) 'MLNSET   ',SIZE(MLNSET   ),SHAPE(MLNSET   )
ALLOCATE(MTSLSET (NMXSET))
IF(LLP)WRITE(IU,9) 'MTSLSET  ',SIZE(MTSLSET  ),SHAPE(MTSLSET  )

!    -------------------------------------------------------------------
!*          3.1 ARRAYS FOR THREAD-SAFE OBSERVATION SETS (YOMOBSET) [NON (TOVS/SCATT)]
!               --------------------------------------------------

IMAX_THREADS = OML_MAX_THREADS()
ALLOCATE(OBSET(IMAX_THREADS))
DO ITID=1,IMAX_THREADS
  ALLOCATE(OBSET(ITID)%MTYPOB (NMXSET))
  ALLOCATE(OBSET(ITID)%MMXBDY (NMXSET))
  ALLOCATE(OBSET(ITID)%MLNSET (NMXSET))
  ALLOCATE(OBSET(ITID)%MTSLSET(NMXSET))
ENDDO

!    -------------------------------------------------------------------
9 FORMAT(1X,'ARRAY ',A10,' ALLOCATED ',8I8)
!    -------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('SUALOBS',1,ZHOOK_HANDLE)
END SUBROUTINE SUALOBS
