;+
; PROJECT: SDAC
;
; NAME: Run_FILE_SEARCH
;
;
; PURPOSE: Look for files satisfying passed directory and filename strings,
;	   Find file or files satisfying passed strings, and let user select filename
;	   of choice.  Passed strings may also be a set of templates using wildcards
;	   and replacement values
;
; CATEGORY: SPEX, i/o
;
;
; CALLING SEQUENCE:  run_file_search, data_tipe=data_tipe, file_type=file_type, $
;	spex_test_dir = spex_test_dir, test_file=test_file, $
;	det_id=det_id, flare=flare, out_fname=out_fname, out_dir=out_dir, $
;	sher_only=sher_only, sherb_only=sherb_only
;
; CALLED BY: SPEX menu
;
;
; CALLS TO:
;	build_fname
;	file_searcher
;	datatype
; INPUTS:
;	data_tipe - e.g. ['BATSE','CONT'], ['BATSE','HERS'], ['BATSE','SHERS']
;	file_type - 'DATA' for time history files, e.g. sherb_ibdb_00468.fits
;	            'DRM' detector response matrix files
;	spex_test_dir  - directory to be combined with templates using concat_dir
;		    there is already a list of default directories within this procedure
;	test_file - string for file name over and above defaults list within code
;	dir_queue - hierarchical list of directories to search, some to be combined
;		    with burst numbers
;	(see build_fname.pro for explanations of the following optional arguments)
;	det_id    - detector id number, for BATSE 0-7
;	flare     - flare number from 
;		    SDAC BATSE archive
;	batse_burst - This burst number overrides the BATSE burst trigger number
;		      returned by the burst_flare routine
;	sherb_only - only look for sherb or herb in BATSE SHERS or HERS
;	sher_only  - only look for sher or her in BATSE SHER or HER
;	event_time - time with event day, anytim format, used to construct tjds etc
; OUTPUTS:
;       out_fname - filename satisfying input specification, '' if none
;       out_dir   - directory satisfying input specification, '' if none
;
; PROCEDURE: uses file_searcher, build_fname, and findfile to test strings in filename searches.
;	     if more than one is returned, requests the user to specify interactively.
;            If templates are passed, then they are checked first before test_file and spex_test_dir
; MODIFICATION HISTORY: 
;	ras, 22-jan-93
;	ras, 20-sep-94, updated hxrbs search to reflect FITS archive
;	ras, 18-oct-94, added batse discsp
;	ras, windows 95 day, changed order of hxrbs search
;	ras, 20-sep-95, added default sher template
;	ras, 30-oct-95, added batse_burst keyword
;	ras, 1-nov-95, cleaned up directory choices
;	ras, 14-nov-96, added event_time
;	Version 9, ras, 26-mar-1997, made sure that simple case with known file and
;		directory for random data format works.
;	Version 10,
;	richard.schwartz@gsfc.nasa.gov, 26-sep-1997 added BATSE DISCLA.
;	Version 11,
;	richard.schwartz@gsfc.nasa.gov, 26-sep-1997 killed
;	BATSE branch, covered in spex_batse_preview and batse_file_search.
;	Version 12, richard schwartz 6-jun-2000, fixed test_dir() conflict.
;-

pro run_file_search, data_tipe=data_tipe, file_type=file_type, spex_test_dir = in_dir, test_file=test_file, $
det_id=det_id, flare=flare, out_fname=out_fname, out_dir=out_dir, sherb_only=sherb_only, $
sher_only=sher_only, dir_queue=dir_queue, batse_burst=burst, event_time=event_time

spex_test_dir = in_dir
;Locate the filenames consistent with the specified directory and filename
;save them in the string array, found_files. 
;This is mainly to interactively select the strings used to find data and drm files


case 1 of
    strupcase(data_tipe(0)) eq 'YOHKOH': begin 
        ; do following line as an execute since data_paths isn't 
        ; available unless we're in YIDL.  AKT, 28 apr 94
        result = execute('spex_test_dir = [spex_test_dir, data_paths()]')
        templates= [test_file]
        file_searcher,templates=templates, spex_test_dir=spex_test_dir, out_fname=out_fname,out_dir=out_dir
        end
    strupcase(data_tipe(0)+data_tipe(1)) eq 'SMMHXRBS' :begin 
        hxrbsdata = chklog('HXRBS_FITS')
        spex_test_dir = [hxrbsdata, spex_test_dir]
        templates= [test_file,'hxrbs_'+strtrim(flare,2)+'.fits']
        file_searcher,templates=templates, spex_test_dir=spex_test_dir, out_fname=out_fname,out_dir=out_dir
        end
    else: begin
        file_searcher, templates=[test_file], spex_test_dir=spex_test_dir, out_fname=out_fname,out_dir=out_dir
        end
    endcase

return
end
