
       subroutine getv(cvsct,ntxpol,nrxpol,nrcs,s)
c
c subroutine to compute the scattered voltage (s) , given the
c scattering matrix (cvsct)
c polarization index: 1=v   2=h   3=r   4=l
c the array cvsct contains the following:
c      cvsct(1:2,1:2,i) = vv   vh   hv   hh  scattering voltages
c where a scattering voltage is 
c     cv = e_sct * e_rec
c
       integer ntxpol, nrxpol, nrcs
       complex cvsct(2,2,nrcs), s(nrcs), cj
       real sq2
       integer j

       cj = cmplx(0.,1.)
       sq2 = sqrt(2.)

c  there are 16 cases to consider. 

       go to (100,200,300,400) ntxpol

 100   continue		!tx = v
       go to (110,120,130,140) nrxpol
 110   continue
         do j = 1,nrcs
            s(j) = cvsct(1,1,j)					!vv
         enddo
         go to 999
 120   continue
         do j = 1,nrcs
            s(j) = cvsct(1,2,j)					!vh
         enddo
         go to 999
 130   continue
         do j = 1,nrcs
            s(j) = (cvsct(1,1,j) + cj*cvsct(1,2,j))/sq2		!vr
         enddo
         go to 999
 140   continue
         do j = 1,nrcs
            s(j) = (cvsct(1,1,j) - cj*cvsct(1,2,j))/sq2		!vl
         enddo
         go to 999

 200   continue		!tx = h
       go to (210,220,230,240) nrxpol
 210   continue
         do j = 1,nrcs
            s(j) = cvsct(2,1,j)					!hv
         enddo
         go to 999
 220   continue
         do j = 1,nrcs
            s(j) = cvsct(2,2,j)					!hh
         enddo
         go to 999
 230   continue
         do j = 1,nrcs
            s(j) = (cvsct(2,1,j) + cj*cvsct(2,2,j))/sq2		!hr
         enddo
         go to 999
 240   continue
         do j = 1,nrcs
            s(j) = (cvsct(2,1,j) - cj*cvsct(2,2,j))/sq2		!hl
         enddo
         go to 999


 300   continue		!tx = r
       go to (310,320,330,340) nrxpol
 310   continue
         do j = 1,nrcs
            s(j) = (cvsct(1,1,j) + cj*cvsct(2,1,j))/sq2		!rv
         enddo
         go to 999
 320   continue
         do j = 1,nrcs
            s(j) = (cvsct(1,2,j) + cj*cvsct(2,2,j))/sq2		!rh
         enddo
         go to 999
 330   continue
         do j = 1,nrcs
            s(j) = (cvsct(1,1,j) - cvsct(2,2,j) +   		!rr
     %          cj*(cvsct(2,1,j) + cvsct(1,2,j)))/2.
         enddo
         go to 999
 340   continue
         do j = 1,nrcs
            s(j) = (cvsct(1,1,j) + cvsct(2,2,j) +   		!rl
     %          cj*(cvsct(2,1,j) - cvsct(1,2,j)))/2.
         enddo
         go to 999


 400   continue		!tx = l
       go to (410,420,430,440) nrxpol
 410   continue
         do j = 1,nrcs
            s(j) = (cvsct(1,1,j) - cj*cvsct(2,1,j))/sq2		!lv
         enddo
         go to 999
 420   continue
         do j = 1,nrcs
            s(j) = (cvsct(1,2,j) - cj*cvsct(2,2,j))/sq2		!lh
         enddo
         go to 999
 430   continue
         do j = 1,nrcs
            s(j) = (cvsct(1,1,j) + cvsct(2,2,j) -   		!lr
     %          cj*(cvsct(2,1,j) - cvsct(1,2,j)))/2.
         enddo
         go to 999
 440   continue
         do j = 1,nrcs
            s(j) = (cvsct(1,1,j) - cvsct(2,2,j) -   		!ll
     %          cj*(cvsct(2,1,j) + cvsct(1,2,j)))/2.
         enddo
         go to 999


 999   continue	
       return
       end

       subroutine gethinc(chinc,ntxpol,nrcs,htheta,hphi)
c
c purpose: to compute the incident h-field for polarization (ntxpol)
c          where ntxpol means  1=v   2=h   3=r   4=l. 
c          the incident h-fields for v-pol & h=pol (theta & phi components)
c
       integer ntxpol, nrcs, j
       real sq2
       complex chinc(2,2,nrcs),htheta(nrcs),hphi(nrcs)
       complex cj

       cj = cmplx(0.,1.)
       sq2 = sqrt(2.)

       if(ntxpol.eq.1) then		!v pol
          do j = 1,nrcs
            htheta(j) = chinc(1,1,j)
            hphi(j)  =  chinc(2,1,j)
          enddo
       elseif(ntxpol.eq.2) then		!h pol
          do j = 1,nrcs
            htheta(j) = chinc(1,2,j)
            hphi(j)  =  chinc(2,2,j)
          enddo
       elseif(ntxpol.eq.3) then		!r pol
          do j = 1,nrcs
            htheta(j) = (chinc(1,2,j) + cj*chinc(1,1,j))/sq2
            hphi(j)  =  (chinc(2,2,j) + cj*chinc(2,1,j))/sq2
          enddo
       elseif(ntxpol.eq.4) then		!l pol
          do j = 1,nrcs
            htheta(j) = (chinc(1,2,j) - cj*chinc(1,1,j))/sq2
            hphi(j)  =  (chinc(2,2,j) - cj*chinc(2,1,j))/sq2
          enddo
       endif

        return
        end
