pro chk_dataqual, infil
;
;
;
close, 1
openr, 1, infil, /block
close, 2
openw, 2, 'chk_dataqual.txt'
printf, 2, 'CHK_DATAQUAL.PRO  
printf, 2, 'Input File: ', infil
printf, 2, 'Program Run ', !stime
printf, 2, '  '
;
nbad = 0
nbad2 = 0
irec = 0
last_tim = ' '
while not eof(1) do begin
    rd_telem, 1, irec, rec1, err, badmf, /force
    if ((err ne 0) and (err ne 36)) then begin
	str1 = '     '
	str2 = '     '
	if (btest0(err,0)) then str1 = ' Sync'
	if (btest0(err,1)) then str2 = ' FI  '
	str = string(irec) + str1 + str2 + string(fix(total(badmf)),format='(i4)')  + $
			string(rec1(16:31,0),format='(3x,16(1x,Z2.2))') + '  ' + last_tim
	print, str
	printf, 2, str
	nbad = nbad + 1
	if (total(badmf) lt 16) then nbad2 = nbad2 + 1
    end else begin
	ttim2ex, rec1, tarr
	last_tim = fmt_tim(tarr)
    end
    irec = irec + 1
end
print, 'Total of ', irec, ' records'
print, '  #Bad = ', nbad
print, 'Percent = ', nbad/float(irec)*100
print, '  #Bad (with less than 16 frames corrupted) = ', nbad2
print, 'Percent =                                     ', nbad2/float(irec)*100
;
printf,2, 'Total of ', irec, ' records'
printf,2, '  #Bad = ', nbad
printf,2, 'Percent = ', nbad/float(irec)*100
printf,2, '  #Bad (with less than 16 frames corrupted) = ', nbad2
printf,2, 'Percent =                                     ', nbad2/float(irec)*100
;
close, 1
close, 2
end
;----------------------------------------------------------------------
;
;chk_dataqual, '/0d1/ops/raw/09040127.09040139
;chk_dataqual, '/0d1/ops/raw/09181527.09182049
;chk_dataqual, '/0d1/ops/raw/09241800.09251710
;
;chk_dataqual, '/flare1_raw_tlm_mount/v1/9111/11121840.11131920
 chk_dataqual, '/flare1_raw_tlm_mount/v1/9111/11081700.11082040
;
end
