Index: doc/histogram.texi =================================================================== RCS file: /cvs/gsl/gsl/doc/histogram.texi,v retrieving revision 1.49 diff -u -r1.49 histogram.texi --- histogram.texi 2001/10/20 18:33:38 1.49 +++ histogram.texi 2002/01/14 15:15:46 @@ -365,6 +365,11 @@ calculation. The accuracy of the result is limited by the bin width. @end deftypefun +@deftypefun double gsl_histogram_sum (const gsl_histogram * @var{h}) +This function returns the sum of all bin values. Negative bin values +are not ignored. +@end deftypefun + @node Histogram Operations @section Histogram Operations @@ -939,6 +944,11 @@ @comment distribution. Negative bin values are ignored for the purposes of this @comment calculation. @comment @end deftypefun + +@deftypefun double gsl_histogram2d_sum (const gsl_histogram2d * @var{h}) +This function returns the sum of all bin values. Negative bin values +are not ignored. +@end deftypefun @node 2D Histogram Operations @section 2D Histogram Operations Index: histogram/gsl_histogram.h =================================================================== RCS file: /cvs/gsl/gsl/histogram/gsl_histogram.h,v retrieving revision 1.18 diff -u -r1.18 gsl_histogram.h --- gsl_histogram.h 2001/10/18 21:55:49 1.18 +++ gsl_histogram.h 2002/01/14 15:15:47 @@ -116,6 +116,7 @@ double gsl_histogram_mean (const gsl_histogram * h); +double gsl_histogram_sum (const gsl_histogram * h); int gsl_histogram_fwrite (FILE * stream, const gsl_histogram * h) ; int gsl_histogram_fread (FILE * stream, gsl_histogram * h); Index: histogram/gsl_histogram2d.h =================================================================== RCS file: /cvs/gsl/gsl/histogram/gsl_histogram2d.h,v retrieving revision 1.16 diff -u -r1.16 gsl_histogram2d.h --- gsl_histogram2d.h 2001/10/18 21:55:49 1.16 +++ gsl_histogram2d.h 2002/01/14 15:15:47 @@ -112,6 +112,10 @@ void gsl_histogram2d_min_bin (const gsl_histogram2d *h, size_t *i, size_t *j); + +double +gsl_histogram2d_sum (const gsl_histogram2d *h); + int gsl_histogram2d_equal_bins_p(const gsl_histogram2d *h1, const gsl_histogram2d *h2) ; Index: histogram/maxval2d.c =================================================================== RCS file: /cvs/gsl/gsl/histogram/maxval2d.c,v retrieving revision 1.3 diff -u -r1.3 maxval2d.c --- maxval2d.c 2001/10/03 11:37:05 1.3 +++ maxval2d.c 2002/01/14 15:15:47 @@ -137,3 +137,21 @@ *imin_out = imin; *jmin_out = jmin; } + +/* + sum up all bins of histogram2d + */ + +double +gsl_histogram2d_sum(const gsl_histogram2d * h) +{ + const size_t n; + double sum=0; + size_t i=0; + n=h->nx*h->ny; + + while(i < n) + sum += h->bin[i++]; + + return sum; +} Index: histogram/stat.c =================================================================== RCS file: /cvs/gsl/gsl/histogram/stat.c,v retrieving revision 1.4 diff -u -r1.4 stat.c --- stat.c 2001/10/03 11:37:05 1.4 +++ stat.c 2002/01/14 15:15:48 @@ -119,3 +119,21 @@ } } + +/* + sum up all bins of histogram + */ + +double +gsl_histogram_sum(const gsl_histogram * h) +{ + double sum=0; + size_t i=0; + size_t n; + n=h->n; + + while(i < n) + sum += h->bin[i++]; + + return sum; +} Index: histogram/test.c =================================================================== RCS file: /cvs/gsl/gsl/histogram/test.c,v retrieving revision 1.21 diff -u -r1.21 test.c --- test.c 2001/10/18 21:55:49 1.21 +++ test.c 2002/01/14 15:15:48 @@ -275,6 +275,11 @@ g->bin[i] = (i + 27) * (i + 1); } + { + double sum=gsl_histogram_sum (h); + gsl_test(sum != N*27+((N-1)*N)/2, "gsl_histogram_sum sum all bin values"); + } + gsl_histogram_memcpy (h1, g); gsl_histogram_add (h1, h); Index: histogram/test2d.c =================================================================== RCS file: /cvs/gsl/gsl/histogram/test2d.c,v retrieving revision 1.18 diff -u -r1.18 test2d.c --- test2d.c 2001/06/26 11:57:49 1.18 +++ test2d.c 2002/01/14 15:15:48 @@ -416,6 +416,11 @@ g->bin[i] = (i + 27) * (i + 1); } + { + double sum=gsl_histogram2d_sum (h); + gsl_test(sum != N*M*27+((N*M-1)*N*M)/2, "gsl_histogram2d_sum sum all bin values"); + } + gsl_histogram2d_memcpy (h1, g); gsl_histogram2d_add (h1, h);