      PROGRAM etorp
*************************************************************************
* Conversion of dielectric functions to p-and s- reflectivity.          *
* from standard input it reads 
* input file name for epsilon for the ordinary and extraordinary directions.
* angle of incidence in degree
* the lightray scatters in the yz plane
* z is the surface normal
* for s-polarization E parr x
* for p-polarization E parr yz
* the  input files must have the format x e1x e2x e1y e2y e1z e2z       *
* The output comes as: x  real(crs) aimag(crs) real(crp) aimag(crp)     *
*************************************************************************
      REAL X(100000),e1x,e2x,e1y,e2y,e1z,e2z,angle,cst,snt2
      complex epsilx(100000),epsily(100000),epsilz(100000),cn,cb,crp,crs
      INTEGER I,mm
      character*40 flin
      read(*,'(a40)') flin
      open(23,file=flin)
      read(*,*) angle
      angle=angle*3.14159265/180 
      cst=cos(angle)
      snt2=1-cst*cst   
      mm=100000 
      do 10 i=1,mm                                                  
       READ(23,*,END=11) X(i),e1x,e2x,e1y,e2y,e1z,e2z
       epsilx(i)=cmplx(e1x,e2x)
       epsily(i)=cmplx(e1y,e2y)
       epsilz(i)=cmplx(e1z,e2z)
10    continue
      close(23)   
11    mm=i-1
      do 25 i=1,mm
       cn=csqrt(epsilz(i)-snt2)
       cb=csqrt(epsilz(i))*csqrt(epsily(i))*cst
       crp=(cb-cn)/(cb+cn)
       cn=csqrt(epsilx(i)-snt2)
       crs=(cst-cn)/(cst+cn)
       write(*,*) x(i),real(crs),aimag(crs),real(crp),aimag(crp)
25    continue
      END  

