program stackout
use sep
  implicit none
  integer :: j1,i1,j2,i2,i3,j3,a,b,c,d,i,j,k,k1,k2,k3,ompi,ompn,nof
  integer :: n1,n2,n3,n4,n5,esize,n1out,blck,nb,er,nf,nt,trace
  real    :: o1,o2,o3,d1,d2,d3,df,maxf,minf,mem,scale,min1,max1,dt
  complex   , pointer,dimension(:,:)  :: data,data2
  real   , pointer,dimension(:,:)  :: rdata,rdata2
 
call sep_init()
call from_history("esize",esize)
call from_history ("n1",n1);call from_history ("n2",n2);call from_history ("n3",n3)
call to_history("n3",1)
call sep_close()
if(esize==8) then
   allocate(data(n1,n2)); data=0.
   allocate(data2(n1,n2)); data2=0.
   do i3=1,n3
      call sep_read(data)
      data2=data2+data/n3
   end do
   call sep_write(data2)
else
   allocate(rdata(n1,n2)); data=0.
   allocate(rdata2(n1,n2)); data2=0.
   do i3=1,n3
      call sep_read(rdata)
      rdata2=rdata2+rdata/n3
   end do
   call sep_write(rdata2)
end if

end program stackout
   
