;+
;
; NAME: 
;       LISTQUAL
;
; PURPOSE:
;
; Routine to read the quality file passed in argument 'file', and print
; it on the screen and in file qual.out, changing the times from day and
; seconds of day to our standard (more easily readable) yy/mm/dd,hhmm:ss
;
;
; 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:
;	file is read using readqual, then reformatted for output and display.
;
; MODIFICATION HISTORY:
; 	Kim Tolbert 6/5/91
;	Mod. 03/27/97 by RCJ. Fix structure reading.
;	ras, 16-oct-1997, use the new readqual.
;-
pro listqual, file, overflow=overflow, type=type
;
readqual, 0, text, filename=file
@qual_struct
err_rec = replicate( qual_rec, n_elements(text))
for i=0,n_elements(text)-1 do begin
	reads, text(i), format='(2x,i3,2(2x,i5,3x,f8.2),3x,a2,3x,a5,3x,a23)',qual_rec
	err_rec(i)=qual_rec
endfor

openw, luno, 'qual.out', /get_lun
printf, luno, ' '
printf, luno, ' Quality file ',file,'  (reformatted)'
printf, luno, ' '
print, ' '
print, ' Quality file ',file,'  (reformatted)'
print, ' '
for i = 0,n_elements(err_rec)-1 do begin
   if (keyword_set(overflow)) and (err_rec(i).error_type ne 30) then goto, next
   if (keyword_set(type)) then if (err_rec(i).error_type ne type) $
       then goto, next
   ed_start_day = err_rec(i).start_day - 3874; Convert TJD to ED
   ed_stop_day = err_rec(i).stop_day - 3874; Convert TJD to ED
   ed_start_sec = err_rec(i).start_sec
   ed_stop_sec = err_rec(i).stop_sec
   start = 86400.d0 * ed_start_day + ed_start_sec
   stop = 86400.d0 * ed_stop_day + ed_stop_sec
   printf, luno, format='(i3, 5x, a, " - ", a)', $
      err_rec(i).error_type, atime(start,/hxr), atime(stop,/hxr)
   print, format='(i3, 5x, a, " - ", a)', $
      err_rec(i).error_type, atime(start,/hxr), atime(stop,/hxr)
next:
endfor
print, 'This information is saved in file ', findfile('qual.out')
;
close, luno
free_lun, luno
;
getout:
end
