!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer,
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer
!version 3 or (at your option) any later version that should be found at:
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software;
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec),
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
!

      subroutine bilin_sigmab,19
*
#if defined (DOC)
*
***s/r bilin_sigmab  - Horizontal bilinear interpolation of the model variables
*               in grid-point space to observation points.
*
*     Author  : Luc Fillion - ARMA/EC - 18 Nov 2009
*     .         -------------------------------
*     Purpose:  Perform interpolation of Background error standard-deviation fields to observation points.
*               This sub. is called for the background check.
#endif
      IMPLICIT NONE
*implicits
#include "pardim.cdk"
#include "comdim.cdk"
#include "comlun.cdk"
#include "comstate.cdk"
#include "comgrd_param.cdk"
*
*     Local variables
*
      integer ilev
!
!!
      write(nulout,*)'bilin_sigmab- Horizontal interpolation GD --> MVO'
!
!     Conversion of wind images to physical winds
!
      call uvwi2uv
!
!     3D fields interpolation
!
      if(grd_typ.eq.'GU'.and.(.not.grd_roule)) then      ! i.e. original global Gaussian grid approach
        if(NGEXIST(nguu).eq.1)  call gd2mvo('UU',nflev)
        if(NGEXIST(ngvv).eq.1)  call gd2mvo('VV',nflev)
        if(NGEXIST(ngq).eq.1)   call gd2mvo('Q0',nflev)
        if(NGEXIST(ngtt).eq.1)  call gd2mvo('TT',nflev)
        if(NGEXIST(ngoz).eq.1)  call gd2mvo('OZ',nflev)
        if(NGEXIST(ngtr).eq.1)  call gd2mvo('TR',nflev)
        if(NGEXIST(nggz).eq.1)  call gd2mvo('GZ',nflev)
*
*       2D fields interpolation
*
        ilev = 1
        if(NGEXIST(ngps).eq.1)  call gd2mvo('PS',ilev)
        if(NGEXIST(ngtg).eq.1)  call gd2mvo('TG',ilev)
      else
        if(NGEXIST(nguu).eq.1)  call gd2mvogen('UU',nflev)
        if(NGEXIST(ngvv).eq.1)  call gd2mvogen('VV',nflev)
        if(NGEXIST(ngq).eq.1)   call gd2mvogen('Q0',nflev)
        if(NGEXIST(ngtt).eq.1)  call gd2mvogen('TT',nflev)
        if(NGEXIST(ngoz).eq.1)  call gd2mvogen('OZ',nflev)
        if(NGEXIST(ngtr).eq.1)  call gd2mvogen('TR',nflev)
        if(NGEXIST(nggz).eq.1)  call gd2mvogen('GZ',nflev)
!
!       No need to Rotate tangential wind components to real sphere tangential components
!       here (as done during the minimization) since sigmab_uu and sigmab_vv are treated as scalars
!
*
*       2D fields
*
        ilev = 1
        if(NGEXIST(ngps).eq.1)  call gd2mvogen('PS',ilev)
        if(NGEXIST(ngtg).eq.1)  call gd2mvogen('TG',ilev)
      endif
*
      return
      end subroutine bilin_sigmab