;+ ; PROJECT: SDAC ; ; NAME: batse_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, BATSE, SYSTEM ; ; ; CALLING SEQUENCE: batse_file_search, 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_form - e.g. 'DISCLA','CONT','HERS','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: ; Version 1 ; richard.schwartz@gsfc.nasa.gov, 29-sep-1997 from run_file_search. ; Version 1.1 richard.schwartz@gsfc.nasa.gov, 29-sep-1997 from run_file_search.6-jun-2000. ; remove conflict with test_dir.pro ; ;- pro batse_file_search, data_form, 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 checkvar, burst, 0 ;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 ;Automatic file selection for BATSE data types if burst eq 0 then bno = (strtrim(burst_flare(flare, /flare),2))(0) $ else bno = strtrim(burst,2) ;Construct a directory name consistent with the flare number, too! checkvar, spex_test_dir, '' bno_mask = '00000' strput, bno_mask, bno, 5-strlen(bno) fno = (strtrim( flare, 2))(0) ;Load in specific knowledge about BATSE databases on HXRBS w=where( strupcase(strcompress(/rem,data_form) ) eq ['DISCLA','CONT','DISCSP'],nw) if nw eq 1 then begin call_procedure,'find_dbfile','f,'+fno,0, dd_open, w(0)+1 if datatype(dd_open) eq 'STC' then begin test_file = dd_open.filename free_lun, dd_open.lun endif endif test_queue = dir_queue(1:*) for i=0,n_elements(test_queue)-1 do if strpos( test_queue(i), dir_queue(0)) ne -1 then $ test_queue(i) = build_fname(test_queue(i), dir_queue(0), bno_mask,/lowcase) spex_test_dir = [spex_test_dir, test_queue ] spex_test_dir = spex_test_dir(where( spex_test_dir ne '',ndir)) case strupcase(file_type) of 'DATA': begin case 1 of strpos(data_form,'CONT') ne -1: begin test_file = (fcheck(test_file,''))(0) wildcard = '^' template=['continuous_ibdb_^.fits', $ 'continuous_ibdb.^', $ 'continuous_data.dat','*.cont_^'] if test_file ne '' then begin template = [test_file,template] inserts = reform(['',bno,bno,'',fno],1,5) endif else inserts = reform([bno,bno,'',fno],1,4) file_searcher,templates=template, spex_test_dir=spex_test_dir, wildcard=wildcard, inserts=inserts, $ out_fname=out_fname, out_dir=out_dir end strpos(data_form,'DISCSP') ne -1: begin test_file = (fcheck(test_file,''))(0) wildcard = '^' template=['discsp_ibdb_^.fits', $ 'discsp_ibdb.^', $ 'discsp_data.dat','*.discsp_^'] if test_file ne '' then begin template = [test_file,template] inserts = reform(['',bno,bno,'',fno],1,5) endif else inserts = reform([bno,bno,'',fno],1,4) file_searcher,templates=template, spex_test_dir=spex_test_dir, wildcard=wildcard, inserts=inserts, $ out_fname=out_fname, out_dir=out_dir end strpos(data_form,'DISCLA') ne -1: begin test_file = (fcheck(test_file,''))(0) wildcard = '^' template=['discla_ibdb_^.fits', $ 'discla_ibdb.^', $ 'discla_data.dat','*.fdb_^'] if test_file ne '' then begin template = [test_file,template] inserts = reform(['',bno,bno,'',fno],1,5) endif else inserts = reform([bno,bno,'',fno],1,4) file_searcher,templates=template, spex_test_dir=spex_test_dir, wildcard=wildcard, inserts=inserts, $ out_fname=out_fname, out_dir=out_dir end strpos(data_form,'HER') ne -1 or strpos(data_form,'STTE') ne -1 $ : begin ;Account for Sher(b) and Her(b) test_file = fcheck(test_file,['','']) if data_form eq 'STTE' then its_stte=1 else its_stte=0 if data_form eq 'SHERS' then its_sher=1 else its_sher=0 if its_sher or its_stte then prfx='sher' else prfx='her if not its_stte then begin uprfx = strupcase(prfx) wsherb = where( strpos(strupcase(test_file), uprfx+'B') ne -1, nsherb) if nsherb eq 1 then begin test_sherb = test_file(wsherb) test_sher = test_file(1-wsherb(0)) endif else begin test_sherb='' test_sher ='' endelse endif else begin ;The case of SHER and STTE uprfx = strupcase(prfx) wstte = where( strpos(strupcase(test_file), 'STTE') ne -1, nstte) if nstte eq 1 then begin test_stte = test_file(wstte) test_sher = test_file(1-wstte(0)) endif else begin test_stte='' test_sher ='' endelse endelse wildcard = '%' ;Protect against both sher_only and sherb_only, both enabled if fcheck(sher_only) and fcheck(sherb_only) then begin sher_only = 0 & sherb_only=0 endif ;Locate SHERB or HERB or STTE first if not fcheck(sher_only) then begin if not its_stte then begin template=prfx+ ['b_ibdb_%.fits', $ 'b_ibdb.%', $ 'b_data.%'] inserts = reform([bno,bno,bno],1,3) if test_sherb(0) ne '' then begin template = [test_sherb, template] inserts = reform(['',inserts(*)],1,4) endif endif else begin ; Look for STTE template='stte'+ ['_ibdb_%.fits', $ '_ibdb.%', $ '_data.%'] inserts = reform([bno,bno,bno],1,3) if test_stte(0) ne '' then begin template = [test_stte, template] inserts = reform(['',inserts(*)],1,4) endif endelse file_searcher,templates=template, spex_test_dir=spex_test_dir, wildcard=wildcard, inserts=inserts, $ out_fname=out_sherb, out_dir=out_dir endif else out_sherb = '' ;Locate SHER or HER second if not fcheck(sherb_only) then begin template= prfx+ ['_cor_ibdb_%_%.fits', $ '_ibdb_%_%.fits', $ '_cor_ibdb_%.%', $ '_ibdb_%.%', $ '_cor_data.%', $ '_cor_data_%.fits', $ '_data.%', $ '_cor_data_%.fits_%'] ids = strtrim(det_id,2) if flare ne 0 then begin read_flare, flare, fldata tjds=strtrim( ymd2tjd(fldata.(1)),2) endif else if keyword_set(event_time) then $ tjds=strtrim(ymd2tjd(event_time),2) else tjds='0000' inserts = reform([ids,bno,ids,bno,ids,bno,ids,bno,ids,$ '',ids,'',ids,'',ids,tjds],2,8) if test_sher ne '' then begin template = [test_sher, template] inserts = reform(['','',inserts(*)],2,9) endif sher_test_dir = [spex_test_dir,out_dir] file_searcher,templates=template, spex_test_dir=sher_test_dir, wildcard=wildcard,$ inserts=inserts, out_fname=out_sher, out_dir=out_dir endif else out_sher='' out_fname = [out_sherb, out_sher] end 1: ;closes cases for BATSE data types endcase ;end BATSE data files end 'DRM': begin ;find response matrix files if they exist ;find BATSE drm files flr_mask = '00000' fno = strtrim(flare,2) strput, flr_mask, fno, 5-strlen(fno) case data_form of 'CONT': det_type='lad' 'HERS': det_type='lad' 'SHERS':det_type='spec' else: det_type='lad' endcase wildcard = '^' ids = strtrim(det_id,2) template = ['^_direct_^_^.drm'] inserts = reform([det_type,ids,flr_mask],3,1) file_searcher,templates=template, spex_test_dir=spex_test_dir, wildcard=wildcard, inserts=inserts, $ out_fname=out_direct, out_dir=out_dir1 ; template = ['^_scatter_^_^.drm'] file_searcher,templates=template, spex_test_dir=spex_test_dir, wildcard=wildcard, inserts=inserts, $ out_fname=out_scatter, out_dir=out_dir2 out_fname = [out_direct,out_scatter] out_dir = [out_dir1, out_dir2] end else: begin end endcase ;closes cases of BATSE file types end