pro bcs_getfile,filename,defstr=defstr
;+
; NAME:				BCS_GETFILE
;
; PURPOSE:			Present a list of files for selection.
;
; CALLING SEQUENCE:  		bcs_getfile,filename,defstr="bda*.*"
;
; INPUTS:			defstr - default file specification.
;
; OUTPUTS:			filename - filename chosen
;
; OPTIONAL OUTPUTS:		none
;
; RESTRICTIONS:			single file only chosen
;				 - does not assume X-terminal
;
; PROCEDURE:			Uses code from test_rd.pro 
;
; MODIFICATION HISTORY:		atp 1991 - Blatant rip off of MDM's test_rd
;				 code.
;
;-
;
; get a filename
;
dum = ' '
get_file=1; /* historical */
;
if not keyword_set(defstr) then defstr="*.*";
;
repeat begin
if (get_file eq 1) then begin
    ssss = intarr(1)-1
    infil0 = '' 
    print,'Default file spec is - ',defstr
    read, 'Enter file name (or wild cards) ', infil0

    if (infil0 eq '') then begin    
     if (dum ne ' ' and dum ne '') then infil0=filename else infil0 = defstr
     endif
    endif else infil0 = filename; /* get_file */

    if ((infil0 eq '*') or (infil0 eq '')) then infil0 = defstr
    p1 = strpos(infil0,'*')
    p2 = strpos( strmid(infil0,p1,100),'.')
    if (p2 eq -1) then infil0 = infil0+'.*'

    ff = findfile(infil0)
    if (ff(0) eq '') then begin
	print, '** No files found **'
        get_file = 1
	qfound = 0
                endif else begin
	qfound = 1
	n = n_elements(ff)
	lconter = 0
	if (n gt 1) then begin
	    ; print out list of filenames
	    ;
	    i = 0
	    repeat begin
		lconter = lconter + 1;
		print, 'File', string(i,'(i3)'), ' - ', ff(i)
                                if (lconter eq 20) then begin
		   lconter = 0
		   print,'--More-- (Q to quit listing, any other key to see next page)'
		   if (strlowcase(get_kbrd(1)) eq 'q') then i = n-1;
		   endif
		i = i + 1
                endrep until (i gt n-1) 

                ldone = 0
	    while (ldone eq 0) do begin
	       read, 'Enter file number (-1 to quit) ', ifil
                       ldone = 1;
	
	       if ((ifil ge n) or (ifil lt -1)) then begin
		 print,'Please enter a number in the range 0 to ',n-1
                                 ldone = 0;
		 endif
	       endwhile 

 
	 if (ifil eq -1) then filename = '-1' else filename = ff(ifil)
	endif else begin
	    filename = ff(0)
	endelse
    endelse
 endrep until (qfound)
end
