!-------------------------------------- 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 --------------------------------------
!
!
!  X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
!

      subroutine pc2UVg_c(pum,pvm,psi,chi) 2,6
!
!**s/r pc2UVg_c  - Compute gridpoint wind images (U,V) from gridpoint (psi,chi)
!
!Author  : Luc Fillion - CGD/NCAR - 7 sept 99
!Revision: Luc Fillion - MSC/CAN - 15 oct 2004 -GEM Arakawa-C grid.
!
!     -------------------
!*    Purpose: To build gridpoint analysis increments during 4D-Var.
!
!Arguments
!
      IMPLICIT NONE
#include "taglam4d.cdk"
#include "pardim.cdk"
#include "comdim.cdk"
#include "comgrd_param.cdk"
#include "comcst.cdk"
#include "comct0.cdk"
#include "comsim.cdk"
#include "comgemla.cdk"
!
      real*8 pum(0:ni+1,nflev,0:nj+1)
      real*8 pvm(0:ni+1,nflev,0:nj+1)
      real*8 psi(ni,nflev,nj)
      real*8 chi(ni,nflev,nj)
!
      integer ji,jj,jk,idim,idum1,idum2,idum3,idum4
      integer ip1,jp1
      INTEGER myid,numthd,omp_get_thread_num,omp_get_num_threads
      real*8 zdlon,zdx,ztheta,ztheta1,zmin,zmax
      real*8 zcos2(0:nj+1),zcos2h(0:nj+1)
      real*8 zpsi(-1:ni+2,nflev,-1:nj+2)
      real*8 zchi(-1:ni+2,nflev,-1:nj+2)
!
!!
      idim=(ni+2)*(nj+2)*nflev
      call zero(idim,pum)
      call zero(idim,pvm)
!
      ip1=ni+4
      jp1=nj+4
      idim=ip1*jp1*nflev
      call zero(idim,zpsi)
      call zero(idim,zchi)
!
      zdlon=rdlon_an(1,1)
      zdx=1./(ra*zdlon)
!
      do jj=0,nj+1
        zcos2(jj)=r1mmu2(jj)/(ra*rdmuh(jj-1))
        zcos2h(jj)=r1mmu2h(jj)/(ra*rdmu(jj))
      enddo
!
! symmetrize
!
      call symmetrize(zpsi,psi,ni,nj,nflev)
      call symmetrize(zchi,chi,ni,nj,nflev)
!
! Compute Wind-Images
!
!$OMP PARALLEL PRIVATE(ji,jj,jk,myid,numthd)
      myid=omp_get_thread_num()+1
      numthd=omp_get_num_threads()
      do jk = myid,nflev,numthd
        do jj=1,nj+1
        do ji=0,ni
          pum(ji,jk,jj)=zdx*(zchi(ji+1,jk,jj)-zchi(ji,jk,jj))
     &                -zcos2(jj)*( zpsi(ji,jk,jj)-zpsi(ji,jk,jj-1) )
        enddo
        enddo
!
        do jj=0,nj
        do ji=1,ni+1
          pvm(ji,jk,jj)=zcos2h(jj)*(zchi(ji,jk,jj+1)-zchi(ji,jk,jj))
     &              +zdx*( zpsi(ji,jk,jj)-zpsi(ji-1,jk,jj) )
        enddo
        enddo
      enddo
!$OMP END PARALLEL
!
      return
      end