

;;; zero-order check


IF !ioflags.do_read EQ 1 THEN BEGIN
   
   fpath = '/wiwaxia/d3/ciao_tests/2.0alpha_000605/1318-AP/'
   fn = 'acisf01318N002_pha2.fits.gz'
   fen = 'acisf01318N002_evt2.fits.gz'
   e=mrdfits(fpath+fen,1,he)
   p=mrdfits(fpath+fn,1,hp)
   
ENDIF


xra=[4115,4140]
yra=[4045,4075]

ll=where(between(e.x,xra) and between(e.y,yra))

x0m=(moment(e[ll].x))[0]
y0m=(moment(e[ll].y))[0]

x0=p[0].x
y0=p[0].y

dpix = sqrt( (x0-x0m)^2+(y0-y0m)^2)
dmegbin = dpix*0.024/!x_tg*!meg_period/0.005
print, dpix, dmegbin

foo = ps_open()

IF !ioflags.do_plot EQ 1 THEN BEGIN
   
   IF !ioflags.do_ps EQ 0 THEN window,1,xsi=512,ysi=512, retain = 2
   IF !ioflags.do_ps EQ 1 THEN BEGIN
      set_plot,'ps' &  device,/port,/inch,xsi=6,ysi=6,/color,file='1318_zo_check.ps'
   ENDIF

   plot,e.x,e.y,xra=xra,yra=yra,xtit='Sky X',ytit='Sky Y',tit=tit, psy = 3
   plots,x0m,y0m,psy=7,symsi=2, thick = 3, col = 99
   plots,x0,y0,psy=1,symsi=2, thick = 2, col = 177
   legend,['cxcds','idl'], psy=[1,7], col = [177, 99], symsi=[2, 2], thick=[2, 3]
   xyouts, 0.15, 0.15, 'Z.O. Sep='+string(dpix, format = '(f4.2)')+' [pix]', /norm
   xyouts, 0.4, 0.15, '='+string(dmegbin, format = '(f4.2)')+' MEG bins (max)', /norm
   id_plot
   gif_out,'1318_zo_check.gif'

   
ENDIF



IF !ioflags.do_plot EQ 2 THEN BEGIN

   IF !ioflags.do_ps EQ 0 THEN wset, 0

;;;;;; look at line regions


   ww=[15.014,17.051,17.096,16.780,11.131] ; wavelengths of best lines from Brown98 


   IF !ioflags.do_ps EQ 1 THEN BEGIN
      device, /land, file = '1318_Wave_checks.ps', /inch, xsi=10, ysi=6, /color
   ENDIF



   plot,p[8].bin_lo,p[8].counts,psy=10,xra=[14.9,15.1], xtit = 'Wavelength '+ !anglbl, tit = tit
   oplot,p[9].bin_lo,p[9].counts,psy=10,col = 222
   plots,[1,1]*15.014,[0,250],psy=0, col = 155
   oplot,p[2].bin_lo,p[2].counts,psy=10,col = 111
   oplot,p[3].bin_lo,p[3].counts,psy=10,col = 111
   legend, ['MEG-1', 'MEG+1', 'HEG-1', 'HEG+1', 'Lab value'], $
    col = [254, 222, 111, 111, 155], line = [0, 0, 0, 0, 0]
   id_plot
   gif_out, '1318_15A.gif'


   plot,p[8].bin_lo,p[8].counts,psy=10,xra=[17.0,17.15], /xst, xtit = 'Wavelength '+ !anglbl, tit = tit
   oplot,p[9].bin_lo,p[9].counts,psy=10,col = 222
   plots,[1,1]*17.051,[0,300],psy=0,col=155
   plots,[1,1]*17.096,[0,300],psy=0,col=155
   oplot,p[2].bin_lo,p[2].counts,psy=10,col = 111
   oplot,p[3].bin_lo,p[3].counts,psy=10,col = 111
   legend, ['MEG-1', 'MEG+1', 'HEG-1', 'HEG+1', 'Lab value'], $
    col = [254, 222, 111, 111, 155], line = [0, 0, 0, 0, 0]
   id_plot
   gif_out, '1318_17A.gif'
   
   plot,p[8].bin_lo,p[8].counts,psy=10,xra=[16.7,16.85], /xst, xtit = 'Wavelength '+ !anglbl, tit = tit
   oplot,p[9].bin_lo,p[9].counts,psy=10,col = 222
   plots,[1,1]*16.780,[0,200],psy=0,col=155
   oplot,p[2].bin_lo,p[2].counts,psy=10,col = 111
   oplot,p[3].bin_lo,p[3].counts,psy=10,col = 111
   legend, ['MEG-1', 'MEG+1', 'HEG-1', 'HEG+1', 'Lab value'], $
    col = [254, 222, 111, 111, 155], line = [0, 0, 0, 0, 0]
   id_plot
   gif_out, '1318_16A.gif'
   
   plot,p[8].bin_lo,p[8].counts,psy=10,xra=[11.0,11.2], xtit = 'Wavelength '+ !anglbl, tit = tit
   oplot,p[9].bin_lo,p[9].counts,psy=10,col = 222
   plots,[1,1]*11.131,[0,300],psy=0,col=155
   oplot,p[2].bin_lo,p[2].counts,psy=10,col = 111
   oplot,p[3].bin_lo,p[3].counts,psy=10,col = 111
   legend, ['MEG-1', 'MEG+1', 'HEG-1', 'HEG+1', 'Lab value'], $
    col = [254, 222, 111, 111, 155], line = [0, 0, 0, 0, 0]
   id_plot
   gif_out, '1318_11A.gif'
   
   
; MEG OVIII
   plot,p[8].bin_lo, p[8].counts,xra=[18.8,19.1],/xst, psy = 10, xtit = 'Wavelength '+ !anglbl, tit = tit
   oplot,p[9].bin_lo,p[9].counts, col=222, psy = 10
   plots,[1,1]*18.967,[0,1000],psy=0,col=155
   legend, ['MEG-1', 'MEG+1', 'HEG-1', 'HEG+1', 'Lab value'], $
    col = [254, 222, 111, 111, 155], line = [0, 0, 0, 0, 0]
   id_plot
   gif_out, '1318_19A.gif'
   
ENDIF


ps_close



END
