function iruhxa_fit,iru_i,iru_d,hxa_i,hir_d,hxa_d,degree=degree

; various constants
hxa_parms,spix=spix,gpix=gpix
gpix = gpix/spix       ; gpix now = giro unit / sxt pixel size

if n_elements(degree) ne 1 then degree = 2    ; linear fit is default
n_i = n_elements(iru_i)
out = fltarr(2,n_i)                     ; output variable

; do the fitting procedure

if n_elements(hxa_i) ge degree then begin

   ofxy = hxa_d(*,0)

   ; gyro data for index and reference points.  Subtract constant offset.
   gix = reform(iru_d(1,*) - hir_d(1,0))
   giy = reform(iru_d(0,*) - hir_d(0,0))
   gcx = reform(hir_d(1,*) - hir_d(1,0))
   gcy = reform(hir_d(0,*) - hir_d(0,0))

   ; take care of iru "roll over"
   ww = where(gix + '800000'XL lt 0L)
   if ww(0) ge 0 then gix(ww) = gix(ww) + '1000000'XL
   ww = where(giy + '800000'XL lt 0L)
   if ww(0) ge 0 then giy(ww) = giy(ww) + '1000000'XL
   ww = where(gcx + '800000'XL lt 0L)
   if ww(0) ge 0 then gcx(ww) = gcx(ww) + '1000000'XL
   ww = where(gcy + '800000'XL lt 0L)
   if ww(0) ge 0 then gcy(ww) = gcy(ww) + '1000000'XL
   ww = where(gix - '800000'XL ge 0L)
   if ww(0) ge 0 then gix(ww) = gix(ww) - '1000000'XL
   ww = where(giy - '800000'XL ge 0L)
   if ww(0) ge 0 then giy(ww) = giy(ww) - '1000000'XL
   ww = where(gcx - '800000'XL ge 0L)
   if ww(0) ge 0 then gcx(ww) = gcx(ww) - '1000000'XL
   ww = where(gcy - '800000'XL ge 0L)
   if ww(0) ge 0 then gcy(ww) = gcy(ww) - '1000000'XL

   gix = float(gix) * gpix
   giy = float(giy) * gpix
   gcx = float(gcx) * gpix - (hxa_d(0,*)-ofxy(0))
   gcy = float(gcy) * gpix - (hxa_d(1,*)-ofxy(1))

   ; floating point time vectors for numerics
   tti = int2secarr(iru_i,hxa_i(0))
   ttc = int2secarr(hxa_i,hxa_i(0))

   ; linear fit through (hxa corrected) gyro values
   px = svdfit(ttc,gcx,degree)
   py = svdfit(ttc,gcy,degree)

   ; gyro corrected suncenter pos. for output times
   out(0,*) = gix - (px(0) + tti * px(1)) + ofxy(0)
   out(1,*) = giy - (py(0) + tti * py(1)) + ofxy(1)

endif else begin

   print,'!!! Error: not enough HXA values !!!'

endelse

return,out
end