program ampick
use sep
implicit none
logical                       :: maxamp
integer			:: i1,i2,i3,n1,n2,n3,stat
real                          :: o1,o2,o3,d1,d2,d3
real, allocatable	          :: in(:,:),out(:)

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",n2); call to_history("d1",d2); call to_history("o1",o2)
call to_history("n2",n3); call to_history("d2",d3); call to_history("o2",o3)
call to_history("n3",1); call to_history("d3",1.); call to_history("o3",0.)
call to_history("eout",4);call to_history("label3","")
allocate(in(n1,n2),out(n2))
call from_param("maxamp",maxamp,.true.)
do i3=1,n3
   call sreed("in",in,4*n1*n2) 
   out=0
   if (maxamp) then
      do i2=1,n2
         out(i2)=maxval(in(:,i2))
      end do
   else
      do i2=1,n2
         out(i2)=minval(in(:,i2))
      end do
   end if
   call srite("out",out,4*n2)
end do
deallocate(in,out)
call sep_end_prog()
end program
