program rnph

 use sep
 use inicia
 use solver_irls_mod
 use cgstep_mod
 use opera
 use fileio

 implicit none

 real, allocatable, dimension(:)	:: m,m0
 real, allocatable, dimension(:)	:: data
 real				:: time,pi
 integer				:: time0(8),seed(2)
 integer				:: nw,nx,nz,nreal
 integer				:: niter, nmem, nfreq
 integer				:: dados,nwind

 call sep_init()
 call sep_begin_prog()

 call from_param("nw",nw,20)
 call from_param("nx",nx,50)
 call from_param("nz",nz,20)
 call from_param("nreal",nreal,1)
 call from_param("nwind",nwind,7)
 call from_param("niter",niter,100)
 call from_param("nmem",nmem,20)
 call from_param("nfreq",nfreq,10)
 call from_param("dados",dados,1)

 open(unit=2,file="lixo")

  allocate(m0(nw*nx*nz*nreal),m(nw*nx*nz*nreal))
  allocate(data(nx*nx*nz*nz));data=0.
  call genmodel(m0)
  call gendata_init(nw,nx,nz,nwind,nreal,dados)
  call gendata(data)

! Nonlinear solver
  call opera_init(nw,nx,nz,nreal)
  call solver_irls(m=m, d=data,Fop=opera_lop,stepper=cgstep,niter=niter, &
                    m0=m0, nmem=nmem, nfreq=nfreq, verb=.true.)

  deallocate(m0,data)
 call io(nw,nz,nx,nreal,m)
 close(2) 
 call sep_end_prog()
end program 
!
!  call solver_irls(m=rand2,d=data,Fop=opera_lop,stepper=cgstep,niter=niter, &
!                    Wop=,Jop=,Wdiag=,m0=m0, nmem=, nfreq=, &
!                    err=, resd=, mmov=, rmov=, verb=.true.)
