pro plot_phist, x, y1, y2, mlab1, mlab2, lab1, lab2, fact1, fact2, ss, print=print
;
;
!p.multi=[0,1,4]
!p.charsize = 1.8
;
if (n_elements(ss) eq 0) then ss = indgen(n_elements(x))
;
d = (y1*fact1 - y2*fact2)/2.45		;convert to arcsec, and then to SXT pixels
avg = total(d)/n_elements(d)
dev = stdev(d)
ff = 0.25
pp = 0
while (pp lt .98) do begin
    yrange = [avg-dev*ff, avg+dev*ff]
    ss0 = where( (d gt yrange(0)) and (d lt yrange(1)), count)
    pp = float(count) / n_elements(d)
    ff = ff + 0.25
end
;
str = ' '
if (keyword_set(print)) then begin
    dd = d(ss)
    avg = total(dd)/n_elements(dd)
    dev = stdev(dd)
    str = '  Average = ' + string(avg) + '  STDDEV = ' + string(dev)
end
;
utplot, x(ss), y1(ss), /ynozero, /year, tit=mlab1, ytit=lab1
utplot, x(ss), y2(ss), /ynozero, /year, tit=mlab2, ytit=lab2
utplot, x(ss),  d(ss), /ynozero, /year, tit=mlab1 + ' - ' + mlab2, ytit='SXT Pixels'
utplot, x(ss),  d(ss), /ynozero, /year, tit=mlab1 + ' - ' + mlab2+str, ytit='SXT Pixels', yrange=yrange
plottime, 0, 0, 'PLOT_PHIST Ver 1.3' & plottime & pause

end
;------------------------------------------------------------------------------
;
if (n_elements(sot) eq 0) then begin
    rd_sot, '1-sep-91', !stime, index, sot
    ss = where((gt_filta(index) eq 2) and (sot.find_limb(3) le .2) and (sot.find_limb(1) gt 400))
    index = index(ss)
    sot = sot(ss)
    ;
    get_pnt, index, pnt, offset=pnt_delta
    hxa0 = gt_hxa(pnt, /hxacen)
    hxa = hxa0
    hxa(0,*) = (hxa0(0,*) + hxa0(1,*)) / 1.41421	;take 45 degree tilt out of it
    hxa(1,*) = (hxa0(0,*) - hxa0(1,*)) / 1.41421
    tfss = gt_tfss(pnt)
    tfss(0,*) = -1*tfss(0,*)
    ;
    cmd = sxt_cen(index, /cmd)
    ;;sc  = sxt_cen(index)		;get_suncenter (HXA+IRU)
    ;
    ;off = get_del_pnt(index, '1-oct-91')
    ;
    ff = file_list('$DIR_SXT_SXC', 'sxc*')
    rd_roadmap, ff, rmap_sxc
    ii = tim2dset(rmap_sxc, index, delta=sxc_delta)
    rd_xda, ff, ii, index_sxc, sxc, rmap_sxc

    yesnox, 'Do you wish to save the results', ans, 'Yes'
    if (ans eq 1) then begin
	input, 'Enter the save file name ', outfil, '/2p/morrison/temp/phist.idl'
	save, file=outfil, index, sot, pnt, hxa, tfss, cmd, index_sxc, sxc, sxc_delta, pnt_delta
    end
end
;
s_pix = 2.45
h_pix = 2.072
;
ss1 = where(sxc_delta lt 600)
ss2 = sel_timrange(index, '9-apr-92 12:00', '14-apr-92 12:00')		;eliminate bad HXA values 9-Apr-92 to 14-Apr-92
ok = bytarr(n_elements(index))+1b & ok(ss2) = 0 & ss2 = where(ok)
ss3 = sel_timrange(index, '1-sep-91 00:00', '20-Oct-92 00:00')		;eliminate bad TFSS-X values after 20-Oct-92
ss4 = sel_timrange(index, '20-Oct-92 00:00', !stime)			;eliminate bad TFSS-X values after 20-Oct-92
ok(ss4) = 0 & ss4 = where(ok)						;eliminate bad HXA and TFSS
;
plot_phist, index, sot.find_limb(0), cmd(0,*), 'SOT', 'CMD', 'Pixels E/W', 'Pixels E/W', s_pix, s_pix
plot_phist, index, sot.find_limb(1), cmd(1,*), 'SOT', 'CMD', 'Pixels N/S', 'Pixels N/S', s_pix, s_pix
;
plot_phist, index, sot.find_limb(0), sxc.sxt_center(0,*), 'SOT', 'SXC', 'Pixels E/W', 'Pixels E/W', s_pix, s_pix, ss1, /print
plot_phist, index, sot.find_limb(1), sxc.sxt_center(1,*), 'SOT', 'SXC', 'Pixels N/S', 'Pixels N/S', s_pix, s_pix, ss1, /print
;
plot_phist, index, sot.find_limb(0), hxa(0,*), 'SOT', 'HXA', 'Pixels E/W', 'HXA Address E/W', s_pix, h_pix, ss2
plot_phist, index, sot.find_limb(1), hxa(1,*), 'SOT', 'HXA', 'Pixels N/S', 'HXA Address N/S', s_pix, h_pix, ss2
;
plot_phist, index, sot.find_limb(0), tfss(0,*), 'SOT', 'TFSS', 'Pixels E/W', 'TFSS Arcsec E/W', s_pix, 1.0, ss3
plot_phist, index, sot.find_limb(1), tfss(1,*), 'SOT', 'TFSS', 'Pixels N/S', 'TFSS Arcsec N/S', s_pix, 1.0, ss3
;
plot_phist, index, cmd(0,*), tfss(0,*), 'CMD', 'TFSS', 'Pixels E/W', 'TFSS Arcsec E/W', s_pix, 1.0, ss3
plot_phist, index, cmd(1,*), tfss(1,*), 'CMD', 'TFSS', 'Pixels N/S', 'TFSS Arcsec N/S', s_pix, 1.0, ss3
;
plot_phist, index, hxa(0,*), tfss(0,*), 'HXA', 'TFSS', 'Pixels E/W', 'TFSS Arcsec E/W', h_pix, 1.0, ss4
plot_phist, index, hxa(1,*), tfss(1,*), 'HXA', 'TFSS', 'Pixels N/S', 'TFSS Arcsec N/S', h_pix, 1.0, ss4
;
end

