module wei_tag
  use wei_util
  use wei_pro
  use wei_par

  implicit none
  
  !----------------------------------------------------------------  
  type weitag

     character(len=128) :: dS,   dR
     character(len=128) ::  S, D, R, W, U !! file tags

  end type weitag
  !----------------------------------------------------------------

  !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!
  type(weitag), public :: wtag
  !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!

contains
  !----------------------------------------------------------------
  subroutine weitag_init()
    integer :: mpierr

    wtag%S = 'S'
    wtag%D = 'D'
    wtag%U = 'U'
    wtag%R = 'R'
    wtag%W = 'W'
    wtag%dS='dS'
    wtag%dR='dR'

    if(wpar%impi/=0) call weitag_mpi()

    if(wpro%dbg>0) then
       if(wpar%impi==0) call weitag_report()
       if(wpar%impi==1) call weitag_report()
    end if

    call MPI_BARRIER(MPI_COMM_WORLD ,mpierr)
  end subroutine weitag_init
  !----------------------------------------------------------------
  subroutine weitag_mpi()
    character(len=128) :: tmp

    tmp = wtag%S;  write(wtag%S, '(a,a,a)') ".", trim(tmp), trim(wpar%suffix)
    tmp = wtag%D;  write(wtag%D, '(a,a,a)') ".", trim(tmp), trim(wpar%suffix)
    tmp = wtag%U;  write(wtag%U, '(a,a,a)') ".", trim(tmp), trim(wpar%suffix)
    tmp = wtag%R;  write(wtag%R, '(a,a,a)') ".", trim(tmp), trim(wpar%suffix)
    tmp = wtag%W;  write(wtag%W, '(a,a,a)') ".", trim(tmp), trim(wpar%suffix)
    tmp = wtag%dS; write(wtag%dS,'(a,a,a)') ".", trim(tmp), trim(wpar%suffix)
    tmp = wtag%dR; write(wtag%dR,'(a,a,a)') ".", trim(tmp), trim(wpar%suffix)

  end subroutine weitag_mpi
  !----------------------------------------------------------------
  subroutine weitag_report()
    call weiline()
    write(0,'(a,a,i2)') weitab," WEITAG REPORT",wpar%impi
    call weiline()
    write(0,'(a,a,a)') weitab," wtag%S  =  ",trim(wtag%S)
    write(0,'(a,a,a)') weitab," wtag%D  =  ",trim(wtag%D)
    write(0,'(a,a,a)') weitab," wtag%U  =  ",trim(wtag%U)
    write(0,'(a,a,a)') weitab," wtag%R  =  ",trim(wtag%R)
    write(0,'(a,a,a)') weitab," wtag%W  =  ",trim(wtag%W)
     
    write(0,'(a,a,a)') weitab," wtag%dS = ",trim(wtag%dS)
    write(0,'(a,a,a)') weitab," wtag%dR = ",trim(wtag%dR)
    call weiline()

  end subroutine weitag_report
  !----------------------------------------------------------------  
end module wei_tag








