ftp.nice.ch/pub/next/unix/developer/plplot.3.0.s.tar.gz#/plplot/src/plbin.c

This is plbin.c in view mode; [Download] [Up]

/* Plot a histogram using the arrays x and y to represent data       */
/* values and frequencies respectively. If centre is false, x values     */
/* denote the lower edge of the bin, and if centre is true, they        */
/* they denote the centre of the bin                                */

#include "plplot.h"
#include <math.h>

void plbin(nbin,x,y,centre)
int nbin;
int centre;
FLOAT *x, *y;
{

   int i;
   double xmin, xmax, vpwxmi, vpwxma, vpwymi, vpwyma;
   int level;

   glev(&level);
   if (level<3)plexit("Please set up window before calling plbin.");

   /* Check x[i] are in ascending order */
   for(i=0;i<nbin-1;i++)
     if (x[i] >= x[i+1])
        plexit("Elements of x[] must be increasing in plbin.");

   gvpw(&vpwxmi,&vpwxma,&vpwymi,&vpwyma);
   if (!centre) {
     for(i=0; i<nbin-1; i++){
       pljoin(x[i],vpwymi,x[i],y[i]);
       pljoin(x[i],y[i],x[i+1],y[i]);
       pljoin(x[i+1],y[i],x[i+1],vpwymi);
     }
     if (x[nbin-1] < vpwxma) {
       pljoin(x[nbin-1],vpwymi,x[nbin-1],y[nbin-1]);
       pljoin(x[nbin-1],y[nbin-1],vpwxma,y[nbin-1]);
       pljoin(vpwxma,y[nbin-1],vpwxma,vpwymi);
     }
   }
   else {
     if (nbin < 2) return;
     xmin = vpwxmi;
     xmax = MAX(0.5*(x[0]+x[1]),vpwxmi);
     if (xmin < xmax) {
       pljoin(xmin,vpwymi,xmin,y[0]);
       pljoin(xmin,y[0],xmax,y[0]);
       pljoin(xmax,y[0],xmax,vpwymi);
     }
     for (i=1;i<nbin-1;i++) {
       xmin = xmax;
       xmax = MIN(0.5*(x[i]+x[i+1]),vpwxma);
       pljoin(xmin,vpwymi,xmin,y[i]);
       pljoin(xmin,y[i],xmax,y[i]);
       pljoin(xmax,y[i],xmax,vpwymi);
     }
     xmin = xmax;
     xmax = vpwxma;
     if (xmin < xmax) {
       pljoin(xmin,vpwymi,xmin,y[nbin-1]);
       pljoin(xmin,y[nbin-1],xmax,y[nbin-1]);
       pljoin(xmax,y[nbin-1],xmax,vpwymi);
     }
   }
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Marcel Waldvogel and Netfuture.ch.