PRO better,date,list,time,quality
;
;Reads a "qwl*.tmp" file, selects the better of a pair of frames
;per sel. interval, and stores the names, times, and quality numbers
;of "better" frames into arrays
;LIST = string array with filenames
;TIME = float array with times UT in seconds
;QUALITY = SVST quality number
;
;INPUT: date = date (integer, 23 or 25)
;
;SUBROUTINES: readqual.pro
;
;1 July 1999, Michal

on_error,1

n=0
if date eq 23 then n=642
if date eq 25 then n=720
if n eq 0 then message,'Sorry, I do not know how to handle this dataset'

date=strtrim(date,2)
name='m16b_im'+date+'Jun97.'

tq=readqual('qwl'+date+'jun.tmp')	;time | quality array
list=strarr(n/2)			;output arrays
time=fltarr(n/2)
quality=fltarr(n/2)
k=0			;k is a subscript of the arrays above

for i=0,n-2,2 do begin	;loop on pairs of frames (increment 2)

  j=0
  if tq(1,i+1) gt tq(1,i) then j=1	;2nd frame is better, j=1

  time(k)=tq(0,i+j)
  quality(k)=tq(1,i+j)

;building up the filename
  seq=strtrim(i+j+1,2)	;sequential no. of better frame (counted from 1)
   if strlen(seq) eq 3 then seq='000'+ seq
   if strlen(seq) eq 2 then seq='0000'+seq
   if strlen(seq) eq 1 then seq='00000'+seq
  list(k)=name+seq

	print,list(k),time(k),quality(k)-tq(1,i)

  k=k+1			;incrementing the subscript

endfor

END