function rd_ads_dir, infil=infil, outfil=outfil, sort=sort, copy=copy, all=all
;
;+
;
;
;HISTORY:
;	Written Jul-92 by M.Morrison
;	27-Aug-92 (MDM) - Added /ALL keyword - default is to pass only the
;			  "final" processing solutions
;       27-oct-92 (slf) - add diagnostic
;	 4-Apr-93 (MDM) - Added OUTFIL option to get text summary
;-
;
if (keyword_set(copy)) then begin
   message,/info,'Copying index file...'
   get_ads, 'PSK239.SAADF.INDEX'
endif
;
if (n_elements(infil) eq 0) then infil = '/ydb/ads/PSK239.SAADF.INDEX'
openr, lun, infil, /get_lun
;
ff = file_info(infil, finfo)
siz = finfo.size
nlin = siz/100
;
out = {rd_ads_dir, file: ' ', time: 0L, day: 0, duration: 0L, recs: 0L, comment: ' '}
out = replicate(out, nlin)
;
b = bytarr(100)
readu, lun, b		;skip first line
i = 0
qdone = 0
while (not qdone) do begin
    readu, lun, b
    a = str_ebc2asc(b)
    ss = where(a eq 0)
    if (ss(0) ne -1) then a(ss) = 32b
    a = string(a)

    if (strtrim(a,2) eq '') then begin
	qdone = 1
    end else begin
	fid = strmid(a, 40, 6) + '.' + strmid(a, 46, 4)
	sttim = anytim2ints( fid2ex(fid) )
	fid = strmid(a, 52, 6) + '.' + strmid(a, 58, 4)
	entim = anytim2ints( fid2ex(fid) )
	;
	out(i).file = strmid(a, 0, 28)
	out(i).time = sttim.time
	out(i).day  = sttim.day
	out(i).duration = int2secarr(entim, sttim)
	out(i).recs     = long(strmid(a, 64, 6))
	out(i).comment  = strmid(a, 71, 30)
	i = i + 1
    end
    ;
    if (i eq nlin) then qdone = 1
end
;
if (i ne nlin) then out = out(0:i-1)
;
if (not keyword_set(all)) then out = out(56:*)		;drop first 56 sets - they were test sets
;
if (keyword_set(sort)) then begin
    x = int2secarr(out)
    ss = sort(x)
    out = out(ss)
end
free_lun, lun
;
if (keyword_set(outfil)) then begin
    openw, lun, outfil, /get_lun
    printf, lun, 'RD_ADS_DIR.PRO  Program Run: ', !stime
    printf, lun, ' '
    printf, lun, '
    for i=0,n_elements(out)-1 do begin
	out0 = out(i)
	entim = anytim2ints(out0, off=out0.duration)
	fmt = '(1x, 4(a,2x), f6.2, i8)'
	str = string(out0.file, fmt_tim(out0), ' to ', fmt_tim(entim), out0.duration/60./60., out0.recs, format=fmt)
	printf, lun, str
	print, str
    end
    free_lun, lun
end
return, out
end
