home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / gsl-histogram.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-01  |  1.9 KB  |  79 lines

  1. /* histogram/gsl-histogram.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <config.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <gsl/gsl_histogram.h>
  24.  
  25. int
  26. main (int argc, char **argv)
  27. {
  28.   double a = 0.0, b = 1.0;
  29.   size_t n = 10;
  30.  
  31.   if (argc != 3 && argc !=4)
  32.     {
  33.       printf ("Usage: gsl-histogram xmin xmax [n]\n");
  34.       printf (
  35. "Computes a histogram of the data on stdin using n bins from xmin to xmax.\n"
  36. "If n is unspecified then bins of integer width are used.\n");
  37.       exit (0);
  38.     }
  39.  
  40.   a = atof (argv[1]);
  41.   b = atof (argv[2]);
  42.  
  43.   if (argc == 4) 
  44.     {
  45.       n = atoi (argv[3]);
  46.     }
  47.   else
  48.     {
  49.       n = (int)(b - a) ;
  50.     }
  51.  
  52.   {
  53.     double x;
  54.     gsl_histogram *h = gsl_histogram_alloc (n);
  55.  
  56.     gsl_histogram_set_ranges_uniform (h, a, b);
  57.  
  58.     while (fscanf(stdin, "%lg", &x) == 1)
  59.       {
  60.     gsl_histogram_increment(h, x);
  61.       }
  62.  
  63. #ifdef DISPLAY_STATS
  64.     {
  65.       double mean = gsl_histogram_mean (h);
  66.       double sigma = gsl_histogram_sigma (h);
  67.       fprintf (stdout, "# mean = %g\n", mean);
  68.       fprintf (stdout, "# sigma = %g\n", sigma);
  69.     }
  70. #endif
  71.  
  72.     gsl_histogram_fprintf (stdout, h, "%g", "%g");
  73.  
  74.     gsl_histogram_free (h);
  75.   }
  76.  
  77.   return 0;
  78. }
  79.