pro cfl_summary, sttim, entim, month=month, outdir=outdir, outfil=outfil
;+
;NAME:
;       cfl_summary
;PURPOSE:
;       Make MDI control file summaries 
;HISTORY:
;       Written 6-Oct-99 by R. Bush
;	Combines and replaces go_arch_sum and go_arch_sum2
;-
;

if (n_elements(entim) eq 0) then entim = ut_time()
if (n_elements(sttim) eq 0) then sttim = fmt_tim(anytim2ints(entim, off= -86400.))
if (n_elements(outdir) eq 0) then outdir = getenv('MDI_CAL_INFO')
if (n_elements(outfil) eq 0) then outfil = 'last24hrs'

tmpdir = getenv('MDI_TEMP_DIR')
outfil1 = concat_dir(tmpdir, 'mdicmd.cfl_summary')
outfil2 = concat_dir(tmpdir, 'archive.cfl_summary')
outfil_cron = concat_dir(outdir, outfil + '.cfl_sum_cron')
outfil_alph = concat_dir(outdir, outfil + '.cfl_sum_alph')

indir1 = '/mdisw_cmd/archive'
trim1 = 19
indir2 = '/mdisw/archive'
trim2 = 15
ssw_file_delete, outfil1

print,sttim,'  ',entim

stt=anytim2ints(sttim)
ett=anytim2ints(entim)
nday = ett.day - stt.day
if (nday eq 0) then nday = 1
ff = strarr(2000)
n = 0

if (keyword_set(month)) then begin
    fid_st = ex2fid(anytim2ex(sttim))
    fid =  strmid(fid_st, 0, 4) + '*'
    flist = file_list(indir1, fid)
    nfl = n_elements(flist)
    if (flist(0) ne '') then begin
        ff(0:nfl-1) = flist
        n = nfl
        end
end else begin
    for i = 0, nday do begin
        tim = anytim2ints(sttim, off= i*(86400.D))
        fid = strmid(ex2fid(anytim2ex(tim)) , 0, 6) + '*'
        flist = file_list(indir1, fid)
        nfl = n_elements(flist)
        if (flist(0) ne '') then begin
            ff(n:n+nfl-1) = flist
            n = n + nfl
        end
    end
end

for j = 0, floor(n/100.) do begin
    yy = ''
    for i = 0, 99 do begin 
        cnt = i + j*100
        if (ff(cnt) ne '') then yy = yy + ff(cnt) + ' '
    end
    if (yy ne '') then begin
        cmd = '/sbin/grep ^source ' + yy + ' >> ' + outfil1 
        print, cmd
        spawn, cmd
    end
end

mat1 = rd_tfile(outfil1,2)
print,mat1

if (mat1(0) eq '') then begin
    out = ['*** No control files executed in last '+ strtrim(nday,2) +' days ***']
    out2 = out
end else begin
    fids1 = reform(strmid(mat1(0,*), trim1, 13))
    files1 = str_replace(reform(mat1(1,*)), '"', '')
    break_file, files1, dsk_log, dir00, filenam, ext
print,fids1
print, filenam
    out = fids1 + '       ' + filenam + ext
print,out
    out2 = out(sort(filenam+fids1))
end

tit = ['CFL_SUMMARY   Ver 1.0  Run: ' + ut_time() + ' UT', $
       '    Processing from ' + fmt_tim(sttim) + ' to ' + fmt_tim(entim), ' ']

ssw_file_delete, outfil_cron
prstr, [tit, out], file=outfil_cron
ssw_file_delete, outfil_alph
prstr, [tit, out2], file=outfil_alph

end
