      subroutine double_peak(nhist,hist,max1,min0,max2,wght1,wght2)
c bernd berg aug 2 2005. locates the two maxima and the in-between 
c minimum of a double-peak histogram. calculates their weights.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension hist(0:nhist)
      data max0/0/, min1/0/, min2/0/ ! prevents compiler warnings.
 
      hmax=zero ! find the absolute maximum:
      do ihist=0,nhist
        if(hist(ihist).gt.hmax) then
          max0=ihist
          hmax=hist(ihist)
        endif
      enddo
      if(max0.le.1.or.max0.ge.nhist-1) stop "doble_peak: max0 false."
 
      hmin=hmax
      delh2=zero
      minwork=max0
      do ihist=max0+1,nhist
        if(hist(ihist).lt.hmin) then
          minwork=ihist
          hmin=hist(ihist)
        endif
        if(hist(ihist)-hmin.gt.delh2) then
          max2=ihist
          min2=minwork
          delh2=hist(ihist)-hmin
        endif
      enddo
 
      hmin=hmax
      delh1=zero
      minwork=max0
      do ihist=max0-1,0,-1
        if(hist(ihist).lt.hmin) then
          minwork=ihist
          hmin=hist(ihist)
        endif
        if(hist(ihist)-hmin.gt.delh1) then
          max1=ihist
          min1=minwork
          delh1=hist(ihist)-hmin
        endif
      enddo
 
      if(delh1.gt.delh2) then
        max2=max0
        min0=min1
      else
        max1=max0
        min0=min2
      endif
 
      wght1=zero
      do ihist=0,min0-1
        wght1=wght1+hist(ihist)
      enddo
      wght2=zero
      do ihist=min0+1,nhist
        wght2=wght2+hist(ihist)
      enddo
 
      return
      end
