c
c
c***********************************************************************
C----------------------------------------------------------------------
      subroutine metric(nt)
c***********************************************************************
c
      include 'comm.inc'
c 
      data eps /1.e-26/
c***********************************************************************
      nt = 1
 
      do 100 i=1,imx(nt)
        im1 = i - 1
        ip1 = i + 1
      do 100 k = 1,kmx(nt)

        if( i .eq. 1 ) then
          xxi = x(2,k) - x(1,k)
          zxi = z(2,k) - z(1,k)
        elseif( i .eq. imx(nt) ) then
          xxi = x(imx(nt),k) - x(imx1(nt),k)
          zxi = z(imx(nt),k) - z(imx1(nt),k)
	else
          xxi = 0.5 * ( x(ip1,k) - x(im1,k) )
          zxi = 0.5 * ( z(ip1,k) - z(im1,k) )
	endif

        if( k .eq. 1 ) then
          xze = 2.*x(i,2) - 1.5*x(i,1) - 0.5*x(i,3)
          zze = 2.*z(i,2) - 1.5*z(i,1) - 0.5*z(i,3)
        elseif( k .eq. kmx(nt) ) then
          xze = 1.5*x(i,kmx(nt)) - 2.*x(i,kmx1(nt)) + 0.5*x(i,kmx2(nt))
          zze = 1.5*z(i,kmx(nt)) - 2.*z(i,kmx1(nt)) + 0.5*z(i,kmx2(nt))      
        else
          km1 = k - 1
          kp1 = k + 1
          xze = 0.5 * ( x(i,kp1) - x(i,km1) )
          zze = 0.5 * ( z(i,kp1) - z(i,km1) )
        endif
c
        xix(i,k) = zze
        xiz(i,k) =-xze
        zex(i,k) =-zxi
        zez(i,k) = xxi

        yacob = ( xxi*zze - xze*zxi ) 
        if ( yacob .eq. 0. ) then
	   print *, 'zero jac at ', i,k
           yacob = eps
        endif
        vol(i,k) = 1.0 / yacob
100   continue            

c
c***********************************************************************
c         compute max and min values of jacobian and check for
c         negative values
c***********************************************************************
c
      ajmax       = -1.0e35
      ajmin       =  1.0e35
      do 63 k = 1,kmx(nt)
      do 63 i = 1,imx(nt)
      ajmax       = max( ajmax, vol(i,k) )
      ajmin       = min( ajmin, vol(i,k) )
   63 continue
      write(6,602) ajmax,ajmin
 
c..write negative jacobians and stop
      if( ajmin.lt.0.0 ) then
          do 64 k = 1,kmx(nt)
          do 64 i = 1,imx(nt)
          if( aja(i,k).lt.0.0 ) then
              write(6,603) vol(i,k), i, k
	      stop
          end if
   64 continue
      end if
c
  602 format( ' The range of the jacobian is: ',
     >          ' jmax = ',e10.3,5x,'jmin =  ',e10.3,/    )
  603 format( ' ',10x,'negative jacobian = ',e10.3,1x,'at i,k =',
     >                 2i5 )
c-----
c   end of metric
c----- 
      return
      end 
