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

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

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

 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('Enter period range to consider (Pmin Pmax):  ',$)
      read(5,*) permin,permax

C      write(6,122)
C 122  format('Enter number of templates used: ',$)
C      read(5,*) ncol

C  EACH TIME THRU LOOP IS ANOTHER COLUMN OF OUTPUT
      do 10 i=1,ncol
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)
            if(per.lt.permin.or.per.gt.permax) goto 20
            val = chi(i)
            if(val.lt.vmin) then
              vmin = val
              pmin = per
            endif
 20         continue
 21      write(6,200) i,vmin,pmin
 200     format('Col  chimin  per(chimin) = 'i2,2f11.7)
         rewind(10)
 10      continue

       close(10)
       stop
       end

