C*************************************************************************
	SUBROUTINE SETSUB(sname,s_ln,filename,ln)
C*************************************************************************
C Set value(s) for SEARCH parameters
C*************************************************************************
	CHARACTER*(*) filename,sname
	INTEGER ln,s_ln
	logical*1 tflag
	INTEGER STATUS,CLI$DCL_PARSE,CLI$GET_VALUE,CLI$PRESENT
	LOGICAL GET_NUMBER,flag,GET_LOGICAL,DEF_LOGICAL,GET_FNUMBER
	EXTERNAL CLI$_PRESENT,CLI$_DEFAULTED,CLI$_ABSENT,CLI$_NEGATED
	
	include '[-.shared]jcpds.parms'
	include 'SEARCH.cmn'
	include 'SEARCH.par'

71	format(a)
72	format(Q,a)
73	format(Q,f10.0)
74	format(Q,i)
	tflag = .false.

C Overall Parameter
	FLAG = .true.
	IF (CLI$PRESENT('ERROR')) FLAG = GET_FNUMBER('ERROR',D2T)
	IF (.NOT. FLAG) tflag = .true.
	
	FLAG = .true.
	IF (CLI$PRESENT('R_INDEX')) FLAG = GET_NUMBER('R_INDEX',I)
	IF (.NOT. FLAG) then
	  tflag = .true.
	  IF (i .lt. 0) then
	    i = -1
	    call getindex(i,ind,LUND)
	    CLOSE(unit=LUND)
	  ELSEIF (i .ge. 100) then
	    i = 100
	    ind = 100
C check if the requested number is available
	  ELSE
	    call getindex(i,ind,LUND)
	    CLOSE(unit=LUND)
	  ENDIF
	  IF (ind .gt. 99 .and. i .eq. -1) THEN
C no three strongest file -- error!
	    write(*,'(2a)') ' WARNING -- Unable to open d-space INDEX',
	1   ' file: PS_BITMAP:DSP3S.BITMAP'
	    i = pindex
	    call ps_PAUSE(PROMPT)
	  ELSEIF (ind .gt. 99) THEN
C unable to open a lower intensity peak threshold file -- error!
	    write(*,'(2a)') ' ERROR -- Unable to open d-space INDEX',
	1  ' file (PS_BITMAP:DSP00.BITMAP)'
	    i = 100
	    call ps_PAUSE(PROMPT)
	  ELSEIF (ind .ne. i) THEN
C warn
	    write(*,'(/a,i2,a,i2,a/)') ' *** Unable to open the ',i
	1	,'% Index file, will substitute the ',ind,'% file.'
	    i = ind
	    call ps_PAUSE(PROMPT)
	  ENDIF
	  pindex = i
	ENDIF

	FLAG = .true.
	IF (CLI$PRESENT('Rmin')) FLAG = GET_NUMBER('Rmin',I)
	IF (.NOT. FLAG .and. i .ge. 0 .and. i .le. 100) then
	   pimin = i
	   tflag = .true.
	ENDIF

	FLAG = .true.
	IF (CLI$PRESENT('F_INDEX')) FLAG = GET_NUMBER('F_INDEX',I)
	IF (.NOT. FLAG) then
	  tflag = .true.
	  IF (i .lt. 0) then
	    i = -1
	  ELSEIF (i .ge. 100) then
	    i = 100
	  ENDIF
C check if the requested number is available
	  IF (i .lt. 100) then
	    call getindex(i,ind,LUND)
	    CLOSE(unit=LUND)
	  ELSE
	    ind = i
	  ENDIF
	  IF (ind .gt. 99 .and. i .eq. -1) THEN
C no three strongest file -- error!
	    write(*,'(2a)') ' WARNING -- Unable to open d-space INDEX',
	1   ' file: PS_BITMAP:DSP3S.BITMAP'
	    i = iindex
	    call ps_PAUSE(PROMPT)
	  ELSEIF (ind .gt. 99) THEN
C unable to open a lower intensity peak threshold file -- error!
	    write(*,'(2a)') ' ERROR -- Unable to open d-space INDEX',
	1  ' file (PS_BITMAP:DSP00.BITMAP)'
	    i = 100
	    call ps_PAUSE(PROMPT)
	  ELSEIF (ind .ne. i) THEN
C warn
	    write(*,'(/a,i2,a,i2,a/)') ' *** Unable to open the ',i
	1	,'% Index file, will substitute the ',ind,'% file.'
	    i = ind
	    call ps_PAUSE(PROMPT)
	  ENDIF
	  iindex = i
	ENDIF

	FLAG = .true.
	IF (CLI$PRESENT('Fmin')) FLAG = GET_NUMBER('Fmin',I)
	IF (.NOT. FLAG .and. i .ge. 0 .and. i .le. 100) then
	   iimin = i
	   tflag = .true.
	ENDIF

	FLAG = .true.
	IF (CLI$PRESENT('FWIDTH')) FLAG = GET_FNUMBER('FWIDTH',FFWHM)
	IF (.NOT. FLAG) tflag = .true.

C MATCH parameters
	FLAG = .true.
	IF (CLI$PRESENT('DB_IMIN')) FLAG = GET_NUMBER('DB_IMIN',imin)
	IF (.NOT. FLAG) tflag = .true.

	FLAG = .true.
	IF (CLI$PRESENT('MAXDBMISS')) 
	1	FLAG = GET_NUMBER('MAXDBMISS',JCMSMX)
	IF (.NOT. FLAG) tflag = .true.

	FLAG = .true.
	IF (CLI$PRESENT('MATCHOBS')) 
	1	FLAG = GET_NUMBER('MATCHOBS',minmatch)
	IF (.NOT. FLAG) tflag = .true.
	FLAG = .true.
	IF (CLI$PRESENT('OBS_IMIN')) FLAG = GET_NUMBER('OBS_IMIN',iomin)
	IF (.NOT. FLAG) tflag = .true.

	FLAG = .true.
	IF (CLI$PRESENT('MAXCARDS')) FLAG = GET_NUMBER('MAXCARDS',mphase)
	IF (.NOT. FLAG) tflag = .true.

	IF (CLI$PRESENT('SORT') .eq. %loc(CLI$_PRESENT)) THEN
	  NSORT = 0
	  FLAG = GET_NUMBER('SORT',NSORT)
	  tflag = .true.
	ELSEIF (CLI$PRESENT('SORT') .eq. %loc(CLI$_NEGATED)) THEN
	  NSORT = -1
	  tflag = .true.
	ENDIF
	FLAG = .true.
	IF (CLI$PRESENT('FOM')) FLAG = GET_NUMBER('FOM',NFOM)
	IF (.NOT. FLAG) tflag = .true.

	FLAG = .true.
	IF (CLI$PRESENT('NAME')) then
	  ln = 0
	  STATUS = CLI$GET_VALUE('NAME',filename,ln)
	  IF (ln .gt. 0) Call valname(filename,ln,sname,s_ln,*3)
	  tflag = .true.
	ENDIF	    
C------------------------------------------------------------------------
C------------------------------------------------------------------------
710	if (TFLAG) RETURN

	write (lo,'(A)') ' Enter values for the SEARCH parameters. '//
	1 'Current values are shown',' as the defaults (in square brackets)'
	2 //'. At any point enter a question mark (?) ',
	3 ' for information on the current parameter',' '

	write (lo,'(/A)') ' OVERALL PARAMETERS:'
	write (lo,'(A)')  ' -------------------'
621	write (lo,777) 'the maximum 2theta error, DEL_2THETA',d2t
777	format('$Enter ',A,' ([',f7.3,' deg], ?): ')
	read (li,73,end=3,err=631) i,d1
	if (i .gt. 0) d2t = d1

	write (lo,'(A)') ' '
690	write (lo,776) sname(1:s_ln)
776	format('$Enter a search name (default=',A,'): ')
	read (li,72,end=3,err=691) ln,filename
	IF (filename(1:1) .eq. '?') goto 691
	IF (ln .gt. 0) Call valname(filename,ln,sname,s_ln,*691)
C---------------------------------------------------------------
	write (lo,'(/A)') ' REDUCE PARAMETERS:'
	write (lo,'(A)')  ' ------------------'

601	write (lo,779) 
	1  'the "Required Line" peak index, Req_Index',pindex
779	format('$Enter ',A,' ([',i3,'], ?): ')
	read (li,74,end=3,err=611) j,i
	if (j .gt. 0) THEN
	  IF (i .lt. 0) then
	    i = -1
	  ELSEIF (i .ge. 100) then
	    i = 100
	  ENDIF
C check if the requested number is available
	  IF (i .lt. 100) then
	    call getindex(i,ind,LUND)
	    CLOSE(unit=LUND)
	  ELSE
	    ind = i
	  ENDIF
	  IF (ind .gt. 99 .and. i .eq. -1) THEN
C no three strongest file -- error!
	    write(*,'(2a)') ' WARNING -- Unable to open d-space INDEX',
	1   ' file: PS_BITMAP:DSP3S.BITMAP'
	    goto 601
	  ELSEIF (ind .gt. 99 .and. i .ne. 100) THEN
C unable to open a lower intensity peak threshold file -- error!
	    write(*,'(2a)') ' ERROR -- Unable to open d-space INDEX',
	1  ' file (PS_BITMAP:DSP00.BITMAP)'
	    pindex = 100
	    goto 601
	  ELSEIF (ind .ne. i) THEN
C warn
	    write(*,'(/a,i2,a,i2,a/)') ' *** Unable to open the ',i
	1	,'% Index file, will substitute the ',ind,'% file.',
	2	'$Is this acceptible? ([Y]/N): '
	    read (li,'(A1)',end=3,err=601) ians
	    IF (ians .eq. 'N' .or. ians .eq. 'n') goto 601
	    i = ind
	  ENDIF
	  pindex = i
	ENDIF

	IF (pindex .lt. 100) then
	  write (lo,779) 'minimum "Required Line" intensity, R_Imin'
	1	,pimin
	  read (li,74,end=3,err=611) j,i
	  if (i .gt. 0 .and. j .ge. 0 .and. j .le. 100) pimin = j
	  if (i .gt. 0 .and. (j .lt. 0 .or. j .le. 100)) goto 611
	ENDIF
C---------------------------------------------------------------
602	CONTINUE
	write (lo,'(A)') 
	write (lo,779) 
	1  'the "Forbidden Line" peak index, Forbid_Index',iindex
	read (li,74,end=3,err=612) j,i
	if (j .gt. 0) THEN
	  IF (i .lt. 0) then
	    i = -1
	  ELSEIF (i .ge. 100) then
	    i = 100
	  ENDIF
C check if the requested number is available
	  IF (i .lt. 100) then
	    call getindex(i,ind,LUND)
	    CLOSE(unit=LUND)
	  ELSE
	    ind = i
	  ENDIF
	  IF (ind .gt. 99 .and. i .eq. -1) THEN
C no three strongest file -- error!
	    write(*,'(2a)') ' WARNING -- Unable to open d-space INDEX',
	1   ' file: PS_BITMAP:DSP3S.BITMAP'
	    goto 602
	  ELSEIF (ind .gt. 99 .and. i .ne. 100) THEN
C unable to open a lower intensity peak threshold file -- error!
	    write(*,'(2a)') ' ERROR -- Unable to open d-space INDEX',
	1  ' file (PS_BITMAP:DSP00.BITMAP)'
	    iindex = 100
	    goto 602
	  ELSEIF (ind .ne. i) THEN
C warn
	    write(*,'(/a,i2,a,i2,a/)') ' *** Unable to open the ',i
	1	,'% Index file, will substitute the ',ind,'% file.',
	2	'$Is this acceptible? ([Y]/N): '
	    read (li,'(A1)',end=3,err=602) ians
	    IF (ians .eq. 'N' .or. ians .eq. 'n') goto 602
	    i = ind
	  ENDIF
	  iindex = i
	ENDIF

	IF (iindex .lt. 100) then
	  write (lo,779) 'minimum "Forbidden Line" intensity, F_Imin'
	1	,iimin
	  read (li,74,end=3,err=612) j,i
	  if (i .gt. 0 .and. j .ge. 0 .and. j .le. 100) iimin = j
	  if (i .gt. 0 .and. (j .lt. 0 .or. j .le. 100)) goto 612
C
          write (lo,777) 'the approximate peak width, FWHM',FFWHM
	  read (li,73,end=3,err=612) i,d1
	  if (i .gt. 0) FFWHM = d1
	ENDIF
C---------------------------------------------------------------
C
	write (lo,'(/A)') ' MATCH PARAMETERS:'
	write (lo,'(A)')  ' -----------------'
640	write (lo,778) 'minimum significant JCPDS intensity, DB_min_int',
	1	imin
778	format('$Enter ',A,' (default=',i3,'%): ')
	read (li,74,end=3,err=650) i,j
	if (i .gt. 0) imin = j
C
	write (lo,779) 'maximum # of missed JCPDS lines, DB_max_miss'
	1	,JCMSMX
	read (li,74,end=3,err=650) i,j
	if (i .gt. 0) JCMSMX = j
C---------------------------------------------------------------
660	write (lo,'(A)') 
	write (lo,778) 'minimum % of Obs lines to be matched, OBS_min_lines'
	1	,minmatch
	read (li,74,end=3,err=670) i,j
	if (i .gt. 0) minmatch = j

	write (lo,778) 'minimum significant Obs intensity, OBS_min_int',
	1	iomin
	read (li,74,end=3,err=670) i,j
	if (i .gt. 0) iomin = j
C---------------------------------------------------------------
665	write (lo,'(A)') 
	write (lo,779) 'maximum allowed matches, MAX_hits',mphase
	read (li,74,end=3,err=675) i,j
	if (i .gt. 0)  mphase = j
C---------------------------------------------------------------
	write (lo,'(/A)') ' REPORT PARAMETERS:'
	write (lo,'(A)')  ' ------------------'
C
680	  WRITE(lo,'(A)') ' Sorting of entries by FOM for reports:',
	1	'     -1  for no sorting,',
	1	'      0  for sorting of all entries,',
	1	'      N  to sort the top N entries.'
	  write (lo,779) 'the # of hits for sorting by FOM, Num_Sort',NSORT
	  read (li,74,end=3,err=681) i,j
	  if (i .gt. 0)  NSORT = j
C
685	WRITE(lo,'(A)') ' ',' Overall FOM calculation methods:',
	1	'      0  to use peak position & intensity,',
	1	'      1  to ignore peak position discrepancies,',
	1	'      2  to ignore peak intensity discrepancies,',
	1	'      3  to use the full-pattern formula'
	write (lo,779) 'the FOM computation method, Calc_type',NFOM
	read (li,74,end=3,err=686) i,j
	if (i .gt. 0)  NFOM = j
C
	return

631	call help1('SET /ERROR','search_hlp',prompt)
	goto 621
611	call help1('SET /Rmin','search_hlp',prompt)
	goto 601
612	call help1('SET /Fmin','search_hlp',prompt)
	goto 602
650	call help1('SET /MAXDBMISS','search_hlp',prompt)
	goto 640
670	call help1('SET /MATCHOBS','search_hlp',prompt)
	goto 660
675	call help1('SET /MAXCARDS','search_hlp',prompt)
	goto 665
681	call help1('SET /SORT','search_hlp',prompt)
	goto 680
686	call help1('SET /FOM','search_hlp',prompt)
	goto 685
691	call help1('SET /NAME','search_hlp',prompt)
	goto 690
3	return
	end
