pro xrt_metrics, start_date, end_date, exclude = exclude

;; exclude keyword is for xrt_telemetry_metrics, for excluding op
;; periods at the end of the month

;; date format:  '1-May-2008'

  report = start_date +'.txt'

;; get start month and year in integers for missing files program

  date = atime(start_date, /hxrbs, /y2k)
  str_year = strmid(date, 0, 4)
  str_month = strmid(date, 5, 2) 

  year = str_year*1
  month = str_month*1

;; check to make sure we're not overwriting an existing report

  file = file_info('$XRT/metrics/reports/'+str_year+'/'+str_month+'/'+report)

  if file.exists then begin
     answer = '' 
     read, answer, prompt='Telemetry report file exists. Continue [y/n]?'
     if strcmp(answer,'y') eq 0 then begin 
        print, 'Exiting...' 
        return
     endif
  endif

;; open report and include header info

openw, unit, report, /get_lun

printf, unit, 'XRT metrics report from ' + start_date + ' to ' + end_date
printf, unit

free_lun,unit

;; make a plot of XRT software mode

print, '========== Plotting XRT software mode....'

plot_xrt_software_mode, start_date, end_date

;; calculate XRT telemetry metrics

print, '========== Calculating telemetry usage...'

xrt_telemetry_metrics, alloc_vol=alloc_vol, planned_vol=planned_vol,$
                       actual_vol=actual_vol, st_str1=st_str1, en_str1=en_str1,$
                       report=report, exclude=exclude, nbad_index=nbad_index

;; add telemetry metrics info to report

telemetry_report, report, planned_vol, alloc_vol, actual_vol, nbad_index

;; find missing files and packets

print, '========== Finding missing files and missing packets...'

wrap_xrt_ecid_monthly, year, month,miss_files,miss_pkts, miss_pfiles, fi_idx, $
                       p_idx, files, tstamps


;; add info on missing files and packets to report

missing_files_report, report, miss_files, miss_pkts, miss_pfiles, files
  
;; make directory, move files there

spawn, 'mkdir -p $XRT/metrics/reports/'+str_year+'/'+str_month
spawn, 'mv '+ report +  ' $XRT/metrics/reports/'+str_year+'/'+str_month
spawn, 'mv xrt_software_mode_'+str_year+str_month + $
       '.gif $XRT/metrics/reports/'+str_year+'/'+str_month

end

  
