
pro plot_the_madness_sp_data_ops, filnam=filnam, do_grid=do_grid, do_write=do_write, filnam_gif=filnam_gif, new_win=new_win, $
  xycen_max=xycen_max, plot_sym=plot_sym, yrange_full=yrange_full, yrange_partial=yrange_partial, save_old=save_old, $
  no_zbuff=no_zbuff, qstop=qstop

; TODO:

if keyword_set(do_grid) then yticklen=1 else yticklen=0
if not exist(xycen_max) then xycen_max = 100
if not exist(plot_sym) then plot_sym = 3
if not exist(yrange_full) then yrange_full = [0.0,1.1]
if not exist(yrange_partial) then yrange_partial = [0.50,1.05]
if ~keyword_set(new_win) then new_win = 1

;if not exist(filnam) then filnam = '$HOME/soft/idl/idl_startup/sp_tp_tab.txt'
if not exist(filnam) then filnam = '/archive1/hinode/sot/sp_throughput/sp_tp_tab.txt'

;filnam_sp_sav = '$HOME/soft/idl/idl_startup/sp_throughput_mission.sav'
;filnam_sp_sav = '/sanhome/slater/public_html/sot/instrument/mechanisms_data_ops/sp_throughput_mission.sav'
 filnam_sp_sav = '/archive1/hinode/sot/instrument/mechanisms_data_ops/sp_throughput_mission.sav'
t0_ex = anytim('01-oct-2006', /ex)
t1_ex = anytim(anytim(!stime) + 31d*86400d, /ex)
t1_ex[0:3] = 0
t1_ex[4] = 1
timerange = anytim([[t0_ex], [t1_ex]], /yoh)

;if not exist(dirnam_gif) then dirnam_gif = '/sanhome/slater/public_html/sot/instrument/mechanisms_data_ops'
if not exist(dirnam_gif) then dirnam_gif = '/archive1/hinode/sot/sp_throughput'
if not exist(filnam_gif) then begin
  filnam_gif =  concat_dir(dirnam_gif, 'sp_throughput_mission.gif')
  filnam_gif_backup = concat_dir(dirnam_gif, 'sp_throughput_mission_' + time2file(!stime) + '.gif')
  if (file_exist(filnam_gif) ne 0) and (keyword_set(save_old)) then $
    spawn, 'cp -p ' + filnam_gif + ' ' + filnam_gif_backup
endif

if file_exist(filnam_sp_sav) then restore, filnam_sp_sav else $
  stop, 'Stopping.  Problem.'

if ( ~exist(struct_sp) and exist(index_arr) ) then struct_sp = index_arr

;mean_sp = struct_sp.mean_sp
median_sp = struct_sp.median_sp
xcen = struct_sp.xcen
ycen = struct_sp.ycen
ss_good = where( ((abs(xcen) le xycen_max) and (abs(ycen) le xycen_max)), n_good)

date_obs_good = struct_sp[ss_good].date_obs
median_good = median_sp[ss_good]
median_fac = 600.
median_norm = median_good / median_fac

if ~keyword_set(no_zbuff) then set_plot,'z'
set_plot, 'z'
cleanplot
if keyword_set(new_win) then wdef,2,1024+256,1024 ;768
!p.multi = [0,1,2]
;!p.region = [.1,.1,.9,.9]
title = 'Normalized SP Response For Pointings Within ' + strtrim(xycen_max,2) + ' arcsec of Sun Center'
ytitle = 'Normalized Response'
;utplot, tim_good, median_norm, psym=plot_sym, timerange=timerange, xstyle=1, yrange=yrange_full,    ystyle=1, $
utplot, date_obs_good, median_norm, psym=plot_sym, timerange=timerange, xstyle=1, yrange=yrange_full,    ystyle=1, $
  yticklen=yticklen, title=title, ytitle=ytitle, charsize=1.6, charthick=1
;utplot, tim_good, median_norm, psym=plot_sym, timerange=timerange, xstyle=1, yrange=yrange_partial, ystyle=1, $
utplot, date_obs_good, median_norm, psym=plot_sym, timerange=timerange, xstyle=1, yrange=yrange_partial, ystyle=1, $
  yticklen=yticklen, title=title, ytitle=ytitle, charsize=1.6, charthick=1

plot_time_stamp = 'Plot Created: ' + !stime
xyouts,0.75,0.02,plot_time_stamp,/norm,charsize=1

if keyword_set(do_write) then begin
   write_gif, filnam_gif, 255b-tvrd()
   chmod, filnam_gif, '0664'o
endif

!p.multi = 0
!p.region = 0
set_plot,'x'

if keyword_set(qstop) then stop, ' Stopping on request.'

end

