!-------------------------------------- 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 su1obsbg 2,1
*
#if defined (DOC)
*
***s/r su1obsbg  - For GU and LU versions: Put first guess fields on analysis grid 
*                     into GOMOBSG for 1 Observation experiment mode.
*
*Author  : Luc Fillion - ARMA/EC - 13 Mar 2008 
*Revision:
* Luc Fillion - ARMA/EC - 13 Oct 2009 - Include rotated Gaussian global grid option. 
* Luc Fillion - ARMA/EC - 10 Feb 2010 - Write utg,ttg profile.
*
*    -------------------
**    Purpose: Useful for 1 Obs experiment mode.
*
*Arguments
*
#endif
C
      IMPLICIT NONE
*implicits
#include "pardim.cdk"
#include "comdim.cdk"
#include "comlun.cdk"
#include "comcst.cdk"
#include "comdimo.cdk"
#include "commvog.cdk"
#include "commvo.cdk"
#include "comgem.cdk"
#include "rpnstd.cdk"
#include "cvcord.cdk"
#include "compdg.cdk"
#include "comoba.cdk"
#include "comoahdr.cdk"
#include "comoabdy.cdk"
#include "comgrd_param.cdk"
#include "comgrd.cdk"
!
      INTEGER jlev,ji,jj,ILAT,ilon,igdgid,ezqkdef
      INTEGER ILEN,IDATA,JDATA,IDATA2,iobs,ii,ij
      REAL*8 zps(1)
!
      EXTERNAL ABORT3D
!
!!
      WRITE(NULOUT,FMT='(/,4X,"Starting su1obsbg",//)')
!
!*1.  Set (ii,ij) analysis-grid location of Simulated Obs
!     ---------------------------------------------------
!
      if(grd_roule) then
        ii = aint(robhdr(ncmtlo,1)) 
        ij = aint(robhdr(ncmtla,1)) 
      else
        ii = mobhdr(ncmtlo,1) 
        ij = mobhdr(ncmtla,1) 
      endif
      write(nulout,*) 'su1obsbg: (I,J) = ',ii,ij
!
!*2.  Setup gomobs
!     ------------
!
      do jlev = 1, nflev
        gomtg(jlev,1) = ttg(ii,jlev,ij)
        gomqg(jlev,1) = qg(ii,jlev,ij)
        gomug(jlev,1) = utg(ii,jlev,ij)*CONPHY(ij)  ! utg contains wind-image
        gomvg(jlev,1) = vtg(ii,jlev,ij)*CONPHY(ij)
      enddo
      write(nulout,*) 'su1obsbg:  '
      do jlev = 1,nflev
        write(nulout,*) 'su1obsbg: jlev, gomug(jlev,1) = ',jlev,gomug(jlev,1)
      enddo
      write(nulout,*) 'su1obsbg:  '
      do jlev = 1,nflev
        write(nulout,*) 'su1obsbg: jlev, gomtg(jlev,1) = ',jlev,gomtg(jlev,1)
      enddo
!
      gompsg(1,1) = gpsg(ii,1,ij)
!
!*3.  Setup rppobs, rmtmobs, other variable types in gomobsg
!     ------------------------------------------------------ 
!
      zps(1) = gompsg(1,1)
      write(nulout,*) 'su1obsbg: nobtot = ',nobtot
!      write(nulout,*) 'su1obsbg: vhybinc = ',vhybinc
      write(nulout,*) 'su1obsbg: rptopinc = ',rptopinc
      write(nulout,*) 'su1obsbg: rprefinc = ',rprefinc
      write(nulout,*) 'su1obsbg: rcoefinc = ',rcoefinc
!
      call calcpres(rppobs(1,1),vhybinc,nflev,zps,rptopinc
     &             ,rprefinc,rcoefinc,1)
      write(nulout,*) 'su1obsbg: zps(1) = ',zps(1)
      do jlev = 1,nflev
        write(nulout,*) 'su1obsbg: RPPOBS(jlev,1) = ',RPPOBS(jlev,1)
      enddo
!
      rmtmobs(1) = gomgzg(nflev,1)
!
      return
      end