prpgram killwave
  use OW_parms_areal
  use OW_type
  use killwave_mod
  use killwave_ns
  implicit none
!!
!infile=in.H verb=2 verb1=1 nfilt=9 nang=40 dip=dip1.H destroy=n outfile=outfile5
!!

  real, allocatable, dimension(:)                   :: indips, infile
  real, allocatable, dimension(:)                   :: dips_,infile_
  integer                                           :: i,j,k

  call sep_init()
  call sep_begin_prog()
 
  call dip_params()

  allocate(indips(img%z%n*img%xm%n), infile(img%z%n*img%xm%n))
  allocate(dips_(img%z%n*img%xm%n), infile_(img%z%n*img%xm%n))

  call sreed("infile",infile,4*img%z%n*img%xm%n)
  call sreed("indips",indips,4*img%z%n*img%xm%n)

  do k=1,img%z%n
     do i=1,img%xm%n
        infile_((i-1)*img%z%n+k)=infile((k-1)*img%xm%n+i)
        dips_((i-1)*img%z%n+k)  =indips((k-1)*img%xm%n+i)
     end do
  end do
  infile=infile_
  infile_=0.

  call killA_init(nang,nfilt)
  call killwave_io_init(nang,nfilt) 
  call ns_init(dips_)
  call solver_reg( m=infile_,d=infile, Fop=ns_lop, Aop=laplac2_lop, stepper=cgstep, nAop=img%xm%n*img%z%n, &
                 niter=niter,eps=eps,verb=.true.)!,rm0,err,resd,resm,mmov,rmov,verb)
!!              call solver_prc( m=scatS,d=B_image, Fop=owwemva_lop, Sop=laplac2_lop, stepper=cgstep, nSop=img%xm%n*img%z%n, &
!              call solver_prc( m=scatS,d=B_image, Fop=owwemva_lop, Sop=igrad1_lop, stepper=cgstep, nSop=img%xm%n*img%z%n, &
!                           niter=niter,eps1=epscg,verb=.true.)!,rm0,err,resd,resm,mmov,rmov,verb)
  call killA_close()
  do k=1,img%z%n
     do i=1,img%xm%n
        infile((k-1)*img%xm%n+i)=infile_((i-1)*img%z%n+k)
     end do
  end do

  call srite()
  deallocate(indips,infile,dips_,infile_)
  call sep_end_prog()
end program
