/* Bucketize data into a crude histogram of X's */ /* Usage: cc -o xify xify.c */ /* ./xify < datafile */ #include #include #define MAX_BUCKETS 60 /* #define VERBOSE 1 */ int main(argc, argv) int argc; char *argv[]; { int i, index, counter, cumcount; int counthist[MAX_BUCKETS]; int total, tallest; float obs, num; int numbuckets; float startvalue, endvalue, stepsize; numbuckets = MAX_BUCKETS; startvalue = 0; endvalue = MAX_BUCKETS; stepsize = 1; tallest = 0; counter = 0; for( i = 0; i < numbuckets; i++ ) counthist[i] = 0; while( (i = scanf("%f\n", &obs)) == 1 ) { counter += 1; #ifdef VERBOSE printf("Value on line %d is %f\n", counter, obs); #endif if( obs > endvalue ) { #ifdef VERBOSE fprintf(stderr, "Value on line %d is too large! %f > %f\n", counter, obs, endvalue); #endif counthist[numbuckets-1]++; if( counthist[numbuckets-1] > tallest ) tallest = counthist[numbuckets-1]; total++; continue; } if( obs < startvalue ) { #ifdef VERBOSE fprintf(stderr, "Value on line %d is too small! %f < %f\n", counter, obs, startvalue); #endif counthist[0]++; if( counthist[0] > tallest ) tallest = counthist[0]; total++; continue; } /* figure out bucket number for this observation */ num = startvalue; index = 0; while( (num + 1) < obs ) { num += stepsize; index++; } #ifdef VERBOSE printf("Putting it into bin %d\n", index); #endif counthist[index]++; if( counthist[index] > tallest ) tallest = counthist[index]; total++; } /* Summary info */ printf(" Crude X Histogram of Data Distribution\n"); printf("\n"); for( ; tallest > 0 ; tallest-- ) { printf(" %2d | ", tallest); for( i = 0; i < numbuckets; i++ ) { if( counthist[i] >= tallest ) printf("X"); else printf(" "); } printf("\n"); } printf(" ----------------------------------------------------------------\n"); printf(" "); printf(" %3.1f %3.1f %3.1f\n", startvalue, (startvalue+endvalue)/2.0, endvalue); }