SUBROUTINE ADD_MODBIAS_TL(KLEN,KBLK,KGLO,PB1,YDGPERR)

!     Author.
!     ------
!        Y.Tremolet

!     Modifications.
!     -------------
!        Original   : 28-Jul-2005
!    -------------------------------------------------------------------

USE PARKIND1, ONLY: JPIM, JPRB
USE YOMHOOK , ONLY: LHOOK, DR_HOOK
USE YOMDIM  , ONLY: NFLEVG
USE YOMMP   , ONLY: NSLCORE, NASLB1
USE YOMSC2  , ONLY: NFLDOBB1
USE YOMMODEL_ERROR, ONLY: NTYPE_MODERR, MERROBS
USE GRIDPOINT_FIELDS_MIX

IMPLICIT NONE

INTEGER(KIND=JPIM), INTENT(IN) :: KLEN,KBLK,KGLO
REAL(KIND=JPRB), INTENT(INOUT) :: PB1(NASLB1,NFLDOBB1) 
TYPE(GRIDPOINT_FIELD), INTENT(IN) :: YDGPERR

INTEGER(KIND=JPIM) :: ibgn,jl,il,ioff,jj,ii,jf
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

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

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

IF (NTYPE_MODERR/=3) CALL ABOR1('ADD_MODBIAS_TL: Error model error type')

ibgn=kglo-1

DO jf=1,YDGPERR%NG3D
  ioff=MERROBS(jf)-1
  DO jl=1,NFLEVG
    il=ioff+jl
    DO jj=1,klen
      ii=NSLCORE(ibgn+jj)
      PB1(ii,il)=PB1(ii,il)+YDGPERR%GP3D(jj,jl,jf,kblk)
    ENDDO
  ENDDO
ENDDO

DO jf=1,YDGPERR%NG2D
  ioff=MERROBS(YDGPERR%NG3D+jf)
  DO jj=1,klen
    ii=NSLCORE(ibgn+jj)
    PB1(ii,ioff)=PB1(ii,ioff)+YDGPERR%GP2D(jj,jf,kblk)
  ENDDO
ENDDO

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