void gproject_free(GProject *gp) { if (gp) { quark_free(gp->q); grfile_free(gp->grf); xfree(gp); } }
/* * join several sets together; all but the first set in the list will be killed */ int join_sets(Quark **sets, int nsets) { int i, j, n, ncols, old_length, new_length; Quark *pset, *pset_final; double *x1, *x2; char **s1, **s2; if (nsets < 2) { errmsg("nsets < 2"); return RETURN_FAILURE; } pset_final = sets[0]; ncols = set_get_ncols(pset_final); for (i = 0; i < nsets; i++) { pset = sets[i]; if (!pset) { errmsg("Invalid pset in the list"); return RETURN_FAILURE; } if (set_get_ncols(pset) != ncols) { errmsg("Can't join datasets with different number of cols"); return RETURN_FAILURE; } } new_length = set_get_length(pset_final); for (i = 1; i < nsets; i++) { pset = sets[i]; old_length = new_length; new_length += set_get_length(pset); if (set_set_length(pset_final, new_length) != RETURN_SUCCESS) { return RETURN_FAILURE; } for (j = 0; j < ncols; j++) { x1 = set_get_col(pset_final, j); x2 = set_get_col(pset, j); for (n = old_length; n < new_length; n++) { x1[n] = x2[n - old_length]; } } s1 = set_get_strings(pset_final); s2 = set_get_strings(pset); if (s1 != NULL && s2 != NULL) { for (n = old_length; n < new_length; n++) { s1[n] = copy_string(s1[n], s2[n - old_length]); } } quark_free(pset); } return RETURN_SUCCESS; }
/* * Coalesce two SSDs. fromq will be deleted, preceded by transferring of all * its children to toq */ int ssd_coalesce(Quark *toq, Quark *fromq) { unsigned int nrows, ncols, i, j; ss_data *ssd; AMem *amem = toq->amem; coalesce_hook_t p; nrows = ssd_get_nrows(fromq); if (nrows > ssd_get_nrows(toq)) { if (ssd_set_nrows(toq, nrows) != RETURN_SUCCESS) { return RETURN_FAILURE; } } /* original number of columns */ ncols = ssd_get_ncols(toq); ssd = ssd_get_data(fromq); for (i = 0; i < ssd->ncols; i++) { ss_column *col = &ssd->cols[i]; ss_column *col_new = ssd_add_col(toq, col->format); if (!col_new) { return RETURN_FAILURE; } col_new->label = amem_strdup(amem, col->label); if (col->format == FFORMAT_STRING) { for (j = 0; j < nrows; j++) { ((char **) col_new->data)[j] = amem_strdup(amem, ((char **) col->data)[j]); } } else { memcpy(col_new->data, col->data, nrows*SIZEOF_DOUBLE); } } p.toq = toq; p.nshift = ncols; quark_traverse(fromq, coalesce_hook, &p); quark_free(fromq); return RETURN_SUCCESS; }
void gapp_free(GraceApp *gapp) { unsigned int i; if (!gapp) { return; } for (i = 0; i < gapp->gpcount; i++) { gproject_free(gapp->gplist[i]); } xfree(gapp->gplist); quark_free(gapp->pc); gui_free(gapp->gui); runtime_free(gapp->rt); grace_free(gapp->grace); xfree(gapp); }
static int leval_aac_cb(void *data) { int i, nscols, type; double start, stop; int npts; char *formula[MAX_SET_COLS]; Quark *pset, *gr; GVar *t; Leval_ui *ui = (Leval_ui *) data; Grace *grace; gr = ui->gr; type = GetOptionChoice(ui->set_type); nscols = settype_cols(type); if (xv_evalexpr(ui->start, &start) != RETURN_SUCCESS) { errmsg("Start item undefined"); return RETURN_FAILURE; } if (xv_evalexpr(ui->stop, &stop) != RETURN_SUCCESS) { errmsg("Stop item undefined"); return RETURN_FAILURE; } if (xv_evalexpri(ui->npts, &npts) != RETURN_SUCCESS) { errmsg("Number of points undefined"); return RETURN_FAILURE; } TableCommitEdit(ui->mw, FALSE); for (i = 0; i < nscols; i++) { formula[i] = TableGetCell(ui->mw, i, 0); } pset = gapp_set_new(gr); set_set_type(pset, type); grace = grace_from_quark(pset); t = graal_get_var(grace_get_graal(grace), "$t", TRUE); if (t == NULL) { errmsg("Internal error"); return RETURN_FAILURE; } #if 0 if (t->length != 0) { xfree(t->data); t->length = 0; } t->data = allocate_mesh(start, stop, npts); if (t->data == NULL) { return RETURN_FAILURE; } t->length = npts; if (set_set_length(pset, npts) != RETURN_SUCCESS) { quark_free(pset); XCFREE(t->data); t->length = 0; return RETURN_FAILURE; } #endif for (i = 0; i < nscols; i++) { char buf[32], *expr; int res; /* preparing the expression */ sprintf(buf, "%s = ", dataset_col_name(grace, i)); expr = copy_string(NULL, buf); expr = concat_strings(expr, formula[i]); /* evaluate the expression */ res = graal_parse_line(grace_get_graal(grace), expr, NULL); xfree(expr); if (res != RETURN_SUCCESS) { quark_free(pset); return RETURN_FAILURE; } } #if 0 XCFREE(t->data); t->length = 0; #endif update_set_lists(gr); return RETURN_SUCCESS; }
static void popup_any_cb(ExplorerUI *eui, int type) { TreeItemList items; int count, i; Quark *qnew = NULL; Quark *q; GProject *gp; int gpcount = 0; GProject **gplist; TreeGetHighlighted(eui->tree, &items); count = items.count; if (!count) { xfree(items.items); return; } gplist = xmalloc(gapp->gpcount*sizeof(GProject)); if (!gplist) { return; } for (i = 0; i < count; i++) { q = TreeGetQuark(items.items[i]); gp = gproject_from_quark(q); add_to_list(gplist, &gpcount, gp); switch (type) { case HIDE_CB: quark_set_active(q, FALSE); break; case SHOW_CB: quark_set_active(q, TRUE); break; case DELETE_CB: quark_free(q); break; case DUPLICATE_CB: quark_copy(q); break; case ADD_FRAME_CB: qnew = frame_new(q); break; case ADD_GRAPH_CB: qnew = graph_new(q); break; case ADD_SSD_CB: qnew = gapp_ssd_new(q); break; case ADD_SET_CB: qnew = gapp_set_new(q); break; case ADD_AXISGRID_CB: qnew = axisgrid_new(q); break; case ADD_AXIS_CB: qnew = axis_new(q); break; case ADD_LINE_CB: qnew = object_new_complete(q, DO_LINE); break; case ADD_BOX_CB: qnew = object_new_complete(q, DO_BOX); break; case ADD_ARC_CB: qnew = object_new_complete(q, DO_ARC); break; case ADD_TEXT_CB: qnew = atext_new(q); break; } } xfree(items.items); for (i = 0; i < gpcount; i++) { explorer_snapshot(gapp, gplist[i], TRUE); } xfree(gplist); if (qnew) { select_quark_explorer(qnew); } }
int uniread(Quark *pr, FILE *fp, DataParser parse_cb, DataStore store_cb, void *udata) { int nrows, nrows_allocated; int ok, readerror; Quark *q = NULL; char *linebuf = NULL; int linebuflen = 0; int linecount; linecount = 0; readerror = 0; nrows = 0; nrows_allocated = 0; ok = TRUE; while (ok) { char *s; int maybe_data; int ncols, nncols, nscols; int *formats; if (read_long_line(fp, &linebuf, &linebuflen) == RETURN_SUCCESS) { linecount++; s = linebuf; /* skip leading whitespaces */ while (*s == ' ' || *s == '\t') { s++; } /* skip comments */ if (*s == '#') { continue; } /* EOL EOD */ if (*s == '\n' || *s == '\0') { maybe_data = FALSE; } else if (parse_cb && parse_cb(s, udata) == RETURN_SUCCESS) { maybe_data = FALSE; } else { maybe_data = TRUE; } } else { ok = FALSE; maybe_data = FALSE; } if (maybe_data) { if (!nrows) { /* parse the data line */ if (parse_ss_row(pr, s, &nncols, &nscols, &formats) != RETURN_SUCCESS) { errmsg("Can't parse data"); xfree(linebuf); return RETURN_FAILURE; } ncols = nncols + nscols; /* init the SSD */ q = gapp_ssd_new(pr); if (!q || ssd_set_ncols(q, ncols, formats) != RETURN_SUCCESS) { errmsg("Malloc failed in uniread()"); quark_free(q); xfree(formats); xfree(linebuf); return RETURN_FAILURE; } xfree(formats); } if (nrows >= nrows_allocated) { if (!nrows_allocated) { nrows_allocated = BUFSIZE; } else { nrows_allocated *= 2; } if (ssd_set_nrows(q, nrows_allocated) != RETURN_SUCCESS) { errmsg("Malloc failed in uniread()"); quark_free(q); xfree(linebuf); return RETURN_FAILURE; } } if (insert_data_row(q, nrows, s) != RETURN_SUCCESS) { char tbuf[128]; sprintf(tbuf, "Error parsing line %d, skipped", linecount); errmsg(tbuf); readerror++; if (readerror > MAXERR) { if (yesno("Lots of errors, abort?", NULL, NULL, NULL)) { quark_free(q); xfree(linebuf); return RETURN_FAILURE; } else { readerror = 0; } } } else { nrows++; } } else if (nrows) { /* free excessive storage */ ssd_set_nrows(q, nrows); /* store accumulated data */ if (store_cb && store_cb(q, udata) != RETURN_SUCCESS) { quark_free(q); xfree(linebuf); return RETURN_FAILURE; } /* reset state registers */ nrows = 0; nrows_allocated = 0; readerror = 0; } } xfree(linebuf); return RETURN_SUCCESS; }
/* * split a set into lpart length sets */ int do_splitsets(Quark *pset, int lpart) { int i, j, k, ncols, len, plen, npsets; double *x; char s[256]; Quark *gr, *ptmp; Dataset *dsp, *dsptmp; if ((len = set_get_length(pset)) < 2) { errmsg("Set length < 2"); return RETURN_FAILURE; } if (lpart >= len) { errmsg("Split length >= set length"); return RETURN_FAILURE; } if (lpart <= 0) { errmsg("Split length <= 0"); return RETURN_FAILURE; } npsets = (len - 1)/lpart + 1; /* get number of columns in this set */ ncols = set_get_ncols(pset); gr = get_parent_graph(pset); dsp = set_get_dataset(pset); /* now load each set */ for (i = 0; i < npsets; i++) { plen = MIN2(lpart, len - i*lpart); ptmp = gapp_set_new(gr); if (!ptmp) { errmsg("Can't create new set"); return RETURN_FAILURE; } dsptmp = set_get_dataset(ptmp); /* set the plot parameters */ copy_set_params(pset, ptmp); if (set_set_length(ptmp, plen) != RETURN_SUCCESS) { return RETURN_FAILURE; } if (dsp->s) { dataset_enable_scol(dsptmp, TRUE); } /* load the data into each column */ for (k = 0; k < ncols; k++) { x = set_get_col(ptmp, k); for (j = 0; j < plen; j++) { x[j] = dsp->ex[k][i*lpart + j]; } } if (dsp->s) { for (j = 0; j < plen; j++) { dsptmp->s[j] = copy_string(NULL, dsp->s[i*lpart + j]); } } sprintf(s, "partition %d of set %s", i + 1, quark_idstr_get(pset)); set_set_comment(ptmp, s); } /* kill the original set */ quark_free(pset); return RETURN_SUCCESS; }