Avoid coredumps if stddev cannot be computed (if all datapoints are identical)

Small cleanup of label printing.
This commit is contained in:
Poul-Henning Kamp 2006-05-02 07:34:38 +00:00
parent 96b468e33b
commit 5f72b6ac80
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=158246
2 changed files with 32 additions and 24 deletions

View File

@ -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++)

View File

@ -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++)