pro wfile,date, t_name, f_name, quiet=quiet
;+
;
;  Procedure to inform where (which tape and which data file) a specified
;  event is likely to be.
;
;  Input:
;           date         Date and time of event. 
;                        Formats accepted are the usual 
;                        1) Vax-type date/time  (17-mar-92 17:23)
;                        2) 7-element time array (hh mm ss msec dd mm yy)
;                        3) File id format (920412.0123)
;
;  Keyword: quiet        if set, do not echo results to terminal
;
;  Output:
;           t_name        name of the archive tape
;           f_name        file name within that tape (or on disk)
;
;  Use:
;          IDL>  wfile,'12-Mar-92 15:34',t_name,f_name
;          IDL>  wfile,'920423.1234'
;
;  	CDP 	April 92
;	RDB	20-Jun-92	Capitalized $DIR_GEN_XDB for Unix
;				Added use on CONCAT_DIR
;       CDP     17-Sept-92      Fix bug for week numbers < 10 and for files
;                               before the beginning of the first file of the 
;                               week. 
;       CDP     28-Jan-93       Cater for the new tape versions .02/.03 etc
;                               by picking the last (and latest version) for
;                               searching.
;                               Added quiet keyword.
;
;-
;                                                   
;  try and interpret any date/time
;
;
;  is time given in fileid format?
;
if n_elements(date) eq 1 then begin
   dot = strpos(date,'.')
   if dot gt 0 then date = fid2ex(date)
endif
ddate = ex2fid(anytim2ex(date))
tarr = fid2ex(ddate)
;
;  calculate week of year
;
week = ex2week(tarr)
week = week + 100
;
;  look in this directory file
;
rqfile = 'xbd' + strtrim(string(tarr(6)),2) + '_' +  $
                           strmid(strtrim(string(week),2),1,2) + '*.*'
need   = concat_dir('$DIR_GEN_XBD',rqfile)
ff = findfile(need,count=cc)
if cc eq 0 and not keyword_set(quiet) then begin
   print,' '
   print,' '
   print,'There are no archive data for that week yet.'
   print,' '
   print,' '
   t_name = ' '
   f_name = ' '
   return
endif
;
;  **assume only one file at present**   updated
;  pick last/latest file
;
rd_tapdir,ff(n_elements(ff)-1),hdr,drecs

num_nam = n_elements(drecs.fileid)/11
xx = where(string(drecs(1:num_nam-1).fileid) lt ddate) + 1
it = xx(n_elements(xx)-1)

f_name = string(drecs(it).fileid)
t_name = string(drecs(0).fileid)

if not keyword_set(quiet) then begin
   if it gt 0 then begin
      print,' '
      print,' '
      print,'The event (tape: ',t_name,') may be in files xxx',f_name
      print,' '
      print,' '
   endif else begin
      print,' '
      print,'The requested time is probably in the last file of the previous'
      print,'week.  Try again with a time at the end of the previous day.'
      print,' '
   endelse
endif

end
 
