;+
; NAME:
;       MUXBLEED_SF
;
; PURPOSE:
;       Calculate mux-bleed scaling factor, using algorithm from Hora document

; INPUTS:
;       Counts in the high-flux, offending pixel
;
; KEYWORD PARAMETERS:
;
;       CHANNEL      - IRAC channel number (should be 1 or 2)
;	PRELAUNCH    - switch; use prelaunch algorithm coefficients
;	VERBOSE	     - switch; give extra information
;
; OUTPUTS:
;       Value of scale factor
;
; COMMON BLOCKS:
;       None.
;
;
; MODIFICATION HISTORY:
;       DS '03nov14 - written
;-
function muxbleed_sf, I,                     $
                    CHANNEL = channel,	     $
		    PRELAUNCH = prelaunch,   $
		    VERBOSE = verbose 

     if n_elements(CHANNEL)    eq 0 then CHANNEL = 1
     if n_elements(PRELAUNCH)  eq 0 then PRELAUNCH = 0

;    prelaunch muxbleed parameters:
     if CHANNEL eq 1 and PRELAUNCH eq 1 then begin
     if n_elements(VERBOSE) ne 0 then $
       print,'% MUXBLEED_SF: Using prelaunch coefficients to derive muxbleed scale factor'
	Iref = 36070.6
	A =  4.802
	B = -2.961
	C = -2.055
	D =  1.232
     endif 

;    newly-calculated muxbleed parameters (13.nov):
     if CHANNEL eq 1 and PRELAUNCH eq 0 then begin
     if n_elements(VERBOSE) ne 0 then $
       print,'% MUXBLEED_SF: Using new coefficients to derive muxbleed scale factor'
        Iref = 36070.6
        A =  7.78478
        B = -3.47243
        C = -3.73251
        D =  0.524064
     endif

     I2 = Iref / I
     sf = C + A*I2 + B*I2*I2 + D*I2*I2*I2
     return, sf
  
     end


