c
c----------------------------------------------------------------------------
c
      subroutine michel(pos_tot, p0)
c
c     routine to throw the e+ energy spectrum in muon decay.
c
c       T. Prokscha,    15-Sep-2000,    PSI
c
c       Unix version
c
c       TP,     05-Apr-2001,    PSI             Unix, NT, Linux
c
c----------------------------------------------------------------------------
c
      implicit none
c
#include "common.inc"
c
      real*4  pos_tot, p0
      real*4  eta, temp, rho, ratio
      real*4  random(2)
c
c---------------------------
c
c     MICHEL distributed e+ energy by using NEUMANN rejection
c     "rejection function" is 2.25 * eta
c
10    continue
#if defined (OS_UNIX)
      call ranlux(random, 2)
#else
      random(1) = ran(ix1)
      random(2) = ran(ix2)
#endif
      eta = sqrt(random(1))
      temp  = 2. * eta**2 * (3. - 2. * eta)
      ratio = temp / (2.25 * eta) 
      rho   = random(2)
      if ( rho .gt. ratio ) then
                rejcou =  rejcou + 1
                goto 10
      else
                cou = cou + 1
      endif
c
      pos_tot = MAX_TOTAL_ENERGY * eta
c
      if ( pos_tot .ge. POS_MASS ) then
            p0 = sqrt(pos_tot**2 - SQR_POS_MASS)            
      else
            p0 = 0.
      endif
c
      return
      end
