;+
; Project     : SOHO - CDS     
;                   
; Name        : HC_SINCE()
;               
; Purpose     : Determine FITS file names within date range.
;               
; Explanation : Uses the RAL header catalogue to determine the names
;               of FITS data files within a data range.
;               
; Use         : IDL> f = hc_since(date, duration)
;    
; Inputs      : Date - start date for search
;               
; Opt. Inputs : Duration - date window (in days) - default = 5
;               
; Outputs     : Function returns list of filenames
;               
; Opt. Outputs: None
;               
; Keywords    : None
;
; Calls       : HEADCAT
;
; Common      : None
;               
; Restrictions: None
;               
; Side effects: None
;               
; Category    : Catalogues
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 
;               
; Modified    : Extend to 2004 and beyond, CDP.  05-Jan-2004
;
; Version     : Version 3, 05-jan-2004
;-            

function hc_since, date, duration

;
;  check input date
;
if n_params() eq 0 then begin
   print,'Must give start date.'
   return,0
endif

;
;  default duration of 1 day
;
if n_elements(duration) eq 0 then duration = 5.0

;
;  convert to TAI
;
errmsg = ''
tai = anytim2tai(date, errmsg=errmsg)
if errmsg ne '' then begin
   print,errmsg
   return,0
endif

;
;  time now and a week ago
;
get_utc,utc
now = utc2tai(utc)
now_7 = now - 86400.*7.

;
;  marker at start of 1997 to select which catalogue
;
t96 = anytim2tai('1996-1-1')
t97 = anytim2tai('1997-1-1')
t98 = anytim2tai('1998-1-1')
t99 = anytim2tai('1999-1-1')
t00 = anytim2tai('2000-1-1')
t01 = anytim2tai('2001-1-1')
t02 = anytim2tai('2002-1-1')
t03 = anytim2tai('2003-1-1')
t04 = anytim2tai('2004-1-1')
t05 = anytim2tai('2005-1-1')
t06 = anytim2tai('2006-1-1')
t07 = anytim2tai('2007-1-1')


;
;  load appropriate part of catalogue
;
case 1 of
      (tai ge now_7):                headcat,cat,/latest
      (tai ge t07 and tai lt now-7): headcat,cat,y=2007
      (tai ge t06 and tai lt now-7): headcat,cat,y=2006
      (tai ge t05 and tai lt now-7): headcat,cat,y=2005
      (tai ge t04 and tai lt now-7): headcat,cat,y=2004
      (tai ge t03 and tai lt now-7): headcat,cat,y=2003
      (tai ge t02 and tai lt now-7): headcat,cat,y=2002
      (tai ge t01 and tai lt now-7): headcat,cat,y=2001
      (tai ge t00 and tai lt now-7): headcat,cat,y=2000 
      (tai ge t99 and tai lt now-7): headcat,cat,y=99 
      (tai ge t98 and tai lt now-7): headcat,cat,y=98 
      (tai ge t97 and tai lt now-7): headcat,cat,y=97 
      (tai ge t96 and tai lt now-7): headcat,cat,y=96 
      else:                          headcat,cat 
endcase

;
;  find the files in range
;
n = where(cat.obt_time ge tai and $
          cat.obt_time le tai + duration*8.640d04,count)

;
;  return result
;
if count gt 0 then return,cat(n).filename else return,0

end
