gsl_histogram__maxval.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "gsl__config.h"
  35. #include "gsl_errno.h"
  36. #include "gsl_histogram.h"
  37. double
  38. gsl_histogram_max_val (const gsl_histogram * h)
  39. {
  40. const size_t n = h->n;
  41. size_t i;
  42. double max = h->bin[0];
  43. for (i = 0; i < n; i++)
  44. {
  45. if (h->bin[i] > max)
  46. {
  47. max = h->bin[i];
  48. }
  49. }
  50. return max;
  51. }
  52. size_t
  53. gsl_histogram_max_bin (const gsl_histogram * h)
  54. {
  55. size_t i;
  56. size_t imax = 0;
  57. double max = h->bin[0];
  58. for (i = 0; i < h->n; i++)
  59. {
  60. if (h->bin[i] > max)
  61. {
  62. max = h->bin[i];
  63. imax = i;
  64. }
  65. }
  66. return imax;
  67. }
  68. double
  69. gsl_histogram_min_val (const gsl_histogram * h)
  70. {
  71. size_t i;
  72. double min = h->bin[0];
  73. for (i = 0; i < h->n; i++)
  74. {
  75. if (h->bin[i] < min)
  76. {
  77. min = h->bin[i];
  78. }
  79. }
  80. return min;
  81. }
  82. size_t
  83. gsl_histogram_min_bin (const gsl_histogram * h)
  84. {
  85. size_t i;
  86. size_t imin = 0;
  87. double min = h->bin[0];
  88. for (i = 0; i < h->n; i++)
  89. {
  90. if (h->bin[i] < min)
  91. {
  92. min = h->bin[i];
  93. imin = i;
  94. }
  95. }
  96. return imin;
  97. }