Back to index

plt-scheme  4.2.1
Functions
plhist.c File Reference
#include "plplotP.h"

Go to the source code of this file.

Functions

void c_plhist (PLINT n, PLFLT *data, PLFLT datmin, PLFLT datmax, PLINT nbin, PLINT flags)
void c_plbin (PLINT nbin, PLFLT *x, PLFLT *y, PLINT flags)

Function Documentation

void c_plbin ( PLINT  nbin,
PLFLT x,
PLFLT y,
PLINT  flags 
)

Definition at line 97 of file plhist.c.

{
    PLINT i;
    PLFLT xmin, xmax, vpwxmi, vpwxma, vpwymi, vpwyma;

    if (plsc->level < 3) {
       plabort("plbin: Please set up window first");
       return;
    }

    /* Check x[i] are in ascending order */

    for (i = 0; i < nbin - 1; i++) {
       if (x[i] >= x[i + 1]) {
           plabort("plbin: Elements of x array must be increasing");
           return;
       }
    }

    plgvpw(&vpwxmi, &vpwxma, &vpwymi, &vpwyma);
    if (!(flags & 1)) {
       for (i = 0; i < nbin - 1; i++) {
           if (!(flags & 4) || (y[i] != vpwymi)) {
              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 (flags & 2) {
           if (!(flags & 4) || (y[i] != vpwymi)) {
              int xm = x[i] + (x[i] - x[i-1]);
              pljoin(x[i], vpwymi, x[i], y[i]);
              pljoin(x[i], y[i], xm, y[i]);
              pljoin(xm, y[i], xm, vpwymi);
           }
       } else {
           if (x[i] < vpwxma) {
              if (!(flags & 4) || (y[i] != vpwymi)) {
                  pljoin(x[i], vpwymi, x[i], y[i]);
                  pljoin(x[i], y[i], vpwxma, y[i]);
                  pljoin(vpwxma, y[i], vpwxma, vpwymi);
              }
           }
       }
    } else {
       if (nbin < 2)
           return;
       if (flags & 2) {
           xmin = MAX(vpwxmi, 0.5 * (3 * x[0] - x[1]));
       } else {
           xmin = vpwxmi;
       }
       /* Vince fixed bug May 1998 */
       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);
           if (!(flags & 4) || (y[i] != vpwymi)) {
              pljoin(xmin, vpwymi, xmin, y[i]);
              pljoin(xmin, y[i], xmax, y[i]);
              pljoin(xmax, y[i], xmax, vpwymi);
           }
       }
       xmin = xmax;
       xmax = vpwxma;
       if (flags & 2) {
           xmax = MIN(vpwxma, 0.5 * (3 * x[i] - x[i-1]));
       } else {
           xmax = vpwxma;
       }
       if (xmin < xmax) {
           if (!(flags & 4) || (y[i] != vpwymi)) {
              pljoin(xmin, vpwymi, xmin, y[i]);
              pljoin(xmin, y[i], xmax, y[i]);
              pljoin(xmax, y[i], xmax, vpwymi);
           }
       }
    }
}

Here is the call graph for this function:

void c_plhist ( PLINT  n,
PLFLT data,
PLFLT  datmin,
PLFLT  datmax,
PLINT  nbin,
PLINT  flags 
)

Definition at line 25 of file plhist.c.

{
    PLINT i, bin;
    PLFLT *x, *y, dx, ymax;

    if (plsc->level < 1) {
       plabort("plhist: Please call plinit first");
       return;
    }
    if (plsc->level < 3 && (flags & 1)) {
       plabort("plhist: Please set up window first");
       return;
    }
    if (datmin >= datmax) {
       plabort("plhist: Data range invalid");
       return;
    }
    if ( ! (x = (PLFLT *) malloc((size_t) nbin * sizeof(PLFLT)))) {
       plabort("plhist: Out of memory");
       return;
    }
    if ( ! (y = (PLFLT *) malloc((size_t) nbin * sizeof(PLFLT)))) {
       free((void *) x);
       plabort("plhist: Out of memory");
       return;
    }

    dx = (datmax - datmin) / nbin;
    for (i = 0; i < nbin; i++) {
       x[i] = datmin + i * dx;
       y[i] = 0.0;
    }

    for (i = 0; i < n; i++) {
       bin = (data[i] - datmin) / dx;
       if ((flags & 2) == 0) {
           bin = bin > 0 ? bin : 0;
           bin = bin < nbin ? bin : nbin - 1;
           y[bin]++;
       } else {
           if(bin >= 0 && bin < nbin) {
              y[bin]++;
           }
       }
    }

    if (!(flags & 1)) {
       ymax = 0.0;
       for (i = 0; i < nbin; i++)
           ymax = MAX(ymax, y[i]);

       plenv(datmin, datmax, (PLFLT) 0.0, (PLFLT) (1.1 * ymax), 0, 0);
    }
    /* We pass on the highest couple of bits to the 'plbin' routine */
    plbin(nbin, x, y, (flags & (4+8+16+32)) >> 2);
    free((void *) x);
    free((void *) y);
}

Here is the call graph for this function: