;+
;NAME:
;       go_arch_sum2
;PURPOSE:
;       Grep through the control file archive to make summaries of last 24-48 hours
;HISTORY:
;       Written 16-Apr-96 by M.Morrison
;	 8-May-96 (MDM) - Echo the rcp command
;	13-May-96 (MDM) - Changed grep command to always grep last24hrs.cfl_sum_cron
;			  so that when there is only one cfl file executed in the day
;			  it will list the file name
;			- Modified rcp command to have the destination file name
;			  explicitly
;V2.0    5-Aug-96 (MDM) - Modified to make the output directory $MDI_CAL_INFO
;V2.1   28-Oct-98 (RIB) - Modified to send outfil0 to outdir instead of indir
;V2.2    9-Nov-99 (RIB) - Removed trig_mirror command - to be run in a separate
;                         cron job.
;-
;
if (n_elements(date) eq 0) then date = ut_time()
indir = '/mdisw_cmd/archive'
outdir = '$MDI_CAL_INFO'
cd, indir
;
qredone = 0
;
top:
date = gt_day(date,/str)
tarr = anytim2ex(date)
fid1 = ex2fid(tarr)
tarr = anytim2ex(anytim2ints(date, off=-86400))
fid2 = ex2fid(tarr)
;
outfil0 = concat_dir(outdir, 'last24hrs.summary')
outfil1 = concat_dir(outdir, 'last24hrs.cfl_sum_cron')
;
ssw_file_delete, outfil0
spawn, '/bin/csh -c "grep ^source last24hrs.cfl_sum_cron ' + strmid(fid2, 0, 6) + '* >> ' + outfil0 + '"'
spawn, '/bin/csh -c "grep ^source last24hrs.cfl_sum_cron ' + strmid(fid1, 0, 6) + '* >> ' + outfil0 + '"'
;
mat = rd_tfile(outfil0,2)
if (mat(0) eq '') then begin
    out = ['*** No control files executed in last 24 hours ***']
end else begin
    fids = reform(strmid(mat(0,*), 0, 13))
    files0 = str_replace(reform(mat(1,*)), '"', '')
    break_file, files0, dsk_log, dir00, filenam, ext
    out = fids + '       ' + filenam + ext
end
;
tit = ['GO_ARCH_SUM2   Ver 2.0  Program Run: ' + ut_time() + ' UT', ' ']
ssw_file_delete, outfil1
prstr, [tit, out], file=outfil1
;
;;cmd = 'rcp -p ' + outfil1 + ' diapason:/hosts/pore1/usr/local/etc/httpd/htdocs/MDI/ops/run_stuff/last24hrs.cfl_sum_cron'
;;cmd = '/mdisw/bin/trig_mirror ' + getenv('MDI_CAL_INFO')
;;print, cmd
;;spawn, cmd
;
end
