      dimension x(2048),p(2048)
      character id*56, pgm*8, ifile*50
      print *,'enter x-derivative file:'
      read(5,100) ifile
  100 format(a)
      open(10,file=ifile,form='unformatted',status='old')
      read(10) id,pgm,nc,nr,nz,xo,dx,yo,dy
      print *,'enter y-derivative file:'
      read(5,100) ifile
      open(11,file=ifile,form='unformatted',status='old')
      read(11) id,pgm,nc,nr,nz,xo,dx,yo,dy
      print *,'enter output file:'
      read(5,100) ifile
      open(12,file=ifile,form='unformatted',status='new')
      pgm='hgrad   '
      id='horizontal gradient magnitude'
      write(12) id,pgm,nc,nr,nz,xo,dx,yo,dy
      do 20 j=1,nr
      read(10) dlx,(x(i),i=1,nc)
      read(11) dlx,(p(i),i=1,nc)
      do 10 i=1,nc
   10 p(i)=sqrt(p(i)**2+x(i)**2)
      write(12) dlx,(p(i),i=1,nc)
   20 continue
      stop
      end
      subroutine spline(f,p,n,dx)
      dimension f(n),p(n),c(2048),d(2048)
      c(1)=.5
      d(1)=1.5*(f(2)-f(1))/dx
      n1=n-1
      do 10 i=2,n1
      dnm=(4.0-c(i-1))*dx
c      print *,'dnm = ',dnm,' d(i-1) = ',d(i-1)
      c(i)=dx/dnm
   10 d(i)=(3.0*(f(i+1)-f(i-1)) - dx*d(i-1))/dnm
c      print *,'c(n1) = ',c(n1)
      p(n)=(3.*(f(n)-f(n1))/dx - d(n1))/(2.-c(n1))
      do 9 i=1,n1
      k=n-i
    9 p(k)=d(k)-c(k)*p(k+1)
      return
      end

