!-------------------------------------- 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 sumvog,6
c
#if defined (DOC)
*
***s/r SUMVOG - Setup things for Calculating background standard deviations
*               for observed variable types on the analysis grid
*
*Author  : Mark Buehner, October 1998
*Revision: C.Charette ARMA/AES NOV 1998
*          - DOCTOR standards for local variables. Adapt to new names
*            for variables related to oneobs experiments in comcse1.cdk
*            Added background fields options
*
*          C.Charette ARMA/AES NOV 1999
*          Replace subackgnd by subasic. Initialize RMTMOBS to zero
*          instead of 10.*RG
*
*    -------------------
**    Purpose: Setup for Project Background statistics into observation space
*     .
#endif
      IMPLICIT NONE
*implicits
#include "pardim.cdk"
#include "comdim.cdk"
#include "comdimo.cdk"
#include "comlun.cdk"
#include "commvo.cdk"
#include "commvog.cdk"
#include "comgem.cdk"
#include "com1obs.cdk"
*
C
      INTEGER IERR,ILEN,JK,JOBS
      REAL*8 PTOP(NOBTOT)
      POINTER(PPTOP,PTOP)
C
      WRITE(NULOUT,FMT='(/,4X,"Starting SUMVOG",//)')
      WRITE(NULOUT,FMT='(/,4X,"NOBTOT = ",I6,//)')NOBTOT
C
C*    0.1 Memory allocation
C     .   -----------------
      ILEN = NOBTOT
      CALL HPALLOC(PPTOP,MAX(ILEN,1),IERR,8)
C
C*    0.2 Initialize the background statistics and background field
C
      IF( C1OBSBG .EQ. 'ZONAL' ) THEN
         call sumvogz
      ELSEIF( C1OBSBG .EQ. 'FGUESS' ) THEN
         call sumvogf
      ELSEIF( C1OBSBG .EQ. 'PROFILE' ) THEN
         call sumvogp
      ELSE
         WRITE(NULOUT,*)' SUMVOG: C1OBSBG= ',C1OBSBG
         CALL ABORT3D(NULOUT,'SUMVOG: BACKGRP OPTION NOT SUPPORTED')
      ENDIF

      DO JK=1, NFLEV
        DO JOBS=1, NOBTOT
          PTOP(JOBS)=1000.0
          RPPOBS(JK,JOBS)=VLEV(JK)*
     &      (GOMPSG(1,JOBS)-PTOP(JOBS))+PTOP(JOBS)
        ENDDO
      ENDDO
      DO JOBS=1, NOBTOT
        RMTMOBS(jobs) = 0.0
      enddo
      call subackgrd(PTOP,NOBTOT)
      call preobs
c
      CALL HPDEALLC(PPTOP,IERR,1)
c
      return
      end