function hxaxy2sxt,time,hxa_d,noorbit=noorb,nomission=nomis

; various constants
hxa_parms,hpix=hpix,h_xx=h_xx,h_yy=h_yy,spix=spix,phi=phi,sxt_off=sxt_off, $
              cox=cox,coy=coy,tofac=tofac,clx=clx,cly=cly,tloff=tloff, $
              cmx=cmx,cmy=cmy,tmoff=tmoff,tmcut=tmcut
; hpix = HXA pixel size
; h_xx, h_yy = HXA detector crossing point coordinates
; spix = SXT pixel size  (Note: in hxa_suncenter: spix = hpix/spix!)
; phi = angle between SXT (E->W) and HXA (SE->NW)
; sxt_off = SXT coordinates of HXA detector crossing point
; cox, coy = coefficients for orbital phase correction
; tofac = multiplier for relative orbital phase
; clx, cly = coefficients for orbit duration correction
; tloff = time offset for orbit duration correction (in minutes)
; cmx, cmy = coefficients for mission time correction
; tmoff = time offset for mission time correction (in days)
; tmcut = last day for which mission correction can be used
spix = hpix/spix            ; spix is pixel size ratio now

sunc = float(hxa_d)
sunc(0,*) = sunc(0,*) - h_xx       ; subtract HXA offset
sunc(1,*) = sunc(1,*) - h_yy

sunout = sunc  ; create output array

; sxt transformation
sinphi = sin(phi/!radeg)
cosphi = cos(phi/!radeg)
sunout(0,*) = spix * (sunc(0,*)*cosphi + sunc(1,*)*sinphi) + sxt_off(0)
sunout(1,*) = spix * (sunc(0,*)*sinphi - sunc(1,*)*cosphi) + sxt_off(1)


; orbital time correction and correction for duration of day
if (not keyword_set(noorb)) then begin

  tim2orbit,time,tim2fms=t_orb,tim2night=t_nit,/simple
  t_nit = t_nit+t_orb               ; length of day in minutes
  t_orb = tofac*(t_orb/t_nit)       ; relative orb. phase * tofac
  t_nit = t_nit-tloff               ; subtract a constant for numerics

  sunout(0,*) = sunout(0,*) + cox(0) + cox(1)*t_orb + cox(2)*t_orb*t_orb
  sunout(1,*) = sunout(1,*) + coy(0) + coy(1)*t_orb + coy(2)*t_orb*t_orb

  sunout(0,*) = sunout(0,*) + clx(0) + clx(1)*t_nit + clx(2)*t_nit*t_nit
  sunout(1,*) = sunout(1,*) + cly(0) + cly(1)*t_nit + cly(2)*t_nit*t_nit
endif

; correction for non-periodic variation over mission
if (not keyword_set(nomis)) then begin
   t_day = gt_day(time)
   ww = where(t_day le tmcut,nww)          ; apply correction only before tmcut
   if nww gt 0 then begin
      t_day = float(t_day(ww) - tmoff)     ; time for secular variations
      sunout(0,ww) = sunout(0,ww) + cmx(0) + cmx(1)*t_day + cmx(2)*t_day*t_day
      sunout(1,ww) = sunout(1,ww) + cmy(0) + cmy(1)*t_day + cmy(2)*t_day*t_day
   endif
endif


return,sunout
end