c
c   get perpendicular distance estimators
c
      subroutine getpst
      include 'screen.inc'
      integer*2 irowt,irowtt,nlines,iopt
      integer*2 maxsop
      parameter (maxsop=5)
      character*4 sopstr(maxsop)
      integer*2 subopt(maxsop),iest,nlen(maxsop)
      integer*2 maxest
      parameter (maxest=10)
      character*80 savest(maxest)
      common /plots/ savest
      character*8 nstart(maxsop)
      logical mset,strt
      logical yesno
      external yesno
      data sopstr/'FSER','EXPS','EXPL','NEXP','HNOR'/
      data nstart/'up to 15','2','2','1','1'/
      data nlen/8,1,1,1,1/
c
 15   call cls
      do 5 iopt=1,maxsop
 5       subopt(iopt)=0
      iest=0
      irow=1
      icol=15
      line='Select from the following perpendicular distance estimators'
      call scrlin
      irow=irow+1
      line='by moving the cursor with the up and down arrow keys, and'
      call scrlin
      irow=irow+1
      line='hitting a carriage return to select a particular option,'
      call scrlin
      irow=irow+1
      line='or to re-select an option already selected.  An estimator'
      call scrlin
      irow=irow+1
      line='can be selected more than once if different starting values'
      call scrlin
      irow=irow+1
      line='or numbers of parameters (FSER only) are specified, for up'
      call scrlin
      irow=irow+1
      line='to 10 estimates.'
      call scrlin
      irow=irow+2
      irowt=irow
      icol=10
      line='FSER - Fourier series estimator (default).'
      call scrlin
      irow=irow+2
      line='EXPS - exponential power series estimator.'
      call scrlin
      irow=irow+2
      line='EXPL - exponential polynomial (quadratic) estimator.'
      call scrlin
      irow=irow+2
      line='NEXP - negative exponential estimator.'
      call scrlin
      irow=irow+2
      line='HNOR - half normal estimator.'
      call scrlin
      irow=irow+2
      line='FINISHED selecting options, and ready to proceed.'
      call scrlin
      irow=irow+1
      line='(Don''t hit Enter here until '//
     1   'satisfied with above selections'
      call scrlin
      irow=irow+2
      icol=1
      line='Do you want to specify starting '//
     1   'values for the estimators?'
      if (yesno(1)) then
         strt=.true.
         mset=.false.
      else
         strt=.false.
         line='Do you want to select the number of '//
     1      'parameters for FSER?'
         if (yesno(1)) then
            mset=.true.
            call putcur(irowt+2,17,ivpage,ierror)
            call wchars(ivpage,'User specifying no. of parameters.',34,
     1            icolor,ibckgd,0,ierror)
         else
            mset=.false.
         endif
      endif
      icol=9
      call putcur(irowt,icol,ivpage,ierror)
      nlines=maxsop*2
      call scroll(1,0,irowt+nlines+2,1,25,80,7,ierror)
 60   call inkey(line,keycde,nchar)
      if (keycde.eq.0) then
         continue
c     up arrow
      else if (keycde.eq.72) then
         call getcur(ivpage,irow,icol,ierror)
         irow=irow-2
         if (irow.lt.irowt) irow=irowt+nlines
         call putcur(irow,icol,ivpage,ierror)
c     down arrow
      else if (keycde.eq.80) then
         call getcur(ivpage,irow,icol,ierror)
         irow=irow+2
         if (irow.gt.irowt+nlines) irow=irowt
         call putcur(irow,icol,ivpage,ierror)
c     carriage return, meaning this area is selected.
      else if (keycde.eq.28) then
         call getcur(ivpage,irow,icol,ierror)
         iopt=(irow-irowt)/2+1
         if (iopt.le.maxsop) then
            if (iopt.eq.1 .and. subopt(1).gt.0 .and.
     1         (mset .or. strt)) then
               continue
            else if (subopt(iopt).gt.0 .and. strt) then
               continue
            else if (subopt(iopt).eq.0) then
               continue
            else
               go to 32
            endif
            iest=iest+1
            subopt(iopt)=subopt(iopt)+1
            line='Selected '
            line(9:9)=char(26)
            call putcur(irow,1,ivpage,ierror)
            call wchars(ivpage,line,9,icolor,ibckgd,1,ierror)
            if (strt) then
               call putcur(irowt+nlines+2,1,ivpage,ierror)
               write(line,'(a,a,a)')'Enter ',nstart(iopt)(1:nlen(iopt)),
     1            ' starting values separated by commas: '
               nchar=index(line,':')+1
               call wchars(ivpage,line,nchar,icolor,ibckgd,0,ierror)
               call lnebuf(line,nchar,80,iatt,0)
               write(savest(iest),'(a1,a4,a2,a)') '*',sopstr(iopt),'* ',
     1            line(1:nchar)
               line=' '
               call putcur(irow,1,ivpage,ierror)
               call wchars(ivpage,line,9,icolor,ibckgd,0,ierror)
            else if (mset .and. iopt.eq.1) then
               call putcur(irowt+nlines+2,1,ivpage,ierror)
               line='Enter number of starting values: '
               nchar=33
               call wchars(ivpage,line,nchar,icolor,ibckgd,0,ierror)
               call lnebuf(line,nchar,80,iatt,0)
               write(savest(iest),'(a1,a4,a2,a)') '*',sopstr(iopt),'* ',
     1            line(1:nchar)
               line=' '
               call putcur(irow,1,ivpage,ierror)
               call wchars(ivpage,line,9,icolor,ibckgd,0,ierror)
            else
               write(savest(iest),'(a1,a4,a1)') '*',sopstr(iopt),'*'
            endif
 32         call putcur(irow,icol,ivpage,ierror)
            call scroll(1,0,irowt+nlines+2,1,irowt+nlines+2,80,7,ierror)
            if (iest.eq.maxest) go to 70
         else
c           come here when satisfied with options specified.
            go to 70
         endif
      endif
      go to 60
c   check input to see that it is valid
 70   nlines=0
      do 75 iopt=1,maxsop
 75      nlines=nlines+subopt(iopt)
      if (nlines.eq.0 .or. nlines.gt.10) then
         call putcur(25,1,ivpage,ierror)
         line='No options were specified.  Re-do input.'//
     1        '    Press any key to continue.'
         call wchars(ivpage,line,70,icolor,ibckgd,1,ierror)
 76      call inkey(line,keycde,nchar)
         if (keycde.eq.0) go to 76
         go to 15
      endif
      irow=1
      icol=15
      call cls
      line='Options specified are:'
      nchar=22
      call scrlin
      icol=20
      do 80 i=1,iest
         irow=irow+1
         line=savest(i)
         call scrlin
 80      continue
      irow=irow+2
      icol=5
      line='Are these options OK and ready to proceed?'
      if (.not. yesno(0)) go to 15
      write(line,'(i3)') iest
      if (mset) line(5:10)='*MSET*'
      if (strt) line(11:16)='*STRT*'
      write(unit=iout,fmt='(a)') line(1:20)
      do 140 i=1,iest
         write(unit=iout,fmt='(a)') savest(i)(1:79)
 140     continue
      return
      end
