pro find_dbfile, instring, start, dd_open, dd_type, sec_st, sec_to, sec_en, $
    error = error

error = 0
;
;  if start ge 2 then instring includes a leading character plus comma
;  if start eq 0 then the instring is stripped of 'INP,'
;
; Parse the input string, remove white space
args = strcompress(/remove,strlowcase(parse_comline( instring,nargs,/nocase )))
if start eq 0 then begin
    args = ['',args]
    nargs= nargs+1
endif

; If there are 4 arguments, the last two are a hxrbs format time string.
;
if nargs eq 4 then args=[args(0:1),args(2)+','+args(3)]
case strlowcase(args(1)) of
;
; Operator has entered a date and/or time to get a file.
;
  't': begin
    in_time = args(2)
    time = utime(in_time)
    keyword = "time='" + anytim(time,/hxrbs) + "'"
  end
;
; Operator has entered a flare number.
;
  'f': begin
    in_flare = args(2)
    flare_n = long(in_flare)
    if dd_type ne 0 then begin   ; for fdb files, can get file name from flare number
       keyword = 'flare=' + strtrim(flare_n,2)
   endif else begin  ; for bdb files, get flare time to get file name
       read_flare, flare_n, flare_rec, error=error_f
       if error_f then goto,error_exit 
       keyword = "time='" + anytim(flare_rec.start_secs,/hxrbs) + "'"
    endelse
  end        

; Operator has entered a TJD or YY/MM/DD, and Secs of Day(optional).

  'j': begin
    in_j = args(2)
    in_j_parsed_arr = parse_comline(in_j,nvalues)
    if (nvalues gt 2) or (nvalues lt 1) then goto,error_exit

    if strpos(in_j_parsed_arr(0),'/') ne -1 $       ;For YY/MM/DD...
    then time = utime(in_j_parsed_arr(0)) $
    else time = tjd2ymd(in_j_parsed_arr(0)) ;For TJD...
    if nvalues eq 2 then time = time + long(in_j_parsed_arr(1))
    keyword = 'time=' + anytim(time,/hxrbs)
  end

; Operator has entered a file name.

  else : begin
    fs_infile  =     args(1)
    paths = [curdir(),'BATSE_'+(['BDB','FDB','CONT','DISCSP'])(dd_type < 3 > 0)]
    fs_infile_in = loc_file( path=paths, fs_infile,  count=count_infile)
     if count_infile eq 0 then $ 
    fs_infile_in = loc_file(path=paths, strlowcase(fs_infile),  count=count_infile)
     if count_infile eq 0 then $ 
    fs_infile_in = loc_file(path=paths, strupcase(fs_infile),  count=count_infile)
     if count_infile ge 1  then fs_infile_in = fs_infile_in(0) else $
    fs_infile_in=fs_infile(0)
    keyword =  'file="' + strtrim( fs_infile_in) + '"'

  end
endcase
;  
; Open the file.
;
result = execute ('fs_open, ' + keyword + ',dd_type=dd_type, dd_open=dd_open,'+ $
   'error=error')
if not(result) or error then goto,error_exit
;
; Get start and end times from file header and put into op/com.
;
sec_st = dd_open.startsec
if dd_type eq 0 then begin
   sec_to = 300.d0
   sec_en = sec_st + sec_to
endif else begin
   sec_en = dd_open.endsec
   sec_to = sec_en - sec_st
endelse  
;
setut,utbase=atime(sec_st),utstart=atime(sec_st),utend=atime(sec_en), $
      error = error
if error then begin
   print,'In find_dbfile-- setut error =',error
   goto,error_exit
endif
;
goto,getout
;
error_exit:
error = 1
;
getout:
;
end