	function total_flux, x, pixel_size = pixel_size, frequency = frequency

;+
; NAME:
; 	TOTAL_FLUX
;
; PURPOSE:
; 	Returns vector of totals over each frame in 3-dimensional array.
; 	When both PIXEL_SIZE and FREQUENCY are specified, the output 
; 	value is expressed in Solar Flux Units.
; 
; CATEGORY:
; 	Image analysis.
;
; CALLING SEQUENCE:
; 	TF = TOTAL_FLUX(Array[, PIXEL_SIZE=PIXEL_SIZE, FREQUENCY=FREQUENCY])
; 
; INPUTS:
; 	Array:	The array to be analyzed. This array may be of any type.
;
; OPTIONAL INPUT PARAMETERS:
; 	None
;
; KEYWORD PARAMETERS:
; 	PIXEL_SIZE: Size of pixels of the Array expressed in arc seconds.
; 		    Pixels are intended to be square-shaped.
; 	FREQUENCY:  Working frequency expressed in GHz.
;
; OUTPUTS:
; 	Total over two first dimensions.
;
; COMMON BLOCKS:
; 	None.
;
; SIDE EFFECTS:
; 	None.
;
; RESTRICTIONS:
; 	Both keyword parameters PIXEL_SIZE and FREQUENCY must be specified
; 	to cause output to be expressed in s.f.u.
; 
; PROCEDURE:
; 	RESULT = total(total(Array, 1), 1)
;
; MODIFICATION HISTORY:
;
;	ISTP SD RAS, 1999.
;	Victor Grechnev (grechnev@iszf.irk.ru): Initially written.
;
;	ISTP SD RAS, 2000, Jan.
;	Victor Grechnev (grechnev@iszf.irk.ru)
;	Keyword parameters FREQUENCY and PIXEL_SIZE added.
;
;	ISTP SD RAS, Jul, 2002.
;	Natalia Meshalkina (nata@iszf.irk.ru): Help added.
;-


k_B = 1.3804200e-23	; Boltzmann's constant
c = 2.9979250e+08	; Speed of light

tf = total(total(x, 1), 1)

	CASE 1 OF

keyword_set(pixel_size) and keyword_set(frequency):	begin

	lam = c/(frequency*1d9)				; Wavelength
	sfu=float(2*k_B/lam^2*(pixel_size/3600d0*!dtor)^2*1d22)

tf = tf*sfu
		end

(keyword_set(pixel_size) and not(keyword_set(frequency))) or $
	(not(keyword_set(pixel_size)) and keyword_set(frequency)): $

		begin

print, 'Both Frequency and Pixel_size must be specified. '
print, 'Returning no-normalized total only.'
		end

ELSE:
	ENDCASE

return, tf

	end
