gsl_histogram__maxval2d.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* gsl_histogram2d_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_histogram2d_maxval.c:
  22. * Routine to find maximum and minumum content of a 2D hisogram.
  23. * Need GSL library and header.
  24. * Contains the routines:
  25. * gsl_histogram2d_max_val find max content values
  26. * gsl_histogram2d_min_val find min content values
  27. * gsl_histogram2d_bin_max find coordinates of max contents bin
  28. * gsl_histogram2d_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_histogram2d.h"
  37. /*
  38. * Return the maximum contents value of a 2D histogram
  39. */
  40. double
  41. gsl_histogram2d_max_val (const gsl_histogram2d * h)
  42. {
  43. const size_t nx = h->nx;
  44. const size_t ny = h->ny;
  45. size_t i;
  46. double max = h->bin[0 * ny + 0];
  47. for (i = 0; i < nx * ny; i++)
  48. {
  49. if (h->bin[i] > max)
  50. {
  51. max = h->bin[i];
  52. }
  53. }
  54. return max;
  55. }
  56. /*
  57. * Find the bin index for maximum value of a 2D histogram
  58. */
  59. void
  60. gsl_histogram2d_max_bin (const gsl_histogram2d * h, size_t * imax_out, size_t * jmax_out)
  61. {
  62. const size_t nx = h->nx;
  63. const size_t ny = h->ny;
  64. size_t imax = 0, jmax = 0, i, j;
  65. double max = h->bin[0 * ny + 0];
  66. for (i = 0; i < nx; i++)
  67. {
  68. for (j = 0; j < ny; j++)
  69. {
  70. double x = h->bin[i * ny + j];
  71. if (x > max)
  72. {
  73. max = x;
  74. imax = i;
  75. jmax = j;
  76. }
  77. }
  78. }
  79. *imax_out = imax;
  80. *jmax_out = jmax;
  81. }
  82. /*
  83. * Return the minimum contents value of a 2D histogram
  84. */
  85. double
  86. gsl_histogram2d_min_val (const gsl_histogram2d * h)
  87. {
  88. const size_t nx = h->nx;
  89. const size_t ny = h->ny;
  90. size_t i;
  91. double min = h->bin[0 * ny + 0];
  92. for (i = 0; i < nx * ny; i++)
  93. {
  94. if (h->bin[i] < min)
  95. {
  96. min = h->bin[i];
  97. }
  98. }
  99. return min;
  100. }
  101. /*
  102. * Find the bin index for minimum value of a 2D histogram
  103. */
  104. void
  105. gsl_histogram2d_min_bin (const gsl_histogram2d * h, size_t * imin_out, size_t * jmin_out)
  106. {
  107. const size_t nx = h->nx;
  108. const size_t ny = h->ny;
  109. size_t imin = 0, jmin = 0, i, j;
  110. double min = h->bin[0 * ny + 0];
  111. for (i = 0; i < nx; i++)
  112. {
  113. for (j = 0; j < ny; j++)
  114. {
  115. double x = h->bin[i * ny + j];
  116. if (x < min)
  117. {
  118. min = x;
  119. imin = i;
  120. jmin = j;
  121. }
  122. }
  123. }
  124. *imin_out = imin;
  125. *jmin_out = jmin;
  126. }