	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 dimensions: total(total(Array, 1), 1).
;
; 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:
;	Straightforward.
;
; MODIFICATION HISTORY:
;
;	ISTP SD RAS, 1999.
;	Victor Grechnev (grechnev@iszf.irk.ru)
;	ISTP SD RAS, 2000, Jan.
;	Victor Grechnev (grechnev@iszf.irk.ru)
;		Keyword parameters FREQUENCY and PIXEL_SIZE have been added.
;
;-


k_B = 1.3804200e-23	; Boltzmann 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)		; Wave length
	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