pro plot_fits

restore,'test.sav
;set_plot,'ps

!p.multi = [0,2,5]

 for p = 0, 9 do begin

        j=120
        Chanlist = [5,7,9,11,13,15,17,19,21,23]

        state.chan = Chanlist(p)
        c1 = state.chan
        range = state.range
        x = reform(state.avg(c1,0:j))
        y = reform(state.avg(c1+1,0:j))
        ax = indgen(4*range+1)-2*range
        if (c1 ne 5) then begin
           if ((j mod 2) eq 0) then begin
              ; J is even, so length of arrays is odd--drop last and avg
              x = congrid(x(0:j-1),j/2)
              y = congrid(y(0:j-1),j/2)
           endif else begin
              ; J is odd, so length of arrays is even--avg directly
              x = congrid(x,(j+1)/2)
              y = congrid(y,(j+1)/2)
           endelse
           ax = indgen(2*range)-range
        endif
        amp = sqrt(x^2+y^2)
        pha = (atan(x,y)/!dtor+720.) mod 360.

        plot,ax,amp,psym=1,background=255,color=0,xsty=1,ytitle='Amplitude',$
                xtitle='Delay [nsec] relative to delay center'

        width = 10
        dlafit, ax, amp, width, pk, ax_fit, fit, chi
        oplot,ax_fit,fit,color=0,thick=1
        peak_val = ax_fit(where(fit EQ max(fit)))
        peak_val = pk

        plots,[peak_val,peak_val],[min(!y.crange),max(!y.crange)],/data,color=0

        ichan = ((c1-5)/2)>0<9
        xyouts,0.8,0.8,/norm,state.srclist(ichan),align=0.5,charthick=1,charsize=1,color=0
        xyouts,0.8,0.7,/norm,'Delay Center Shift = '+strmid(arr2str(peak_val,/trim),0,5),align=0.5,charthick=1,charsize=1,color=0

        wset,state.wid(1)
        plot,ax,pha,psym=6,symsize=0.5,background=255,color=0,xsty=1,ytitle='Phase',$
                xtitle='Delay [nsec] relative to delay center'


endfor
!p.multi = 0
set_plot,'win


end