diff options
author | phk <phk@FreeBSD.org> | 2006-05-02 07:34:38 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2006-05-02 07:34:38 +0000 |
commit | 3399511e52110d2646b3db3438fa9577a4b730c3 (patch) | |
tree | aa6c9b96111e253329fff2172262c1fe00346c99 /tools | |
parent | d8e06a4a6ad69000a6a4f92a0bbeec479ad69115 (diff) | |
download | FreeBSD-src-3399511e52110d2646b3db3438fa9577a4b730c3.zip FreeBSD-src-3399511e52110d2646b3db3438fa9577a4b730c3.tar.gz |
Avoid coredumps if stddev cannot be computed (if all datapoints are identical)
Small cleanup of label printing.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/tools/ministat/ministat.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/tools/tools/ministat/ministat.c b/tools/tools/ministat/ministat.c index af3f803..9d280b0 100644 --- a/tools/tools/ministat/ministat.c +++ b/tools/tools/ministat/ministat.c @@ -134,6 +134,7 @@ static char symbol[MAX_DS] = { ' ', 'x', '+', '*', '%', '#', '@', 'O' }; TAILQ_HEAD(pointlist, point); struct dataset { + char *name; struct pointlist list; double sy, syy; int n; @@ -399,13 +400,15 @@ PlotSet(struct dataset *ds, int val) } pl->data[j * pl->width + x] |= val; } - x = ((Avg(ds) - Stddev(ds)) - pl->x0) / pl->dx; - m = ((Avg(ds) + Stddev(ds)) - pl->x0) / pl->dx; - pl->bar[bar][m] = '|'; - pl->bar[bar][x] = '|'; - for (i = x + 1; i < m; i++) - if (pl->bar[bar][i] == 0) - pl->bar[bar][i] = '_'; + if (!isnan(Stddev(ds))) { + x = ((Avg(ds) - Stddev(ds)) - pl->x0) / pl->dx; + m = ((Avg(ds) + Stddev(ds)) - pl->x0) / pl->dx; + pl->bar[bar][m] = '|'; + pl->bar[bar][x] = '|'; + for (i = x + 1; i < m; i++) + if (pl->bar[bar][i] == 0) + pl->bar[bar][i] = '_'; + } x = (Median(ds) - pl->x0) / pl->dx; pl->bar[bar][x] = 'M'; x = (Avg(ds) - pl->x0) / pl->dx; @@ -483,6 +486,7 @@ ReadSet(char *n) if (f == NULL) err(1, "Cannot open %s", n); s = NewSet(); + s->name = strdup(n); line = 0; while (fgets(buf, sizeof buf, f) != NULL) { line++; @@ -588,19 +592,19 @@ main(int argc, char **argv) argv += optind; if (argc == 0) { - ds[0] = ReadSet(NULL); - printf("x stdin\n"); + ds[0] = ReadSet("-"); nds = 1; } else { if (argc > (MAX_DS - 1)) usage("Too many datasets."); nds = argc; - for (i = 0; i < nds; i++) { + for (i = 0; i < nds; i++) ds[i] = ReadSet(argv[i]); - printf("%c %s\n", symbol[i+1], argv[i]); - } } + for (i = 0; i < nds; i++) + printf("%c %s\n", symbol[i+1], ds[i]->name); + if (!flag_n) { SetupPlot(termwidth, flag_s, nds); for (i = 0; i < nds; i++) |