Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / histogram / maxval.c
1 /* gsl_histogram_maxval.c
2  * Copyright (C) 2000  Simone Piccardi
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 /***************************************************************
20  *
21  * File gsl_histogram_maxval.c: 
22  * Routine to find maximum and minumum content of a hisogram. 
23  * Need GSL library and header.
24  * Contains the routines:
25  * gsl_histogram_max_val find max content values
26  * gsl_histogram_min_val find min content values
27  * gsl_histogram_bin_max find coordinates of max contents bin
28  * gsl_histogram_bin_min find coordinates of min contents bin
29  *
30  * Author: S. Piccardi
31  * Jan. 2000
32  *
33  ***************************************************************/
34 #include <config.h>
35 #include <gsl/gsl_errno.h>
36 #include <gsl/gsl_histogram.h>
37
38 double
39 gsl_histogram_max_val (const gsl_histogram * h)
40 {
41   const size_t n = h->n;
42   size_t i;
43   double max = h->bin[0];
44   for (i = 0; i < n; i++)
45     {
46       if (h->bin[i] > max)
47         {
48           max = h->bin[i];
49         }
50     }
51   return max;
52 }
53
54 size_t
55 gsl_histogram_max_bin (const gsl_histogram * h)
56 {
57   size_t i;
58   size_t imax = 0;
59   double max = h->bin[0];
60   for (i = 0; i < h->n; i++)
61     {
62       if (h->bin[i] > max)
63         {
64           max = h->bin[i];
65           imax = i;
66         }
67     }
68   return imax;
69 }
70
71 double
72 gsl_histogram_min_val (const gsl_histogram * h)
73 {
74   size_t i;
75   double min = h->bin[0];
76   for (i = 0; i < h->n; i++)
77     {
78       if (h->bin[i] < min)
79         {
80           min = h->bin[i];
81         }
82     }
83   return min;
84 }
85
86 size_t
87 gsl_histogram_min_bin (const gsl_histogram * h)
88 {
89   size_t i;
90   size_t imin = 0;
91   double min = h->bin[0];
92   for (i = 0; i < h->n; i++)
93     {
94       if (h->bin[i] < min)
95         {
96           min = h->bin[i];
97           imin = i;
98         }
99     }
100   return imin;
101 }