;+
; PROJECT:
;       SDAC
; NAME:
;	F_DIV
;
; PURPOSE:	
;	THIS FUNCTION RETURNS THE QUOTIENT WITH ZERO CHECKING.	
;
; CATEGORY:
;	MATH, NUMERICAL ANALYSIS, UTILITY
;
; CALLING SEQUENCE:
;	Result = F_DIV( Numerator, Denominator)
;
; EXAMPLES:
;	count_sec = f_div( total(counts,1) , delta_t )
;	count_sec_prm = f_div( count_sec , 1.- f_div(dead_channel # counts,delta_t) )
;
; INPUTS: 	
;	NUMERATOR - dividend in a quotient
;	DENOMINATOR - divisor in a quotient
;
; KEYWORDS:	
;	DEFAULT - if DENOMINATOR is zero, value is set to 0.0 or to DEFAULT. (INPUT)
;		
; PROCEDURE:	
;	The divisor is scanned for zeroes which are excluded from the quotient.
;	The value for those elements is 0.0 or the DEFAULT.
; RESTRICTIONS:
; 	Real numbers only.
;
; COMMON BLOCKS:
;	None.
; MODIFICATION HISTORY:
;
;	mod, 22-dec-93, ras, returns vector if numerator or denominator are vectors and other scalar
;	ras, 17-jun-94 renamed div to f_div
;	ras, 14-oct-94, liberal use of temporary
;	Version 4, richard.schwartz@gsfc.nasa.gov, 7-sep-1997, more documentation
;-

FUNCTION F_DIV, NUMERATOR, DENOMINATOR, DEFAULT = DEFAULT

if (size(numerator))(0) eq 0 then numerator = numerator + 0.0 * denominator
if (size(denominator))(0) eq 0 then denominator = denominator + 0.0 * numerator
;
NZERO = where( DENOMINATOR ne 0.0, NZ)
;
RESULT      = DENOMINATOR
;
IF NZ GE 1 THEN RESULT( NZERO ) = temporary( NUMERATOR( NZERO ) / DENOMINATOR( NZERO))
;
S_DEFAULT = size( DEFAULT )
;
;	If a value is passed for DEFAULT, then place it in RESULT wherever there
;	is a zero in the original DENOMINATOR.
if S_DEFAULT(1) ne 0 then begin ; replace 

	ZERO = where( DENOMINATOR eq 0.0, Z)
	
	IF Z GE 1 THEN RESULT( ZERO ) = DEFAULT

endif
;
return, RESULT
end
