;+
;
; NAME: 
;       TIME_ARC_NAME
;
; PURPOSE:
;
;
; CATEGORY:
;       BATSE
;
; CALLING SEQUENCE:
;
;
; CALLS:
;	none
;
; INPUTS:
;       none explicit, only through commons;
;
; OPTIONAL INPUTS:
;	none
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORDS:
;	none
; COMMON BLOCKS:
;	none
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	none
;
; MODIFICATION HISTORY:
;
;-
pro time_arc_name, in_time, filename, num_file, error=error
;
;
; Procedure to generate name of FDB archived plot files (FILENAME) based on the
; requested start time in seconds since 79/1/1,0000 (IN_TIME).  NUM_FILE is
; the number of files available for the operator to choose from.  If operator
; does not choose a file or if no files exist, then NUM_FILE equals 0.  If
; error = 1 then no FDB archived plot files exist for given input.
;
;
@flare_catalog
;
batse_read_cat
;
a_in_time = atime(in_time,/hxr)
time=strmid(a_in_time,10,11)
;
; if user specified a time of day as well as date, find all flares containing
; that time.  Otherwise, find all flares that are on (or overlap with)
; requested date.

if time ne '0000:00.000' then begin
   n1 = where((in_time ge fldata.start_secs) and $
              (in_time le (fldata.start_secs + fldata.duration)),tmp_count)
endif else begin	; time is just date, no hours, min, sec
   n1 = where(((fldata.start_secs + fldata.duration) ge in_time) and $
	      ((fldata.start_secs) le (in_time+86400.d0)),tmp_count)
endelse
if tmp_count eq 0 then goto,error_exit
fl_num_arr = fldata(n1).flare_num
peak_time_arr = fldata(n1).peak_secs
;
file_arr = strarr(tmp_count)
for i = 0,tmp_count-1 do begin
   search_name = concat_dir((chklog('BATSE_FLARES'))(0),'flare_' + $
             strtrim(fl_num_arr(i),2) + '.sav')
   file_arr(i) = findfile(search_name)
endfor
file_arr=file_arr(where(file_arr ne '',num_file))
peak_time_arr = peak_time_arr(where(file_arr ne ''))
;
;
if num_file eq 0 then goto,error_exit
;
; Print list of available files.
;
if num_file eq 1 then begin
   fil_num = 0
   goto,get_name
endif
;
print,'The following files contain the flare numbers corresponding to'
print,'the requested date.'
print,'   '
;
for i = 0,num_file-1 do begin
   brack = strpos(file_arr(i),']') + 1
   print, i,'  ',strmid(file_arr(i), brack, 50), '     Peak Time: ',$
      atime(peak_time_arr(i),/hxr)
endfor
;
; Prompt operator for choice.
;
read_num:
fil_num = ' '
read,$
  'Enter number of file to select, or press return to return to main menu. ',$
  fil_num

if fil_num eq '' then begin
   num_file = 0
   goto,getout
endif

if (fil_num lt 0) or (fil_num gt num_file-1) then begin
   print, 'Invalid choice, please reenter'
   goto,read_num
endif

get_name:
fil_num = fix(fil_num)
brack = strpos(file_arr(fil_num),']') + 1
new_name = strmid(file_arr(fil_num), brack, 30)
filename = strtrim(new_name,2)
print,' '
print,'Selected file: ',filename
print,' '
goto,getout

error_exit:
print,'No plot file available for this time or flare.'
num_file=0
error=1

getout:
return&end
