program owimgscale

use sep
implicit none
real,allocatable                    :: data(:,:,:), a(:)
integer                             :: i1,i2,i3,i4,n1,n2,n3,n4
real                                :: d1,d2,d3,d4,o1,o2,o3,o4

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 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("eout",4);call to_history("label3","")
allocate(data(n1,n2,n3),a(n1))
do i4=1,n4
  call sreed("in", data, 4*n1*n2*n3)
  a=tiny(1.)
  do i1=1,n1;do i2=1,n2;do i3=1,n3;
     if (abs(data(i1,i2,i3)) > a(i1)) a(i1)=abs(data(i1,i2,i3))
  end do;end do;end do
  do i1=1,n1
     if(a(i1).ne.0)  data(i1,:,:)=data(i1,:,:)/a(i1)
  end do
  call srite("out", data, 4*n1*n2*n3)
end do
deallocate(data,a)
call sep_end_prog()
end program
