      PROGRAM pscor 
*************************************************************************
* corrects s and p reflectivity or transmission data files for nonideal
* properties of the polarizer. A frequency dependency of the ratio
* T(wrong polarization)/T(correct polarization) should be provided.
* Make sure that all three input files have the same set of x-values.
* The program lump should be used to ensure this.
**************************************************************************
      REAL X(100000),e1,e2,pi,phi,csp2,snp2,rp(100000),rs(100000)
     *     ,rpp,rss,f(100000)
      CHARACTER*40 flinp,flins,flf,flss,flpp                                          
      INTEGER I,mm    
      read(*,'(a40)') flins
      read(*,'(a40)') flinp
      read(*,'(a40)') flf     
      read(*,'(a40)') flss
      read(*,'(a40)') flpp 
      OPEN(23,FILE=flins)
      OPEN(24,FILE=flinp)
      open(15,file=flf)
      OPEN(13,FILE=flss)                                      
      OPEN(14,FILE=flpp)  
      mm=100000 
      do 10 i=1,mm                                                  
       READ(15,*,END=11) X(i),f(i)
10    continue   
11    mm=i-1
      do 20 i=1,mm                                                  
       READ(23,*) X(i),rs(i)
20    continue  
      do 23 i=1,mm 
       read(24,*) x(i),rp(i)
23    continue
      do 30 i=1,mm
       rpp=(rp(i)-f(i)*rs(i))/(1.-f(i))
       rss=(rs(i)-f(i)*rp(i))/(1.-f(i))
       write(13,*) x(i),rss
       write(14,*) x(i),rpp
30    continue
      close(23)
      close(24)
      close(13)
      close(14)
      close(15)
      close(17)       
      END 
 

