!-------------------------------------- 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 gradfld(pgradx,pgrady,pfld) 2,4
!
!**s/r gradfld  - Compute gridpoint Gradient vector from input gridpoint field.
!
!Author  : Luc Fillion - CGD/NCAR - 23 Sep 2005.
!Revision: 
!
!     -------------------
!*    Purpose: 
!
!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 pgradx(ni,nj)
      real*8 pgrady(ni,nj)
      real*8 pfld(ni,nj)
!
      integer ji,jj,jk,idim
      integer ip1,jp1
      real*8 zdlon
      real*8 zdx(0:nj+1)
      real*8 zdy(0:nj+1)
      real*8 zfld(-1:ni+2,-1:nj+2)
!
!!
      idim=(ni+2)*(nj+2)
      call zero(idim,pgradx)
      call zero(idim,pgrady)
!
      ip1=ni+4
      jp1=nj+4
      idim=ip1*jp1
      call zero(idim,zfld)
!
      zdlon=rdlon_an(1,1)
!
      do jj=0,nj+1
        zdx(jj) = rrcos_an(1,jj)/(ra*zdlon)
        zdy(jj)=1.0/(rrcos_an(1,jj)*ra*rdmuh(jj-1))
      enddo
!
! symmetrize
!
      call symmetrize(zfld,pfld,ni,nj,1)
!
      do jj=1,nj
      do ji=1,ni
        pgradx(ji,jj) = zdx(jj)*( zfld(ji,jj)-zfld(ji-1,jj) )
      enddo
      enddo
!
      do jj=1,nj
      do ji=1,ni
        pgrady(ji,jj) = zdy(jj)*( zfld(ji,jj)-zfld(ji,jj-1) )
      enddo
      enddo
!
      return
      end