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

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

      complex*8 trans(nnn,nlinesaz),ref(ranfft*2),tmp(ranfft)
      
      write(*,*)'I/Q range starting record, pixel: ',irec,ifrst
      if(iflip.ne.0.and.iflip.ne.1)then
         write(*,*)'I/Q flip error!'
         stop
      end if
      if(iflip.eq.1)write(*,*)'Flipping i/q data...'

      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/2-ifrst
            tmp(i)=
     1        cmplx(unpacki(1+iand(255,inbuf(((i+ifrst)*2-1+iflip)))),
     $              unpackq(1+iand(255,inbuf(((i+ifrst)*2-iflip)))))
         end do
         do i=ngood/2-ifrst+1,ranfft
            tmp(i)=cmplx(0.,0.)
         end do

         call cfft1d(ranfft,tmp,-1)

         do i=1,ranfft
            tmp(i)=tmp(i)*ref(i)
         end do

         call cfft1d(ranfft,tmp,1)

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

      return
      end



