function WSUM, A ;+ ;NAME: ; WSUM ; ;PURPOSE: ; To sum all of the elements in an array or matrix. ; If A is a matrix, then sum(A) is a row vector with ; the sum over each column. This function is an equiv- ; alent of Matlab's sum function. ; ;CATEGORY: ; Simple math. ; ;CALLING SEQUENCE: ; Result = WSUM(A) ; ;INPUTS: ; A: A vector or matrix ; ;OUTPUTS: ; The sum of the vector or matrix. ; ;RESTRICTIONS: ; None. ; ;EXAMPLE: ; IDL> a = [[8,2,6],[3,6,7],[4,9,3]] ; IDL> print, a ; 8 2 6 ; 3 6 7 ; 4 9 3 ; IDL> print, WSUM(A) ; 15.0000 17.0000 16.0000 ; ;MODIFICATION HISTORY: ; Amara Graps, BAER, December 1994. ; (c) copyright Amara Graps 1995, 1996 ;- t = SIZE(A) IF t(0) EQ 1 THEN BEGIN ;1D array ssum = TOTAL(A) ENDIF ELSE BEGIN ;Matrix numcol = t(1) ;number of columns numrow=t(2) ;number of rows ssum = FLTARR(numcol) ;Step through the cols FOR i = 0, numcol-1 DO BEGIN ;And sum up all values ssum(i) = TOTAL(A(i,*)) END ;i ENDELSE RETURN, ssum END ;************************************************