C  STDLC_PERANAL2.F -- another handy analysis tool for finding minima
C     in output from stdlc_per.e         ALC 98mar13

      implicit real*8 (a-h,o-z)

      character*50 inf
      parameter(ndat=99999,ncol=20)
      dimension chi(ncol)

 100  format(a)
      write(6,110)
 110  format('Enter name of STDLC_PER output:  ',$)
      read(5,100) inf
      open(10,file=inf,status='old')
C      write(6,112)
C 112  format('Enter name _PER output:  ',$)
C      read(5,100) inf
C      open(10,file='mksinlc.dat',status='new')

      write(6,120)
 120  format('Which x^2 column should I consider (1,2,...,ncol):  ',$)
      read(5,*) icol
      write(6,123)
 123  format('Find minima below this value of x^2 (eg 0.05):  ',$)
      read(5,*) chilim

C   THIS LOOP TAKES US THRU THE DATA FILE
      vmin = 99.
      do 20 j=1,ndat
         read(10,*,err=20,end=21) per,(chi(k),k=1,ncol)
         val = chi(icol)
         if(val.lt.chilim) write(6,200) val,per
 200     format('chimin  per(chimin) = '2f12.7)
 20      continue

 21    close(10)
       stop
       end
