      program averagepr
      
      real :: cal, average
      integer :: min, max, n, index
      
      open(1,file='../acc_prob.dat',status='old')
      
      
      min=0
      max=0
      
      print *,'min='
      read(*,*) min
      
      print *,'max='
      read(*,*) max
      
      n=0
      index=0
      average=0.0
      
      do while(.TRUE.)
         read(1,*,end=12) index, val
         if((index.ge.min).and.(index.le.max)) then
            average=average+val
            n=n+1
         endif
      enddo
      
 12   average=average/n
      print *,'average=',average
      
      stop
      end program
      
