source: tags/release-0.9/Utils/cpghist_log.c @ 813

Last change on this file since 813 was 3, checked in by Matthew Whiting, 18 years ago

This is the first full import of all working code to
the Duchamp repository.
Made three directories at top level:

branches/ tags/ trunk/

and trunk/ has the full set of code:
ATrous/ Cubes/ Detection/ InputComplete? InputExample? README Utils/ docs/ mainDuchamp.cc param.cc param.hh

File size: 2.1 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <cpgplot.h>
4#include <math.h>
5void cpghistlog(int npts, float *data, float datamin, float datamax, int nbin, int pgflag)
6{
7  int i,bin;
8  float *num;
9  float maxNum,binSize,x1,x2,y1,y2,older,newer,fraction;
10  float MINCOUNT=-0.2;
11
12/*   if(npts<1) grwarn( */
13/* ||(datamax<datamin)||(nbin<1)||(nbin>MAXBIN)) */
14
15  num = (float *)calloc(nbin,sizeof(float));
16
17  cpgbbuf();
18
19  // HOW MANY VALUES IN EACH BIN?
20/*   for(i=0; i<nbin; i++) num[i] = 0.; */
21  for(i=0; i<npts; i++){
22    fraction = (data[i] - datamin) / (datamax - datamin);
23    bin = (int)( floor(fraction*nbin) );
24    if((bin>=0)&&(bin<nbin)) num[bin]+=1.;
25  }
26  for(i=0; i<nbin;i++){
27    if(num[i]>0) num[i] = log10(num[i]);
28    else num[i] = MINCOUNT;
29  }
30  maxNum = num[0];
31  for(i=1; i<nbin; i++) if(num[i]>maxNum) maxNum = num[i];
32  binSize = (datamax - datamin) / (float)nbin;
33
34  // BOUNDARIES OF PLOT
35  x1 = datamin;
36  x2 = datamax;
37  y1 = MINCOUNT;
38  y2 = ceil(maxNum);
39
40  // DEFINE ENVIRONMENT IF NECESSARY
41  if(pgflag%2 == 0) cpgenv(x1,x2,y1,y2,0,20);
42
43  // DRAW HISTOGRAM
44  if(pgflag/2 == 0){
45    older = 0.;
46    x2 = datamin;
47    cpgmove(datamin,MINCOUNT);
48    for(i=0;i<nbin;i++){
49      newer = num[i];
50      x1 = x2;
51      x2 = datamin + i*binSize;
52      if(newer!=MINCOUNT){
53        if(newer<=older){
54          cpgmove(x1,newer);
55          cpgdraw(x2,newer);
56        }
57        else{
58          cpgmove(x1,older);
59          cpgdraw(x1,newer);
60          cpgdraw(x2,newer);
61        }
62      }
63      cpgdraw(x2,MINCOUNT);
64      older=newer;
65    }
66  }
67  else if(pgflag/2 == 1){
68    older = MINCOUNT;
69    x2 = datamin;
70    for(i=0;i<nbin;i++){
71      newer = num[i];
72      x1 = x2;
73      x2 = datamin + i*binSize;
74      if(newer!=MINCOUNT) cpgrect(x1,x2,0.,newer);     
75    }
76  }
77  else if(pgflag/2 == 2){
78    older = 0.;
79    cpgmove(datamin,MINCOUNT);
80    x2 = datamin;
81    for(i=0;i<nbin;i++){
82      newer = num[i];
83      x1 = x2;
84      x2 = datamin + i*binSize;
85      if((newer==MINCOUNT)&&(older==MINCOUNT)) cpgmove(x2,MINCOUNT);
86      else {
87        cpgdraw(x1,newer);
88        if(newer==MINCOUNT) cpgmove(x2,newer);
89        else cpgdraw(x2,newer);
90      }
91      older = newer;
92    }
93  }
94
95  cpgebuf();
96   
97}
Note: See TracBrowser for help on using the repository browser.