; restore, 'plot_pnt_off.idl'
if (n_elements(index) eq 0) then begin
    get_sfm,timegrid('1-oct-91',!stime,days=1),index,/nodata
    cmd = sxt_cen(index, /cmd)
    att = sxt_cen(index, delta=delta)
    diff = att-cmd
end
;
progver = 'PLOT_PNT_OFF  Ver 3.1  Mar-95'
!p.multi = [0,1,2]
goto, skip
;
utplot, index, cmd(0,*), tit='Commanded X', /ynozero, ytit='FR Pixels'
utplot, index, cmd(1,*), tit='Commanded Y', /ynozero, ytit='FR Pixels'
plottime, 0, 0, progver & plottime & pause
;
utplot, index, att(0,*), tit='ATT X', /ynozero, ytit='FR Pixels'
utplot, index, att(1,*), tit='ATT Y', /ynozero, ytit='FR Pixels'
plottime, 0, 0, progver & plottime & pause
;
utplot, index, diff(0,*), tit='ATT-CMD X', /ynozero, ytit='FR Pixels'
utplot, index, diff(1,*), tit='ATT-CMD Y', /ynozero, ytit='FR Pixels'
plottime, 0, 0, progver & plottime & pause

utplot, index, diff(0,*), tit='ATT-CMD X', /ynozero, ytit='FR Pixels', yrange=[-10,10]
utplot, index, diff(1,*), tit='ATT-CMD Y', /ynozero, ytit='FR Pixels'
plottime, 0, 0, progver & plottime & pause

;---------------------------
ref_time = '1-jan-92'
x = int2secarr(index, ref_time)
x_yr = x/(365*86400.)
y = sin(2*!pi*x_yr - !pi/2)*4
utplot, index, diff(0,*), tit='ATT-CMD X', /ynozero, ytit='FR Pixels', yrange=[-10,10]
outplot, index, y

y = sin(2*!pi*x_yr + !pi/2)*7*x_yr + 7*x_yr
utplot, index, diff(1,*), tit='ATT-CMD Y', /ynozero, ytit='FR Pixels'
outplot, index, y
plottime, 0, 0, progver & plottime 
;---------------------------
skip:
n = n_elements(diff(0,*))
for i=1,n-1 do if (diff(0,i) lt -10) then diff(0,i) = diff(0,i-1)
for i=1,n-1 do if (diff(1,i) lt -11) then diff(1,i) = diff(1,i-1)

!p.charsize=0
!p.multi=[0,1,2]
w = fltarr(n)+1
ref_time = '1-jan-92'
x = int2secarr(index, ref_time)
x_yr = x/(365.25*86400.)
y0 = diff(0,*)
param1 = [2, 0.75, 0.0]
;attcmd_funct1, x_yr, param1, y
y0fit = curvefit(x_yr, y0, w, param1, sigmaa, function_name = 'attcmd_funct1')
utplot, index, y0, tit='ATT-CMD X', /ynozero, ytit='FR Pixels', yrange=[-10,10]
plottimes, .01, .90, 'ATTCMD_FUNCT1 Params ' + arr2str(string(param1,format='(f8.4)')) + ' (X=years past 1-Jan-92)', 1.2
outplot, index, y0fit
;
y1 = diff(1,*)
param2 = [2, 5, 0.25, 10, -5.0]
;attcmd_funct2, x_yr, param2, y
y1fit = curvefit(x_yr, diff(1,*), w, param2, sigmaa, function_name = 'attcmd_funct2')
utplot, index, y1, tit='ATT-CMD Y', /ynozero, ytit='FR Pixels'
plottimes, .01, .90, 'ATTCMD_FUNCT2 Params ' + arr2str(string(param2,format='(f8.4)')) + ' (X=years past 1-Jan-92)', 1.2
outplot, index, y1fit
plottime, 0, 0, progver & plottime & pause

diff3 = y1-y1fit
coeff3=poly_fit(x_yr,diff3,5,yfit3)
;
;;!p.charsize=1.3
;;!p.multi=[0,1,3]
utplot, index, y0-y0fit, tit='ATT-CMD X MINUS Fit', /ynozero, ytit='FR Pixels'
utplot, index, y1-y1fit, tit='ATT-CMD Y MINUS Fit', /ynozero, ytit='FR Pixels'
;;outplot, index, yfit3
;;utplot, index, diff3-yfit3, tit='ATT-CMD Y MINUS Fit MINUS Fit2', /ynozero, ytit='FR Pixels'
;;plottimes, .01, .90, 'POLY_FIT Params ' + arr2str(coeff3, /trim) + ' (X=years past 1-Jan-92)', 1.2
plottime, 0, 0, progver & plottime & pause

; for i=680,700 do print, i, fmt_tim(index(i)), cmd(*,i), att(*,i), diff(*,i), format='(i3,2x,a,3x,6f8.3)'


stop
    cmd2 = sxt_cen(index, /cmd)
    diff2 = att-cmd2
    utplot, index, diff2(0,*), tit='ATT-CMD X (corrected)', /ynozero, ytit='FR Pixels', yrange=[-10,10]
    utplot, index, diff2(1,*), tit='ATT-CMD Y (corrected)', /ynozero, ytit='FR Pixels'
    plottime, 0, 0, progver & plottime & pause


end