      subroutine rcov(fdsc,nnn,nlinesaz,trans,unpacki,unpackq,
     1     ref,irec,ifrst,nbytes,ngood)

      implicit none
      integer*4 ranfft
      parameter (ranfft=16384)
      integer*4 nnn,irec,ifrst,nbytes,ngood,fdsc,nlinesaz,i,j,k
      integer*4 nseek, nread, ioseek, ioread
      byte      inbuf(16384)
      real*4    unpacki(256),unpackq(256),t0,t1,secnds

      complex*8 trans(nnn,nlinesaz),ref(ranfft),tmp(ranfft)
      
      write(*,*)'O/V range starting record, pixel: ',irec,ifrst

      do j = 1, nnn
         if(mod(j,1024).eq.1)write(*,*)'Line ',j
         nseek = ioseek(fdsc,(j-1+irec-1)*nbytes)
         nread = ioread(fdsc,inbuf,nbytes)

         do i=1,ngood-ifrst
            tmp(i)=cmplx(unpacki(iand(1+inbuf(i+ifrst),255)),0.)
         end do
         do i=ngood-ifrst+1,ranfft
            tmp(i)=cmplx(0.,0.)
         end do

         call cfft1d(ranfft,tmp,-1)
         
c  baseband the resulting spectrum since input is offset video
         do i=1,ranfft/4
            tmp(i)=tmp(i+3*ranfft/4)*ref(i+3*ranfft/4)
         end do
         do i=1,ranfft/4
            tmp(i+ranfft/4)=tmp(i+ranfft/2)*ref(i+ranfft/2)
         end do

         call cfft1d(ranfft/2,tmp,1)

         do i=1,nlinesaz
            trans(j,i)=tmp(i)
         end do
      end do

      return
      end



