pro telemetry_report, report, planned_vol, alloc_vol, actual_vol, nbad_index

;;  2010/01/13 KKR
;;      Added nbad_index keyword, which reports number of 
;;      files without bitspp keyword.

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

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

  ;; open report

  openu, unit, report, /get_lun, /append
  
  printf, unit, '-Telemetry usage'
  printf, unit

  printf, unit, "The following metrics are used to evaluate XRT's usage of " $
         + 'available telemetry.'
  printf, unit, 'V (volume) = allocated volume per timeline [Mbits]'
  printf, unit, 'P (planned) = volume we intended to use per timeline [Mbits]'
  printf, unit, 'A (actual) = volume of the respective Level-0 data, per timeline [Mbits]'
  printf, unit


;; This tells us what we planned versus what was allocated to us.
  cc = planned_vol/alloc_vol
;  print, mean(cc)
;  print, stdev(cc)

  printf, unit, 'The ratio P:V is the volume we planned to use versus the ' $
         + 'the volume we were allocated. Discrepancy is solely due to ' $
         + 'choices by the Chief Observers. It is possible to plan an overusage.'
  printf, unit, 'Mean(P:V) = ' + strcompress(mean(cc, /nan),/rem) + '.'
  printf, unit, 'StdDev(P:V) = ' + strcompress(stddev(cc ,/nan),/rem) + '.'
  printf, unit, 'Comments: [[Add text: are these numbers okay? Is progress to be expected?]]'
  printf, unit


;; This tells us how well we actually did versus what we intended to do.
  aa = actual_vol/planned_vol
;  print, mean(aa)
;  print, stdev(aa)

  printf, unit, 'The ratio A:P is the actual volume used versus the volume we ' $
         + 'planned to use. Discrepancy is chiefly due to the ' $
         + 'imprecision with which we know the effect of compression ' $
         + 'for different solar features, as well as due to the variability.'
  printf, unit, 'Mean(A:P) = ' + strcompress(mean(aa, /nan),/rem) + '.'
  printf, unit, 'StdDev(A:P) = ' + strcompress(stddev(aa, /nan),/rem) + '.'
  printf, unit, 'Comments: [[Add text: are these numbers okay? Is progress to be expected?]]'
  printf, unit


;; This tells us how well we actually did versus what we were allocated.
  bb = actual_vol/alloc_vol
 ; print, mean(bb)
 ; print, stdev(bb)

  printf, unit, 'The ratio A:V is the actual volume used versus the volume we ' $ 
         + 'were allocated. This ratio obviously conflates factors ' $
         + 'within the previous two ratios. However, it most directly ' $
         + "answers the question of how effectively we are using XRT's " $
         + 'telemetry resources.'
  printf, unit, 'Mean(A:V) = ' + strcompress(mean(bb, /nan),/rem) + '.'
  printf, unit, 'StdDev(A:V) = ' + strcompress(stddev(bb, /nan),/rem) + '.'
  printf, unit, 'Comments: [[Add text: are these numbers okay? Is progress to be expected?]]'
  printf, unit
  printf, unit, 'NOTE: ' + trim(nbad_index, 1) +$
          ' 64x64 pixel files were not counted due to missing bits per pixel keyword in FITS file.'
  free_lun, unit 

end
