int GraphBase::Add(GraphDat newgraph, wxString tag, wxString settag, bool set) // default settag = "", set=true { int sdex; wxString text; GraphSet *graphset = NULL; newgraph.diagbox = mainwin->diagbox; newgraph.strokecolour = mainwin->colourpen[newgraph.colour]; // If single graph, create new single graph set, otherwise add to set 'settag' if(set) { if(settag == "") graphset = NewSet(newgraph.gname, tag); else graphset = GetSet(settag); if(graphset) graphset->Add(numgraphs); //newgraph.sdex = graphset->sdex; } // Expand graphbase if necessary if(numgraphs == storesize) { storesize++; graphstore.resize(storesize); } // Add the new graph to graphbase graphstore[numgraphs] = newgraph; graphstore[numgraphs].gindex = numgraphs; tagindex[tag] = numgraphs; nameindex[newgraph.gname] = numgraphs; indextag[numgraphs] = tag; if(graphset && mainwin->diagbox) mainwin->diagbox->Write(text.Format("new graph sdex %d\n", graphset->sdex)); numgraphs++; return numgraphs-1; };
static struct dataset * ReadSet(const char *n, int column, const char *delim) { FILE *f; char buf[BUFSIZ], *p, *t; struct dataset *s; double d; int line; int i; if (n == NULL) { f = stdin; n = "<stdin>"; } else if (!strcmp(n, "-")) { f = stdin; n = "<stdin>"; } else { f = fopen(n, "r"); } 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++; i = strlen(buf); if (buf[i-1] == '\n') buf[i-1] = '\0'; for (i = 1, t = strtok(buf, delim); t != NULL && *t != '#'; i++, t = strtok(NULL, delim)) { if (i == column) break; } if (t == NULL || *t == '#') continue; d = strtod(t, &p); if (p != NULL && *p != '\0') err(2, "Invalid data on line %d in %s\n", line, n); if (*buf != '\0') AddPoint(s, d); } fclose(f); if (s->n < 3) { fprintf(stderr, "Dataset %s must contain at least 3 data points\n", n); exit (2); } qsort(s->points, s->n, sizeof *s->points, dbl_cmp); return (s); }
static struct dataset * ReadSet(FILE *f, const char *n, int column, const char *delim) { char buf[BUFSIZ], *p, *t; struct dataset *s; double d; int line; int i; s = NewSet(); s->name = strdup(n); line = 0; while (fgets(buf, sizeof buf, f) != NULL) { line++; i = strlen(buf); while (i > 0 && isspace(buf[i - 1])) buf[--i] = '\0'; for (i = 1, t = strtok(buf, delim); t != NULL && *t != '#'; i++, t = strtok(NULL, delim)) { if (i == column) break; } if (t == NULL || *t == '#') continue; d = strtod(t, &p); if (p != NULL && *p != '\0') errx(2, "Invalid data on line %d in %s", line, n); if (*buf != '\0') AddPoint(s, d); } if (s->n < 3) { fprintf(stderr, "Dataset %s must contain at least 3 data points\n", n); exit (2); } qsort(s->points, s->n, sizeof *s->points, dbl_cmp); return (s); }
setADT NewPtrSet(cmpFnT cmpFn) { return (NewSet(PtrSet, cmpFn)); }
setADT NewIntSet(void) { return (NewSet(IntSet, IntCmpFn)); }