pro plot_shutter_perf, sttim, entim, every=every, info=info, $
                  outfil=outfil, ps=ps, gif=gif
;+
;NAME:
;	plot_shutter_perf
;PURPOSE:
;	To plot the pointing correction applied by the ISS PZT mirrors
;SAMPLE CALLING SEQUENCE:
;	plot_shutter_perf, '1-may', '6-jun', every=30
;INPUTS:
;	sttim	- The starting time/date
;	entim	- The ending time/date
;OPTIONAL KEYWORD INPUT:
;	every	- Only read every N data values
;
;HISTORY:
;V1.0	23-May-2001 (RIB) - Based on plot_pzt_corr
;V1.1	22-Jul-2003 (RIB) - Added avoid_spikes to remove bad points
;-
;
prog_ver = 'Plot_Shutter_Perf  Ver 1.1'

if (n_elements(sttim) eq 0) then sttim = fmt_tim(anytim2ints(ut_time(), off=-48.*60.*60))
if (n_elements(entim) eq 0) then entim = ut_time()

dev_status = !d.name

if (keyword_set(ps)) then begin
    if (n_elements(outfil) eq 0) then outfil = 'shutter_perf.ps'
    set_plot, 'ps'
    device, filename= outfil, /land
    loadct, 0
end

if (keyword_set(gif)) then begin
    if (n_elements(outfil) eq 0) then outfil = 'shutter_perf.gif'
    set_plot, 'z'
    tv2, 700, 600, /init
    loadct, 0
    erase
end

info = get_hk_info([sttim, entim], ['mksqsho1','mksqshc1','mksqrt1'], /nostring, every=every)
if (data_type(info) ne 8) then begin
    print, 'Plot_shutter:  Read of HK failed.  Returning...
    return
end

sho1 = info.mdi.value(*,0)
shc1 = info.mdi.value(*,1)
shr1 = info.mdi.value(*,2)

shrr = shr1
xx = where(shrr gt 64000)
shrr(xx) = shrr(xx) - 65536.

sh_open = sho1/256.
sh_exp = (shc1 - sho1)/256.
sh_rt = shrr/16.
yy = where((sh_rt ge -13.5) and (sh_rt le 13.5) and (sh_exp gt 0.0))

struc_time = info.mdi.daytime(yy)
struc_open = sh_open(yy)
struc_exp  = sh_exp(yy)

aa = avoid_spikes(struc_open)
bb = avoid_spikes(struc_exp)

!p.multi=[0,1,2]
tit1 = 'MDI Shutter Opening Time'
ytit1 = 'Time (msec)'
tit2 = 'MDI Shutter Exposure Time'
ytit2 = 'Time (msec)'

utplot, struc_time(aa), struc_open(aa), title=tit1, ytit=ytit1, /ynozero
utplot, struc_time(bb), struc_exp(bb),  title=tit2, ytit=ytit2, /ynozero

plottime, 0, 0, prog_ver
plottime, 0.6, 0, 'Plot Made '+!stime 

if (keyword_set(ps)) then begin
    device,/close
end

if (keyword_set(gif)) then begin
    ssw_file_delete, outfil
    zbuff2file, outfil, /gif
end

set_plot, dev_status

end
