function sxt_mk3, index, data, diameter=diameter, outsize=outsize
;+
;   Name: sxt_mk3, mk3, index, data
;
;   Purpose: embed an SXT image in an MLSO MarkIII coronograph image
;
;   Input Parameters:
;      index	- SXT index
;      data     - SXT data
;
;   Keyword Parameters;
;      diameter - output size of composite (outer diameter of MK3 in device pix)
;      outsize  - synonym for diameter
;
;   Calling Sequnce:
;      composite=sxt_mk3(index, data [diameter=diameter])
;
;   History:
;      24-sep-1995 (SLF) (one optional replacement for Nobeyama)
;      18-apr-1995 (SLF) annotation style updated
;
;   Assumptions:
;      more than I could possibly list here 
;-
get_mk3, index, mk3, /mask, dattim=mk3time
mklimb=210		; limb diameter per mk3 "standard"

if keyword_set(outsize) then diameter=outsize
if not keyword_set(diameter) then diameter=512		; output image size
data=congrid(data,512,512)
; find SXT limb via fit_limb
fit_limb, data, index=index, x, y, radius, /quiet	; full res pixels
help,data,mk3,diameter

sizsxt=(size(data))(1)				; I assume SXT is square
fact=1024./sizsxt
sxtdiam=(2.*radius)/fact

; extract the disk+some corona (around centroid)
masked=set_back(data,trgt=[x/fact,y/fact,(radius/fact)+25])
; center to nearest full pixel (close enough for this application)
masked=shift(masked,sizsxt/fact-(x/fact),sizsxt/fact-(y/fact))
; scale SXT limb to MK3 assumed limb
sizscl=sizsxt*(mklimb/sxtdiam)
sclsxt=congrid(masked,sizscl,sizscl)

; ----------- form the composite using the Z-buffer ------------
ptemp=!d.name					; save graphics state
device,get_graphics=gtemp			
wdef,xx,sizsxt,sizsxt,/zbuffer			; image buffer 
set_plot,'z'
device,set_graphics=3				; Source OR Desitnation
erase
tv,bytscl(sclsxt,max=100),(sizsxt-sizscl)/2,(sizsxt-sizscl)/2		; centered/scaled SXT
device,set_graphics=7				; Source OR Desitnation
tv,bytscl(mk3,min=10,max=180)			; overlay MK3
outimage=tvrd()					; read the image -> output
device,set_graphics=gtemp
; ---------------------------------------------------------------

if keyword_set(diameter) then begin
   outimage=congrid(outimage,diameter,diameter)
   wdef,zz,diameter,diameter,/zbuffer
   set_plot,'z'
   tv,bytarr(diameter,diameter)
   erase
   tv,outimage
   xyouts,2,5,'!3MLSO MK3 w/SXT',align=0,/dev,charsize=.77
   xyouts,diameter-2,5, '!3'+strmid(mk3time,0,6) + '  ' + strmid(mk3time,11,5),/dev,/align,charsize=.77
   outimage=tvrd()
endif

set_plot,ptemp					; restore graphics state

return, outimage
end
