!-------------------------------------- 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 BGCHECK 1,18
#if defined (DOC)
*
***s/r BGCHECK  - BACKGROUND CHECK
*
*
*Author  : P. Koclas *CMC/CMDA  Nov 1998
*Revision:
*         1.0 P. Koclas
*         -modifications for version 8.06
*
*         1.1 JM Belanger CMDA/SMC  Jan 2001
*                   . 32 bits conversion
*         P. KOCLAS Sept 2001
*                   . eliminate unnessary call to suprep
*         P. KOCLAS Nov 2001
*                   . add 'call vint3dfd'
*         C. Charette ARMA Feb 2002
*                   . displaced 'call vint3dfd' to the end
*         J. St-James CMDA/SMC July 2003
*                   . add profiler family to the background check
*         JM Belanger CMDA/SMC Feb 2004
*                   . Introduce "scatterometer family SC"
*         J.M. Aparicio ARMA Octobre 2006
*                   . add GPSRO family to the background check
*         S. Macpherson ARMA/MRD September 2007
*                   . add GB-GPS (GP) family
*         L. Fillion ARMA/EC 6 Jul 09 - Call to sigmaop3d.ftn
*         L. Fillion ARMA/EC Sept 09 - Use sigmaop for grd_typ = 'GU' options.
*         L. Fillion ARMA/EC May 2010 - Prepare for different sigmaop.ftn if rotated mode.
*
*    -------------------
**    Purpose: DO  a background check on all observations
*
*Arguments
*    -NONE-
#endif
      IMPLICIT NONE
*implicits
#include "comlun.cdk"
#include "comdim.cdk"
#include "comdimo.cdk"
#include "comoabdy.cdk"
#include "comoahdr.cdk"
#include "comoba.cdk"
#include "comcva.cdk"
#include "comgrd_param.cdk"
*
C
      INTEGER J,JDATA
      REAL*8 ZJO
*----------------------------------------------------------------------
      WRITE(NULOUT,FMT=9000)
 9000 FORMAT(//,3(" *****************"),/
     S     ," BEGIN BACKGROUND CHECK",/
     S     ,3(" *****************"),/)
C
C*    1. Preliminary initializations
C     .  ---------------------------
C
 100  CONTINUE

C     Transfer REAL*8 part of CMA to REAL*4
C     (follows observation operators computations).

      call cprob8to4
C
C     TRANSFER O-A to O-P in cma
C
      DO JDATA=1,NDATA
         ROBDATA(NCMOMF,JDATA) = ROBDATA(NCMOMA,JDATA)
      ENDDO
C
C      CALCULATE Sigmap AND INNOVATIONS(O-P)
C     ----------------------------------------------
C
      if(grd_typ.eq.'GU') then
        if(lcva_hemis) then
          call sigmaop
        else
          CALL SIGMAOP
        endif
      else
        call sigmaop3d
      endif
C
C
C     DO A BACKGROUND CHECK ON ALL THE OBSERVATIONS
C     ----------------------------------------------
C
      CALL BGCDATA(ZJO,'UA')
      CALL BGCDATA(ZJO,'AI')
      CALL BGCDATA(ZJO,'HU')
      CALL BGCDATA(ZJO,'SF')
      CALL BGCDATA(ZJO,'ST')
      CALL BGCDATA(ZJO,'SW')
      CALL BGCDATA(ZJO,'SC')
      CALL BGCDATA(ZJO,'PR')
      CALL BGCGPSRO
      CALL BGCDATA(ZJO,'GP')
C
C
C     .   3.4.3 Convert CMA ---> BURP file and write it
C
      CALL VINT3DFD(NCMOMF)	
      CALL FILBRPPOST
c     CALL SUPREP
      DO j =1,1
         CALL PRNTHDR(j,NULOUT)
         CALL PRNTBDY(j,NULOUT)
      END DO
      RETURN
      END