;$Id: pdelt0.pro,v 1.1 2018/05/08 16:21:33 brandenb Exp $
if !d.name eq 'PS' then begin
  ;device,xsize=18,ysize=8,yoffset=3
  device,xsize=18,ysize=18,yoffset=3
  !p.charthick=3 & !p.thick=3 & !x.thick=3 & !y.thick=3
end
;
;  mv idl.ps ~/tex/roper/GW/fig/pdelt.ps
;
siz=1.6
siz=2.0
@parameters
!p.charsize=1.8
;!p.charsize=1.8
!x.margin=[7.2,0.5]
!y.margin=[3.2,0.2]
;
pc_read_ts,obj=ts
t=ts.t
;
nt=n_elements(t)
nt_shift=101
;
hhTp2_shift=fltarr(nt,nt_shift)
hhXp2_shift=fltarr(nt,nt_shift)
dt_shift=findgen(nt_shift)-nt_shift/2
dt_crit=findgen(nt)
;
for it_shift=0,nt_shift-1 do begin
  jt_shift=it_shift-nt_shift/2
  print,jt_shift
  hhTp2_shift(*,it_shift)=abs(ts.hhTpt-shift(ts.hhTp2,jt_shift))
  hhXp2_shift(*,it_shift)=abs(ts.hhXpt-shift(ts.hhXp2,jt_shift))
endfor
;
tot_shift=hhTp2_shift+hhXp2_shift
;tvscl,congrid(hhTp2_shift,nt,nt_shift*10)
yr=[0,.0005]
;
ldebug=0
ldebug=1
for it=0,nt-1 do begin
  s=reform(tot_shift[it,*])
  good=where(s eq min(s))
  if ldebug then begin
    ;print,it,n_elements(good)
    print,t[it]
    plot,dt_shift,tot_shift[it,*],yr=yr
    oplot,dt_shift,hhTp2_shift[it,*],col=122
    oplot,dt_shift,hhXp2_shift[it,*],col=55
    oplot,[1,1]*dt_shift(good[0]),yr
    ;help,[1,1]*dt_shift(good[0]),yr
    wait,.01
  endif
  dt_crit[it]=dt_shift(good[0])
endfor
;
circ_sym,.9,1
!p.multi=[0,1,2]
!x.title='!6'
!y.title='!610!u4!n!8h!6!d+!n  and  !610!u4!n!8h!6!d!9X!6!n'
fac=1e4 & fac2=7.2e-4 & fac3=10 ;(for f3 run)
fac=2e6 & fac2=5.0e-7 & fac3=30 ;(for g3 run)
plot,t,fac*ts.hhTpt,yr=fac*[-1,1]*fac2
oplot,t,fac*ts.hhTp2,col=122
oplot,t,fac*ts.hhXpt
oplot,t,fac*ts.hhXp2,col=55
!x.title='!8t!6'
!y.title='!7D!8t!6'
plot,t,dt_crit,yr=[-1,1]*fac3
oplot,t,t*0
;
notpos=where(dt_crit le 0.)
notneg=where(dt_crit ge 0.)
END
