program merge
use sep
implicit none

integer             :: n1,n2,n3,n4,n5,esize,m,i5
real                :: d1,d2,d3,d4,d5,o1,o2,o3,o4,o5
complex,allocatable :: data(:,:,:)

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 from_history("n4",n4); call from_history("d4",d4); call from_history("o4",o4)
call from_history("n5",n5); call from_history("d5",d5); call from_history("o5",o5)
call from_history("esize",esize)

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)
call to_history("n4",n4); call to_history("d4",d4); call to_history("o4",o4)
call to_history("n5",2*n5-1); call to_history("d5",d5); call to_history("o5",-((n5-1)*d5+o5))
call to_history("esize",esize);call to_history("label3","")
allocate(data(n1,n2,n3));data=0
do i5=1,2*n5-1
   call srite("out", data, 8*n1*n2*n3)
end do
call sreed("in", data, 8*n1*n2*n3)
call srite_window("out",5,(/n1,n2,n3,1,2*n5-1/),(/n1,n2,n3,1,1/),(/0,0,0,0,n5-1/),(/1,1,1,1,1/),8,data) 
do i5=2,n5
   call sreed("in", data, 8*n1*n2*n3)
   write(0,*) i5,n5+i5-2,n5-i5
   call srite_window("out",5,(/n1,n2,n3,1,2*n5-1/),(/n1,n2,n3,1,1/),(/0,0,0,0,n5+i5-2/),(/1,1,1,1,1/),8,data) 
   call srite_window("out",5,(/n1,n2,n3,1,2*n5-1/),(/n1,n2,n3,1,1/),(/0,0,0,0,n5-i5/),(/1,1,1,1,1/),8,data) 
end do
deallocate(data)
call sep_end_prog()
end program
