      subroutine perg(li,modes,nper,permax)
*
* this subroutine computes trial periods for the pulsation programs 
* from the discriminant values. It uses a simple linear interpolation
* between data points where the sign changes. 
*
      implicit double precision(a-h,o-z)

      common/perds/periods(1000),discr(1000),pguess(3,101),yguess(101)
      integer modes(3)
*
* load up Y3 guess array
*
      yguess(1) = -0.5
      yguess(2) = -0.02
      yguess(3) = -0.02
      yguess(4) = -0.02
      yguess(5) = -0.02
      yguess(101) = 0.0
      do 100 i=6,18
        yguess(i) = -0.001
100   continue
      do 101 i=19,100
        yguess(i) = -0.0001
101   continue
*
* start computing period guesses
*
      num = 0
      do 110 i=1,nper-1
*
* if we have more periods than the array allows, 
* truncate and use what we have already.
*
        if(num.eq.100)then
          pguess(li,num+1) = 0.0
          modes(li) = num+1
          return
        endif
*
* pass through zero going down 
*
        if(discr(i).gt.0.0.and.discr(i+1).lt.0.0)then
          num = num + 1
          if(periods(i).lt.permax)then
            frac=discr(i)/(discr(i)+dabs(discr(i+1)))
            pguess(li,num)=periods(i)+(periods(i+1)-periods(i))*frac
          endif
        endif
*
* pass through zero going up
*
        if(discr(i).lt.0.0.and.discr(i+1).gt.0.0)then
          num = num + 1
          if(periods(i).lt.permax)then
            frac=discr(i)/(discr(i)-discr(i+1))
            pguess(li,num)=periods(i)+(periods(i+1)-periods(i))*frac
          endif
        endif
110   continue
      pguess(li,num+1)=0.0
      modes(li)=num+1

      return 
      end

************************************************************************

