program OW_trcedit

use sep

!implicit none

character*80                  :: hor1
real			:: o1,o2,o3,d1,d2,d3
integer			:: i1,i2,i3,n1,n2,n3
integer, allocatable          :: pick1(:,:)
real,allocatable		:: in(:,:,:)

call sep_init()
call sep_begin_prog()

call from_history("n1",n1); call from_history("d1",d1); call from_history("o1",o1)
call from_history("n2",n2); call from_history("d2",d2); call from_history("o2",o2)
call from_history("n3",n3); call from_history("d3",d3); call from_history("o3",o3)
call to_history("n1",n1); call to_history("d1",d1); call to_history("o1",o1)
call to_history("n2",n2); call to_history("d2",d2); call to_history("o2",o2)
call to_history("n3",n3); call to_history("d3",d3); call to_history("o3",o3)

allocate(in(n1,n2,n3));in=0;
call sreed("in",in,4*n1*n2*n3)

!call from_param("zero",zero,.true.)

!!!!!!!
! horizon
call from_param('hor1',hor1)
open(51,file=hor1,status='old')
allocate(pick1(n3,5));pick1=9999.
do i3=1,n3
   read(51,*,end=1) pick1(i3,:)
end do
1  close(51)
m3=i3-1
do i3=1,m3
   in(:,:,pick1(i3,1)+1)=0.
end do
do i3=1,m3
   in(:,:,pick1(i3,1)+1)=(in(:,:,pick1(i3,1))+in(:,:,pick1(i3,1)+2))/2
end do
call srite("out",in,4*n1*n2*n3)
deallocate(in)
call sep_end_prog()
end program
