SUBROUTINE cvarbcin
!-----------------------------------------------------------------------
!   CVARBCIN - Inverse change-of-variable for variational bias parameters

!   Purpose.
!   --------
!   Applies inverse change-of-variable to the control vector section
!   associated with the observation bias parameters

!   Interface.
!   ----------
!   CALL cvarbcin ()

!   Implicit input:
!      YVARBC

!   Implicit output:
!      YVARBC

!   Author.
!   -------
!   Dick Dee (ECMWF)

!   Modifications.
!   --------------
!   Original    2004/03/19
!        P.Burton :  29-09-04 LVARBC cleanup
!-----------------------------------------------------------------------

USE parkind1, ONLY : JPIM, JPRB
USE yomhook,  ONLY : lhook, dr_hook
USE YOMJG   , ONLY : LSUBBG
USE varbc_setup, ONLY : YVARBC, NOBGROUP, JPMXNPARAM

IMPLICIT NONE

INTEGER(KIND=JPIM) :: jg, jp, inp
REAL(KIND=JPRB)    :: zp(JPMXNPARAM)
REAL(KIND=JPRB)    :: zhook_handle

IF (lhook) CALL DR_HOOK('CVARBCIN',0,zhook_handle)

CALL GSTATS(1446,0)
!$OMP PARALLEL DO SCHEDULE(STATIC) PRIVATE(jg,inp,jp,zp)
DO jg = 1, NOBGROUP
  inp = YVARBC(jg)%NPARAM

  DO jp = 1, inp
    zp(jp) = SUM(YVARBC(jg)%ACVARIN(jp,:) * YVARBC(jg)%APARAMS(1:inp))
  ENDDO

  IF (LSUBBG) THEN
    YVARBC(jg)%APARAMS = zp(1:inp) + YVARBC(jg)%APARAM0 - YVARBC(jg)%APARAM5  
  ELSE
    YVARBC(jg)%APARAMS = zp(1:inp)
  ENDIF
ENDDO
!$OMP END PARALLEL DO
CALL GSTATS(1446,1)

IF (lhook) CALL DR_HOOK('CVARBCIN',1,zhook_handle)

END SUBROUTINE cvarbcin
