Introduction
Introduction Statistics Contact Development Disclaimer Help
make plotting work with arbitrary scale - ploot - simple plotting tools
git clone git://bitreich.org/ploot git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65…
Log
Files
Refs
Tags
README
LICENSE
---
commit d97badd46c19a6903a589c41b8b87d044f48f8dc
parent c9c242228362e465b83fc106675981fd45419228
Author: Josuah Demangeon <[email protected]>
Date: Wed, 2 May 2018 05:46:29 +0200
make plotting work with arbitrary scale
Diffstat:
M ffplot.c | 2 +-
M main.c | 30 +++++++++++++++++++++---------
2 files changed, 22 insertions(+), 10 deletions(-)
---
diff --git a/ffplot.c b/ffplot.c
@@ -159,7 +159,7 @@ graph(Canvas *can, Vlist *v,
int x, y, n, xlast, ylast, first;
first = 1;
- for (tp = v->t, vp = v->v, n = v->n; n-- > 0; n--, vp++, tp++) {
+ for (tp = v->t, vp = v->v, n = v->n; n > 0; n--, vp++, tp++) {
x = v2x(*vp, vmin, vmax);
y = t2y(*tp, tmin, tmax);
diff --git a/main.c b/main.c
@@ -66,6 +66,17 @@ read_labels(Vlist *v, char **argv, char *buf)
fputs("more columns than arguments\n", stderr), exit(1);
}
+double
+eatof(char *str)
+{
+ char *s;
+
+ for (s = str; *s != '\0'; s++)
+ if (!isdigit(*s) && *s != '.')
+ fputs("invalid floatrformat", stderr), exit(0);
+ return atof(str);
+}
+
long
eatol(char *str)
{
@@ -78,22 +89,25 @@ eatol(char *str)
}
void
-add_value(Vlist *v, int *bufsiz, int nval, char *field)
+add_val(Vlist *v, int *bufsiz, int nval, double field, time_t epoch)
{
if (nval >= *bufsiz) {
*bufsiz = *bufsiz * 2 + 1;
- if ((v->v = realloc(v->v, *bufsiz)) == NULL)
+ if ((v->v = realloc(v->v, *bufsiz * sizeof(*v->v))) == NULL)
+ perror("reallocating values buffer"), exit(1);
+ if ((v->t = realloc(v->t, *bufsiz * sizeof(*v->t))) == NULL)
perror("reallocating values buffer"), exit(1);
}
- v->v[nval] = eatol(field);
- v->n = nval;
+ v->v[nval] = field;
+ v->t[nval] = epoch;
+ v->n = nval + 1;
}
/*
* Add to each column the value on the current row.
*/
void
-add_each_value(Vlist *v, int *bufsiz, int ncol, int nval, char *line)
+add_row(Vlist *v, int *bufsiz, int ncol, int nval, char *line)
{
time_t epoch;
int n;
@@ -103,11 +117,10 @@ add_each_value(Vlist *v, int *bufsiz, int ncol, int nval,…
fprintf(stderr, "%d: missing epoch\n", nval), exit(0);
epoch = eatol(field);
-
for (n = 0; (field = strsep(&line, ",")) != NULL; n++, v++) {
if (n > ncol)
fprintf(stderr, "%d: too many fields\n", nval), exit(0…
- add_value(v, bufsiz, nval, field);
+ add_val(v, bufsiz, nval, eatof(field), epoch);
}
if (n < ncol)
fprintf(stderr, "%d: too few fields\n", nval), exit(0);
@@ -128,9 +141,8 @@ read_values(Vlist *v, int ncol)
bufsiz = 0;
for (nval = 0; fgets(line, sizeof(line), stdin); nval++) {
estriplf(line);
- add_each_value(v, &bufsiz, ncol, nval, line);
+ add_row(v, &bufsiz, ncol, nval, line);
}
- fprintf(stderr, "nval: %d, bufsiz: %d\n", nval, bufsiz), fflush(stderr…
}
static void
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.