-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhistogram_builder.c
More file actions
59 lines (40 loc) · 1.07 KB
/
histogram_builder.c
File metadata and controls
59 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "stdio.h"
// Reads a CoMet Czekanowski input in binary and outputs a human readable
// histogram
//
#ifndef NUM_BINS
#define NUM_BINS 1000
#endif
#define HIST_MIN 0
#define HIST_MAX 1
int main(){
int bin_assigned;
int histogram[NUM_BINS] = 0;
typedef unsigned int UINT32;
typedef float Float_t;
if (sizeof(UINT32 != 4)) {
return 1;
}
typedef struct {
UINT32 vec0;
UINT32 vec1;
Float_t value;
} Element;
Element e;
double bin_width = ((double)HIST_MAX - (double)HIST_MIN) / (double)NUM_BINS;
printf("Creating histogram with %d bins of width %d\n",(double)NUM_BINS,bin_width);
while(true) {
const size_t num_read = fread(&e, sizeof(e), 1, stdin);
if(num_read != 1) {
break;
}
bin_assigned = (double)e.value/bin_width;
histogram[bin_assigned - 1] += 1;
}
printf("Final histogram\n");
printf("---------------\n");
for(int i=0; i<NUM_BINS; i++) {
printf("bin[%i]\t=\t%i\n",i,histogram[i]);
}
return 0;
}