module  verb_mod
use sep
implicit none
integer, external,private :: sep_thread_num
logical,private,save :: verb,debug,verb_all
integer, private, save :: jprint, ido, ndo,fprint,depth

contains

logical function init_verbose()
  init_verbose=.false.

  call from_param("debug",debug,.false.)
  call from_param("verb",verb_all,.true.)
  verb=.false.
 if(sep_thread_num()==0) call from_param("verb",verb,.false.)

 depth=2
  init_verbose=.true.
end function


logical function my_debug()
my_debug=debug
end function

logical function my_verb()
my_verb=verb
end function

logical function init_print_progress(fsteps,nsteps,v) 
integer :: nsteps,fsteps
logical, optional ::v
real    :: pct

write(0,*) "ABBB",fsteps,nsteps
if(present(v)) verb=v
if(present(v)) verb_all=v
if(sep_thread_num()==0) then
  call from_param("pct_master",pct,2.)
else
  call from_param("pct_slave",pct,10.)
end if
ndo=nsteps
ido=fsteps
jprint=real(ndo)*pct/100.

fprint=floor(real(ido)/real(jprint))
init_print_progress=.true.
write(0,*) "In init print progress",fprint,verb_all,ido,jprint
end function

subroutine print_progress(string,ijump)
integer, optional  :: ijump
integer           :: iadd
character(len=*)  :: string
real :: pct
iadd=1
if(present(ijump)) iadd=ijump
if(verb_all) then
  ido=ido+iadd
  pct=real(nint(1000.*real(ido)/real(ndo)))/10.
  if(ido >= fprint) then
    write(0,*) sep_thread_num(),"=thread finished ",pct, "% of ",trim(string)
    fprint=fprint+jprint
  end if
end if
end subroutine





end module
