program ray_view
  use sep
  real, pointer :: buf_in(:,:,:)
  real, pointer :: buf_out(:,:,:)
  integer :: nt,nang,npts,n1,i3,nbuf
  integer :: plane,done,todo
  call sep_init()
  call from_history("n1",n1)
  call from_history("n2",npts)
  call from_param("plane",plane,13)
  if(.not.(plane==13 .or. plane ==12 .or. plane ==23)) then
     call seperr("plane must be 13,12, or 23")
  end if
  call to_history("esize",8)
 
  nt=n1/3
 write(0,*) "CHECK",n1,nt
 call to_history("n1",nt)
  call from_param("nbuf",nbuf,10000)
  if(nbuf > npts) nbuf=npts
  allocate(buf_in(3,nt,nbuf))
  allocate(buf_out(2,nt,nbuf))
  done =0
  do while(done < npts)
    todo=min(npts-done,nbuf)
     call sreed("in",buf_in,12*nt*todo)
     if(plane==12) then
       do i2=1,todo
         do i1=1,nt
            buf_out(1,i1,i2)=buf_in(1,i1,i2)
            buf_out(2,i1,i2)=buf_in(2,i1,i2)
         end do
       end do
     else if(plane==13) then
       do i2=1,todo
         do i1=1,nt
            buf_out(1,i1,i2)=buf_in(1,i1,i2)
            buf_out(2,i1,i2)=buf_in(3,i1,i2)
         end do
       end do  
     else if(plane==23) then
       do i2=1,todo
         do i1=1,nt
            buf_out(1,i1,i2)=buf_in(2,i1,i2)
            buf_out(2,i1,i2)=buf_in(3,i1,i2)
         end do
       end do
     end if
     done=done+todo
     call srite("out",buf_out,8*nt*todo)
   end do
  



end program