	FUNCTION sfd_comp, data, index=index
;+	-----------------------------------------------------------
;	NAME: sfd_comp
;
;	PURPOSE: Compress data using the "SFD" compression algorithm
;
;	CALLING SEQUENCE:
;		cdata = sfd_comp(data)
;		cdata = sfd_comp(data, index=index)
;
;	INPUT:
;		data 	data to be compressed.
;       OPTIONAL INPUT KEYWORD:
;		index	The SXT index structure.
;			If present, convert to DN/sec/HR pixel
;	RETURNED/OUTPUT:
;		compressed data
;
;	HISTORY:
;		written 9-Dec-93 by M.Morrison
;	24-jun-94, SLF+JRL, Added index=index keyword
;-
;	-----------------------------------------------------------

if data_chk(data, /type) eq 1 then begin
   message,/cont,'Data must not be byte-type -- returning'
   return, data
endif

out = data>1.		; Really assumes integer input

;;-----------------------------------------------------------------
;; The following code is formally correct, but is only relevant if
;; 1. data is floating type
;; 2. index=index is specified AND
;; 3. the gt_expdur(index) is less than 1sec
;;
;;i0 = where(data le 0.,n0)
;;if n0 gt 0 then begin
;;  i1 = where(data gt 0., n1)
;;  if n1 gt 0 then out(i0) = min(data(i1)) else out(i0) = 1
;;endif
;;-----------------------------------------------------------------


case 1 of
  data_chk(index, /struct): begin			; Convert to DN/sec/HR
     fac = ([4.,1,.25])(gt_res(index))/gt_expdur(index)*1000.	; Multiply FR by 4; QR by .25
     for i=0,n_elements(index)-1 do out(0,0,i) = out(*,*,i)*fac(i)
  endcase
  data_chk(index,/defined): message,/cont,"Index must be SXT structure type"
  else:
endcase

out = alog10(out)
out = bytscl(temporary(out), max=6., min=0., top=255)
;
return, out
end
