function pfi_composite,index,data

;+
; NAME:
;   pfi_composite
; PURPOSE:
;   Prepare a composite PFI movie.
; CALLING SEQUENCE:
;   movie = pfi_composite(index,data)
; INPUTS:
;   index = SXT index structure
;   data  = 3-d data cube (at least 2 images) of alternately 
;	long and short (or short and long) exposures
;  If data is byte then decompress and leak_sub
;  If data is not byte type then assume already decompressed,
;           -- and background subtracted
; OUTPUT:
;  Function result is a movie of composite frames.
;   plot the results as we go.  The results are displayed
;            on a logarithmic scale.
; MODIFICATION HISTORY:
;	LWA - August 1993
;-

siz = size(data)
n_x = siz(1) & n_y = siz(2)

satpix=data gt 3300
for i=0,siz(3)-1 do begin
pp = where(satpix(*,*,i) gt 0,nsat)
    if nsat gt 0 then begin
      xx = pp mod n_x
      yy = pp / n_x
      ppup = ((yy+1)<(n_x-1))*n_x + xx          ; 1 pixels abovesaturation
      ppdn = ((yy-1)>0)*n_x + xx                ; 1 pixels belowsaturation
      ddata = bytarr(n_x,n_y)
      ddata(pp)   = 1                           ; Flag saturated pixelswith -1
      ddata(ppup) = 1                           ; Flag +1 (up)   pixels
      ddata(ppdn) = 1                           ; Flag -1 (down) pixels
      satpix(0,0,i) = ddata                     ; Insert into the cube
    endif
endfor

out = intarr(siz(1),siz(2),siz(3)/2)

for i = 0,(siz(3)-1)/2 do begin

   out(*,*,i)=sxt_composite(index,data,sx=[2*i,2*i+1],satpix=satpix,/plot)

endfor

return,out

end


