program WEIrefslo_main  
  use sep 
  use mpi_sep 
  use wei_util 
  use wei_par 
  use wei_pro 
  use wei_tag 
  use wei_ref

  use weiop_sll 

  implicit none
  character(len=3) :: operation
  integer :: stat 

  integer :: mpierr 

  !----------------------------------------------------------------
  call MPI_INIT(mpierr)
  call sep_init()

  !----------------------------------------------------------------
  !! init params for MPI and OMP
  call weipar_init()
  call weipar_report()

  if(wpar%impi==0) then
     call MPI_SEP_SEND_ARGS(wpar%nmpi,1,0)
  else
     call MPI_SEP_RECEIVE_ARGS()
  end if

  !! init tag names on all nodes
  call weitag_init()

  !! init process parameters on the MASTER
  if(wpar%impi==0) call weipro_init()
  !! broadcast parameters from MASTER to NODES
  if(wpar%nmpi >0) call weipro_bcast()
  if(wpar%impi==0) call from_param("operation",operation,'mig')
  if(wpar%nmpi >0) call MPI_BCAST(operation, 3,MPI_CHARACTER,0,MPI_COMM_WORLD,mpierr) 
  !----------------------------------------------------------------
  call weiref_init(SLin=weiop_sllN_init)
  !----------------------------------------------------------------
  if(wpar%impi==0) call weipro_report()
  !----------------------------------------------------------------
  if(wpar%impi==0 .and. wpro%verb) call weimessage("Start")
  stat = weiref(SLop=weiop_sllN)
  if(wpar%impi==0 .and. wpro%verb) call weimessage("OK")
  !----------------------------------------------------------------  
  !! shutdown MPI
  call MPI_FINALIZE(mpierr) 
  !----------------------------------------------------------------
  call exit(0)
end program WEIrefslo_main
