program main
  use killwave_mod
  use killwave_ns
  implicit none


    call initpar()
        
    if (exist_file(infile_))then
        call from_aux(infile_,"n1",n1); call from_aux(infile_,"d1",d1); call from_aux(infile_,"o1",o1)
        call from_aux(infile_,"n2",n2); call from_aux(infile_,"d2",d2); call from_aux(infile_,"o2",o2)
        call from_aux(infile_,"n3",n3); call from_aux(infile_,"d3",d3); call from_aux(infile_,"o3",o3)
        allocate(   dips(n1*n2*n3)); 
        allocate( infile(n1*n2*n3)); 
        allocate(outfile(n1*n2*n3)); 
        call sep_read(infile, infile_)
        if(exist_file(dip_))call sep_read(dips,dip_)
        all=.false.
    else
        call from_param('n1',n1, 64); call from_param('d1',d1, 10.); call from_param('o1',o1, 0.); 
        call from_param('n2',n2, 32); call from_param('d2',d2, 10.); call from_param('o1',o1, 0.); 
        call from_param('n3',n3, 1 ); call from_param('d3',d3, 10.); call from_param('o1',o1, 0.); 
        allocate(   dips(n1*n2*n3)); 
        allocate( infile(n1*n2*n3) ); 
        allocate(outfile(n1*n2*n3) ); 
        call random_number(infile)
   endif        

   call params()
   if (rand_in)call random_number(infile)
   if (rand_in)write(0,*)'ssssssssssssss1111111'
   call killA_init(nang,nfilt)
   call killwave_io_init(nang,nfilt) 
   call ns_init()
   call ns_lop()

stop
!old procedure starts here...you can continue to save the A and/ATA filters
   if (all)then
           do iang=1, nang
                dips(iang)=oang+(iang-1)*dang
                if(verb>=2) then
                        write(0,'(        A50) ')'================================================'
                        write(0,'(A15, 2F15.5) ')'ang: deg/rad==>', degrad(1,dips(iang)), dips(iang)
                        write(0,'(        A50) ')'================================================'
                endif
                call killA(dips(iang))
                call A_io('rite',A,iang)
                call ATA_io('rite',ATA,iang)
                call FILT_io('rite',FILT,iang)
                if(verb>=2) then
                        write(0,'(        A50) ')'+++++++++++++++++++++++++++++++++++++++++++++++'
                endif
           enddo
   else
        dip0=-45
        dip0 = degrad(-1,dip0)
        dip0 = pi/4
!        write(0,*)hfilt%flt
!        write(0,*)hfilt%lag
        call killA(dip0)

        outfile=0.
        !stat = filt_conv_lop3 ( .false., .true., infile, outfile) 
        stat = filt_decon_lop3 ( .false., .true., infile, outfile) 
        call srite("outfile", outfile, 4*n1*n2*n3)
    endif
    call killA_close()
end program
