home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / src / plbin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  1.8 KB  |  66 lines

  1. /* Plot a histogram using the arrays x and y to represent data       */
  2. /* values and frequencies respectively. If centre is false, x values     */
  3. /* denote the lower edge of the bin, and if centre is true, they        */
  4. /* they denote the centre of the bin                                */
  5.  
  6. #include "plplot.h"
  7. #include <math.h>
  8.  
  9. void plbin(nbin,x,y,centre)
  10. PLINT nbin;
  11. PLINT centre;
  12. PLFLT *x, *y;
  13. {
  14.  
  15.    PLINT i;
  16.    PLFLT xmin, xmax, vpwxmi, vpwxma, vpwymi, vpwyma;
  17.    PLINT level;
  18.  
  19.    glev(&level);
  20.    if (level<3)plexit("Please set up window before calling plbin.");
  21.  
  22.    /* Check x[i] are in ascending order */
  23.    for(i=0;i<nbin-1;i++)
  24.      if (x[i] >= x[i+1])
  25.         plexit("Elements of x[] must be increasing in plbin.");
  26.  
  27.    gvpw(&vpwxmi,&vpwxma,&vpwymi,&vpwyma);
  28.    if (!centre) {
  29.      for(i=0; i<nbin-1; i++){
  30.        pljoin(x[i],vpwymi,x[i],y[i]);
  31.        pljoin(x[i],y[i],x[i+1],y[i]);
  32.        pljoin(x[i+1],y[i],x[i+1],vpwymi);
  33.      }
  34.      if (x[nbin-1] < vpwxma) {
  35.        pljoin(x[nbin-1],vpwymi,x[nbin-1],y[nbin-1]);
  36.        pljoin(x[nbin-1],y[nbin-1],vpwxma,y[nbin-1]);
  37.        pljoin(vpwxma,y[nbin-1],vpwxma,vpwymi);
  38.      }
  39.    }
  40.    else {
  41.      if (nbin < 2) return;
  42.      xmin = vpwxmi;
  43.      xmax = max(0.5*(x[1]+x[2]),vpwxmi);
  44.      if (xmin < xmax) {
  45.        pljoin(xmin,vpwymi,xmin,y[0]);
  46.        pljoin(xmin,y[0],xmax,y[0]);
  47.        pljoin(xmax,y[0],xmax,vpwymi);
  48.      }
  49.      for (i=1;i<nbin-1;i++) {
  50.        xmin = xmax;
  51.        xmax = min(0.5*(x[i]+x[i+1]),vpwxma);
  52.        pljoin(xmin,vpwymi,xmin,y[i]);
  53.        pljoin(xmin,y[i],xmax,y[i]);
  54.        pljoin(xmax,y[i],xmax,vpwymi);
  55.      }
  56.      xmin = xmax;
  57.      xmax = vpwxma;
  58.      if (xmin < xmax) {
  59.        pljoin(xmin,vpwymi,xmin,y[nbin-1]);
  60.        pljoin(xmin,y[nbin-1],xmax,y[nbin-1]);
  61.        pljoin(xmax,y[nbin-1],xmax,vpwymi);
  62.      }
  63.    }
  64. }
  65.  
  66.