/* * Process the collected data by do_ptimer. It tries to fit them * as normal distribution. * * Copyright (C) 2001 MontaVista Software Inc. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * */ #include #include #include "statistic/include/random_variates.h" double *interval; main(int argc, char **argv) { FILE *file; long count, overrun, min, max; int i; Normal *cv; double f; if (argc == 1) { printf("Usage : fitdata \n"); exit(-1); } file = fopen(argv[1], "r"); if (file == NULL) { printf("failed to open file : %s\n", argv[1]); exit(-1); } fscanf(file, "%lu%lu%lu%lu", &count, &overrun, &min, &max); printf("count=%lu, overrun=%lu, min=%lu, max=%lu\n", count, overrun, min, max); if (overrun > 0) { printf("WARNING: overrun(%ld) > 0, data may be distorted.\n", overrun); } interval = (double*)malloc(sizeof(double) * count); if (interval == NULL) { printf("failed to alloc interval[%ld]\n", count); } for (i=0; i< count; i++) { int ret; long temp; ret = fscanf(file, "%ld", &temp); interval[i] = temp; if (ret != 1) { printf("failed to read interval[%d]: ret=%d.\n", i, ret); exit(-1); } } fclose(file); cv = new Normal(interval, count); printf("miu = %.2f, sigma2=%.2f, sigma=%.2f\n", cv->miu(), cv->sigma2(), cv->sigma()); /* create distribution curves */ file = fopen("dist.data", "w"); if (file == NULL) { printf("failed to create file : dist.data\n"); exit(-1); } fprintf(file, "# column 0: the data value .\n"); fprintf(file, "# column 1: distribut curve based on the collected data.\n"); fprintf(file, "# column 2: distribut curve based on fitting normal functione.\n"); fprintf(file, "# column 3: density curve based on fitting normal functione.\n"); fprintf(file, "#\n"); fprintf(file, "# Normal dist: miu(mean) = %.2f, sigma2=%.2f, sigma(stddev)=%.2f\n", cv->miu(), cv->sigma2(), cv->sigma()); fprintf(file, "#\n"); fprintf(file, "# count=%lu, overrun=%lu, min=%lu, max=%lu\n", count, overrun, min, max); fprintf(file, "#\n"); for (f=min+0.5; f < max; f+=1.0) { int count1=0; fprintf(file, "%f\t", f); /* count the number of points less than f */ for (i=0; i< count; i++) { if (interval[i] < f) count1++; } fprintf(file, "%f\t", (double)count1 / (double)count); fprintf(file, "%f\t", cv->distribution(f)); fprintf(file, "%f\n", cv->density(f)); } fclose(file); #if 0 for (i=0; i< count; i++) { printf("%ld\n", interval[i]); } #endif }