program OW_windowing

use sep
use OW_type
use OW_parms_areal
use OW_shaper

implicit none
character*80                                      :: hor
real, allocatable				:: temp(:,:,:),pick(:,:,:)
integer					:: ikx,ih,par1(3),k,i,n

call sep_init()
call sep_begin_prog()

 call from_param("nhorz",nhorz)
 call from_history("n1",sog%xm%n);call from_history("d1",sog%xm%d);call from_history("o1",sog%xm%o)  
 call from_history("n2",sog%sh%n);call from_history("d2",sog%sh%d);call from_history("o2",sog%sh%o)
 call from_history("n3",sog%z%n);call from_history("d3",sog%z%d);call from_history("o3",sog%z%o)
 call to_history("n1",sog%xm%n);call to_history("d1",sog%xm%d);call to_history("o1",sog%xm%o)  
 call to_history("n2",sog%sh%n);call to_history("d2",sog%sh%d);call to_history("o2",sog%sh%o)
 call to_history("n3",sog%z%n);call to_history("d3",sog%z%d);call to_history("o3",sog%z%o)
 call to_history("n4",nhorz);call to_history("d4",1.);call to_history("o4",1.)  
 call to_history("eout",4);call to_history("label3","")

!--------------------------------------------------
!
! Read rotated CIGs
!
allocate(pick(sog%xm%n,sog%sh%n,nhorz));pick=9999.
call from_param('hor1',hor)
open(51,file=hor,status='old')
read(51,*,end=1) par1
do i=1,nhorz
   if (i.eq.1) then
      do n=1,par1(2)
         read(51,*,end=1) pick(par1(1)+n-1,:,i)
         pick(par1(1)+n-1,:,i)=pick(par1(1)+n-1,:,i)+par1(3)
      end do
   end if
end do
1 close(51)
allocate(temp(sog%xm%n,sog%sh%n,sog%z%n));temp=0
do i=1,nhorz
  call sreed("in",temp,4*sog%z%n*sog%xm%n*sog%sh%n)
  do ih=1,sog%sh%n
     do ikx=1,sog%xm%n
        if (int(pick(ikx,ih,i)).ne.9999) then
           k=int(pick(ikx,ih,i))
           call owpeak(temp(ikx,ih,:),k)
        end if
     end do
  end do
call srite("out",temp,4*sog%z%n*sog%xm%n*sog%sh%n)
end do
deallocate(temp)

call sep_end_prog()
end program
