pro ext1pfi, ref, rec1, sxtos2, img, nx, ny, istcol, iencol, ix, iy, qfimg, next
;
;+
;NAME:
;	ext1pfi
;PURPOSE:
;	Extract the SXT-PFI portion of the telemetry stream
;HISTORY:
;	Written Fall '91 by M.Morrison
;	30-Nov-92 (MDM) - Added check for insertion of telemetry buffer into
;			  the image array in the Y dimension as well as the
;			  X dimension.
;       12-Apr-95 (MDM) - Added check that the portion was not
;                         already inserted (due to SIRIUS duplication)
;                         when updating number of pixels extracted
;-
;
iew = mask(rec1(sxtos2, 43), 0, 4)
ins = mask(rec1(sxtos2, 43), 4, 4)
;
p_dumdat = btest0( rec1(sxtos2, 0), 5)
qok = 0
if (not p_dumdat) then begin
    ;
    img0 = rec1(16:*, *)		;drop first 16 bytes of each minor frame
    img0 = byte(img0,0, 16,8,64)	;16x8 by 64 minor frames
    img0 = img0(istcol:iencol, *, *)
    ;
    ninmf = (iencol-istcol+1)*8*64	;1024 or 4096
    nlin = ninmf / 64			;always 64 columns in buffer
					;nlin = 16 or 64
    ;
    img0 = byte(img0,0, 64,nlin)
    ;if (iew*64+ix+63 gt nx) then begin
    if ((iew*64+ix+63 gt nx) or (iy+nlin gt 64)) then begin	;check Y range also
	err_log, 'STR', 'ERR/SXT: PFI tried to insert outside of array'
	err_log, 'SXT_EXT1PFI', 'PFI: iew, ix,iy, nx,ny', iew, ix, iy, nx, ny
    end else begin
        qok = img(iew*64+ix, iy) eq 0	;MDM added 12-Apr-95 -  check that that portion was not already inserted
					;                       when updating number of pixels extracted
	img(iew*64+ix, iy) = img0
    end
    ;
    ix = 0				;always is zero
    iy = iy + nlin
    if (iy ge 64) then iy=0		;reset to beginning
    ;qok = 1
    if (min(img0) eq "AA"x) and (max(img0) eq "AA"x) then qok = 0       ;MDM added 12-Apr-95
end

if (ref.log_sxt_ext1pfi) then err_log, 'SXT_EXT1PFI', 'PFI: iew, ix,iy, nx,ny', iew, ix, iy, nx, ny
qfimg = 0
if ((((iew+1)*64+ix) ge nx) and (iy eq 0)) then qfimg = 1	;full image
if (qok) then next = next + n_elements(img0)

end
