##########################################################################
##									##
##									##
##				MadWeight				##
##				*********				##
##									##
##	Autor:	 Olivier Mattelaer 					##
##		 Pierre Artoisenet					##
##									##
##	date:	August 08						##
##									##
##########################################################################
##########################################################################
##									##
##  rule to modify ./SubProcesses/driver.f  file from ME template	##
##             and ./SubProcesses/symetry.f file			##
##									##
##									##
## TAG:									##
##	setpara								##
##      new_def
##									##
##########################################################################
##
##
##########################################################################
$B$ setpara $B$
##************************************************************************
C Begin Madweight edit
      buffer="./param.dat"
      do i=1,3
	open(unit=90,file=buffer,status='old',err=12)
	read(90,*) param_name	
	exit
 12     if (i.eq.3)then
	  write(*,*) 'failed to open param.dat'
	  stop
        endif	
        buffer='../'//buffer 
      enddo
      write(*,*) 'param name',param_name	     
      call setpara(param_name,.true.)
      buffer="./seedvalue.inc"
      do i=1,3
	open(unit=90,file=buffer,status='old',err=13)
	read(90,*) seed	
	exit
 13     if (i.eq.3)then
	  write(*,*) 'failed to open seedvalue.inc'
	  stop
        endif	
        buffer='../'//buffer 
      enddo
	write(*,*) 'using seed value ',seed 
C End MadWeight edit
##************************************************************************
$E$ setpara $E$
##########################################################################
##
##
##########################################################################
$B$ new_def $B$
##************************************************************************
C
C MW definition
C
      character*40 param_name
      character*40 buffer
      integer seed
      common/to_seed/seed
##************************************************************************
$E$ new_def $E$
##########################################################################
##
##
##########################################################################
$B$ get_user_params_old $B$
##************************************************************************
      subroutine get_user_params(ncall,itmax,iconfig)
c**********************************************************************
c     Routine to get user specified parameters for run
c     Modify for MadWeight (read data in file)
c**********************************************************************
      implicit none
c
c     Constants
c
      include 'nexternal.inc'
c
c     Arguments
c
      integer ncall,itmax,iconfig, jconfig
c
c     Local
c
      integer i, j
      double precision dconfig
c
c     Global
c
      integer           isum_hel
      logical                   multi_channel
      common/to_matrix/isum_hel, multi_channel
      double precision    accur
      common /to_accuracy/accur
      integer           use_cut
      common /to_weight/use_cut

      integer        lbw(0:nexternal)  !Use of B.W.
      common /to_BW/ lbw

c-----
c  Begin Code
c-----
      open(unit=89,file='../../madevent_param',status='old')

      write(*,'($a)') 'Enter number of events and iterations: '
      read(89,*) ncall,itmax
      write(*,*) 'Number of events and iterations ',ncall,itmax
      write(*,'($a)') 'Enter desired fractional accuracy: '
      read(89,*) accur
      write(*,*) 'Desired fractional accuracy: ',accur

      write(*,'($a)') 'Enter 0 for fixed, 2 for adjustable grid: '
      read(89,*) use_cut
      if (use_cut .lt. 0 .or. use_cut .gt. 2) then
         write(*,*) 'Bad choice, using 2',use_cut
         use_cut = 2
      endif

      write(*,10) 'Suppress amplitude (0 no, 1 yes)? '
      read(89,*) i
      if (i .eq. 1) then
         multi_channel = .true.
         write(*,*) 'Using suppressed amplitude.'
      else
         multi_channel = .false.
         write(*,*) 'Using full amplitude.'
      endif

      write(*,10) 'Exact helicity sum (0 yes, n = number/event)? '
      read(89,*) i
      if (i .eq. 0) then
         isum_hel = 0
         write(*,*) 'Explicitly summing over helicities'
      else
         isum_hel= i
         write(*,*) 'Summing over',i,' helicities/event'
      endif

      write(*,10) 'Enter Configuration Number: '
      read(89,*) dconfig
      iconfig = int(dconfig)
      write(*,12) 'Running Configuration Number: ',iconfig
c
c     Here I want to set up with B.W. we map and which we don't
c
      dconfig = dconfig-iconfig
      if (dconfig .eq. 0) then
         write(*,*) 'Not subdividing B.W.'
         lbw(0)=0
      else
         lbw(0)=1
         jconfig=dconfig*1000.1
         write(*,*) 'Using dconfig=',jconfig
         call DeCode(jconfig,lbw(1),3,nexternal)
         write(*,*) 'BW Setting ', (lbw(j),j=1,nexternal-2)
c         do i=nexternal-3,0,-1
c            if (jconfig .ge. 2**i) then
c               lbw(i+1)=1
c               jconfig=jconfig-2**i
c            else
c               lbw(i+1)=0
c            endif 
c            write(*,*) i+1, lbw(i+1)
c         enddo
      endif
      close(89)
 10   format( a)
 12   format( a,i4)
      end
##************************************************************************
$E$ get_user_params_old $E$
##########################################################################
##
##
##########################################################################
