 
 
!
! ============================== zmap_larmor_stat ======================================
!
! returns some interesting statistics.  this is in a separate subroutine
! so it can be called from the output subroutines without importing map_larmor
!
!  map_larmor      -> fraction of calls which returned each ioops value
!  map_larmor_loss -> fraction of times each section was hit
!
function zmap_larmor_stat(isub, istat) result(stat)
  use iso_c_binding, only: fp => c_double
  use map_larmor_mod       ! get ic_loss and ic_map
 
  implicit none
  integer :: isub          ! select the subroutine
                           ! 1 -> map_larmor
                           ! 2 -> map_larmor_loss
                           ! 3 -> map_larmor_cache
  integer :: istat         ! select the statistic
  integer :: ii,i          ! temporary
 
  real(fp) :: stat             ! the statistics returned
 
  stat = 0._fp
  select case (isub)
  case (1)
     ! -- map_larmor --
     ii = 0                ! total number of map_larmor calls
     do i = 1, size(ic_map)
        ii = ii + ic_map(i)
     end do
     if (istat>=0 .and. istat<size(ic_map)) then
        stat = real(ic_map(istat+1),fp)/max(1._fp,real(ii,fp))
     end if
  case (2)
     ! -- map_larmor_loss --
     ii = ic_loss(1)       ! total number of map_larmor_loss calls
     if (istat>=1 .and. istat<=size(ic_loss)) then
        stat = real(ic_loss(istat),fp)/max(1._fp,real(ii,fp))
     end if
  end select
end function zmap_larmor_stat
 
 
! 11sep2004 fgtok -s r8_precision.sub nubeam_test_r8.sub "r8con.csh conversion"
! 11sep2004 fgtok
