      subroutine rmpatch(trans,slope,inter,nnn,nl,nls,r0,delr,wavl,vel,
     .     fd,fdd,fddd,prf,ideskew)

        integer*4 mmm,nmax,mmax
        real*4 pi, pi2
        parameter (mmm=6144, nmax=4096,mmax= 30)
        parameter (pi=3.14159625265359,pi2=6.28318530718)
        real*8     r0,delr,wavl,fd,fdd,fddd, slope, inter, tmpd, tmpdd
        real*8     rd0(mmm)
        real*4        vel,prf
        integer*4     nfilter, nnn, nl, nls,ideskew
        real*4        xintp
	real*4        frac, ratio
	integer*4     na,nr,i,j,ifrac, n, k
	complex*8     trans(nnn,nl)

        real*4 tmpv
 
        integer firsttime
        real*4 f0(mmm), f_rate(mmm),bdel(mmm)
	real*8 r(mmm)
        real*4 vtmp(mmm)
        integer nvtmp(mmm)
 
        data firsttime/1/
        save firsttime

        common /intp/ xintp(0:65544), nfilter

        complex*8 c_ctmpb(8)
        real*4    c_xintp(8)
        complex*8 c_ctmpa(mmm)

c initializations        

c     load the interpolation array

        if(firsttime .eq. 1) then
           nfilter = 8192
           call intp_coef(nfilter,xintp)
           firsttime=0
c          write(6,*) 'sinc initialized '
        end if

        dx = vel/prf
        v1 =wavl**2/(8.*dx**2)
        do i = 1, nl
           r(i)      = r0 + (i-1)*delr !range to the line
           f0(i)     = fd+fdd*r(i)+fddd*r(i)*r(i) !Doppler centroid
           rd0(i)    = r(i)/(1 + v1*(f0(i)/prf)**2)
           f_rate(i) = -2.d0 * vel**2*(rd0(i)/r(i))**2/(wavl*r(i))
           bdel(i)   = slope * r(i) + inter
        end do
        
c        type *, 'linear arrays computed '
	do na = 1,nnn

c get the interpolation amounts for a given azimuth pixel na as f(line)
              freq=(na-1)/float(nnn)*prf 
              do i = 1,nl
c     frequencies must be within 0.5*prf of centroid
                 ratio = (freq-f0(i))/prf
                 n = nint(ratio)
                 freq = freq - n * prf
c     range of a pixel at freq f, bdel is range correction for interferogram
                 
                 if(ideskew.eq.1)then
c  deskewing
                    tmpd = bdel(i)+ ((r(i)-(wavl/4.)*f0(i)**2/
     $                f_rate(i))-r(1))/delr +
     $                rd0(i)*(v1/delr)*(freq**2-f0(i)**2)/prf**2
                 else
c  not deskewing
                    tmpd  = i + rd0(i)*(v1/delr)*(freq**2-f0(i)**2)/prf**2
     $                + bdel(i)
                 end if
c                 type *, 'old/new tmpd ', i, tmpdd, tmpd
                 nvtmp(i) = int(tmpd)
                 vtmp(i) = tmpd - int(tmpd)
              enddo
c           type *, 'vtmp computed'

c  interpolate that line according to coeffs determined above
              do i=1,nl
                 c_ctmpa(i)=cmplx(0.,0.)
                 if(nvtmp(i).ge.4 .and. nvtmp(i).lt.(nl-4)) then
                       frac = vtmp(i)
                       ifrac= 8*nint(frac*float(nfilter))
                       do k = 1 , 8
                          c_xintp(k) = xintp(ifrac+k-1)
                          c_ctmpb(k) = trans(na,nvtmp(i)+1-3+k-1)
                      end do
                       c_ctmpa(i)=c_ctmpb(1)*c_xintp(1)
     2                      +c_ctmpb(2)*c_xintp(2)
     3                      +c_ctmpb(3)*c_xintp(3)
     4                      +c_ctmpb(4)*c_xintp(4)
     5                      +c_ctmpb(5)*c_xintp(5)
     6                      +c_ctmpb(6)*c_xintp(6)
     7                      +c_ctmpb(7)*c_xintp(7)
     8                      +c_ctmpb(8)*c_xintp(8)
                    endif
              enddo
              do i = 1, nl
                 trans(na,i) = c_ctmpa(i)
              end do
c           type *, 'interpolation computed'

	enddo                   ! na-loop

999     return
	end

