      PROGRAM etosig
*************************************************************************
* Conversion of pseudo dielectric functions to dielectric function.     *
* this one is for p-polarized light, with isotropic epsilon, so that    *
* sqrt(eps(pseudo))=eps cos(teta) / sqrt( eps - sin^2(teta))            *
* from standard input it reads 
* inputfilename
* angle of incidence
* the standard input file must have the format x eps1 eps2              *
* The outputfile comes as: x e1,e2,e1',e2'                              *
*************************************************************************
      REAL X(100000),e1,e2,phi,pi,csp2,tgp2
      complex epsil(100000),ep,em,ca,cb
      CHARACTER*40 flin
      INTEGER I,mm    
      read(*,'(a40)') flin
      read(*,*) phi
      pi=4*atan(1.)
      phi=phi*pi/180.
      csp2=(cos(phi))**2
      tgp2=(tan(phi))**2
      open(23,FILE=flin)                                      
      mm=100000 
      do 10 i=1,mm                                                  
       READ(23,*,END=11) X(i),e1,e2
       epsil(i)=cmplx(e1,e2)
10    continue   
11    mm=i-1
      close(23)
      do 25 i=1,mm
       ca=0.5*epsil(i)/csp2
       cb=ca*csqrt(1-epsil(i)*tgp2/(ca*ca))
       ep=(ca+cb)
       em=(ca-cb)
       write(*,*) x(i),real(ep),aimag(ep),real(em),aimag(em)
25    continue
      END  

