      real * 4 a(140),y(136)
      logical flag
      character * 16  anal,unstab
      write(6,110)
110   format(' Enter name of file containing analysis data.')
      read(5,11) anal
11    format(a16)
      write(6,112)
112   format(' Enter name of file containing list of unstable frames.')
      read(5,11) unstab
      write(6,113)
113   format(' Enter number of poles (max is 36).')
      read(5,114) npoles
114   format(i2)
      write(6,115)
115   format(' Enter first and last frames to test (2i6 ugh fortran)')    
      read(5,116) ifirst,ilast
116   format(2i6)
      write(6,117) ifirst,ilast
117   format(' testing frames',i6,' to',i6)
      ndata = 4
      nlocs = (npoles + ndata) * 4
      nall = npoles + ndata
	open(unit=18, file=anal,status='old',
     &	access='direct',form='unformatted',recl=nlocs)
	write(6,900)
900	format(' got here')
	open(unit=19, file=unstab,status='new',
     &	access='direct',form='unformatted',recl=4)
      nbad=1
      do 1000 j = ifirst,ilast 
      write(6,901) ifirst,ilast,j
901	format(3i8)
      read(18,rec=j,end=999) (a(jx),jx=1,nall) 
      write(6,900)
      do 1601 ii=1,npoles
      y(ii)= -a(nall+1-ii)
c     print*, ii,y(ii)
1601  continue
      call stable(y,npoles,flag)
      if(flag) goto 1000
      write(6,100) j 
100   format( ' frame ',i5,' is unstable ')
      write(19,rec=nbad)  j
      nbad = nbad + 1
1000  continue
999   stop 
      end
	subroutine stable(frame,n,flag)
	dimension frame(n)
	dimension a(150,150),rk(149)
	logical flag
	flag = .true.
	a(1,n+1)=1.
	do 10 i = 1,n
10	a(i+1,n+1) = frame(i)
	do 25 mm = 1,n
		m = n - mm + 1
		rk(m) = a(m+1,m+1)
		if(abs(rk(m)).lt.1.) goto 20
		flag = .false.
		return
20	do 25 i = 1,m
25	a(i,m) = (a(i,m+1)-rk(m)*a(m-i+2,m+1))/(1.-rk(m)**2)
	return
	end
